Always add UnreadNotifications to joined room reponses (#2793)

Fixes a minor bug, where we failed to add `UnreadNotifications` to the
join response, if it wasn't in
`GetUserUnreadNotificationCountsForRooms`.
This commit is contained in:
Till 2022-10-14 10:38:12 +02:00 committed by GitHub
parent fb44e33909
commit a8bc558a60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package streams
import ( import (
"context" "context"
"github.com/matrix-org/dendrite/internal/eventutil"
"github.com/matrix-org/dendrite/syncapi/storage" "github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/dendrite/syncapi/types"
) )
@ -53,7 +54,7 @@ func (p *NotificationDataStreamProvider) IncrementalSync(
for roomID, jr := range req.Response.Rooms.Join { for roomID, jr := range req.Response.Rooms.Join {
counts := countsByRoom[roomID] counts := countsByRoom[roomID]
if counts == nil { if counts == nil {
continue counts = &eventutil.NotificationData{}
} }
jr.UnreadNotifications = &types.UnreadNotifications{ jr.UnreadNotifications = &types.UnreadNotifications{
HighlightCount: counts.UnreadHighlightCount, HighlightCount: counts.UnreadHighlightCount,

View File

@ -492,9 +492,11 @@ func (jr JoinResponse) MarshalJSON() ([]byte, error) {
} }
} }
if jr.UnreadNotifications != nil && if jr.UnreadNotifications != nil {
jr.UnreadNotifications.NotificationCount == 0 && jr.UnreadNotifications.HighlightCount == 0 { // if everything else is nil, also remove UnreadNotifications
a.UnreadNotifications = nil if a.State == nil && a.Ephemeral == nil && a.AccountData == nil && a.Timeline == nil && a.Summary == nil {
a.UnreadNotifications = nil
}
} }
return json.Marshal(a) return json.Marshal(a)
} }

View File

@ -744,4 +744,6 @@ User in remote room doesn't appear in user directory after server left room
User in shared private room does appear in user directory until leave User in shared private room does appear in user directory until leave
Existing members see new member's presence Existing members see new member's presence
Inbound federation can return missing events for joined visibility Inbound federation can return missing events for joined visibility
outliers whose auth_events are in a different room are correctly rejected outliers whose auth_events are in a different room are correctly rejected
Messages that notify from another user increment notification_count
Messages that highlight from another user increment unread highlight count