Skip to content

Commit efc257a

Browse files
authored
Merge pull request #1180 from sendbird/feat/CLNP-4035
feat: Banned member doesn't affect to the ChannelSettings/Profile
2 parents e9820e6 + faeeb3f commit efc257a

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/modules/ChannelSettings/context/ChannelSettingsProvider.tsx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React, { ReactNode, useEffect, useState } from 'react';
2-
import { GroupChannel, GroupChannelUpdateParams } from '@sendbird/chat/groupChannel';
2+
import { GroupChannel, GroupChannelHandler, GroupChannelUpdateParams } from '@sendbird/chat/groupChannel';
33

44
import type { UserListItemProps } from '../../../ui/UserListItem';
55
import type { RenderUserProfileProps } from '../../../types';
66
import useSendbirdStateContext from '../../../hooks/useSendbirdStateContext';
77
import { UserProfileProvider } from '../../../lib/UserProfileContext';
88
import uuidv4 from '../../../utils/uuid';
99
import { useAsyncRequest } from '../../../hooks/useAsyncRequest';
10+
import compareIds from '../../../utils/compareIds';
1011

1112
interface ApplicationUserListQuery {
1213
limit?: number;
@@ -68,6 +69,7 @@ const ChannelSettingsProvider = ({
6869
const { config, stores } = useSendbirdStateContext();
6970
const { sdkStore } = stores;
7071
const { logger, onUserProfileMessage } = config;
72+
const [channelHandlerId, setChannelHandlerId] = useState<string>();
7173

7274
// hack to keep track of channel updates by triggering useEffect
7375
const [channelUpdateId, setChannelUpdateId] = useState(() => uuidv4());
@@ -94,7 +96,39 @@ const ChannelSettingsProvider = ({
9496
}
9597

9698
try {
97-
return await sdkStore.sdk.groupChannel.getChannel(channelUrl);
99+
if (channelHandlerId) {
100+
if (sdkStore.sdk?.groupChannel?.removeGroupChannelHandler) {
101+
logger.info('ChannelSettings: Removing message reciver handler', channelHandlerId);
102+
sdkStore.sdk.groupChannel.removeGroupChannelHandler(channelHandlerId);
103+
} else if (sdkStore.sdk?.groupChannel) {
104+
logger.error('ChannelSettings: Not found the removeGroupChannelHandler');
105+
}
106+
107+
setChannelHandlerId(undefined);
108+
}
109+
110+
// FIXME :: refactor below code by new state management protocol
111+
const channel = await sdkStore.sdk.groupChannel.getChannel(channelUrl);
112+
const channelHandler: GroupChannelHandler = {
113+
onUserLeft: (channel, user) => {
114+
if (compareIds(channel?.url, channelUrl)) {
115+
logger.info('ChannelSettings: onUserLeft', { channel, user });
116+
refresh();
117+
}
118+
},
119+
onUserBanned: (channel, user) => {
120+
if (compareIds(channel?.url, channelUrl) && channel.isGroupChannel()) {
121+
logger.info('ChannelSettings: onUserBanned', { channel, user });
122+
refresh();
123+
}
124+
},
125+
};
126+
127+
const newChannelHandlerId = uuidv4();
128+
sdkStore.sdk.groupChannel?.addGroupChannelHandler(newChannelHandlerId, new GroupChannelHandler(channelHandler));
129+
setChannelHandlerId(newChannelHandlerId);
130+
131+
return channel;
98132
} catch (error) {
99133
logger.error('ChannelSettings: fetching channel error:', error);
100134
throw error;

0 commit comments

Comments
 (0)