diff --git a/notification.go b/notification.go index 8e004fab..0f46ae68 100644 --- a/notification.go +++ b/notification.go @@ -352,6 +352,25 @@ func (cli *Client) handleMexNotification(node *waBinary.Node) { } } +func (cli *Client) handleStatusNotification(node *waBinary.Node) { + ag := node.AttrGetter() + child, found := node.GetOptionalChildByTag("set") + if !found { + cli.Log.Debugf("Status notifcation did not contain child with tag 'set'") + return + } + status, ok := child.Content.([]byte) + if !ok { + cli.Log.Warnf("Set status notification has unexpected content (%T)", child.Content) + return + } + cli.dispatchEvent(&events.UserAbout{ + JID: ag.JID("from"), + Timestamp: ag.UnixTime("t"), + Status: string(status), + }) +} + func (cli *Client) handleNotification(node *waBinary.Node) { ag := node.AttrGetter() notifType := ag.String("type") @@ -389,6 +408,8 @@ func (cli *Client) handleNotification(node *waBinary.Node) { go cli.handleNewsletterNotification(node) case "mex": go cli.handleMexNotification(node) + case "status": + go cli.handleStatusNotification(node) // Other types: business, disappearing_mode, server, status, pay, psa default: cli.Log.Debugf("Unhandled notification with type %s", notifType) diff --git a/types/events/events.go b/types/events/events.go index f1c3404e..a5a3bf89 100644 --- a/types/events/events.go +++ b/types/events/events.go @@ -471,6 +471,13 @@ type Picture struct { PictureID string // The new picture ID if it was not removed. } +// UserAbout is emitted when a user's about status is changed. +type UserAbout struct { + JID types.JID // The user whose status was changed + Status string // The new status + Timestamp time.Time // The timestamp when the status was changed. +} + // IdentityChange is emitted when another user changes their primary device. type IdentityChange struct { JID types.JID