summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/whatsmeow/presence.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2023-01-28 22:57:53 +0100
committerGitHub <noreply@github.com>2023-01-28 22:57:53 +0100
commit880586bac42817ffcfea5d9f746f503fa29915b8 (patch)
treea89374cba6f88975f12316ec8d1b8aa1d4c6ba79 /vendor/go.mau.fi/whatsmeow/presence.go
parenteac2a8c8dc831f946970d327e2a80b26b0684255 (diff)
downloadmatterbridge-msglm-880586bac42817ffcfea5d9f746f503fa29915b8.tar.gz
matterbridge-msglm-880586bac42817ffcfea5d9f746f503fa29915b8.tar.bz2
matterbridge-msglm-880586bac42817ffcfea5d9f746f503fa29915b8.zip
Update dependencies (#1951)
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/presence.go')
-rw-r--r--vendor/go.mau.fi/whatsmeow/presence.go28
1 files changed, 25 insertions, 3 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/presence.go b/vendor/go.mau.fi/whatsmeow/presence.go
index bc26c21c..0ce94a70 100644
--- a/vendor/go.mau.fi/whatsmeow/presence.go
+++ b/vendor/go.mau.fi/whatsmeow/presence.go
@@ -7,6 +7,7 @@
package whatsmeow
import (
+ "fmt"
"sync/atomic"
waBinary "go.mau.fi/whatsmeow/binary"
@@ -87,19 +88,40 @@ func (cli *Client) SendPresence(state types.Presence) error {
//
// cli.SendPresence(types.PresenceAvailable)
func (cli *Client) SubscribePresence(jid types.JID) error {
- return cli.sendNode(waBinary.Node{
+ privacyToken, err := cli.Store.PrivacyTokens.GetPrivacyToken(jid)
+ if err != nil {
+ return fmt.Errorf("failed to get privacy token: %w", err)
+ } else if privacyToken == nil {
+ if cli.ErrorOnSubscribePresenceWithoutToken {
+ return fmt.Errorf("%w for %v", ErrNoPrivacyToken, jid.ToNonAD())
+ } else {
+ cli.Log.Debugf("Trying to subscribe to presence of %s without privacy token", jid)
+ }
+ }
+ req := waBinary.Node{
Tag: "presence",
Attrs: waBinary.Attrs{
"type": "subscribe",
"to": jid,
},
- })
+ }
+ if privacyToken != nil {
+ req.Content = []waBinary.Node{{
+ Tag: "tctoken",
+ Content: privacyToken.Token,
+ }}
+ }
+ return cli.sendNode(req)
}
// SendChatPresence updates the user's typing status in a specific chat.
//
// The media parameter can be set to indicate the user is recording media (like a voice message) rather than typing a text message.
func (cli *Client) SendChatPresence(jid types.JID, state types.ChatPresence, media types.ChatPresenceMedia) error {
+ ownID := cli.getOwnID()
+ if ownID.IsEmpty() {
+ return ErrNotLoggedIn
+ }
content := []waBinary.Node{{Tag: string(state)}}
if state == types.ChatPresenceComposing && len(media) > 0 {
content[0].Attrs = waBinary.Attrs{
@@ -109,7 +131,7 @@ func (cli *Client) SendChatPresence(jid types.JID, state types.ChatPresence, med
return cli.sendNode(waBinary.Node{
Tag: "chatstate",
Attrs: waBinary.Attrs{
- "from": *cli.Store.ID,
+ "from": ownID,
"to": jid,
},
Content: content,