From fbfde869140315d7eef592a9dbdbf6d9cd37f582 Mon Sep 17 00:00:00 2001 From: Tak Wai Wong <64229756+tak-hntlabs@users.noreply.github.com> Date: Tue, 13 Sep 2022 16:25:32 -0700 Subject: [PATCH] Pull dendrite fork into the harmony repo (#423) Austin's notification fix Signed-off-by: Brian Meek Signed-off-by: Austin Ellis Co-authored-by: Brian Meek Co-authored-by: texuf Co-authored-by: Tak Wai Wong --- syncapi/streams/stream_notificationdata.go | 8 ++++++ syncapi/types/types.go | 31 ++++++++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/syncapi/streams/stream_notificationdata.go b/syncapi/streams/stream_notificationdata.go index 66ee0ded9..8ab4afe63 100644 --- a/syncapi/streams/stream_notificationdata.go +++ b/syncapi/streams/stream_notificationdata.go @@ -62,6 +62,14 @@ func (p *NotificationDataStreamProvider) IncrementalSync( } req.Response.Rooms.Join[roomID] = jr } + // BEGIN ZION CODE but return all notifications regardless of whether they're in a room we're in. + for roomID, counts := range countsByRoom { + unreadNotificationsData := *types.NewUnreadNotificationsResponse() + unreadNotificationsData.HighlightCount = counts.UnreadHighlightCount + unreadNotificationsData.NotificationCount = counts.UnreadNotificationCount + req.Response.Rooms.UnreadNotifications[roomID] = unreadNotificationsData + } + // END ZION CODE return p.LatestPosition(ctx) } diff --git a/syncapi/types/types.go b/syncapi/types/types.go index 57ce7b6ff..75194d3f6 100644 --- a/syncapi/types/types.go +++ b/syncapi/types/types.go @@ -341,10 +341,11 @@ type DeviceLists struct { } type RoomsResponse struct { - Join map[string]*JoinResponse `json:"join,omitempty"` - Peek map[string]*JoinResponse `json:"peek,omitempty"` - Invite map[string]*InviteResponse `json:"invite,omitempty"` - Leave map[string]*LeaveResponse `json:"leave,omitempty"` + Join map[string]*JoinResponse `json:"join,omitempty"` + Peek map[string]*JoinResponse `json:"peek,omitempty"` + Invite map[string]*InviteResponse `json:"invite,omitempty"` + Leave map[string]*LeaveResponse `json:"leave,omitempty"` + UnreadNotifications map[string]UnreadNotificationsResponse `json:"unread_notifications,omitempty"` } type ToDeviceResponse struct { @@ -396,6 +397,7 @@ func (r *Response) HasUpdates() bool { len(r.Rooms.Join) > 0 || len(r.Rooms.Leave) > 0 || len(r.Rooms.Peek) > 0 || + len(r.Rooms.UnreadNotifications) > 0 || len(r.ToDevice.Events) > 0 || len(r.DeviceLists.Changed) > 0 || len(r.DeviceLists.Left) > 0) @@ -406,11 +408,13 @@ func NewResponse() *Response { res := Response{} // Pre-initialise the maps. Synapse will return {} even if there are no rooms under a specific section, // so let's do the same thing. Bonus: this means we can't get dreaded 'assignment to entry in nil map' errors. + res.Rooms = &RoomsResponse{ - Join: map[string]*JoinResponse{}, - Peek: map[string]*JoinResponse{}, - Invite: map[string]*InviteResponse{}, - Leave: map[string]*LeaveResponse{}, + Join: map[string]*JoinResponse{}, + Peek: map[string]*JoinResponse{}, + Invite: map[string]*InviteResponse{}, + Leave: map[string]*LeaveResponse{}, + UnreadNotifications: map[string]UnreadNotificationsResponse{}, } // Also pre-intialise empty slices or else we'll insert 'null' instead of '[]' for the value. @@ -432,6 +436,7 @@ func (r *Response) IsEmpty() bool { return len(r.Rooms.Join) == 0 && len(r.Rooms.Invite) == 0 && len(r.Rooms.Leave) == 0 && + len(r.Rooms.UnreadNotifications) == 0 && len(r.AccountData.Events) == 0 && len(r.Presence.Events) == 0 && len(r.ToDevice.Events) == 0 @@ -513,6 +518,16 @@ func NewJoinResponse() *JoinResponse { } } +type UnreadNotificationsResponse struct { + HighlightCount int `json:"highlight_count"` + NotificationCount int `json:"notification_count"` +} + +func NewUnreadNotificationsResponse() *UnreadNotificationsResponse { + res := UnreadNotificationsResponse{} + return &res +} + // InviteResponse represents a /sync response for a room which is under the 'invite' key. type InviteResponse struct { InviteState struct {