Skip to content

Commit 0b935a9

Browse files
authored
feat: dispatch capabilties.changed event on partial update if own_capabilties are changed (#1230)
1 parent 069870f commit 0b935a9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/channel.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,19 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
398398
this._channelURL(),
399399
update,
400400
);
401+
402+
const areCapabilitiesChanged =
403+
[...(data.channel.own_capabilities || [])].sort().join() !==
404+
[...(Array.isArray(this.data?.own_capabilities) ? (this.data?.own_capabilities as string[]) : [])].sort().join();
401405
this.data = data.channel;
406+
// If the capabiltities are changed, we trigger the `capabilities.changed` event.
407+
if (areCapabilitiesChanged) {
408+
this.getClient().dispatchEvent({
409+
type: 'capabilities.changed',
410+
cid: this.cid,
411+
own_capabilities: data.channel.own_capabilities,
412+
});
413+
}
402414
return data;
403415
}
404416

0 commit comments

Comments
 (0)