mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-07-11 17:46:27 +00:00
Update vendor (#1384)
This commit is contained in:
47
vendor/github.com/Rhymen/go-whatsapp/contact.go
generated
vendored
47
vendor/github.com/Rhymen/go-whatsapp/contact.go
generated
vendored
@ -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)
|
||||
}
|
||||
|
6
vendor/github.com/Rhymen/go-whatsapp/read.go
generated
vendored
6
vendor/github.com/Rhymen/go-whatsapp/read.go
generated
vendored
@ -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
|
||||
|
73
vendor/github.com/Rhymen/go-whatsapp/write.go
generated
vendored
73
vendor/github.com/Rhymen/go-whatsapp/write.go
generated
vendored
@ -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) {
|
||||
|
Reference in New Issue
Block a user