Skip to content

Commit

Permalink
Do not refuse to set read_marker if previous event_id is in wrong room (
Browse files Browse the repository at this point in the history
  • Loading branch information
SpiritCroc authored Mar 21, 2024
1 parent f7a3ebe commit 9ad49e7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/16990.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix case in which `m.fully_read` marker would not get updated. Contributed by @SpiritCroc.
4 changes: 2 additions & 2 deletions synapse/handlers/read_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ async def received_client_read_marker(

should_update = True
# Get event ordering, this also ensures we know about the event
event_ordering = await self.store.get_event_ordering(event_id)
event_ordering = await self.store.get_event_ordering(event_id, room_id)

if existing_read_marker:
try:
old_event_ordering = await self.store.get_event_ordering(
existing_read_marker["event_id"]
existing_read_marker["event_id"], room_id
)
except SynapseError:
# Old event no longer exists, assume new is ahead. This may
Expand Down
8 changes: 5 additions & 3 deletions synapse/storage/databases/main/events_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,16 +1995,18 @@ def get_deltas_for_stream_id_txn(
return rows, to_token, True

@cached(max_entries=5000)
async def get_event_ordering(self, event_id: str) -> Tuple[int, int]:
async def get_event_ordering(self, event_id: str, room_id: str) -> Tuple[int, int]:
res = await self.db_pool.simple_select_one(
table="events",
retcols=["topological_ordering", "stream_ordering"],
keyvalues={"event_id": event_id},
keyvalues={"event_id": event_id, "room_id": room_id},
allow_none=True,
)

if not res:
raise SynapseError(404, "Could not find event %s" % (event_id,))
raise SynapseError(
404, "Could not find event %s in room %s" % (event_id, room_id)
)

return int(res[0]), int(res[1])

Expand Down
8 changes: 4 additions & 4 deletions tests/rest/client/test_read_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def send_message() -> str:

channel = self.make_request(
"POST",
"/rooms/!abc:beep/read_markers",
f"/rooms/{room_id}/read_markers",
content={
"m.fully_read": event_id_1,
},
Expand All @@ -90,7 +90,7 @@ def send_message() -> str:
event_id_2 = send_message()
channel = self.make_request(
"POST",
"/rooms/!abc:beep/read_markers",
f"/rooms/{room_id}/read_markers",
content={
"m.fully_read": event_id_2,
},
Expand Down Expand Up @@ -123,7 +123,7 @@ def send_message() -> str:

channel = self.make_request(
"POST",
"/rooms/!abc:beep/read_markers",
f"/rooms/{room_id}/read_markers",
content={
"m.fully_read": event_id_1,
},
Expand All @@ -142,7 +142,7 @@ def send_message() -> str:
event_id_2 = send_message()
channel = self.make_request(
"POST",
"/rooms/!abc:beep/read_markers",
f"/rooms/{room_id}/read_markers",
content={
"m.fully_read": event_id_2,
},
Expand Down

0 comments on commit 9ad49e7

Please sign in to comment.