Skip to content

Commit

Permalink
Merge pull request #479 from GetStream/empty-channel-last-read-message
Browse files Browse the repository at this point in the history
fix: selecting empty channel
  • Loading branch information
szuperaz authored Sep 25, 2023
2 parents 1f20464 + b25884f commit 85eccdc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions projects/stream-chat-angular/src/lib/channel.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2033,4 +2033,19 @@ describe('ChannelService', () => {

expect(service.activeChannelLastReadMessageId).toBe(undefined);
});

it('should be able to select empty channel as active channel', () => {
const channel = generateMockChannels()[0];
channel.id = 'new-empty-channel';
channel.state.messages = [];
channel.state.latestMessages = [];

service.setAsActiveChannel(channel);

const spy = jasmine.createSpy();
service.activeChannel$.subscribe(spy);

expect(spy).toHaveBeenCalledWith(channel);
expect(service.activeChannelLastReadMessageId).toBeUndefined();
});
});
2 changes: 1 addition & 1 deletion projects/stream-chat-angular/src/lib/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ export class ChannelService<
]?.last_read_message_id;
if (
channel.state.latestMessages[channel.state.latestMessages.length - 1]
.id === this.activeChannelLastReadMessageId
?.id === this.activeChannelLastReadMessageId
) {
this.activeChannelLastReadMessageId = undefined;
}
Expand Down

0 comments on commit 85eccdc

Please sign in to comment.