-
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
Make account_data accessible #295
base: master
Are you sure you want to change the base?
Conversation
This keeps a copy of account_data in the Client object after a sync, which can then be easily accessed through a dictionary. In addition, Client.get_account_data is provided as a means to obtain the current account_data structure for direct feeding into Api.set_account_data. Closes: Github matrix-org#294 Signed-off-by: martin f. krafft <[email protected]>
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.
Thanks for this! Please try to address the comments, as well as the PEP8 errors reported by Travis.
Note also that you're letting out per room account_data
, which would be great to have if you get the time to look into it.
client = MatrixClient(host) | ||
|
||
try: | ||
client.login_with_password_no_sync(username, password) |
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.
This method is deprecated, simply use client.login
with sync=False
.
room_ids = [] | ||
|
||
import yaml | ||
print(yaml.dumps(client.account_data['m.direct']), default_flow_style=False) |
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.
Did you mean to use yaml.dump
? Also you didn't sync so this will always raise KeyError
.
@@ -0,0 +1,40 @@ | |||
#!/usr/bin/env python3 |
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 think you should drop this sample, as adding a 40 lines file with one line worth of information is not useful.
The comments below are FYI :)
@@ -667,3 +680,14 @@ def remove_room_alias(self, room_alias): | |||
return True | |||
except MatrixRequestError: | |||
return False | |||
|
|||
def get_account_data(self): |
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.
Could you explain more precisely how this particular formatting is useful? Maybe give an example, as I don't get in what way it eases a call to api.set_account_data
.
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.
Hey, sorry for the late response, @Zil0. I chose to have another look.
I chose this particular formatting because it matches the JSON that the API returns. But looking at the api.set_account_data
call, you're right, I can probably just return the account_data
dict, do yo agree?
def test_get_account_data(): | ||
client = MatrixClient("http://example.com") | ||
assert isinstance(client.account_data, dict) | ||
assert (len(client.account_data) == 0) |
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.
Outside parentheses look unnecessary, applies also to the lines below.
for event in response['account_data']['events']: | ||
self.account_data[event['type']] = event['content'] | ||
|
||
for listener in self.listeners: |
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 think there's a problem with the way this is done.
A silly example is that if I want to listen for messages, I will add a listener with the event type m.room.message. But nothing stops me (at least not the HS) from having an event type in account_data which is also m.room.message. Then the listener will pick up both, which is not the expected behavior and could cause strange bugs. This may actually happen if you substitute m.room.message for an event type that is less well known.
Hence you should probably handle this with separate listeners, in the same way invite and presence listeners are done. Not 100% sure this is the right way though, so if you have another idea I'd gladly consider it!
@madduck Any idea when this might get finished? |
Yeah, uh, sorry @Zil0 and @Evidlo, I had not seen these comments until now. The project I was working on is finished. At the moment, I have no other business with this SDK, and no spare time. So unless someone steps up to finish this, it'll be a while until I can return, probably until e2e is supported, then there'll be a new project lined up for me. I am fine dropping the example. I find such files useful, but I see the point. The other stuff should be trivial fixes, right? |
This keeps a copy of account_data in the Client object after a sync,
which can then be easily accessed through a dictionary.
In addition, Client.get_account_data is provided as a means to obtain
the current account_data structure for direct feeding into
Api.set_account_data.
Closes: #294
Signed-off-by: martin f. krafft [email protected]