Skip to content

Commit 6ba2d6c

Browse files
authored
event: add event for user "about" text change (tulir#670)
1 parent b405a02 commit 6ba2d6c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Diff for: notification.go

+21
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,25 @@ func (cli *Client) handleMexNotification(node *waBinary.Node) {
352352
}
353353
}
354354

355+
func (cli *Client) handleStatusNotification(node *waBinary.Node) {
356+
ag := node.AttrGetter()
357+
child, found := node.GetOptionalChildByTag("set")
358+
if !found {
359+
cli.Log.Debugf("Status notifcation did not contain child with tag 'set'")
360+
return
361+
}
362+
status, ok := child.Content.([]byte)
363+
if !ok {
364+
cli.Log.Warnf("Set status notification has unexpected content (%T)", child.Content)
365+
return
366+
}
367+
cli.dispatchEvent(&events.UserAbout{
368+
JID: ag.JID("from"),
369+
Timestamp: ag.UnixTime("t"),
370+
Status: string(status),
371+
})
372+
}
373+
355374
func (cli *Client) handleNotification(node *waBinary.Node) {
356375
ag := node.AttrGetter()
357376
notifType := ag.String("type")
@@ -389,6 +408,8 @@ func (cli *Client) handleNotification(node *waBinary.Node) {
389408
go cli.handleNewsletterNotification(node)
390409
case "mex":
391410
go cli.handleMexNotification(node)
411+
case "status":
412+
go cli.handleStatusNotification(node)
392413
// Other types: business, disappearing_mode, server, status, pay, psa
393414
default:
394415
cli.Log.Debugf("Unhandled notification with type %s", notifType)

Diff for: types/events/events.go

+7
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,13 @@ type Picture struct {
471471
PictureID string // The new picture ID if it was not removed.
472472
}
473473

474+
// UserAbout is emitted when a user's about status is changed.
475+
type UserAbout struct {
476+
JID types.JID // The user whose status was changed
477+
Status string // The new status
478+
Timestamp time.Time // The timestamp when the status was changed.
479+
}
480+
474481
// IdentityChange is emitted when another user changes their primary device.
475482
type IdentityChange struct {
476483
JID types.JID

0 commit comments

Comments
 (0)