Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

slipeer
Copy link

@slipeer slipeer commented Aug 10, 2018

This is fix for #106 issue
Rooom state server reply may contain more then one m.room.aliases update_aliases() method must collect aliases from all of them.

Additionally in this code only get_room_state() can raise MatrixRequestError - there is no need to enclose to try block more strings.

Signed-off-by: Pavel Kardash [email protected]

@slipeer slipeer changed the title Handle all m.room.aliases chunk, not only last Handle all m.room.aliases chunk, not only first Aug 10, 2018
Copy link
Collaborator

@non-Jedi non-Jedi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than comment, this LGTM. Note that this doesn't close #106 because the _process_state_event method also needs to be changed to account for multiple m.room.aliases state events.

@@ -454,17 +454,20 @@ def update_aliases(self):
Returns:
boolean: True if the aliases changed, False if not
"""
response = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having trouble understanding why this is necessary. If try block below is successful, response will be bound to something, and if it isn't successful, the method terminates without going further.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is an excessive reinsurance

@@ -73,7 +73,7 @@ def test_state_event():

room.name = False
room.topic = False
room.aliases = False
room.aliases = []
Copy link
Author

@slipeer slipeer Sep 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that when initializing aliases in rooms.py used empty list

self.aliases = []
, so using False here doesn't look correct.


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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since now we are processing list element by element, is will no longer work here.

@@ -97,12 +97,12 @@ def test_state_event():

ev["type"] = "m.room.aliases"
room._process_state_event(ev)
assert room.aliases is None
assert room.aliases == []
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since aliases is initialized as an empty list, it can no longer be None.

@@ -73,7 +73,6 @@ def test_state_event():

room.name = False
room.topic = False
room.aliases = False
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that when initializing aliases in rooms.py used empty list

self.aliases = []
, so using False here doesn't look correct.

Copy link
Contributor

@Zil0 Zil0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice if not for the small bug underlined :)

except MatrixRequestError:
return False
self.aliases = []
Copy link
Contributor

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.

for alias in chunk["content"]["aliases"]:
if alias not in self.aliases:
self.aliases.append(alias)
changed = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works as expected. Since self.aliases will always be empty because of self.aliases = [] above, changed will always be True as long as there is at least one alias, even if it's the same as before.

@Zil0
Copy link
Contributor

Zil0 commented Oct 4, 2018

Is there a reason why Room.aliases is not a set? It seems unlikely that we need ordering (as it is random anyway since it comes from a dict) or indexing, while this PR adds membership tests that could benefit a set, especially in _process_state_event. The only point I can see is to avoid confusing a user, since it is easy to assume from the look of it that an attribute called aliases is a list. Thoughts anyone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants