mirror of
https://github.com/element-hq/synapse
synced 2024-09-17 18:55:10 +00:00
Make EventFormatVersions an enum
This commit is contained in:
parent
f799eac7ea
commit
09f29d5985
3 changed files with 10 additions and 7 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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=[],
|
||||
|
|
Loading…
Reference in a new issue