From fd43c54e824cc72d8d99159968d987e72a4eacaf Mon Sep 17 00:00:00 2001 From: Pavel Kardash Date: Fri, 10 Aug 2018 10:39:43 +0300 Subject: [PATCH 1/2] Handle all m.room.aliases chunk, not only last --- matrix_client/room.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/matrix_client/room.py b/matrix_client/room.py index cc615966..4add0059 100644 --- a/matrix_client/room.py +++ b/matrix_client/room.py @@ -454,17 +454,20 @@ def update_aliases(self): Returns: boolean: True if the aliases changed, False if not """ + response = None try: response = self.client.api.get_room_state(self.room_id) - for chunk in response: - if "content" in chunk and "aliases" in chunk["content"]: - if chunk["content"]["aliases"] != self.aliases: - self.aliases = chunk["content"]["aliases"] - return True - else: - return False except MatrixRequestError: return False + self.aliases = [] + changed = False + for chunk in response: + if "content" in chunk and "aliases" in chunk["content"]: + for alias in chunk["content"]["aliases"]: + if alias not in self.aliases: + self.aliases.append(alias) + changed = True + return changed def add_room_alias(self, room_alias): """Add an alias to the room and return True if successful.""" From 3855f12949e3290067ff8d571a3cac9b6371f1f2 Mon Sep 17 00:00:00 2001 From: Pavel Kardash Date: Mon, 3 Sep 2018 10:25:28 +0300 Subject: [PATCH 2/2] Handle all m.room.aliases, not only first in _process_state_event too --- matrix_client/room.py | 5 +++-- test/client_test.py | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/matrix_client/room.py b/matrix_client/room.py index 4add0059..0bac9e50 100644 --- a/matrix_client/room.py +++ b/matrix_client/room.py @@ -454,7 +454,6 @@ def update_aliases(self): Returns: boolean: True if the aliases changed, False if not """ - response = None try: response = self.client.api.get_room_state(self.room_id) except MatrixRequestError: @@ -652,7 +651,9 @@ def _process_state_event(self, state_event): elif etype == "m.room.topic": self.topic = econtent.get("topic") elif etype == "m.room.aliases": - self.aliases = econtent.get("aliases") + for alias in econtent.get("aliases", []): + if alias not in self.aliases: + self.aliases.append(alias) elif etype == "m.room.join_rules": self.invite_only = econtent["join_rule"] == "invite" elif etype == "m.room.guest_access": diff --git a/test/client_test.py b/test/client_test.py index 472c2bd4..5ad38f70 100644 --- a/test/client_test.py +++ b/test/client_test.py @@ -73,7 +73,6 @@ def test_state_event(): room.name = False room.topic = False - room.aliases = False ev = { "type": "m.room.name", @@ -97,12 +96,12 @@ def test_state_event(): ev["type"] = "m.room.aliases" room._process_state_event(ev) - assert room.aliases is None + assert room.aliases == [] aliases = ["#foo:matrix.org", "#bar:matrix.org"] ev["content"]["aliases"] = aliases room._process_state_event(ev) - assert room.aliases is aliases + assert room.aliases == aliases # test member join event ev["type"] = "m.room.member"