-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle all m.room.aliases chunk, not only first #270
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -456,15 +456,17 @@ def update_aliases(self): | |
""" | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this works as expected. Since |
||
return changed | ||
|
||
def add_room_alias(self, room_alias): | ||
"""Add an alias to the room and return True if successful.""" | ||
|
@@ -649,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": | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -73,7 +73,6 @@ def test_state_event(): | |||
|
||||
room.name = False | ||||
room.topic = False | ||||
room.aliases = False | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found that when initializing aliases in matrix-python-sdk/matrix_client/room.py Line 43 in 00186ba
False here doesn't look correct.
|
||||
|
||||
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 == [] | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||||
|
||||
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 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since now we are processing list element by element, |
||||
|
||||
# test member join event | ||||
ev["type"] = "m.room.member" | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have
self.aliases.clear()
here.