Separate the membership events out.

We need to handle the membership events so we can populate the nicklist
and set nick colors before we print out any messages.
This commit is contained in:
poljar (Damir Jelić) 2018-02-23 18:52:10 +01:00
parent b2eacd468f
commit 28d379a428
2 changed files with 20 additions and 16 deletions

View file

@ -326,6 +326,10 @@ class MatrixSyncEvent(MatrixEvent):
room.prev_batch = info.prev_batch room.prev_batch = info.prev_batch
tags = tags_for_message("message") tags = tags_for_message("message")
for event in info.membership_events:
event.execute(server, room, buf, list(tags))
for event in info.events: for event in info.events:
event.execute(server, room, buf, list(tags)) event.execute(server, room, buf, list(tags))

View file

@ -86,10 +86,11 @@ def matrix_create_room_buffer(server, room_id):
class RoomInfo(): class RoomInfo():
def __init__(self, room_id, prev_batch, events): def __init__(self, room_id, prev_batch, membership_events, events):
# type: (str, str, List[Any]) -> None # type: (str, str, List[Any], List[Any]) -> None
self.room_id = room_id self.room_id = room_id
self.prev_batch = prev_batch self.prev_batch = prev_batch
self.membership_events = membership_events
self.events = events self.events = events
@staticmethod @staticmethod
@ -122,29 +123,28 @@ class RoomInfo():
return None return None
@staticmethod @staticmethod
def _event_from_dict(event): def _parse_events(parsed_dict):
membership_events = []
other_events = []
for event in parsed_dict:
if event["type"] == "m.room.message": if event["type"] == "m.room.message":
return RoomInfo._message_from_event(event) other_events.append(RoomInfo._message_from_event(event))
elif event["type"] == "m.room.member": elif event["type"] == "m.room.member":
return RoomInfo._membership_from_dict(event) membership_events.append(RoomInfo._membership_from_dict(event))
else:
return None return (list(filter(None, membership_events)), other_events)
@classmethod @classmethod
def from_dict(cls, room_id, parsed_dict): def from_dict(cls, room_id, parsed_dict):
prev_batch = sanitize_id(parsed_dict['timeline']['prev_batch']) prev_batch = sanitize_id(parsed_dict['timeline']['prev_batch'])
events = []
state_dict = parsed_dict['state']['events'] state_dict = parsed_dict['state']['events']
timeline_dict = parsed_dict['timeline']['events'] timeline_dict = parsed_dict['timeline']['events']
for event in timeline_dict: membership_events, other_events = RoomInfo._parse_events(timeline_dict)
events.append(RoomInfo._event_from_dict(event))
filtered_events = list(filter(None, events)) return cls(room_id, prev_batch, membership_events, other_events)
return cls(room_id, prev_batch, filtered_events)
class RoomEvent(): class RoomEvent():