Skip to content

Commit bd32338

Browse files
committed
fix: allow adding and removing channels without calling init
1 parent b36b6fc commit bd32338

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ export class ChannelService<
958958
*/
959959
addChannel(channel: Channel<T>) {
960960
if (!this.channelManager) {
961-
throw new Error('Channel service not initialized');
961+
this.createChannelManager({ eventHandlerOverrides: undefined });
962962
}
963963
if (!this.channels.find((c) => c.cid === channel.cid)) {
964964
this.channelManager?.setChannels(
@@ -977,7 +977,7 @@ export class ChannelService<
977977
*/
978978
removeChannel(cid: string) {
979979
if (!this.channelManager) {
980-
throw new Error('Channel service not initialized');
980+
this.createChannelManager({ eventHandlerOverrides: undefined });
981981
}
982982
const remainingChannels = this.channels.filter((c) => c.cid !== cid);
983983

@@ -1878,6 +1878,9 @@ export class ChannelService<
18781878
}: {
18791879
eventHandlerOverrides?: ChannelManagerEventHandlerOverrides<T>;
18801880
}) {
1881+
if (this.channelManager) {
1882+
this.destroyChannelManager();
1883+
}
18811884
this.channelManager = new ChannelManager({
18821885
client: this.chatClientService.chatClient,
18831886
options: {

0 commit comments

Comments
 (0)