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

[CHAT-1565] Sync own_reactions in events #606

Merged
merged 5 commits into from
Feb 16, 2021

Conversation

AnatolyRugalev
Copy link
Contributor

@AnatolyRugalev AnatolyRugalev commented Feb 1, 2021

This PR fixes the issue of synchronizing own_reactions in incoming events.

The original problem comes from the fact that own_reactions field is not populated for each individual client when broadcasting the event. But fortunately, we already sync this data in the channel state, so replacing related fields in the event object seems like a reasonable solution.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2021

Size Change: -2.08 kB (0%)

Total Size: 212 kB

Filename Size Change
dist/browser.es.js 45.9 kB -440 B (0%)
dist/browser.full-bundle.min.js 27 kB -295 B (1%)
dist/browser.js 46.4 kB -454 B (0%)
dist/index.es.js 45.9 kB -438 B (0%)
dist/index.js 46.5 kB -450 B (0%)

compressed-size-action

@AnatolyRugalev AnatolyRugalev marked this pull request as ready for review February 1, 2021 14:51
src/channel_state.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@vishalnarkhede vishalnarkhede left a comment

Choose a reason for hiding this comment

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

@AnatolyRugalev So the change looks fine to me. I have a suggestion:

With current implementation we mutate the event object inside channelState class. And thats a little confusing. If we override the event object, I think it should be done in channel.ts, where we handle the event. So something like following:

_handleChannelEvent(event) {
  ...
  case 'reaction.new':
    if (event.reaction) {
      /**
       * richReactionsData = {
       *  latest_reactions: {},
       *  own_reactions: {},
       *  reactions_count: {}
       * }
       */
      const richReactionsData = s.addReaction(event.reaction, event.message);
      event.message = { ...event.message, ...richReactionsData};
    }
}

This is assuming we are shipping it with #602

@mahboubii what do you think?

@AnatolyRugalev
Copy link
Contributor Author

AnatolyRugalev commented Feb 2, 2021

@vishalnarkhede I was trying to do this by returning entire message from addReaction and removeReaction methods, but it turned out challenging with all this immutable stuff. Let's wait for #602 to merge and I will get back to addressing this point as you suggested 👍

@virdesai
Copy link
Contributor

virdesai commented Feb 5, 2021

@AnatolyRugalev heads up that #602 was just merged into master

@AnatolyRugalev
Copy link
Contributor Author

I am still working on this. More improvements are coming:

  • correct reaction_counts sync
  • on enforce_unique counters could go out of sync if we have more than 1 reaction from this user
  • some reactions sync code improvements

@AnatolyRugalev AnatolyRugalev force-pushed the 1565-own_reactions_in_events branch 2 times, most recently from f7746a3 to 18dcdb1 Compare February 9, 2021 13:34
@AnatolyRugalev
Copy link
Contributor Author

After some experimenting I came to the conclusion that we don't need to sync latest_reactions, reaction_counters and reaction_scores manually. It was tempting to do, but in some edge cases this just wouldn't work properly (e.g. reaction.updated event for a reaction that is not loaded to latest_reactions).

Incoming events contain this fields, so we simply update the message with them in the state. own_reactions field though needs to be synchronized manually because of the reasons given above.

@vishalnarkhede
Copy link
Contributor

I will review this tomorrow :)

Copy link
Contributor

@ferhatelmas ferhatelmas left a comment

Choose a reason for hiding this comment

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

LGTM

A bit harder to follow the call but dropped a lot of repetition, I think it's a great improvement in code quality.

@ferhatelmas
Copy link
Contributor

@AnatolyRugalev might want to update PR title since only own_reactions are synced.

@AnatolyRugalev AnatolyRugalev changed the title [CHAT-1565] Sync own_reactions, latest_reactions and reactions_count in events [CHAT-1565] Sync own_reactions in events Feb 12, 2021
@AnatolyRugalev AnatolyRugalev merged commit b172658 into master Feb 16, 2021
@delete-merged-branch delete-merged-branch bot deleted the 1565-own_reactions_in_events branch February 16, 2021 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants