Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit b6e4112

Browse files
committed
Don't assume RoomStreamTokens can be compared
1 parent d68a91d commit b6e4112

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

synapse/types.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,14 @@ def parse_stream_token(cls, string: str) -> "RoomStreamToken":
413413
pass
414414
raise SynapseError(400, "Invalid token %r" % (string,))
415415

416+
def copy_and_advance(self, other: "RoomStreamToken") -> "RoomStreamToken":
417+
if self.topological or other.topological:
418+
raise Exception("Can't advance topological tokens")
419+
420+
max_stream = max(self.stream, other.stream)
421+
422+
return RoomStreamToken(None, max_stream)
423+
416424
def as_tuple(self) -> Tuple[Optional[int], int]:
417425
return (self.topological, self.stream)
418426

@@ -462,13 +470,16 @@ def copy_and_advance(self, key, new_value) -> "StreamToken":
462470
"""Advance the given key in the token to a new value if and only if the
463471
new value is after the old value.
464472
"""
465-
new_token = self.copy_and_replace(key, new_value)
466473
if key == "room_key":
467-
new_id = new_token.room_stream_id
468-
old_id = self.room_stream_id
469-
else:
470-
new_id = int(getattr(new_token, key))
471-
old_id = int(getattr(self, key))
474+
new_token = self.copy_and_replace(
475+
"room_key", self.room_key.copy_and_advance(new_value)
476+
)
477+
return new_token
478+
479+
new_token = self.copy_and_replace(key, new_value)
480+
new_id = int(getattr(new_token, key))
481+
old_id = int(getattr(self, key))
482+
472483
if old_id < new_id:
473484
return new_token
474485
else:

0 commit comments

Comments
 (0)