Skip to content

Commit

Permalink
fix: channel unreadCount to be set as 0 when notification.mark_read e…
Browse files Browse the repository at this point in the history
…vent is dispatched [CRNS - 433] (#914)
  • Loading branch information
khushal87 committed Feb 28, 2022
1 parent 75ebc95 commit 667969e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.forEach((activeChannelKey) => (this.activeChannels[activeChannelKey].state.unreadCount = 0));
}

if ((event.type === 'channel.deleted' || event.type === 'notification.channel_deleted') && event.cid) {
client.state.deleteAllChannelReference(event.cid);
this.activeChannels[event.cid]?._disconnect();
Expand Down
14 changes: 14 additions & 0 deletions test/unit/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ describe('Client userMuteStatus', function () {
expect(client.userMuteStatus('mute4')).not.to.be.ok;
expect(client.userMuteStatus('missingUser')).not.to.be.ok;
});

it('should update all active channel unread count to 0 when notification.mark_read event is called', function () {
client.activeChannels = { vish: { state: { unreadCount: 1 } }, vish2: { state: { unreadCount: 2 } } };
client.dispatchEvent({
type: 'notification.mark_read',
});

const unreadCountSum = Object.values(client.activeChannels).reduce(
(prevSum, currSum) => prevSum + currSum.state.unreadCount,
0,
);

expect(unreadCountSum).to.be.equal(0);
});
});

describe('Client connectUser', () => {
Expand Down

0 comments on commit 667969e

Please sign in to comment.