Do not refuse to set read_marker if previous event_id is in wrong room (#16990)

This commit is contained in:
SpiritCroc 2024-03-21 19:43:07 +01:00 committed by GitHub
parent f7a3ebe44d
commit 9ad49e7ecf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 9 deletions

1
changelog.d/16990.bugfix Normal file
View File

@ -0,0 +1 @@
Fix case in which `m.fully_read` marker would not get updated. Contributed by @SpiritCroc.

View File

@ -55,12 +55,12 @@ class ReadMarkerHandler:
should_update = True should_update = True
# Get event ordering, this also ensures we know about the event # 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: if existing_read_marker:
try: try:
old_event_ordering = await self.store.get_event_ordering( old_event_ordering = await self.store.get_event_ordering(
existing_read_marker["event_id"] existing_read_marker["event_id"], room_id
) )
except SynapseError: except SynapseError:
# Old event no longer exists, assume new is ahead. This may # Old event no longer exists, assume new is ahead. This may

View File

@ -1995,16 +1995,18 @@ class EventsWorkerStore(SQLBaseStore):
return rows, to_token, True return rows, to_token, True
@cached(max_entries=5000) @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( res = await self.db_pool.simple_select_one(
table="events", table="events",
retcols=["topological_ordering", "stream_ordering"], retcols=["topological_ordering", "stream_ordering"],
keyvalues={"event_id": event_id}, keyvalues={"event_id": event_id, "room_id": room_id},
allow_none=True, allow_none=True,
) )
if not res: 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]) return int(res[0]), int(res[1])

View File

@ -78,7 +78,7 @@ class ReadMarkerTestCase(unittest.HomeserverTestCase):
channel = self.make_request( channel = self.make_request(
"POST", "POST",
"/rooms/!abc:beep/read_markers", f"/rooms/{room_id}/read_markers",
content={ content={
"m.fully_read": event_id_1, "m.fully_read": event_id_1,
}, },
@ -90,7 +90,7 @@ class ReadMarkerTestCase(unittest.HomeserverTestCase):
event_id_2 = send_message() event_id_2 = send_message()
channel = self.make_request( channel = self.make_request(
"POST", "POST",
"/rooms/!abc:beep/read_markers", f"/rooms/{room_id}/read_markers",
content={ content={
"m.fully_read": event_id_2, "m.fully_read": event_id_2,
}, },
@ -123,7 +123,7 @@ class ReadMarkerTestCase(unittest.HomeserverTestCase):
channel = self.make_request( channel = self.make_request(
"POST", "POST",
"/rooms/!abc:beep/read_markers", f"/rooms/{room_id}/read_markers",
content={ content={
"m.fully_read": event_id_1, "m.fully_read": event_id_1,
}, },
@ -142,7 +142,7 @@ class ReadMarkerTestCase(unittest.HomeserverTestCase):
event_id_2 = send_message() event_id_2 = send_message()
channel = self.make_request( channel = self.make_request(
"POST", "POST",
"/rooms/!abc:beep/read_markers", f"/rooms/{room_id}/read_markers",
content={ content={
"m.fully_read": event_id_2, "m.fully_read": event_id_2,
}, },