diff options
author | Wim <wim@42.be> | 2021-02-01 21:29:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-01 21:29:04 +0100 |
commit | 0452be0cb383ff560e340b643b60a35c6e228639 (patch) | |
tree | 41b91af43c2e321d6498a6b56594b1d0c71c516e /vendor/github.com/Rhymen | |
parent | 1624f107739b8ed7b142732430e5295764388de2 (diff) | |
download | matterbridge-msglm-0452be0cb383ff560e340b643b60a35c6e228639.tar.gz matterbridge-msglm-0452be0cb383ff560e340b643b60a35c6e228639.tar.bz2 matterbridge-msglm-0452be0cb383ff560e340b643b60a35c6e228639.zip |
Update vendor (#1384)
Diffstat (limited to 'vendor/github.com/Rhymen')
-rw-r--r-- | vendor/github.com/Rhymen/go-whatsapp/contact.go | 47 | ||||
-rw-r--r-- | vendor/github.com/Rhymen/go-whatsapp/read.go | 6 | ||||
-rw-r--r-- | vendor/github.com/Rhymen/go-whatsapp/write.go | 73 |
3 files changed, 96 insertions, 30 deletions
diff --git a/vendor/github.com/Rhymen/go-whatsapp/contact.go b/vendor/github.com/Rhymen/go-whatsapp/contact.go index 92d0a4ad..e17f724f 100644 --- a/vendor/github.com/Rhymen/go-whatsapp/contact.go +++ b/vendor/github.com/Rhymen/go-whatsapp/contact.go @@ -2,9 +2,11 @@ package whatsapp import ( "fmt" - "github.com/Rhymen/go-whatsapp/binary" "strconv" + "strings" "time" + + "github.com/Rhymen/go-whatsapp/binary" ) type Presence string @@ -241,3 +243,46 @@ func buildParticipantNodes(participants []string) []binary.Node { } return p } + +func (wac *Conn) BlockContact(jid string) (<-chan string, error) { + return wac.handleBlockContact("add", jid) +} + +func (wac *Conn) UnblockContact(jid string) (<-chan string, error) { + return wac.handleBlockContact("remove", jid) +} + +func (wac *Conn) handleBlockContact(action, jid string) (<-chan string, error) { + ts := time.Now().Unix() + tag := fmt.Sprintf("%d.--%d", ts, wac.msgCount) + + netsplit := strings.Split(jid, "@") + cusjid := netsplit[0] + "@c.us" + + n := binary.Node{ + Description: "action", + Attributes: map[string]string{ + "type": "set", + "epoch": strconv.Itoa(wac.msgCount), + }, + Content: []interface{}{ + binary.Node{ + Description: "block", + Attributes: map[string]string{ + "type": action, + }, + Content: []binary.Node{ + { + Description: "user", + Attributes: map[string]string{ + "jid": cusjid, + }, + Content: nil, + }, + }, + }, + }, + } + + return wac.writeBinary(n, contact, ignore, tag) +} diff --git a/vendor/github.com/Rhymen/go-whatsapp/read.go b/vendor/github.com/Rhymen/go-whatsapp/read.go index 1621c0f5..a69147a6 100644 --- a/vendor/github.com/Rhymen/go-whatsapp/read.go +++ b/vendor/github.com/Rhymen/go-whatsapp/read.go @@ -83,10 +83,8 @@ func (wac *Conn) processReadData(msgType int, msg []byte) error { // chan string to something like chan map[string]interface{}. The unmarshalling // in several places, especially in session.go, would then be gone. listener <- data[1] - - wac.listener.Lock() - delete(wac.listener.m, data[0]) - wac.listener.Unlock() + close(listener) + wac.removeListener(data[0]) } else if msgType == websocket.BinaryMessage { wac.loginSessionLock.RLock() sess := wac.session diff --git a/vendor/github.com/Rhymen/go-whatsapp/write.go b/vendor/github.com/Rhymen/go-whatsapp/write.go index 74f43c42..e427825c 100644 --- a/vendor/github.com/Rhymen/go-whatsapp/write.go +++ b/vendor/github.com/Rhymen/go-whatsapp/write.go @@ -15,15 +15,30 @@ import ( "github.com/pkg/errors" ) +func (wac *Conn) addListener(ch chan string, messageTag string) { + wac.listener.Lock() + wac.listener.m[messageTag] = ch + wac.listener.Unlock() +} + +func (wac *Conn) removeListener(answerMessageTag string) { + wac.listener.Lock() + delete(wac.listener.m, answerMessageTag) + wac.listener.Unlock() +} + //writeJson enqueues a json message into the writeChan func (wac *Conn) writeJson(data []interface{}) (<-chan string, error) { + ch := make(chan string, 1) + wac.writerLock.Lock() defer wac.writerLock.Unlock() d, err := json.Marshal(data) if err != nil { - return nil, err + close(ch) + return ch, err } ts := time.Now().Unix() @@ -35,9 +50,13 @@ func (wac *Conn) writeJson(data []interface{}) (<-chan string, error) { wac.timeTag = tss[len(tss)-3:] } - ch, err := wac.write(websocket.TextMessage, messageTag, bytes) + wac.addListener(ch, messageTag) + + err = wac.write(websocket.TextMessage, bytes) if err != nil { - return nil, err + close(ch) + wac.removeListener(messageTag) + return ch, err } wac.msgCount++ @@ -45,8 +64,12 @@ func (wac *Conn) writeJson(data []interface{}) (<-chan string, error) { } func (wac *Conn) writeBinary(node binary.Node, metric metric, flag flag, messageTag string) (<-chan string, error) { + + ch := make(chan string, 1) + if len(messageTag) < 2 { - return nil, ErrMissingMessageTag + close(ch) + return ch, ErrMissingMessageTag } wac.writerLock.Lock() @@ -54,16 +77,21 @@ func (wac *Conn) writeBinary(node binary.Node, metric metric, flag flag, message data, err := wac.encryptBinaryMessage(node) if err != nil { - return nil, errors.Wrap(err, "encryptBinaryMessage(node) failed") + close(ch) + return ch, errors.Wrap(err, "encryptBinaryMessage(node) failed") } bytes := []byte(messageTag + ",") bytes = append(bytes, byte(metric), byte(flag)) bytes = append(bytes, data...) - ch, err := wac.write(websocket.BinaryMessage, messageTag, bytes) + wac.addListener(ch, messageTag) + + err = wac.write(websocket.BinaryMessage, bytes) if err != nil { - return nil, errors.Wrap(err, "failed to write message") + close(ch) + wac.removeListener(messageTag) + return ch, errors.Wrap(err, "failed to write message") } wac.msgCount++ @@ -71,9 +99,15 @@ func (wac *Conn) writeBinary(node binary.Node, metric metric, flag flag, message } func (wac *Conn) sendKeepAlive() error { + + respChan := make(chan string, 1) + wac.addListener(respChan, "!") + bytes := []byte("?,,") - respChan, err := wac.write(websocket.TextMessage, "!", bytes) + err := wac.write(websocket.TextMessage, bytes) if err != nil { + close(respChan) + wac.removeListener("!") return errors.Wrap(err, "error sending keepAlive") } @@ -122,32 +156,21 @@ func (wac *Conn) sendAdminTest() (bool, error) { } } -func (wac *Conn) write(messageType int, answerMessageTag string, data []byte) (<-chan string, error) { - var ch chan string - if answerMessageTag != "" { - ch = make(chan string, 1) - - wac.listener.Lock() - wac.listener.m[answerMessageTag] = ch - wac.listener.Unlock() - } +func (wac *Conn) write(messageType int, data []byte) error { if wac == nil || wac.ws == nil { - return nil, ErrInvalidWebsocket + return ErrInvalidWebsocket } + wac.ws.Lock() err := wac.ws.conn.WriteMessage(messageType, data) wac.ws.Unlock() if err != nil { - if answerMessageTag != "" { - wac.listener.Lock() - delete(wac.listener.m, answerMessageTag) - wac.listener.Unlock() - } - return nil, errors.Wrap(err, "error writing to websocket") + return errors.Wrap(err, "error writing to websocket") } - return ch, nil + + return nil } func (wac *Conn) encryptBinaryMessage(node binary.Node) (data []byte, err error) { |