Skip to content

Commit

Permalink
fix: reload channel state if frozen flag changed
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Nov 14, 2023
1 parent c807d2e commit 50884c4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,10 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
break;
case 'channel.updated':
if (event.channel) {
const isFrozenChanged = event.channel?.frozen !== undefined && event.channel.frozen !== channel.data?.frozen;
if (isFrozenChanged) {
this.query({}, 'latest');
}
channel.data = {
...event.channel,
hidden: event.channel?.hidden ?? channel.data?.hidden,
Expand Down
17 changes: 17 additions & 0 deletions test/unit/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { generateMsg } from './test-utils/generateMessage';
import { generateUser } from './test-utils/generateUser';
import { getClientWithUser } from './test-utils/getClient';
import { getOrCreateChannelApi } from './test-utils/getOrCreateChannelApi';
import sinon from 'sinon';

import { StreamChat } from '../../src/client';
import { ChannelState } from '../../src';
Expand Down Expand Up @@ -478,6 +479,22 @@ describe('Channel _handleChannelEvent', function () {
expect(channel.data.hidden).eq(true);
});

it('should update the frozen flag and reload channel state to update `own_capabilities`', () => {
const event = {
channel: { frozen: true },
type: 'channel.updated',
};
channel.data.frozen = false;
sinon.spy(channel, 'query');

channel._handleChannelEvent(event);
expect(channel.data.frozen).eq(true);
expect(channel.query.called).to.be.true;

channel._handleChannelEvent(event);
expect(channel.query.calledOnce).to.be.true;
});

it('should update channel member ban state on user.banned and user.unbanned events', () => {
const user = { id: 'user_id' };
const shadowBanEvent = {
Expand Down

0 comments on commit 50884c4

Please sign in to comment.