@sendbird/uikit-chat-hooks 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/channel/useGroupChannelListWithCollection.js +1 -1
- package/lib/commonjs/channel/useGroupChannelListWithCollection.js.map +1 -1
- package/lib/commonjs/channel/useGroupChannelListWithQuery.js +1 -1
- package/lib/commonjs/channel/useGroupChannelListWithQuery.js.map +1 -1
- package/lib/commonjs/channel/useGroupChannelMessages/useGroupChannelMessagesWithCollection.js +1 -2
- package/lib/commonjs/channel/useGroupChannelMessages/useGroupChannelMessagesWithCollection.js.map +1 -1
- package/lib/commonjs/channel/useGroupChannelMessages/useGroupChannelMessagesWithQuery.js +1 -1
- package/lib/commonjs/channel/useGroupChannelMessages/useGroupChannelMessagesWithQuery.js.map +1 -1
- package/lib/commonjs/common/useAppFeatures.js +8 -28
- package/lib/commonjs/common/useAppFeatures.js.map +1 -1
- package/lib/commonjs/handler/useChannelHandler.js +16 -5
- package/lib/commonjs/handler/useChannelHandler.js.map +1 -1
- package/lib/module/channel/useGroupChannelListWithCollection.js +1 -1
- package/lib/module/channel/useGroupChannelListWithCollection.js.map +1 -1
- package/lib/module/channel/useGroupChannelListWithQuery.js +1 -1
- package/lib/module/channel/useGroupChannelListWithQuery.js.map +1 -1
- package/lib/module/channel/useGroupChannelMessages/useGroupChannelMessagesWithCollection.js +1 -2
- package/lib/module/channel/useGroupChannelMessages/useGroupChannelMessagesWithCollection.js.map +1 -1
- package/lib/module/channel/useGroupChannelMessages/useGroupChannelMessagesWithQuery.js +1 -1
- package/lib/module/channel/useGroupChannelMessages/useGroupChannelMessagesWithQuery.js.map +1 -1
- package/lib/module/common/useAppFeatures.js +8 -27
- package/lib/module/common/useAppFeatures.js.map +1 -1
- package/lib/module/handler/useChannelHandler.js +17 -6
- package/lib/module/handler/useChannelHandler.js.map +1 -1
- package/lib/typescript/src/handler/useChannelHandler.d.ts +1 -2
- package/package.json +3 -3
- package/src/channel/useGroupChannelListWithCollection.ts +6 -11
- package/src/channel/useGroupChannelListWithQuery.ts +17 -22
- package/src/channel/useGroupChannelMessages/useGroupChannelMessagesWithCollection.ts +11 -17
- package/src/channel/useGroupChannelMessages/useGroupChannelMessagesWithQuery.ts +46 -51
- package/src/common/useAppFeatures.ts +5 -22
- package/src/handler/useChannelHandler.ts +11 -5
|
@@ -80,58 +80,53 @@ export const useGroupChannelMessagesWithQuery: UseGroupChannelMessages = (sdk, c
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
-
useChannelHandler(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (isDifferentChannel(activeChannel, eventChannel)) return;
|
|
90
|
-
channelMarkAs();
|
|
91
|
-
updateNextMessages([message], false, sdk.currentUser.userId);
|
|
92
|
-
},
|
|
93
|
-
onMessageUpdated(eventChannel, message) {
|
|
94
|
-
if (isDifferentChannel(activeChannel, eventChannel)) return;
|
|
95
|
-
updateMessages([message], false, sdk.currentUser.userId);
|
|
96
|
-
},
|
|
97
|
-
onMessageDeleted(eventChannel, messageId) {
|
|
98
|
-
if (isDifferentChannel(activeChannel, eventChannel)) return;
|
|
99
|
-
deleteMessages([messageId], []);
|
|
100
|
-
deleteNextMessages([messageId], []);
|
|
101
|
-
},
|
|
102
|
-
// Channels
|
|
103
|
-
onChannelChanged: channelUpdater,
|
|
104
|
-
onChannelFrozen: channelUpdater,
|
|
105
|
-
onChannelUnfrozen: channelUpdater,
|
|
106
|
-
onChannelHidden: channelUpdater,
|
|
107
|
-
onChannelMemberCountChanged(channels) {
|
|
108
|
-
const channel = channels.find((c) => !isDifferentChannel(c, activeChannel));
|
|
109
|
-
if (channel) channelUpdater(channel);
|
|
110
|
-
},
|
|
111
|
-
onChannelDeleted(channelUrl: string) {
|
|
112
|
-
if (activeChannel.url === channelUrl) options?.onChannelDeleted?.();
|
|
113
|
-
},
|
|
114
|
-
// Users
|
|
115
|
-
onOperatorUpdated: channelUpdater,
|
|
116
|
-
onUserLeft: channelUpdater,
|
|
117
|
-
onUserEntered: channelUpdater,
|
|
118
|
-
onUserExited: channelUpdater,
|
|
119
|
-
onUserJoined: channelUpdater,
|
|
120
|
-
onUserUnbanned: channelUpdater,
|
|
121
|
-
onUserMuted: channelUpdater,
|
|
122
|
-
onUserUnmuted: channelUpdater,
|
|
123
|
-
onUserBanned(eventChannel, bannedUser) {
|
|
124
|
-
if (isDifferentChannel(activeChannel, eventChannel)) return;
|
|
125
|
-
|
|
126
|
-
if (bannedUser.userId === sdk.currentUser.userId) {
|
|
127
|
-
options?.onChannelDeleted?.();
|
|
128
|
-
} else {
|
|
129
|
-
channelUpdater(eventChannel);
|
|
130
|
-
}
|
|
131
|
-
},
|
|
83
|
+
useChannelHandler(sdk, HOOK_NAME, {
|
|
84
|
+
// Messages
|
|
85
|
+
onMessageReceived(eventChannel, message) {
|
|
86
|
+
if (isDifferentChannel(activeChannel, eventChannel)) return;
|
|
87
|
+
channelMarkAs();
|
|
88
|
+
updateNextMessages([message], false, sdk.currentUser.userId);
|
|
132
89
|
},
|
|
133
|
-
|
|
134
|
-
|
|
90
|
+
onMessageUpdated(eventChannel, message) {
|
|
91
|
+
if (isDifferentChannel(activeChannel, eventChannel)) return;
|
|
92
|
+
updateMessages([message], false, sdk.currentUser.userId);
|
|
93
|
+
},
|
|
94
|
+
onMessageDeleted(eventChannel, messageId) {
|
|
95
|
+
if (isDifferentChannel(activeChannel, eventChannel)) return;
|
|
96
|
+
deleteMessages([messageId], []);
|
|
97
|
+
deleteNextMessages([messageId], []);
|
|
98
|
+
},
|
|
99
|
+
// Channels
|
|
100
|
+
onChannelChanged: channelUpdater,
|
|
101
|
+
onChannelFrozen: channelUpdater,
|
|
102
|
+
onChannelUnfrozen: channelUpdater,
|
|
103
|
+
onChannelHidden: channelUpdater,
|
|
104
|
+
onChannelMemberCountChanged(channels) {
|
|
105
|
+
const channel = channels.find((c) => !isDifferentChannel(c, activeChannel));
|
|
106
|
+
if (channel) channelUpdater(channel);
|
|
107
|
+
},
|
|
108
|
+
onChannelDeleted(channelUrl: string) {
|
|
109
|
+
if (activeChannel.url === channelUrl) options?.onChannelDeleted?.();
|
|
110
|
+
},
|
|
111
|
+
// Users
|
|
112
|
+
onOperatorUpdated: channelUpdater,
|
|
113
|
+
onUserLeft: channelUpdater,
|
|
114
|
+
onUserEntered: channelUpdater,
|
|
115
|
+
onUserExited: channelUpdater,
|
|
116
|
+
onUserJoined: channelUpdater,
|
|
117
|
+
onUserUnbanned: channelUpdater,
|
|
118
|
+
onUserMuted: channelUpdater,
|
|
119
|
+
onUserUnmuted: channelUpdater,
|
|
120
|
+
onUserBanned(eventChannel, bannedUser) {
|
|
121
|
+
if (isDifferentChannel(activeChannel, eventChannel)) return;
|
|
122
|
+
|
|
123
|
+
if (bannedUser.userId === sdk.currentUser.userId) {
|
|
124
|
+
options?.onChannelDeleted?.();
|
|
125
|
+
} else {
|
|
126
|
+
channelUpdater(eventChannel);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
});
|
|
135
130
|
|
|
136
131
|
useAsyncEffect(async () => {
|
|
137
132
|
updateLoading(true);
|
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
|
|
3
1
|
import { ApplicationAttributes, PremiumFeatures, SendbirdChatSDK } from '@sendbird/uikit-utils';
|
|
4
2
|
|
|
5
3
|
export const useAppFeatures = (sdk: SendbirdChatSDK) => {
|
|
6
|
-
const
|
|
7
|
-
return Boolean(sdk.appInfo?.premiumFeatureList?.includes?.(PremiumFeatures.delivery_receipt));
|
|
8
|
-
}, [sdk.appInfo?.premiumFeatureList]);
|
|
9
|
-
|
|
10
|
-
const broadcastChannelEnabled = useMemo(() => {
|
|
11
|
-
return Boolean(sdk.appInfo?.applicationAttributes?.includes?.(ApplicationAttributes.allow_broadcast_channel));
|
|
12
|
-
}, [sdk.appInfo?.applicationAttributes]);
|
|
13
|
-
|
|
14
|
-
const superGroupChannelEnabled = useMemo(() => {
|
|
15
|
-
return Boolean(sdk.appInfo?.applicationAttributes?.includes?.(ApplicationAttributes.allow_super_group_channel));
|
|
16
|
-
}, [sdk.appInfo?.applicationAttributes]);
|
|
17
|
-
|
|
18
|
-
const reactionEnabled = useMemo(() => {
|
|
19
|
-
return Boolean(sdk.appInfo?.applicationAttributes?.includes?.(ApplicationAttributes.reactions));
|
|
20
|
-
}, [sdk.appInfo?.applicationAttributes]);
|
|
21
|
-
|
|
4
|
+
const { premiumFeatureList = [], applicationAttributes = [] } = sdk.appInfo ?? {};
|
|
22
5
|
return {
|
|
23
|
-
deliveryReceiptEnabled,
|
|
24
|
-
broadcastChannelEnabled,
|
|
25
|
-
superGroupChannelEnabled,
|
|
26
|
-
reactionEnabled,
|
|
6
|
+
deliveryReceiptEnabled: Boolean(premiumFeatureList.includes(PremiumFeatures.delivery_receipt)),
|
|
7
|
+
broadcastChannelEnabled: Boolean(applicationAttributes.includes(ApplicationAttributes.allow_broadcast_channel)),
|
|
8
|
+
superGroupChannelEnabled: Boolean(applicationAttributes.includes(ApplicationAttributes.allow_super_group_channel)),
|
|
9
|
+
reactionEnabled: Boolean(applicationAttributes.includes(ApplicationAttributes.reactions)),
|
|
27
10
|
};
|
|
28
11
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef } from 'react';
|
|
2
2
|
import type Sendbird from 'sendbird';
|
|
3
3
|
|
|
4
4
|
import { Logger, SendbirdChatSDK } from '@sendbird/uikit-utils';
|
|
@@ -7,19 +7,25 @@ export const useChannelHandler = (
|
|
|
7
7
|
sdk: SendbirdChatSDK,
|
|
8
8
|
handlerId: string,
|
|
9
9
|
hookHandler: Partial<Sendbird.ChannelHandler>,
|
|
10
|
-
deps: React.DependencyList = [],
|
|
11
10
|
) => {
|
|
11
|
+
const handlerRef = useRef(hookHandler);
|
|
12
|
+
useLayoutEffect(() => {
|
|
13
|
+
handlerRef.current = hookHandler;
|
|
14
|
+
});
|
|
15
|
+
|
|
12
16
|
useEffect(() => {
|
|
13
17
|
Logger.debug('[useChannelHandler] hook called by', handlerId);
|
|
14
18
|
|
|
15
19
|
const handler = new sdk.ChannelHandler();
|
|
16
20
|
const handlerKeys = Object.keys(handler) as (keyof typeof handler)[];
|
|
17
21
|
handlerKeys.forEach((key) => {
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
handler[key] = (...args: unknown[]) => {
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
handlerRef.current[key]?.(...args);
|
|
25
|
+
};
|
|
20
26
|
});
|
|
21
27
|
|
|
22
28
|
sdk.addChannelHandler(handlerId, handler);
|
|
23
29
|
return () => sdk.removeChannelHandler(handlerId);
|
|
24
|
-
}, [sdk, handlerId
|
|
30
|
+
}, [sdk, handlerId]);
|
|
25
31
|
};
|