-
-
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
model: Fetch realm emoji using events #827
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.
@mkp6781 Thanks for working on this, it looks like this is on the right path 👍
Did you open this to avoid having the other PR based on your master branch?
We may need special behavior with the zulip emoji - I'm not sure if that can be replaced and if we need to handle that specially locally or not.
The tests are running - and failing right now. This looks like only one or two issues, so you might find this easy to fix, either via travis or running pytest locally (see the pytest tips section).
It would be great if you could write some tests for this - these events aren't really that common to test manually on a normal server.
I have fixed the tests by adding
I am working on writing the test for |
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.
@mkp6781 Thanks for the update - you can just add a note here requesting review, or in principle adjusting the labels (if zulipbot is working). This feedback is a little longer due to giving some ideas about commit structure. I've only reviewed the net changes, and will review in more detail in a later iteration.
You have 6 commits now, but myself and other contributors don't really need to see the intermediate steps you're taking (unless you want to discuss those intermediate stages while working on it), particularly if you're adding/removing debug statements or correcting some other change from a previous commit. Given you have the same commit title for each commit, did you mean to have them all as one commit? If so you may want to investigate --amend
in future. However, there is nothing wrong with multiple commits with temporary names that you can later bring together - it's easier to squash commits together than split them apart, generally.
For now, in terms of adjusting multiple commits, I'd recommend an interactive rebase to adjust your commits to tell a "story" of the changes you're making and why. As a pointer here, it'd be useful to have commits which make minimum changes to achieve:
- migrate from using fetch to using the value possible in the initial_data
- add event handling
After each commit linting/tests should pass, so the tests can be updated and extended for any new functionality in each commit.
You could also consider separate additional commits to refactor the code, to prepare for the related change, such as generalizing the name/parameterization of the emoji code.
If commits are functionally isolated in a sequence like this, this also means that independent groups of commits can sometimes be merged separately first, from the same PR, which can make discussion of the later commits and functionality easier.
@zulipbot claim |
@mkp6781 I've assigned the issue to you manually for now, since zulipbot appears to be unresponsive. |
Hi |
@zulipbot add "PR needs review" |
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.
@mkp6781 Thanks for your work on this! I've left some comments below - let me know if you need more guidance 👍
@zulipbot add "PR needs review" |
Thank you for the elaborate description regarding the commit structure. I have modified my commits accordingly. I have also made the changes mentioned. |
@zulipbot remove "PR needs update" |
@zulipbot add "PR needs review" |
@zulipbot remove "PR awaiting update" |
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.
@mkp6781 This older PR mainly needs a rebase and could benefit from some cleaning up of the tests using fixtures - otherwise we're going to end up with separate emoji data unused or duplicated - but otherwise it looks good to go 👍
The only aspect that comes to mind is that I'm unsure if there are consequences to removing emoji (eg. modifying messages to remove them being used on old messages, or just limiting them on new ones?) - I'm not sure if this is documented in the API or elsewhere.
tests/model/test_model.py
Outdated
assert model.active_emoji_data == OrderedDict(sorted( | ||
{**unicode_emojis, **custom_emojis, **zulip_emoji}.items(), | ||
key=lambda e: e[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.
This and the two asserts below it are related. Given you add more asserts here, you could keep this assert too?
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.
We can use the zulip_emoji
fixture now though.
tests/model/test_model.py
Outdated
"realm_emoji": { | ||
"100": { | ||
"id": "100", | ||
"name": "urwid", | ||
"deactivated": True | ||
}, | ||
"2": { | ||
"id": "2", | ||
"name": "green_tick", | ||
"deactivated": False | ||
}, | ||
"202020": { | ||
"id": "202020", | ||
"name": "joker", | ||
"deactivated": True | ||
}, | ||
"39": { | ||
"id": "39", | ||
"name": "zulip", | ||
"deactivated": 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.
It's not clear reading just the test asserts, how they relate to the original asserts in the initial data. We could extend the comments of course, however:
Since we get the full set of emoji each time, to improve test clarity this could be the same original dict (fixture) as you might get in the initial_data (embedded in this response), but with one variation in each of a number of parametrize? This response itself can be built in the test from a template and an approach used like in other tests where we use a to_vary*
parameter.
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 not sure about implementing a template for the emoji data. But I have modified the test to use the realm_emoji
fixture and the to_vary*
parameter.
This response itself can be built in the test from a template
Could you explain this a bit more!
I have rebased the PR and made changes to the tests. Maybe there are a few more changes to be made which can be done in the next iteration.
I will think about this tomorrow. |
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.
@mkp6781 The test structure looks much better with these changes 👍 A few minor points to consider, but this is essentially ready :)
For the final point in my last review, I'm not sure what the webapp does, if anything, but I'd suggest that could be something to research for a follow-up. If you don't want to take it up straight away, please make sure to file an issue for
tests/model/test_model.py
Outdated
if ( | ||
to_vary_in_realm_emoji['deactivated'] | ||
and ( | ||
emoji_name not in unicode_emojis | ||
and emoji_name not in zulip_emoji | ||
) | ||
): |
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 may be more clearly expressed by using an intermediate boolean variable which you can then use like if emoji_should_be_active:
or similar. That then clearly expresses what the complex expression represents.
The webapp doesn't make any changes to old messages when a realm emoji is added/removed and ZT follows the same behaviour. |
@zulipbot add "PR needs review " |
ERROR: Label "PR needs review " does not exist and was thus not added to this pull request. |
@zulipbot add "PR needs review" |
The existing code to obtain active_emoji_data is used in the generate_all_emoji_data() function to create the dictionary containing all the active emojis whenever required. zulip_extra_emoji fixture also extracted. Tests added for new function.
Earlier, an API call to get_realm_emoji() was used to fetch changes to realm emoji. This commit allows the initial update of realm emoji directly from initial_data. New test fixtures for `realm_emojis` and `realm_emojis_data` are added. Tests for `generate_all_emoji_data` modified to check various cases: * Adding new realm emoji. * Removing deactivated realm emoji. * Restoring unicode emoji with same name as a deactivated realm emoji. * Replacing existing unicode emoji when realm emoji with same name is added. * Ensuring zulip emoji is always of type `zulip_extra_emoji`.
This commit adds event handler for update of realm emoji within a ZT session. Tests added. Fixes zulip#809.
Defined class RealmEmojiData to represent realm emoji data more precisely with each key having value of a specific type.
@mkp6781 Just pushed a few minor changes and merging now 🎉 Ideas for follow-up:
|
Continues work on #825.
Processed
initial_data['realm_emoji]
and setcustom_emoji_data
according to the schema given byNamedEmojiData
.Similar processing for
realm_emoji_update
before updatingactive_emoji_data
in_handle_update_emoji_event
.Also, the deactivated realm emojis are removed from
active_emoji_data
.