diff options
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/presence.go')
-rw-r--r-- | vendor/go.mau.fi/whatsmeow/presence.go | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/presence.go b/vendor/go.mau.fi/whatsmeow/presence.go index e308717b..8de1969a 100644 --- a/vendor/go.mau.fi/whatsmeow/presence.go +++ b/vendor/go.mau.fi/whatsmeow/presence.go @@ -7,6 +7,7 @@ package whatsmeow import ( + "sync/atomic" "time" waBinary "go.mau.fi/whatsmeow/binary" @@ -23,12 +24,14 @@ func (cli *Client) handleChatState(node *waBinary.Node) { } else { child := node.GetChildren()[0] presence := types.ChatPresence(child.Tag) - if presence != types.ChatPresenceComposing && presence != types.ChatPresenceRecording && presence != types.ChatPresencePaused { + if presence != types.ChatPresenceComposing && presence != types.ChatPresencePaused { cli.Log.Warnf("Unrecognized chat presence state %s", child.Tag) } + media := types.ChatPresenceMedia(child.AttrGetter().OptionalString("media")) cli.dispatchEvent(&events.ChatPresence{ MessageSource: source, State: presence, + Media: media, }) } } @@ -62,6 +65,11 @@ func (cli *Client) SendPresence(state types.Presence) error { if len(cli.Store.PushName) == 0 { return ErrNoPushName } + if state == types.PresenceAvailable { + atomic.CompareAndSwapUint32(&cli.sendActiveReceipts, 0, 1) + } else { + atomic.CompareAndSwapUint32(&cli.sendActiveReceipts, 1, 0) + } return cli.sendNode(waBinary.Node{ Tag: "presence", Attrs: waBinary.Attrs{ @@ -89,13 +97,21 @@ func (cli *Client) SubscribePresence(jid types.JID) error { } // SendChatPresence updates the user's typing status in a specific chat. -func (cli *Client) SendChatPresence(state types.ChatPresence, jid types.JID) error { +// +// 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 { + content := []waBinary.Node{{Tag: string(state)}} + if state == types.ChatPresenceComposing && len(media) > 0 { + content[0].Attrs = waBinary.Attrs{ + "media": string(media), + } + } return cli.sendNode(waBinary.Node{ Tag: "chatstate", Attrs: waBinary.Attrs{ "from": *cli.Store.ID, "to": jid, }, - Content: []waBinary.Node{{Tag: string(state)}}, + Content: content, }) } |