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

store: Add realmEmoji, initialized from initial snapshot and updated with its event #394

Merged
merged 3 commits into from
Nov 20, 2023

Conversation

chrisbobbe
Copy link
Collaborator

No description provided.

@chrisbobbe chrisbobbe added the a-api Implementing specific parts of the Zulip server API label Nov 18, 2023
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks! Small comments below.

@@ -16,6 +16,7 @@ sealed class Event {

factory Event.fromJson(Map<String, dynamic> json) {
switch (json['type'] as String) {
case 'realm_emoji': return RealmEmojiUpdateEvent.fromJson(json);
Copy link
Member

Choose a reason for hiding this comment

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

It's true that currently the only possible op for type realm_emoji is update. But the presence of that op field is a way of explicitly leaving space for potentially adding other op values for the same type in the future. So let's respect that future-proofing that the API spec has given itself: check for op the same as we do for other types, and if it's not the op we expect then call it an unexpected event.

(Fine to skip the intermediate base class, though.)

Comment on lines 229 to 231
if (event is HeartbeatEvent) {
if (event is RealmEmojiUpdateEvent) {
Copy link
Member

Choose a reason for hiding this comment

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

If you put this anywhere other than the top of the list, then it won't have to touch any extra lines :-)

I'm happy to have the heartbeat at the top, as it's a boring no-op that exists for the sake of the transport protocol. This could go right after, before AlertWordsEvent, to match the order in events.dart.

Comment on lines 233 to 234
realmEmoji..clear()..addAll(event.realmEmoji);
} else if (event is HeartbeatEvent) {
Copy link
Member

Choose a reason for hiding this comment

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

Should call notifyListeners, no?

if (event is HeartbeatEvent) {
if (event is RealmEmojiUpdateEvent) {
assert(debugLog("server event: realm_emoji/update"));
realmEmoji..clear()..addAll(event.realmEmoji);
Copy link
Member

Choose a reason for hiding this comment

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

Since we already have the new set of emoji in the form of a map, we might as well use that map rather than copy it into the existing one: realmEmoji = event.realmEmoji.

@chrisbobbe
Copy link
Collaborator Author

Thanks for the review! Revision pushed.

@gnprice
Copy link
Member

gnprice commented Nov 20, 2023

Thanks! Looks good; merging.

@gnprice gnprice merged commit 8f67079 into zulip:main Nov 20, 2023
1 check passed
@chrisbobbe chrisbobbe deleted the pr-realm-emoji branch November 20, 2023 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-api Implementing specific parts of the Zulip server API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants