From 15e7580119900fddf0470020c245f36b136de3f1 Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Thu, 29 Aug 2024 14:01:07 +0200 Subject: [PATCH] Revert "fix: unread indicator logic" This reverts commit 0a29d99ae61241ed1d055eedc65ed7472cde107c. --- .../src/lib/channel.service.spec.ts | 28 ------------------- .../src/lib/channel.service.ts | 8 ++---- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/projects/stream-chat-angular/src/lib/channel.service.spec.ts b/projects/stream-chat-angular/src/lib/channel.service.spec.ts index 10c20d43..ce6dcb5d 100644 --- a/projects/stream-chat-angular/src/lib/channel.service.spec.ts +++ b/projects/stream-chat-angular/src/lib/channel.service.spec.ts @@ -2328,22 +2328,6 @@ describe('ChannelService', () => { expect(service.activeChannelUnreadCount).toBe(0); }); - it(`should set last read message id to undefined if unread count is 0`, () => { - const activeChannel = generateMockChannels()[0]; - activeChannel.id = 'next-active-channel'; - activeChannel.state.read[user.id] = { - last_read: new Date(), - last_read_message_id: 'last-read-message-id', - unread_messages: 0, - user: user, - }; - - service.setAsActiveChannel(activeChannel); - - expect(service.activeChannelLastReadMessageId).toBe(undefined); - expect(service.activeChannelUnreadCount).toBe(0); - }); - it('should be able to select empty channel as active channel', () => { const channel = generateMockChannels()[0]; channel.id = 'new-empty-channel'; @@ -2548,18 +2532,6 @@ describe('ChannelService', () => { expect(service.activeChannelLastReadMessageId).toBe('last-read-message'); expect(service.activeChannelUnreadCount).toBe(12); - - events$.next({ - eventType: 'notification.mark_unread', - event: { - channel_id: service.activeChannel?.id, - unread_messages: 0, - last_read_message_id: 'last-read-message', - } as Event, - }); - - expect(service.activeChannelLastReadMessageId).toBe(undefined); - expect(service.activeChannelUnreadCount).toBe(0); }); it('should halt marking the channel as read if an unread call was made in that session', async () => { diff --git a/projects/stream-chat-angular/src/lib/channel.service.ts b/projects/stream-chat-angular/src/lib/channel.service.ts index 32fede50..1f47d21b 100644 --- a/projects/stream-chat-angular/src/lib/channel.service.ts +++ b/projects/stream-chat-angular/src/lib/channel.service.ts @@ -557,14 +557,13 @@ export class ChannelService< const readState = channel.state.read[this.chatClientService.chatClient.user?.id || '']; this.activeChannelLastReadMessageId = readState?.last_read_message_id; - this.activeChannelUnreadCount = readState?.unread_messages || 0; if ( channel.state.latestMessages[channel.state.latestMessages.length - 1] - ?.id === this.activeChannelLastReadMessageId || - this.activeChannelUnreadCount === 0 + ?.id === this.activeChannelLastReadMessageId ) { this.activeChannelLastReadMessageId = undefined; } + this.activeChannelUnreadCount = readState?.unread_messages || 0; this.watchForActiveChannelEvents(channel); this.addChannel(channel); this.activeChannelSubject.next(channel); @@ -1514,9 +1513,6 @@ export class ChannelService< this.ngZone.run(() => { this.activeChannelLastReadMessageId = e.last_read_message_id; this.activeChannelUnreadCount = e.unread_messages; - if (this.activeChannelUnreadCount === 0) { - this.activeChannelLastReadMessageId = undefined; - } this.activeChannelSubject.next(this.activeChannel); }); })