Support redactions
This commit is contained in:
parent
4203f87f3d
commit
92f6a250f1
@ -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)
|
||||
|
||||
|
||||
@ -144,7 +144,7 @@ class MRoomPowerLevelsContent(ContentBase):
|
||||
|
||||
@dataclass
|
||||
class MRoomRedactionContent(ContentBase):
|
||||
reason: str
|
||||
reason: Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user