Support redactions
This commit is contained in:
parent
4203f87f3d
commit
92f6a250f1
@ -160,6 +160,8 @@ class Client:
|
|||||||
return EventBase.from_dict(self, event)
|
return EventBase.from_dict(self, event)
|
||||||
elif event["type"] == "m.room.message":
|
elif event["type"] == "m.room.message":
|
||||||
return MessageEvent.from_dict(self, event)
|
return MessageEvent.from_dict(self, event)
|
||||||
|
elif event['type'] == 'm.room.redaction':
|
||||||
|
return RedactionEvent.from_dict(self, event)
|
||||||
else:
|
else:
|
||||||
return RoomEvent.from_dict(self, event)
|
return RoomEvent.from_dict(self, event)
|
||||||
|
|
||||||
|
|||||||
@ -144,7 +144,7 @@ class MRoomPowerLevelsContent(ContentBase):
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MRoomRedactionContent(ContentBase):
|
class MRoomRedactionContent(ContentBase):
|
||||||
reason: str
|
reason: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@ -18,7 +18,8 @@ class EventBase:
|
|||||||
def from_dict(cls, client: Client, event_dict: dict):
|
def from_dict(cls, client: Client, event_dict: dict):
|
||||||
from .content import content_dispatcher
|
from .content import content_dispatcher
|
||||||
if event_dict['type'] == 'm.room.message':
|
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:
|
else:
|
||||||
content_class = content_dispatcher[event_dict['type']]
|
content_class = content_dispatcher[event_dict['type']]
|
||||||
|
|
||||||
@ -41,11 +42,16 @@ class EventBase:
|
|||||||
|
|
||||||
del event_dict['content']
|
del event_dict['content']
|
||||||
|
|
||||||
return cls(
|
try:
|
||||||
client=client,
|
return cls(
|
||||||
content=content_class(**content_dict),
|
client=client,
|
||||||
**event_dict
|
content=content_class(**content_dict),
|
||||||
)
|
**event_dict
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(content_dict)
|
||||||
|
print(event_dict)
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user