-
-
Notifications
You must be signed in to change notification settings - Fork 251
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
Add handling for User update events #1249
base: main
Are you sure you want to change the base?
Conversation
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.
@mounilKshah Thanks for looking at this - this looks functional, at least in some ways 👍
While not strictly necessary, it'd be clearer to have the api_type changes in a separate commit since it documents the API first (you could even link to it in the commit text). I would also consider separate commits for first updating realm_users and then the active user for reasons below.
As per my inline comments I think you can simplify the update logic you already have, which may mean the additional function is unnecessary. It is called in every branch of the conditional, and the function itself seems like it could become 3 lines of code.
Currently your update of realm_users benefits from the regular calling of get_all_users and subsequently the user list update, and the former propagating that to other user datastructures that are either loosely (eg. by get_user_info()) or more tightly (by eg. user_dict) coupled. However, the logged-in user info updates are not currently updated from the initial_data by other code, so you'll need to add this manually, which I suspect won't be as simple as a dict update.
So, if you split this into 3 commits and address the inline comments, and add/adjust a test for the handler method, I think at least the first 2 commits could be quickly mergeable if you focus on those first. If the first two commits are clean and you re-push then I could re-review while you consider the third more. If the 3rd is also ready that would be fine too of course - just emphasizing that we could merge incrementally, which would help decrease turnaround time :)
zulipterminal/api_types.py
Outdated
class Person(TypedDict): | ||
user_id: int | ||
full_name: str | ||
timezone: str | ||
display_email: str | ||
email: str | ||
role: int | ||
avatar_url: str | ||
avatar_version: int | ||
profile_data: Dict[str, str] |
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 does provide a set of names which the person object may contain, so supports type checking at some level.
You seem to be missing some possible elements of this, though? If some aren't used right now then we can comment them out, with a note to indicate that we don't handle them. That will cause mypy to alert us if we use fields that aren't explicitly listed.
(I referred to https://zulip.com/api/get-events#realm_user-update)
I know the API refers to it as person, but I think we should use a more specific name for the type here given the module namespace, maybe even RealmUserEventPerson
to indicate it's only used there.
For now I would be happy with the current format with the additional elements, perhaps with blank lines between each group of fields. These type additions would be fine in a separate early commit before you use them.
However, it also doesn't represent the actual API, where eg. if we get full_name then nothing other than the user_id common to all cases should be present? So we should be able to encode that in the typing here. Closer to merging we could consider adjusting the separate commit to improve the typing as I mention above, or even after this PR.
zulipterminal/model.py
Outdated
@@ -8,6 +8,7 @@ | |||
from concurrent.futures import Future, ThreadPoolExecutor, wait | |||
from copy import deepcopy | |||
from datetime import datetime | |||
from pprint import pprint |
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.
Debug?
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.
Yeah, it was to print the events containing realm user update. As this is still in draft stage, I thought of keeping it for reference for anybody testing this.
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.
If you think it's useful, it's good to leave such things in a separate followup commit, since then cleaning up should be easier and you can label the commit appropriately.
22a865f
to
9f75b0f
Compare
Hello @mounilKshah, it seems like you have referenced #988 in your pull request description, but you have not referenced them in your commit message description(s). Referencing an issue in a commit message automatically closes the corresponding issue when the commit is merged, which makes the issue tracker easier to manage. Please run An example of a correctly-formatted commit:
To learn how to write a great commit message, please refer to our guide. |
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.
@mounilKshah This is nicely split and tidier, and I appreciate you pushing the changes, but as per inline notes the api types don't seem to match the docs, and I think there was confusion over how to handle what I meant by only 'update' ops.
The above and a test for the new function in the 2nd commit are necessary to get those merged ahead of the 3rd commti.
For the part related to the third commit, this changes initial_data but doesn't go further as per comments in my last review. Look for where the various 'active' user data that could get updated by these events is first extracted from initial_data, and think how we might go from there.
zulipterminal/api_types.py
Outdated
@@ -167,6 +167,35 @@ class ReactionEvent(TypedDict): | |||
message_id: int | |||
|
|||
|
|||
class RealmUserEventPerson(TypedDict): |
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.
The layout looks better here and I can see you've extended them, but they don't seem to match the API still?
The API link from the last review has more fields than you have here, and I'm not seeing display_email or profile_data? Did you seem them elsewhere? Do the docs need updating?
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.
display_email
and profile_data
are actually present in the commit. Did you mean to say delivery_email
instead of display_email
?
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 don't see display_email
in the API, or profile_data
, but they were in the commit.
zulipterminal/model.py
Outdated
@@ -8,6 +8,7 @@ | |||
from concurrent.futures import Future, ThreadPoolExecutor, wait | |||
from copy import deepcopy | |||
from datetime import datetime | |||
from pprint import pprint |
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.
If you think it's useful, it's good to leave such things in a separate followup commit, since then cleaning up should be easier and you can label the commit appropriately.
9f75b0f
to
90a6c66
Compare
90a6c66
to
715fc79
Compare
This commit contains types for RealmUserEvent and RealmUserEventPerson added to api_types.
715fc79
to
58effe5
Compare
|
||
role: int | ||
|
||
email: str |
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.
In comparing the fields that can be updated, this one stands out as different from the remaining one field possible (custom_profile_field), unless I'm missing another use of email?
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.
The email
field does not exist under RealmUserEventPerson
, rather we get new_email
from the API. However, in model.initial_data["realm_users"]
, we use email
and not new_email
. Hence, in the updated code (under Model._handle_realm_user_events()
, where we now have a conditional for replacing the new_email
key with the email
key, mypy returns an error.
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.
Ah, I see your point. Can we avoid that by moving the conditional into the loop where we've found the user-id?
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.
OK, let me just read the code again, I may just merge these first two commits roughly as they are.
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.
@mounilKshah Tests look good, left a few thoughts to make them clearer 👍
API spec isn't critical, but unsure if there's something which has confused your aligning these values with those in the docs.
tests/model/test_model.py
Outdated
"person, changed_details", | ||
[ | ||
( | ||
{"user_id": 11, "full_name": "New Full Name"}, |
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.
The user_id is common in all cases, so let's specify and build it in the test function.
Rather than setting the variable in the test function, you can alternatively list it as a default argument value, as long as it's a non-mutable value.
"delivery_email", | ||
), | ||
], | ||
ids=[ |
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.
There a lot of test cases & ids, so it's simpler to keep them inline - then later we wouldn't have to check where in each list to add/remove/edit them, or to move them around.
event = {"type": "realm_user", "op": "update", "id": 1000, "person": person} | ||
model._handle_realm_user_event(event) | ||
assert ( | ||
initial_data["realm_users"][1][changed_details] |
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'm guessing the 1
is the index into initial_data that corresponds to user_id=11
?
If that's the case, it would be more reliable to make that explicit in the test code, eg. if the initial data gets reordered at a later stage, this would make this test fail even though it's functionally correct?
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.
Okay, I'll add a comment for this 👍
This commit contains Model._handle_realm_user_event() which updates the meta data of the respective user in Model.initia_data["realm_users"]. It also contains test for this function in test_model.
This commit updates Model.initial_data when the realm_user: update event occurs for the current user.
58effe5
to
359dd01
Compare
Heads up @mounilKshah, we just merged some commits that conflict with the changes you made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the |
@mounilKshah Thanks for the updates here! I just merged the first two commits of this manually with some minor adjustments to avoid the need to add the "email" field 🎉 I think we'll likely need to do quite a lot of refactoring before other updates of this form, so the user updates aren't as critical right now. |
What does this PR do?
The PR is for handling any changes made with respect to the users' meta data ie, meta data of the current user and that of other users.
Fixes #988
Tested?
Commit flow
Notes & Questions