Remove FrozenEventBase

This commit is contained in:
Erik Johnston 2020-02-03 17:18:56 +00:00
parent 78589c3b4a
commit d5c9d04b89
2 changed files with 19 additions and 26 deletions

View file

@ -193,6 +193,10 @@ class EventBase(object):
type = _event_dict_property("type")
user_id = _event_dict_property("sender")
@property
def event_id(self) -> str:
raise NotImplementedError()
@property
def membership(self):
return self.content["membership"]
@ -259,16 +263,7 @@ class EventBase(object):
return [e for e, _ in self.auth_events]
class FrozenEventBase(EventBase):
"""Base class for fully initialised events.
"""
@property
def event_id(self) -> str:
raise NotImplementedError()
class FrozenEvent(FrozenEventBase):
class FrozenEvent(EventBase):
format_version = EventFormatVersions.V1 # All events of this type are V1
def __init__(self, event_dict, internal_metadata_dict={}, rejected_reason=None):
@ -317,7 +312,7 @@ class FrozenEvent(FrozenEventBase):
)
class FrozenEventV2(FrozenEventBase):
class FrozenEventV2(EventBase):
format_version = EventFormatVersions.V2 # All events of this type are V2
def __init__(self, event_dict, internal_metadata_dict={}, rejected_reason=None):

View file

@ -25,7 +25,7 @@ from prometheus_client import Counter
from synapse.api.constants import EventTypes, Membership
from synapse.api.filtering import FilterCollection
from synapse.events import FrozenEventBase
from synapse.events import EventBase
from synapse.logging.context import LoggingContext
from synapse.push.clientformat import format_push_rules_for_user
from synapse.storage.roommember import MemberSummary
@ -84,7 +84,7 @@ class SyncConfig:
@attr.s(slots=True, frozen=True)
class TimelineBatch:
prev_batch = attr.ib(type=StreamToken)
events = attr.ib(type=List[FrozenEventBase])
events = attr.ib(type=List[EventBase])
limited = attr.ib(bool)
def __nonzero__(self) -> bool:
@ -100,7 +100,7 @@ class TimelineBatch:
class JoinedSyncResult:
room_id = attr.ib(type=str)
timeline = attr.ib(type=TimelineBatch)
state = attr.ib(type=StateMap[FrozenEventBase])
state = attr.ib(type=StateMap[EventBase])
ephemeral = attr.ib(type=List[JsonDict])
account_data = attr.ib(type=List[JsonDict])
unread_notifications = attr.ib(type=JsonDict)
@ -126,7 +126,7 @@ class JoinedSyncResult:
class ArchivedSyncResult:
room_id = attr.ib(type=str)
timeline = attr.ib(type=TimelineBatch)
state = attr.ib(type=StateMap[FrozenEventBase])
state = attr.ib(type=StateMap[EventBase])
account_data = attr.ib(type=List[JsonDict])
def __nonzero__(self) -> bool:
@ -141,7 +141,7 @@ class ArchivedSyncResult:
@attr.s(slots=True, frozen=True)
class InvitedSyncResult:
room_id = attr.ib(type=str)
invite = attr.ib(type=FrozenEventBase)
invite = attr.ib(type=EventBase)
def __nonzero__(self) -> bool:
"""Invited rooms should always be reported to the client"""
@ -419,7 +419,7 @@ class SyncHandler(object):
sync_config: SyncConfig,
now_token: StreamToken,
since_token: Optional[StreamToken] = None,
potential_recents: Optional[List[FrozenEventBase]] = None,
potential_recents: Optional[List[EventBase]] = None,
newly_joined_room: bool = False,
) -> TimelineBatch:
"""
@ -539,7 +539,7 @@ class SyncHandler(object):
)
async def get_state_after_event(
self, event: FrozenEventBase, state_filter: StateFilter = StateFilter.all()
self, event: EventBase, state_filter: StateFilter = StateFilter.all()
) -> StateMap[str]:
"""
Get the room state after the given event
@ -593,7 +593,7 @@ class SyncHandler(object):
room_id: str,
sync_config: SyncConfig,
batch: TimelineBatch,
state: StateMap[FrozenEventBase],
state: StateMap[EventBase],
now_token: StreamToken,
) -> Optional[JsonDict]:
""" Works out a room summary block for this room, summarising the number
@ -743,7 +743,7 @@ class SyncHandler(object):
since_token: Optional[StreamToken],
now_token: StreamToken,
full_state: bool,
) -> StateMap[FrozenEventBase]:
) -> StateMap[EventBase]:
""" Works out the difference in state between the start of the timeline
and the previous sync.
@ -923,7 +923,7 @@ class SyncHandler(object):
if t[0] == EventTypes.Member:
cache.set(t[1], event_id)
state = {} # type: Dict[str, FrozenEventBase]
state = {} # type: Dict[str, EventBase]
if state_ids:
state = await self.store.get_events(list(state_ids.values()))
@ -1489,7 +1489,7 @@ class SyncHandler(object):
user_id, since_token.room_key, now_token.room_key
)
mem_change_events_by_room_id = {} # type: Dict[str, List[FrozenEventBase]]
mem_change_events_by_room_id = {} # type: Dict[str, List[EventBase]]
for event in rooms_changed:
mem_change_events_by_room_id.setdefault(event.room_id, []).append(event)
@ -1608,9 +1608,7 @@ class SyncHandler(object):
# This is all screaming out for a refactor, as the logic here is
# subtle and the moving parts numerous.
if leave_event.internal_metadata.is_out_of_band_membership():
batch_events = [
leave_event
] # type: Optional[List[FrozenEventBase]]
batch_events = [leave_event] # type: Optional[List[EventBase]]
else:
batch_events = None
@ -2073,7 +2071,7 @@ class RoomSyncResultBuilder(object):
room_id = attr.ib(type=str)
rtype = attr.ib(type=str)
events = attr.ib(type=Optional[List[FrozenEventBase]])
events = attr.ib(type=Optional[List[EventBase]])
newly_joined = attr.ib(type=bool)
full_state = attr.ib(type=bool)
since_token = attr.ib(type=Optional[StreamToken])