Use LastMessageTimestamp in the case there are no bumpEventTypes defined

This commit is contained in:
Till Faelligen 2023-08-15 14:19:42 +02:00
parent fbd68d8c71
commit 2758b62c86
No known key found for this signature in database
GPG Key ID: ACCDC9606D472758
2 changed files with 21 additions and 1 deletions

View File

@ -626,7 +626,7 @@ func (s *ConnState) getInitialRoomData(ctx context.Context, roomSub sync3.RoomSu
if roomListsMeta == nil {
break
}
evMeta := roomListsMeta.LatestEventsByType[t]
if evMeta.Timestamp > maxTs {
maxTs = evMeta.Timestamp
@ -639,6 +639,12 @@ func (s *ConnState) getInitialRoomData(ctx context.Context, roomSub sync3.RoomSu
if maxTs == 0 || maxTs < roomListsMeta.JoinTiming.Timestamp {
if roomListsMeta != nil {
maxTs = roomListsMeta.JoinTiming.Timestamp
// If no bumpEventTypes are specified, use the
// LastMessageTimestamp so clients are still able
// to correctly sort on it.
if len(bumpEventTypes) == 0 {
maxTs = roomListsMeta.LastMessageTimestamp
}
}
}

View File

@ -163,4 +163,18 @@ func TestTimestamp(t *testing.T) {
if gotTs != expectedTs {
t.Fatalf("Charlie should see the timestamp they joined, but didn't: %d, expected %d", gotTs, expectedTs)
}
// Initial sync without bump types should see the most recent timestamp
resAlice = alice.SlidingSync(t, sync3.Request{
RoomSubscriptions: map[string]sync3.RoomSubscription{
roomID: {
TimelineLimit: 10,
},
},
})
// expected TS stays the same, so the join of Charlie
gotTs = resAlice.Rooms[roomID].Timestamp
if gotTs != expectedTs {
t.Fatalf("Alice should see the timestamp of Charlie joining, but didn't: %d, expected %d", gotTs, expectedTs)
}
}