Skip to content
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

Merged
merged 6 commits into from
Aug 15, 2023
Merged

Add timestamp to room responses #247

merged 6 commits into from
Aug 15, 2023

Conversation

S7evinK
Copy link
Collaborator

@S7evinK S7evinK commented Aug 11, 2023

Attempt for #245

Copy link
Member

@kegsay kegsay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there, thanks.

@@ -624,6 +624,7 @@ func (s *ConnState) getInitialRoomData(ctx context.Context, roomSub sync3.RoomSu
JoinedCount: metadata.JoinCount,
InvitedCount: &metadata.InviteCount,
PrevBatch: userRoomData.RequestedLatestEvents.PrevBatch,
Timestamp: metadata.LastMessageTimestamp,
Copy link
Member

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 the bump_event_types values to know what timestamp to pull here. Add that as a param to getInitialRoomData

@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The 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?


// Bob should see a different timestamp than alice, as he just joined
bobTimestampBefore := resBob.Rooms[roomID].Timestamp
if bobTimestampBefore == timestampBeforeBobJoined {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really this should equal res.Rooms[roomID].Timestamp as that is going to be bob's join due to :30.


resBob = bob.SlidingSyncUntilEventID(t, resBob.Pos, roomID, eventID)
bobTimestampAfter = resBob.Rooms[roomID].Timestamp
if bobTimestampBefore == bobTimestampAfter {
Copy link
Member

Choose a reason for hiding this comment

The 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.

if bobTimestampBefore != bobTimestampAfter {
t.Fatalf("expected timestamps to be the same, but they aren't: %v vs %v", bobTimestampBefore, bobTimestampAfter)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs more tests. Specifically:

  • If you now do an initial sync (no pos) as Bob with the same lists, I don't think you'll get the right value. You'll get the latest timestamp (m.room.name) and not the m.reaction timestamp.
  • Ensure you time.Sleep(time.Millisecond) after each send to ensure that timestamps will change.
  • If Charlie now joins the room with the same bump_event_types as bob, he should see the timestamp of his join.

@S7evinK S7evinK requested a review from kegsay August 15, 2023 07:15
@kegsay kegsay merged commit 98abcea into main Aug 15, 2023
6 of 7 checks passed
@S7evinK S7evinK deleted the s7evink/roomtimestamp branch August 15, 2023 08:49
Hywan added a commit to Hywan/ruma that referenced this pull request Aug 16, 2023
This has been added in
matrix-org/sliding-sync#247. This is not part of
the MSC yet.
Hywan added a commit to Hywan/ruma that referenced this pull request Aug 17, 2023
This has been added in
matrix-org/sliding-sync#247. This is not part of
the MSC yet.
jplatte pushed a commit to ruma/ruma that referenced this pull request Aug 17, 2023
This has been added in
matrix-org/sliding-sync#247. This is not part of
the MSC yet.
MadLittleMods added a commit to element-hq/synapse that referenced this pull request Jul 8, 2024
… sorting (#17395)

`bump_stamp` corresponds to the `stream_ordering` of the latest `DEFAULT_BUMP_EVENT_TYPES` in the room. This helps clients sort more readily without them needing to pull in a bunch of the timeline to determine the last activity. `bump_event_types` is a thing because for example, we don't want display name changes to mark the room as unread and bump it to the top. For encrypted rooms, we just have to consider any activity as a bump because we can't see the content and the client has to figure it out for themselves.

Outside of Synapse, `bump_stamp` is just a free-form counter so other implementations could use `received_ts`or `origin_server_ts` (see the [*Security considerations* section in MSC3575 about the potential pitfalls of using `origin_server_ts`](https://github.com/matrix-org/matrix-spec-proposals/blob/kegan/sync-v3/proposals/3575-sync.md#security-considerations)). It doesn't have any guarantee about always going up. In the Synapse case, it could go down if an event was redacted/removed (or purged in cases of retention policies).

In the future, we could add `bump_event_types` as [MSC3575](matrix-org/matrix-spec-proposals#3575) mentions if people need to customize the event types.

---

In the Sliding Sync proxy, a similar [`timestamp` field was added](matrix-org/sliding-sync#247) for the same purpose but the name is not obvious what it pertains to or what it's for.

The `timestamp` field was also added to Ruma in ruma/ruma#1622
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants