diff options
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/presence.go')
-rw-r--r-- | vendor/go.mau.fi/whatsmeow/presence.go | 28 |
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, |