Skip to content

Commit b25884f

Browse files
committed
fix: selecting empty channel
1 parent 1f20464 commit b25884f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

projects/stream-chat-angular/src/lib/channel.service.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,4 +2033,19 @@ describe('ChannelService', () => {
20332033

20342034
expect(service.activeChannelLastReadMessageId).toBe(undefined);
20352035
});
2036+
2037+
it('should be able to select empty channel as active channel', () => {
2038+
const channel = generateMockChannels()[0];
2039+
channel.id = 'new-empty-channel';
2040+
channel.state.messages = [];
2041+
channel.state.latestMessages = [];
2042+
2043+
service.setAsActiveChannel(channel);
2044+
2045+
const spy = jasmine.createSpy();
2046+
service.activeChannel$.subscribe(spy);
2047+
2048+
expect(spy).toHaveBeenCalledWith(channel);
2049+
expect(service.activeChannelLastReadMessageId).toBeUndefined();
2050+
});
20362051
});

projects/stream-chat-angular/src/lib/channel.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ export class ChannelService<
422422
]?.last_read_message_id;
423423
if (
424424
channel.state.latestMessages[channel.state.latestMessages.length - 1]
425-
.id === this.activeChannelLastReadMessageId
425+
?.id === this.activeChannelLastReadMessageId
426426
) {
427427
this.activeChannelLastReadMessageId = undefined;
428428
}

0 commit comments

Comments
 (0)