Skip to content

Commit

Permalink
fix: allow adding and removing channels without calling init
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Feb 28, 2025
1 parent b36b6fc commit bd32338
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions projects/stream-chat-angular/src/lib/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ export class ChannelService<
*/
addChannel(channel: Channel<T>) {
if (!this.channelManager) {
throw new Error('Channel service not initialized');
this.createChannelManager({ eventHandlerOverrides: undefined });
}
if (!this.channels.find((c) => c.cid === channel.cid)) {
this.channelManager?.setChannels(
Expand All @@ -977,7 +977,7 @@ export class ChannelService<
*/
removeChannel(cid: string) {
if (!this.channelManager) {
throw new Error('Channel service not initialized');
this.createChannelManager({ eventHandlerOverrides: undefined });
}
const remainingChannels = this.channels.filter((c) => c.cid !== cid);

Expand Down Expand Up @@ -1878,6 +1878,9 @@ export class ChannelService<
}: {
eventHandlerOverrides?: ChannelManagerEventHandlerOverrides<T>;
}) {
if (this.channelManager) {
this.destroyChannelManager();
}
this.channelManager = new ChannelManager({
client: this.chatClientService.chatClient,
options: {
Expand Down

0 comments on commit bd32338

Please sign in to comment.