Skip to content

Commit 7e50027

Browse files
authored
Merge pull request #506 from GetStream/frozen-channels
Frozen channels
2 parents 0fc8e23 + 250a3c9 commit 7e50027

File tree

7 files changed

+54
-25
lines changed

7 files changed

+54
-25
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/message/message.component.spec.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -991,18 +991,6 @@ describe('MessageComponent', () => {
991991
expect(setAsActiveParentMessageSpy).toHaveBeenCalledWith(component.message);
992992
});
993993

994-
it(`shouldn't display reply count for parent messages if user doesn't have the necessary capability`, () => {
995-
component.message = { ...message, reply_count: 1 };
996-
component.enabledMessageActions = [];
997-
component.ngOnChanges({
998-
message: {} as SimpleChange,
999-
enabledMessageActions: {} as SimpleChange,
1000-
});
1001-
fixture.detectChanges();
1002-
1003-
expect(queryReplyCountButton()).toBeNull();
1004-
});
1005-
1006994
it('should display reply in thread icon, if user has the necessary capability', () => {
1007995
expect(queryReplyInThreadIcon()).not.toBeNull();
1008996

projects/stream-chat-angular/src/lib/message/message.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ export class MessageComponent
198198
}
199199
if (changes.message || changes.enabledMessageActions || changes.mode) {
200200
this.shouldDisplayThreadLink =
201-
!!this.message?.reply_count &&
202-
this.mode !== 'thread' &&
203-
this.enabledMessageActions.indexOf('send-reply') !== -1;
201+
!!this.message?.reply_count && this.mode !== 'thread';
204202
}
205203
if (changes.message || changes.mode) {
206204
this.areOptionsVisible = this.message

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)