mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 05:54:59 -04:00
Add StreamKeyType
class and replace string literals with constants (#12567)
This commit is contained in:
parent
3ce15cc7be
commit
83be72d76c
19 changed files with 125 additions and 80 deletions
|
@ -37,7 +37,7 @@ import attr
|
|||
from frozendict import frozendict
|
||||
from signedjson.key import decode_verify_key_bytes
|
||||
from signedjson.types import VerifyKey
|
||||
from typing_extensions import TypedDict
|
||||
from typing_extensions import Final, TypedDict
|
||||
from unpaddedbase64 import decode_base64
|
||||
from zope.interface import Interface
|
||||
|
||||
|
@ -630,6 +630,22 @@ class RoomStreamToken:
|
|||
return "s%d" % (self.stream,)
|
||||
|
||||
|
||||
class StreamKeyType:
|
||||
"""Known stream types.
|
||||
|
||||
A stream is a list of entities ordered by an incrementing "stream token".
|
||||
"""
|
||||
|
||||
ROOM: Final = "room_key"
|
||||
PRESENCE: Final = "presence_key"
|
||||
TYPING: Final = "typing_key"
|
||||
RECEIPT: Final = "receipt_key"
|
||||
ACCOUNT_DATA: Final = "account_data_key"
|
||||
PUSH_RULES: Final = "push_rules_key"
|
||||
TO_DEVICE: Final = "to_device_key"
|
||||
DEVICE_LIST: Final = "device_list_key"
|
||||
|
||||
|
||||
@attr.s(slots=True, frozen=True, auto_attribs=True)
|
||||
class StreamToken:
|
||||
"""A collection of keys joined together by underscores in the following
|
||||
|
@ -743,9 +759,9 @@ class StreamToken:
|
|||
|
||||
:raises TypeError: if `key` is not the one of the keys tracked by a StreamToken.
|
||||
"""
|
||||
if key == "room_key":
|
||||
if key == StreamKeyType.ROOM:
|
||||
new_token = self.copy_and_replace(
|
||||
"room_key", self.room_key.copy_and_advance(new_value)
|
||||
StreamKeyType.ROOM, self.room_key.copy_and_advance(new_value)
|
||||
)
|
||||
return new_token
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue