Skip to content

Commit

Permalink
Merge pull request #506 from GetStream/frozen-channels
Browse files Browse the repository at this point in the history
Frozen channels
  • Loading branch information
szuperaz authored Nov 16, 2023
2 parents 0fc8e23 + 250a3c9 commit 7e50027
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 25 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"ngx-popperjs": "^12.2.2",
"pretty-bytes": "^5.6.0",
"rxjs": "^7.1.0",
"stream-chat": "^8.14.0",
"stream-chat": "^8.14.2",
"ts-node": "^10.2.1",
"tslib": "^2.3.0",
"uuidv4": "^6.2.12",
Expand Down
19 changes: 19 additions & 0 deletions projects/stream-chat-angular/src/lib/channel.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,25 @@ describe('ChannelService', () => {
expect(updatedChannel!.data!.hidden).toBeDefined();
});

it('should emit changed channel if `capabilities.changed` dispatched', async () => {
await init();
let channel!: Channel<DefaultStreamChatGenerics>;
service.activeChannel$.pipe(first()).subscribe((c) => (channel = c!));
const spy = jasmine.createSpy();
service.channels$.subscribe(spy);
channel.data!.own_capabilities = ['send-message'];
(channel as MockChannel).handleEvent('capabilities.changed', {
type: 'capabilities.changed',
cid: channel.cid,
});

const channels = spy.calls.mostRecent().args[0] as Channel[];

const updatedChannel = channels.find((c) => c.cid === channel.cid);

expect(updatedChannel!.data!.own_capabilities).toEqual(['send-message']);
});

it('should call #customChannelUpdatedHandler, if updated and handler is provided', async () => {
await init();
let channel!: Channel<DefaultStreamChatGenerics>;
Expand Down
23 changes: 22 additions & 1 deletion projects/stream-chat-angular/src/lib/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ChannelResponse,
ChannelSort,
Event,
EventTypes,
FormatMessageResponse,
Message,
MessageResponse,
Expand Down Expand Up @@ -1521,7 +1522,9 @@ export class ChannelService<

private watchForChannelEvents(channel: Channel<T>) {
const unsubscribe = channel.on((event: Event<T>) => {
switch (event.type) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const type = event.type as EventTypes | 'capabilities.changed';
switch (type) {
case 'message.new': {
this.ngZone.run(() => {
if (this.customNewMessageHandler) {
Expand Down Expand Up @@ -1624,6 +1627,24 @@ export class ChannelService<
});
break;
}
case 'capabilities.changed': {
this.ngZone.run(() => {
const cid = event.cid;
if (cid) {
const currentChannels = this.channelsSubject.getValue();
const index = currentChannels?.findIndex((c) => c.cid === cid);
if (index !== -1 && index !== undefined) {
this.channelsSubject.next([...currentChannels!]);
if (cid === this.activeChannelSubject.getValue()?.cid) {
this.activeChannelSubject.next(
this.activeChannelSubject.getValue()
);
}
}
}
});
break;
}
}
});
this.channelSubscriptions[channel.cid] = unsubscribe.unsubscribe;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -991,18 +991,6 @@ describe('MessageComponent', () => {
expect(setAsActiveParentMessageSpy).toHaveBeenCalledWith(component.message);
});

it(`shouldn't display reply count for parent messages if user doesn't have the necessary capability`, () => {
component.message = { ...message, reply_count: 1 };
component.enabledMessageActions = [];
component.ngOnChanges({
message: {} as SimpleChange,
enabledMessageActions: {} as SimpleChange,
});
fixture.detectChanges();

expect(queryReplyCountButton()).toBeNull();
});

it('should display reply in thread icon, if user has the necessary capability', () => {
expect(queryReplyInThreadIcon()).not.toBeNull();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ export class MessageComponent
}
if (changes.message || changes.enabledMessageActions || changes.mode) {
this.shouldDisplayThreadLink =
!!this.message?.reply_count &&
this.mode !== 'thread' &&
this.enabledMessageActions.indexOf('send-reply') !== -1;
!!this.message?.reply_count && this.mode !== 'thread';
}
if (changes.message || changes.mode) {
this.areOptionsVisible = this.message
Expand Down
5 changes: 4 additions & 1 deletion projects/stream-chat-angular/src/lib/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export const generateMockMessages = (offset = 0, isOlder = false) => {
};

export type MockChannel = Channel<DefaultStreamChatGenerics> & {
handleEvent: (name: EventTypes, payload?: any) => void;
handleEvent: (
name: EventTypes | 'capabilities.changed',
payload?: any
) => void;
};

export const generateMockChannels = (length = 25) => {
Expand Down

0 comments on commit 7e50027

Please sign in to comment.