-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add timestamp
to room responses
#247
Changes from 2 commits
926f1c5
36ca09e
de4fa34
778c6cd
dd243f1
3857e67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,14 @@ func (s *connStateLive) processLiveUpdate(ctx context.Context, up caches.Update, | |
// include this update in the rooms response TODO: filters on event type? | ||
userRoomData := roomUpdate.UserRoomMetadata() | ||
r := response.Rooms[roomUpdate.RoomID()] | ||
|
||
conMeta := s.lists.ReadOnlyRoom(roomUpdate.RoomID()) | ||
for _, ts := range conMeta.LastInterestedEventTimestamps { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs comments. This is using the highest timestamp from each list for this room I guess? |
||
if ts >= r.Timestamp { | ||
r.Timestamp = ts | ||
} | ||
} | ||
|
||
r.HighlightCount = int64(userRoomData.HighlightCount) | ||
r.NotificationCount = int64(userRoomData.NotificationCount) | ||
if roomEventUpdate != nil && roomEventUpdate.EventData.Event != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package syncv3_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/matrix-org/sliding-sync/sync3" | ||
"github.com/matrix-org/sliding-sync/testutils/m" | ||
) | ||
|
||
func TestTimestamp(t *testing.T) { | ||
alice := registerNewUser(t) | ||
bob := registerNewUser(t) | ||
|
||
roomID := alice.CreateRoom(t, map[string]interface{}{ | ||
"preset": "public_chat", | ||
}) | ||
|
||
// Init sync to get the latest timestamp | ||
res := alice.SlidingSync(t, sync3.Request{ | ||
RoomSubscriptions: map[string]sync3.RoomSubscription{ | ||
roomID: { | ||
TimelineLimit: 10, | ||
}, | ||
}, | ||
}) | ||
m.MatchResponse(t, res, m.MatchRoomSubscription(roomID, m.MatchRoomInitial(true))) | ||
timestampBeforeBobJoined := res.Rooms[roomID].Timestamp | ||
|
||
bob.JoinRoom(t, roomID, nil) | ||
res = alice.SlidingSyncUntilMembership(t, res.Pos, roomID, bob, "join") | ||
|
||
resBob := bob.SlidingSync(t, sync3.Request{ | ||
Lists: map[string]sync3.RequestList{ | ||
"myFirstList": { | ||
Ranges: [][2]int64{{0, 1}}, | ||
RoomSubscription: sync3.RoomSubscription{ | ||
TimelineLimit: 10, | ||
}, | ||
BumpEventTypes: []string{"m.room.message"}, // only messages bump the timestamp | ||
}, | ||
"mySecondList": { | ||
Ranges: [][2]int64{{0, 1}}, | ||
RoomSubscription: sync3.RoomSubscription{ | ||
TimelineLimit: 10, | ||
}, | ||
BumpEventTypes: []string{"m.reaction"}, // only reactions bump the timestamp | ||
}, | ||
}, | ||
}) | ||
|
||
// Bob should see a different timestamp than alice, as he just joined | ||
bobTimestampBefore := resBob.Rooms[roomID].Timestamp | ||
if bobTimestampBefore == timestampBeforeBobJoined { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really this should equal |
||
t.Fatalf("expected timestamp to differ: %v vs %v", timestampBeforeBobJoined, bobTimestampBefore) | ||
} | ||
|
||
// Send an event which should NOT bump Bobs timestamp, because it is not listed it | ||
// any BumpEventTypes | ||
emptyStateKey := "" | ||
eventID := alice.SendEventSynced(t, roomID, Event{ | ||
Type: "m.room.topic", | ||
StateKey: &emptyStateKey, | ||
Content: map[string]interface{}{ | ||
"topic": "random topic", | ||
}, | ||
}) | ||
|
||
bobTimestampAfter := resBob.Rooms[roomID].Timestamp | ||
|
||
resBob = bob.SlidingSyncUntilEventID(t, resBob.Pos, roomID, eventID) | ||
t.Logf("bobTimestampBefore vs bobTimestampAfter: %v %v", bobTimestampBefore, bobTimestampAfter) | ||
if bobTimestampBefore != bobTimestampAfter { | ||
t.Fatalf("expected timestamps to be the same, but they aren't: %v vs %v", bobTimestampBefore, bobTimestampAfter) | ||
} | ||
bobTimestampBefore = bobTimestampAfter | ||
|
||
// Now send a message which bumps the timestamp in myFirstList | ||
eventID = alice.SendEventSynced(t, roomID, Event{ | ||
Type: "m.room.message", | ||
Content: map[string]interface{}{ | ||
"msgtype": "m.text", | ||
"body": "Hello, world!", | ||
}, | ||
}) | ||
|
||
resBob = bob.SlidingSyncUntilEventID(t, resBob.Pos, roomID, eventID) | ||
bobTimestampAfter = resBob.Rooms[roomID].Timestamp | ||
if bobTimestampBefore == bobTimestampAfter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, we need to know exactly what timestamp this should be - use alice to figure this out. |
||
t.Fatalf("expected timestamps to be different, but they aren't: %v vs %v", bobTimestampBefore, bobTimestampAfter) | ||
} | ||
bobTimestampBefore = bobTimestampAfter | ||
|
||
// Now send a message which bumps the timestamp in mySecondList | ||
eventID = alice.SendEventSynced(t, roomID, Event{ | ||
Type: "m.reaction", | ||
Content: map[string]interface{}{ | ||
"m.relates.to": map[string]interface{}{ | ||
"event_id": eventID, | ||
"key": "✅", | ||
"rel_type": "m.annotation", | ||
}, | ||
}, | ||
}) | ||
|
||
resBob = bob.SlidingSyncUntilEventID(t, resBob.Pos, roomID, eventID) | ||
bobTimestampAfter = resBob.Rooms[roomID].Timestamp | ||
if bobTimestampBefore == bobTimestampAfter { | ||
t.Fatalf("expected timestamps to be different, but they aren't: %v vs %v", bobTimestampBefore, bobTimestampAfter) | ||
} | ||
bobTimestampBefore = bobTimestampAfter | ||
|
||
// Send another event which should NOT bump Bobs timestamp | ||
eventID = alice.SendEventSynced(t, roomID, Event{ | ||
Type: "m.room.name", | ||
StateKey: &emptyStateKey, | ||
Content: map[string]interface{}{ | ||
"name": "random name", | ||
}, | ||
}) | ||
|
||
resBob = bob.SlidingSyncUntilEventID(t, resBob.Pos, roomID, eventID) | ||
bobTimestampAfter = resBob.Rooms[roomID].Timestamp | ||
if bobTimestampBefore != bobTimestampAfter { | ||
t.Fatalf("expected timestamps to be the same, but they aren't: %v vs %v", bobTimestampBefore, bobTimestampAfter) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs more tests. Specifically:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't know if this is what they want.
getInitialRoomData
is a central point called for multiple lists: you need to know thebump_event_types
values to know what timestamp to pull here. Add that as a param togetInitialRoomData