Skip to content

Commit 250a3c9

Browse files
committed
fix: update UI when channel frozen state changes
in progress integrate capabilitied.changed event update stream-chat
1 parent 1ff2fc7 commit 250a3c9

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
"ngx-popperjs": "^12.2.2",
127127
"pretty-bytes": "^5.6.0",
128128
"rxjs": "^7.1.0",
129-
"stream-chat": "^8.14.0",
129+
"stream-chat": "^8.14.2",
130130
"ts-node": "^10.2.1",
131131
"tslib": "^2.3.0",
132132
"uuidv4": "^6.2.12",

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,25 @@ describe('ChannelService', () => {
800800
expect(updatedChannel!.data!.hidden).toBeDefined();
801801
});
802802

803+
it('should emit changed channel if `capabilities.changed` dispatched', async () => {
804+
await init();
805+
let channel!: Channel<DefaultStreamChatGenerics>;
806+
service.activeChannel$.pipe(first()).subscribe((c) => (channel = c!));
807+
const spy = jasmine.createSpy();
808+
service.channels$.subscribe(spy);
809+
channel.data!.own_capabilities = ['send-message'];
810+
(channel as MockChannel).handleEvent('capabilities.changed', {
811+
type: 'capabilities.changed',
812+
cid: channel.cid,
813+
});
814+
815+
const channels = spy.calls.mostRecent().args[0] as Channel[];
816+
817+
const updatedChannel = channels.find((c) => c.cid === channel.cid);
818+
819+
expect(updatedChannel!.data!.own_capabilities).toEqual(['send-message']);
820+
});
821+
803822
it('should call #customChannelUpdatedHandler, if updated and handler is provided', async () => {
804823
await init();
805824
let channel!: Channel<DefaultStreamChatGenerics>;

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
ChannelResponse,
1616
ChannelSort,
1717
Event,
18+
EventTypes,
1819
FormatMessageResponse,
1920
Message,
2021
MessageResponse,
@@ -1521,7 +1522,9 @@ export class ChannelService<
15211522

15221523
private watchForChannelEvents(channel: Channel<T>) {
15231524
const unsubscribe = channel.on((event: Event<T>) => {
1524-
switch (event.type) {
1525+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
1526+
const type = event.type as EventTypes | 'capabilities.changed';
1527+
switch (type) {
15251528
case 'message.new': {
15261529
this.ngZone.run(() => {
15271530
if (this.customNewMessageHandler) {
@@ -1624,6 +1627,24 @@ export class ChannelService<
16241627
});
16251628
break;
16261629
}
1630+
case 'capabilities.changed': {
1631+
this.ngZone.run(() => {
1632+
const cid = event.cid;
1633+
if (cid) {
1634+
const currentChannels = this.channelsSubject.getValue();
1635+
const index = currentChannels?.findIndex((c) => c.cid === cid);
1636+
if (index !== -1 && index !== undefined) {
1637+
this.channelsSubject.next([...currentChannels!]);
1638+
if (cid === this.activeChannelSubject.getValue()?.cid) {
1639+
this.activeChannelSubject.next(
1640+
this.activeChannelSubject.getValue()
1641+
);
1642+
}
1643+
}
1644+
}
1645+
});
1646+
break;
1647+
}
16271648
}
16281649
});
16291650
this.channelSubscriptions[channel.cid] = unsubscribe.unsubscribe;

projects/stream-chat-angular/src/lib/mocks/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ export const generateMockMessages = (offset = 0, isOlder = false) => {
4949
};
5050

5151
export type MockChannel = Channel<DefaultStreamChatGenerics> & {
52-
handleEvent: (name: EventTypes, payload?: any) => void;
52+
handleEvent: (
53+
name: EventTypes | 'capabilities.changed',
54+
payload?: any
55+
) => void;
5356
};
5457

5558
export const generateMockChannels = (length = 25) => {

0 commit comments

Comments
 (0)