From 810607dc082b97128b23c341c3f40ffd6152b606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Fri, 6 Jul 2018 21:34:27 +0200 Subject: [PATCH] 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. --- matrix/rooms.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/matrix/rooms.py b/matrix/rooms.py index 1ca50e6..09e61a4 100644 --- a/matrix/rooms.py +++ b/matrix/rooms.py @@ -287,7 +287,8 @@ class RoomInfo(): error=pformat(error), event=pformat(event)) W.prnt("", message) - raise + e = BadEvent.from_dict(event) + events.append(e) return events @@ -325,6 +326,22 @@ class RoomEvent(): 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): def __init__(self, event_id, sender, timestamp, censor, reason=None):