rooms: Add BadEvent class.

This way if one event in a room is not per spec, we don't end up in a
broken state.
This commit is contained in:
poljar (Damir Jelić) 2018-07-06 21:34:27 +02:00
parent d70e651d3e
commit 810607dc08

View file

@ -287,7 +287,8 @@ class RoomInfo():
error=pformat(error), error=pformat(error),
event=pformat(event)) event=pformat(event))
W.prnt("", message) W.prnt("", message)
raise e = BadEvent.from_dict(event)
events.append(e)
return events return events
@ -325,6 +326,22 @@ class RoomEvent():
self.timestamp = timestamp self.timestamp = timestamp
class BadEvent(RoomEvent):
def __init__(self, event_id, sender, timestamp, source):
self.source = source
def from_dict(cls, event):
event_id = (sanitize_id(event["event_id"])
if "event_id" in event else None)
sender = (sanitize_id(event["sender"])
if "sender" in event else None)
timestamp = (sanitize_id(event["origin_server_ts"])
if "origin_server_ts" in event else None)
source = json.dumps(event)
return cls(event_id, sender, timestamp, source)
class RoomRedactedMessageEvent(RoomEvent): class RoomRedactedMessageEvent(RoomEvent):
def __init__(self, event_id, sender, timestamp, censor, reason=None): def __init__(self, event_id, sender, timestamp, censor, reason=None):