Pull dendrite fork into the harmony repo (#423)

Austin's notification fix

Signed-off-by: Brian Meek <brian@hntlabs.com>
Signed-off-by: Austin Ellis <austin@hntlabs.com>
Co-authored-by: Brian Meek <brian@hntlabs.com>
Co-authored-by: texuf <texuf.eth@gmail.com>
Co-authored-by: Tak Wai Wong <tak@hntlabs.com>
This commit is contained in:
Tak Wai Wong 2022-09-13 16:25:32 -07:00
parent cda7734660
commit fbfde86914
No known key found for this signature in database
GPG key ID: 222E4AF2AA1F467D
2 changed files with 31 additions and 8 deletions

View file

@ -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)
}

View file

@ -345,6 +345,7 @@ type RoomsResponse struct {
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{},
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 {