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

fix: channel unreadCount to be set as 0 when notification.mark_read event is dispatched [CRNS - 433] #914

Merged
merged 2 commits into from
Feb 28, 2022

Conversation

khushal87
Copy link
Member

CLA

  • I have signed the Stream CLA (required).
  • Code changes are tested

Description of the changes, What, Why, and How?

When we use the markAllRead method, we get the event notification.mark_read, which updates the total_unread_count, but not the channel.state.unreadCount. This PR solved the above issue.

Changelog

  • Added the logic to set the activeChannel state's unreadCount to 0.
  • Added tests for the same.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2022

Size Change: +209 B (0%)

Total Size: 285 kB

Filename Size Change
dist/browser.es.js 62.3 kB +50 B (0%)
dist/browser.full-bundle.min.js 34.5 kB +26 B (0%)
dist/browser.js 62.9 kB +44 B (0%)
dist/index.es.js 62.3 kB +45 B (0%)
dist/index.js 63 kB +44 B (0%)

compressed-size-action

AnatolyRugalev
AnatolyRugalev previously approved these changes Feb 24, 2022
src/client.ts Outdated
@@ -1184,6 +1184,11 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
this.mutedUsers = event.me.mutes;
}

if (event.type === 'notification.mark_read') {
const activeChannelKeys = Object.keys(this.activeChannels);
activeChannelKeys.map((activeChannelKey) => (this.activeChannels[activeChannelKey].state.unreadCount = 0));
Copy link
Contributor

@peterdeme peterdeme Feb 26, 2022

Choose a reason for hiding this comment

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

Shouldn't this be .forEach(activeChannelKey =>?

Suggested change
activeChannelKeys.map((activeChannelKey) => (this.activeChannels[activeChannelKey].state.unreadCount = 0));
activeChannelKeys.forEach(activeChannelKey => this.activeChannels[activeChannelKey].state.unreadCount = 0);

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's a better method to handle this case. Thanks, @peterdeme 😄

@khushal87 khushal87 merged commit 667969e into master Feb 28, 2022
@khushal87 khushal87 deleted the khushal87-crns-433-1 branch February 28, 2022 10:52
@github-actions github-actions bot mentioned this pull request Mar 7, 2022
arnautov-anton added a commit that referenced this pull request Apr 15, 2022
…k_read event is dispatched [CRNS - 433] (#914)"

This reverts commit 667969e.
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.

3 participants