Skip to content

Commit 6fa6829

Browse files
authored
feat: update channel's blocked property on channel.hidden and channel.visible events (#1610)
1 parent fa5dcf2 commit 6fa6829

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

src/channel.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,13 +2106,21 @@ export class Channel {
21062106
}
21072107
break;
21082108
case 'channel.hidden':
2109-
channel.data = { ...channel.data, hidden: true };
2109+
channel.data = {
2110+
...channel.data,
2111+
blocked: !!event.channel?.blocked,
2112+
hidden: true,
2113+
};
21102114
if (event.clear_history) {
21112115
channelState.clearMessages();
21122116
}
21132117
break;
21142118
case 'channel.visible':
2115-
channel.data = { ...channel.data, hidden: false };
2119+
channel.data = {
2120+
...channel.data,
2121+
blocked: !!event.channel?.blocked,
2122+
hidden: false,
2123+
};
21162124
this.getClient().offlineDb?.handleChannelVisibilityEvent({ event });
21172125
break;
21182126
case 'user.banned':

test/unit/channel.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,9 @@ describe('Channel _handleChannelEvent', function () {
869869

870870
it('should mark channel visible on channel.visible event', () => {
871871
const channelVisibleEvent = {
872+
channel: {
873+
blocked: false,
874+
},
872875
type: 'channel.visible',
873876
cid: 'messaging:id',
874877
channel_id: 'id',
@@ -885,19 +888,69 @@ describe('Channel _handleChannelEvent', function () {
885888
created_at: '2023-05-24T09:20:43.986615426Z',
886889
};
887890
channel.data.hidden = true;
891+
channel.data.blocked = true;
888892

889893
channel._handleChannelEvent(channelVisibleEvent);
890894
expect(channel.data.hidden).eq(false);
895+
expect(channel.data.blocked).eq(false);
896+
});
897+
898+
it('should treat blocked separately from hidden on channel.visible event', () => {
899+
const channelVisibleEvent = {
900+
channel: {
901+
blocked: true,
902+
},
903+
type: 'channel.visible',
904+
cid: 'messaging:id',
905+
channel_id: 'id',
906+
channel_type: 'messaging',
907+
user: {
908+
id: 'admin',
909+
role: 'admin',
910+
created_at: '2022-03-08T09:46:56.840739Z',
911+
updated_at: '2022-03-15T08:30:09.796926Z',
912+
last_active: '2023-05-24T09:20:31.041292724Z',
913+
banned: false,
914+
online: true,
915+
},
916+
created_at: '2023-05-24T09:20:43.986615426Z',
917+
};
918+
channel.data.hidden = true;
919+
channel.data.blocked = true;
920+
921+
channel._handleChannelEvent(channelVisibleEvent);
922+
expect(channel.data.hidden).eq(false);
923+
expect(channel.data.blocked).eq(true);
891924
});
892925

893926
it('should mark channel hidden on channel.hidden event', () => {
894927
const channelVisibleEvent = {
928+
channel: {
929+
blocked: true,
930+
},
931+
type: 'channel.hidden',
932+
};
933+
channel.data.hidden = false;
934+
channel.data.blocked = false;
935+
936+
channel._handleChannelEvent(channelVisibleEvent);
937+
expect(channel.data.hidden).eq(true);
938+
expect(channel.data.blocked).eq(true);
939+
});
940+
941+
it('should treat blocked separately from hidden on channel.hidden event', () => {
942+
const channelVisibleEvent = {
943+
channel: {
944+
blocked: false,
945+
},
895946
type: 'channel.hidden',
896947
};
897948
channel.data.hidden = false;
949+
channel.data.blocked = false;
898950

899951
channel._handleChannelEvent(channelVisibleEvent);
900952
expect(channel.data.hidden).eq(true);
953+
expect(channel.data.blocked).eq(false);
901954
});
902955

903956
it('should update the frozen flag and reload channel state to update `own_capabilities`', () => {

0 commit comments

Comments
 (0)