summary refs log tree commit diff
diff options
context:
space:
mode:
authorOlivier Wilkinson (reivilibre) <oliverw@matrix.org>2022-09-09 18:15:51 +0100
committerOlivier Wilkinson (reivilibre) <oliverw@matrix.org>2022-09-09 18:15:51 +0100
commit09f29d59851b9aabd341a726e075be6e561e42f5 (patch)
treee54493f694f92ae7d29b5c39341f06780948c626
parentAdd timestamp to user's consent (#13741) (diff)
downloadsynapse-09f29d59851b9aabd341a726e075be6e561e42f5.tar.xz
Make EventFormatVersions an enum
-rw-r--r--synapse/api/room_versions.py6
-rw-r--r--synapse/events/__init__.py4
-rw-r--r--synapse/storage/databases/main/events_worker.py7
3 files changed, 10 insertions, 7 deletions
diff --git a/synapse/api/room_versions.py b/synapse/api/room_versions.py

index e37acb0f1e..3de9eeeca9 100644 --- a/synapse/api/room_versions.py +++ b/synapse/api/room_versions.py
@@ -11,13 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +from enum import Enum from typing import Callable, Dict, Optional import attr -class EventFormatVersions: +class EventFormatVersions(Enum): """This is an internal enum for tracking the version of the event format, independently of the room version. @@ -57,7 +57,7 @@ class RoomVersion: identifier: str # the identifier for this version disposition: str # one of the RoomDispositions - event_format: int # one of the EventFormatVersions + event_format: EventFormatVersions # one of the EventFormatVersions state_res: int # one of the StateResolutionVersions enforce_key_validity: bool diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py
index b2c9119fd0..2afaa8e77c 100644 --- a/synapse/events/__init__.py +++ b/synapse/events/__init__.py
@@ -293,7 +293,7 @@ class _EventInternalMetadata: class EventBase(metaclass=abc.ABCMeta): @property @abc.abstractmethod - def format_version(self) -> int: + def format_version(self) -> EventFormatVersions: """The EventFormatVersion implemented by this event""" ... @@ -584,7 +584,7 @@ class FrozenEventV3(FrozenEventV2): def _event_type_from_format_version( - format_version: int, + format_version: EventFormatVersions, ) -> Type[Union[FrozenEvent, FrozenEventV2, FrozenEventV3]]: """Returns the python type to use to construct an Event object for the given event format version. diff --git a/synapse/storage/databases/main/events_worker.py b/synapse/storage/databases/main/events_worker.py
index 52914febf9..4566f505d8 100644 --- a/synapse/storage/databases/main/events_worker.py +++ b/synapse/storage/databases/main/events_worker.py
@@ -147,7 +147,7 @@ class _EventRow: stream_ordering: int json: str internal_metadata: str - format_version: Optional[int] + format_version: Optional[EventFormatVersions] room_version_id: Optional[str] rejected_reason: Optional[str] redactions: List[str] @@ -1339,7 +1339,10 @@ class EventsWorkerStore(SQLBaseStore): stream_ordering=row[1], internal_metadata=row[2], json=row[3], - format_version=row[4], + # TODO is this the best way to do it? + format_version=( + EventFormatVersions(row[4]) if row[4] is not None else None + ), room_version_id=row[5], rejected_reason=row[6], redactions=[],