Skip to content

Commit

Permalink
event: add event for user "about" text change (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshettrj authored Oct 8, 2024
1 parent b405a02 commit 6ba2d6c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions types/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6ba2d6c

Please sign in to comment.