Skip to content

Commit

Permalink
Revert "fix: unread indicator logic"
Browse files Browse the repository at this point in the history
This reverts commit 0a29d99.
  • Loading branch information
szuperaz committed Aug 29, 2024
1 parent 7c8b6c6 commit 15e7580
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
28 changes: 0 additions & 28 deletions projects/stream-chat-angular/src/lib/channel.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<DefaultStreamChatGenerics>,
});

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 () => {
Expand Down
8 changes: 2 additions & 6 deletions projects/stream-chat-angular/src/lib/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
})
Expand Down

0 comments on commit 15e7580

Please sign in to comment.