From 6ba2d6ce80c21da0122971815e037a7e6f0d22fe Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Tue, 8 Oct 2024 22:20:00 +0530 Subject: [PATCH] event: add event for user "about" text change (#670) --- notification.go | 21 +++++++++++++++++++++ types/events/events.go | 7 +++++++ 2 files changed, 28 insertions(+) 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