mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
bugfix: ensure unread count updates are immediately passed to clients
Previously they weren't because we didn't have delta logic for them.
This likely broke in the refactor done in
19f8b4dbf7
This commit is contained in:
parent
99df9b53b6
commit
f6de179c0a
@ -234,6 +234,16 @@ func (s *connStateLive) processLiveUpdate(ctx context.Context, up caches.Update,
|
||||
|
||||
response.Rooms[roomUpdate.RoomID()] = thisRoom
|
||||
}
|
||||
if delta.HighlightCountChanged || delta.NotificationCountChanged {
|
||||
if !exists {
|
||||
// we need to make this room exist. Other deltas are caused by events so the room exists,
|
||||
// but highlight/notif counts are silent
|
||||
thisRoom = sync3.Room{}
|
||||
}
|
||||
thisRoom.NotificationCount = int64(roomUpdate.UserRoomMetadata().NotificationCount)
|
||||
thisRoom.HighlightCount = int64(roomUpdate.UserRoomMetadata().HighlightCount)
|
||||
response.Rooms[roomUpdate.RoomID()] = thisRoom
|
||||
}
|
||||
}
|
||||
return hasUpdates
|
||||
}
|
||||
|
@ -31,10 +31,12 @@ type RoomListDelta struct {
|
||||
}
|
||||
|
||||
type RoomDelta struct {
|
||||
RoomNameChanged bool
|
||||
JoinCountChanged bool
|
||||
InviteCountChanged bool
|
||||
Lists []RoomListDelta
|
||||
RoomNameChanged bool
|
||||
JoinCountChanged bool
|
||||
InviteCountChanged bool
|
||||
NotificationCountChanged bool
|
||||
HighlightCountChanged bool
|
||||
Lists []RoomListDelta
|
||||
}
|
||||
|
||||
// InternalRequestLists is a list of lists which matches each index position in the request
|
||||
@ -54,6 +56,12 @@ func NewInternalRequestLists() *InternalRequestLists {
|
||||
func (s *InternalRequestLists) SetRoom(r RoomConnMetadata) (delta RoomDelta) {
|
||||
existing, exists := s.allRooms[r.RoomID]
|
||||
if exists {
|
||||
if existing.NotificationCount != r.NotificationCount {
|
||||
delta.NotificationCountChanged = true
|
||||
}
|
||||
if existing.HighlightCount != r.HighlightCount {
|
||||
delta.HighlightCountChanged = true
|
||||
}
|
||||
delta.InviteCountChanged = !existing.SameInviteCount(&r.RoomMetadata)
|
||||
delta.JoinCountChanged = !existing.SameJoinCount(&r.RoomMetadata)
|
||||
delta.RoomNameChanged = !existing.SameRoomName(&r.RoomMetadata)
|
||||
|
58
tests-e2e/unread_count_test.go
Normal file
58
tests-e2e/unread_count_test.go
Normal file
@ -0,0 +1,58 @@
|
||||
package syncv3_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/matrix-org/sliding-sync/sync3"
|
||||
"github.com/matrix-org/sliding-sync/testutils/m"
|
||||
)
|
||||
|
||||
func TestUnreadCountsUpdate(t *testing.T) {
|
||||
alice := registerNewUser(t)
|
||||
bob := registerNewUser(t)
|
||||
roomID := alice.CreateRoom(t, map[string]interface{}{
|
||||
"preset": "public_chat",
|
||||
})
|
||||
bob.JoinRoom(t, roomID, nil)
|
||||
eventID := bob.SendEventSynced(t, roomID, Event{
|
||||
Type: "m.room.message",
|
||||
Content: map[string]interface{}{
|
||||
"msgtype": "m.text",
|
||||
"body": "Hello World",
|
||||
},
|
||||
})
|
||||
|
||||
res := alice.SlidingSync(t, sync3.Request{
|
||||
Lists: []sync3.RequestList{
|
||||
{
|
||||
Ranges: sync3.SliceRanges{{0, 20}},
|
||||
},
|
||||
},
|
||||
})
|
||||
m.MatchResponse(t, res, m.MatchRoomSubscriptionsStrict(map[string][]m.RoomMatcher{
|
||||
roomID: {
|
||||
m.MatchRoomNotificationCount(1),
|
||||
},
|
||||
}))
|
||||
alice.MustDoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "read_markers"}, WithJSONBody(t, map[string]interface{}{
|
||||
"m.fully_read": eventID,
|
||||
"m.read": eventID,
|
||||
}))
|
||||
alice.SlidingSyncUntil(t, res.Pos, sync3.Request{
|
||||
Lists: []sync3.RequestList{
|
||||
{
|
||||
Ranges: sync3.SliceRanges{{0, 20}},
|
||||
},
|
||||
},
|
||||
}, func(r *sync3.Response) error {
|
||||
room, ok := r.Rooms[roomID]
|
||||
if !ok {
|
||||
return fmt.Errorf("no room %s", roomID)
|
||||
}
|
||||
if room.NotificationCount != 0 {
|
||||
return fmt.Errorf("notif count = %d", room.NotificationCount)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user