From dc25487127c2122a6fd3f97c10e89ae212dfd55e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Tue, 6 Mar 2018 17:17:54 +0100 Subject: [PATCH] rooms: Add canonical alias event handling. --- matrix/rooms.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/matrix/rooms.py b/matrix/rooms.py index ad89a18..0044b8c 100644 --- a/matrix/rooms.py +++ b/matrix/rooms.py @@ -175,6 +175,8 @@ class RoomInfo(): other_events.append(RoomRedactionEvent.from_dict(event)) elif event["type"] == "m.room.name": other_events.append(RoomNameEvent.from_dict(event)) + elif event["type"] == "m.room.canonical_alias": + other_events.append(RoomAliasEvent.from_dict(event)) elif event["type"] == "m.room.encryption": other_events.append(RoomEncryptionEvent.from_dict(event)) except (ValueError, TypeError, KeyError) as error: @@ -730,6 +732,22 @@ class RoomNameEvent(RoomEvent): W.buffer_set(buff, "localvar_set_channel", self.name) +class RoomAliasEvent(RoomNameEvent): + + def __init__(self, event_id, sender, timestamp, name): + RoomNameEvent.__init__(self, event_id, sender, timestamp, name) + + @classmethod + def from_dict(cls, event_dict): + event_id = sanitize_id(event_dict["event_id"]) + sender = sanitize_id(event_dict["sender"]) + timestamp = sanitize_ts(event_dict["origin_server_ts"]) + + name = sanitize_id(event_dict["content"]["alias"]) + + return cls(event_id, sender, timestamp, name) + + class RoomEncryptionEvent(RoomEvent): @classmethod