Support redactions

This commit is contained in:
Dusty Pianalto 2019-11-06 22:36:10 -09:00
parent 4203f87f3d
commit 92f6a250f1
3 changed files with 15 additions and 7 deletions

View File

@ -160,6 +160,8 @@ class Client:
return EventBase.from_dict(self, event)
elif event["type"] == "m.room.message":
return MessageEvent.from_dict(self, event)
elif event['type'] == 'm.room.redaction':
return RedactionEvent.from_dict(self, event)
else:
return RoomEvent.from_dict(self, event)

View File

@ -144,7 +144,7 @@ class MRoomPowerLevelsContent(ContentBase):
@dataclass
class MRoomRedactionContent(ContentBase):
reason: str
reason: Optional[str] = None
@dataclass

View File

@ -18,7 +18,8 @@ class EventBase:
def from_dict(cls, client: Client, event_dict: dict):
from .content import content_dispatcher
if event_dict['type'] == 'm.room.message':
content_class = content_dispatcher[event_dict['content']['msgtype']]
content_class = content_dispatcher[event_dict['content']['msgtype']] \
if event_dict['content'].get('msgtype') else ContentBase
else:
content_class = content_dispatcher[event_dict['type']]
@ -41,11 +42,16 @@ class EventBase:
del event_dict['content']
try:
return cls(
client=client,
content=content_class(**content_dict),
**event_dict
)
except Exception as e:
print(content_dict)
print(event_dict)
raise e
@dataclass