@droppii-org/chat-mobile 0.2.65 → 0.2.67
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/module/components/Avatar/Avatar.js +39 -2
- package/lib/module/components/Avatar/Avatar.js.map +1 -1
- package/lib/module/components/Avatar/DoubleAvatar.js +18 -18
- package/lib/module/components/Avatar/DoubleAvatar.js.map +1 -1
- package/lib/module/components/Avatar/QuadAvatar.js +131 -0
- package/lib/module/components/Avatar/QuadAvatar.js.map +1 -0
- package/lib/module/components/Avatar/TripleAvatar.js +97 -0
- package/lib/module/components/Avatar/TripleAvatar.js.map +1 -0
- package/lib/module/components/Avatar/index.js +2 -0
- package/lib/module/components/Avatar/index.js.map +1 -1
- package/lib/module/components/ThreadCard/AvatarSection.js +41 -0
- package/lib/module/components/ThreadCard/AvatarSection.js.map +1 -1
- package/lib/module/components/ThreadCard/NamePrefixIcon.js +5 -4
- package/lib/module/components/ThreadCard/NamePrefixIcon.js.map +1 -1
- package/lib/module/components/ThreadCard/ThreadCard.js +3 -1
- package/lib/module/components/ThreadCard/ThreadCard.js.map +1 -1
- package/lib/module/components/messages/groupNotificationMessage/index.js +25 -0
- package/lib/module/components/messages/groupNotificationMessage/index.js.map +1 -0
- package/lib/module/context/ChatContext.js +1 -1
- package/lib/module/context/ChatContext.js.map +1 -1
- package/lib/module/context/ChatDetailContext.js +9 -0
- package/lib/module/context/ChatDetailContext.js.map +1 -1
- package/lib/module/core/useChatListener.js +120 -21
- package/lib/module/core/useChatListener.js.map +1 -1
- package/lib/module/hooks/conversation/useGetGroupInfo.js +21 -0
- package/lib/module/hooks/conversation/useGetGroupInfo.js.map +1 -0
- package/lib/module/hooks/message/useSendMessage.js +6 -3
- package/lib/module/hooks/message/useSendMessage.js.map +1 -1
- package/lib/module/hooks/query-keys.js +2 -1
- package/lib/module/hooks/query-keys.js.map +1 -1
- package/lib/module/hooks/useConversationList.js +9 -4
- package/lib/module/hooks/useConversationList.js.map +1 -1
- package/lib/module/screens/ChatInfo/ChatInfo.js +18 -2
- package/lib/module/screens/ChatInfo/ChatInfo.js.map +1 -1
- package/lib/module/screens/ChatInfo/ChatInfoActions.js +83 -55
- package/lib/module/screens/ChatInfo/ChatInfoActions.js.map +1 -1
- package/lib/module/screens/ChatInfo/ChatInfoDescriptionRow.js +77 -0
- package/lib/module/screens/ChatInfo/ChatInfoDescriptionRow.js.map +1 -0
- package/lib/module/screens/ChatInfo/ChatInfoProfile.js +4 -2
- package/lib/module/screens/ChatInfo/ChatInfoProfile.js.map +1 -1
- package/lib/module/screens/ChatInfo/GroupDescriptionModal.js +58 -0
- package/lib/module/screens/ChatInfo/GroupDescriptionModal.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatComposer.js +11 -6
- package/lib/module/screens/chat-detail/ChatComposer.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatDetail.js +7 -0
- package/lib/module/screens/chat-detail/ChatDetail.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatDetailHeader.js +10 -3
- package/lib/module/screens/chat-detail/ChatDetailHeader.js.map +1 -1
- package/lib/module/screens/chat-detail/conversationHeader.utils.js +13 -3
- package/lib/module/screens/chat-detail/conversationHeader.utils.js.map +1 -1
- package/lib/module/screens/chat-detail/legend/LegendChatMessage.js +29 -2
- package/lib/module/screens/chat-detail/legend/LegendChatMessage.js.map +1 -1
- package/lib/module/screens/inbox/MessagesTab.js.map +1 -1
- package/lib/module/store/conversation.js +56 -12
- package/lib/module/store/conversation.js.map +1 -1
- package/lib/module/translation/resources/i18n.js +34 -0
- package/lib/module/translation/resources/i18n.js.map +1 -1
- package/lib/module/types/events.js +1 -0
- package/lib/module/types/events.js.map +1 -1
- package/lib/module/utils/conversation.js +3 -0
- package/lib/module/utils/conversation.js.map +1 -1
- package/lib/module/utils/messageUtils.js +95 -2
- package/lib/module/utils/messageUtils.js.map +1 -1
- package/lib/typescript/src/components/Avatar/Avatar.d.ts +1 -1
- package/lib/typescript/src/components/Avatar/Avatar.d.ts.map +1 -1
- package/lib/typescript/src/components/Avatar/Avatar.types.d.ts +5 -1
- package/lib/typescript/src/components/Avatar/Avatar.types.d.ts.map +1 -1
- package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts.map +1 -1
- package/lib/typescript/src/components/Avatar/QuadAvatar.d.ts +16 -0
- package/lib/typescript/src/components/Avatar/QuadAvatar.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/TripleAvatar.d.ts +15 -0
- package/lib/typescript/src/components/Avatar/TripleAvatar.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/index.d.ts +2 -0
- package/lib/typescript/src/components/Avatar/index.d.ts.map +1 -1
- package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts +2 -2
- package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts.map +1 -1
- package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts +3 -1
- package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts.map +1 -1
- package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts.map +1 -1
- package/lib/typescript/src/components/messages/groupNotificationMessage/index.d.ts +3 -0
- package/lib/typescript/src/components/messages/groupNotificationMessage/index.d.ts.map +1 -0
- package/lib/typescript/src/context/ChatDetailContext.d.ts +2 -0
- package/lib/typescript/src/context/ChatDetailContext.d.ts.map +1 -1
- package/lib/typescript/src/core/useChatListener.d.ts.map +1 -1
- package/lib/typescript/src/hooks/conversation/useGetGroupInfo.d.ts +2 -0
- package/lib/typescript/src/hooks/conversation/useGetGroupInfo.d.ts.map +1 -0
- package/lib/typescript/src/hooks/message/useSendMessage.d.ts.map +1 -1
- package/lib/typescript/src/hooks/query-keys.d.ts +1 -0
- package/lib/typescript/src/hooks/query-keys.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useConversationList.d.ts.map +1 -1
- package/lib/typescript/src/screens/ChatInfo/ChatInfo.d.ts +1 -1
- package/lib/typescript/src/screens/ChatInfo/ChatInfo.d.ts.map +1 -1
- package/lib/typescript/src/screens/ChatInfo/ChatInfoActions.d.ts +3 -1
- package/lib/typescript/src/screens/ChatInfo/ChatInfoActions.d.ts.map +1 -1
- package/lib/typescript/src/screens/ChatInfo/ChatInfoDescriptionRow.d.ts +7 -0
- package/lib/typescript/src/screens/ChatInfo/ChatInfoDescriptionRow.d.ts.map +1 -0
- package/lib/typescript/src/screens/ChatInfo/ChatInfoProfile.d.ts.map +1 -1
- package/lib/typescript/src/screens/ChatInfo/GroupDescriptionModal.d.ts +9 -0
- package/lib/typescript/src/screens/ChatInfo/GroupDescriptionModal.d.ts.map +1 -0
- package/lib/typescript/src/screens/ChatInfo/types.d.ts +1 -0
- package/lib/typescript/src/screens/ChatInfo/types.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/conversationHeader.utils.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/conversationHeader.utils.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatMessage.d.ts.map +1 -1
- package/lib/typescript/src/screens/inbox/MessagesTab.d.ts.map +1 -1
- package/lib/typescript/src/store/conversation.d.ts +11 -0
- package/lib/typescript/src/store/conversation.d.ts.map +1 -1
- package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -1
- package/lib/typescript/src/types/events.d.ts +6 -1
- package/lib/typescript/src/types/events.d.ts.map +1 -1
- package/lib/typescript/src/utils/conversation.d.ts +1 -0
- package/lib/typescript/src/utils/conversation.d.ts.map +1 -1
- package/lib/typescript/src/utils/messageUtils.d.ts +6 -1
- package/lib/typescript/src/utils/messageUtils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/build-ignore.d.ts +1 -0
- package/src/components/Avatar/Avatar.tsx +47 -0
- package/src/components/Avatar/Avatar.types.ts +5 -1
- package/src/components/Avatar/DoubleAvatar.tsx +16 -13
- package/src/components/Avatar/QuadAvatar.tsx +161 -0
- package/src/components/Avatar/TripleAvatar.tsx +119 -0
- package/src/components/Avatar/index.ts +2 -0
- package/src/components/ThreadCard/AvatarSection.tsx +58 -2
- package/src/components/ThreadCard/NamePrefixIcon.tsx +32 -25
- package/src/components/ThreadCard/ThreadCard.tsx +2 -0
- package/src/components/messages/groupNotificationMessage/index.tsx +28 -0
- package/src/context/ChatContext.tsx +1 -1
- package/src/context/ChatDetailContext.tsx +15 -0
- package/src/core/useChatListener.ts +175 -23
- package/src/hooks/conversation/useGetGroupInfo.ts +20 -0
- package/src/hooks/message/useSendMessage.ts +11 -3
- package/src/hooks/query-keys.ts +1 -0
- package/src/hooks/useConversationList.ts +17 -7
- package/src/screens/ChatInfo/ChatInfo.tsx +16 -0
- package/src/screens/ChatInfo/ChatInfoActions.tsx +68 -35
- package/src/screens/ChatInfo/ChatInfoDescriptionRow.tsx +102 -0
- package/src/screens/ChatInfo/ChatInfoProfile.tsx +6 -3
- package/src/screens/ChatInfo/GroupDescriptionModal.tsx +67 -0
- package/src/screens/ChatInfo/types.ts +1 -0
- package/src/screens/chat-detail/ChatComposer.tsx +19 -10
- package/src/screens/chat-detail/ChatDetail.tsx +12 -1
- package/src/screens/chat-detail/ChatDetailHeader.tsx +19 -3
- package/src/screens/chat-detail/conversationHeader.utils.ts +14 -6
- package/src/screens/chat-detail/legend/LegendChatMessage.tsx +36 -1
- package/src/screens/inbox/MessagesTab.tsx +0 -1
- package/src/store/conversation.ts +62 -17
- package/src/translation/resources/i18n.ts +34 -0
- package/src/types/events.ts +6 -0
- package/src/utils/conversation.ts +6 -0
- package/src/utils/messageUtils.ts +103 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { memo } from 'react';
|
|
2
2
|
import { Image, StyleSheet } from 'react-native';
|
|
3
|
-
import { KContainer, KImage, KColors } from '@droppii/libs';
|
|
3
|
+
import { KContainer, KImage, KColors, type KSpacing } from '@droppii/libs';
|
|
4
4
|
import Images from '../../assets/images';
|
|
5
5
|
import { PeerType } from '@droppii/openim-rn-client-sdk';
|
|
6
6
|
|
|
@@ -13,34 +13,41 @@ const styles = StyleSheet.create({
|
|
|
13
13
|
|
|
14
14
|
interface NamePrefixIconProps {
|
|
15
15
|
peerType?: PeerType | string;
|
|
16
|
+
marginR?: KSpacing;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export const NamePrefixIcon = memo(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
export const NamePrefixIcon = memo(
|
|
20
|
+
({ peerType, marginR = '0.25rem' }: NamePrefixIconProps) => {
|
|
21
|
+
if (peerType === PeerType.Bot) {
|
|
22
|
+
return (
|
|
23
|
+
<KContainer.View marginR={marginR}>
|
|
24
|
+
<Image source={Images.ICON_DROPPII} style={styles.icon} />
|
|
25
|
+
</KContainer.View>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
if (peerType === PeerType.Group) {
|
|
30
|
+
return (
|
|
31
|
+
<KContainer.View marginR={marginR}>
|
|
32
|
+
<KImage.VectorIcons
|
|
33
|
+
name="user-two-b"
|
|
34
|
+
size={14}
|
|
35
|
+
color={KColors.black}
|
|
36
|
+
/>
|
|
37
|
+
</KContainer.View>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
// if (peerType === DChatPeerType.CUSTOMER) {
|
|
42
|
+
// return (
|
|
43
|
+
// <KContainer.View marginR={marginR}>
|
|
44
|
+
// <Image source={Images.ICON_DROPPII} style={styles.icon} />
|
|
45
|
+
// </KContainer.View>
|
|
46
|
+
// );
|
|
47
|
+
// }
|
|
42
48
|
|
|
43
|
-
|
|
44
|
-
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
);
|
|
45
52
|
|
|
46
53
|
NamePrefixIcon.displayName = 'NamePrefixIcon';
|
|
@@ -33,6 +33,7 @@ const ThreadCard = memo(({ item, onPress }: ThreadCardProps) => {
|
|
|
33
33
|
peerType,
|
|
34
34
|
showName,
|
|
35
35
|
faceURL,
|
|
36
|
+
members,
|
|
36
37
|
unreadCount = 0,
|
|
37
38
|
recvMsgOpt = MessageReceiveOptType.Normal,
|
|
38
39
|
isPinned,
|
|
@@ -120,6 +121,7 @@ const ThreadCard = memo(({ item, onPress }: ThreadCardProps) => {
|
|
|
120
121
|
avatar={faceURL ?? null}
|
|
121
122
|
fullName={fullName}
|
|
122
123
|
peerType={peerType}
|
|
124
|
+
members={members}
|
|
123
125
|
/>
|
|
124
126
|
|
|
125
127
|
{/* Chat-Content */}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { KLabel } from '@droppii/libs';
|
|
3
|
+
import { trans } from '../../../translation';
|
|
4
|
+
import { CHAT_BUBBLE_COLORS } from '../../../screens/chat-detail/constants';
|
|
5
|
+
import {
|
|
6
|
+
GROUP_NOTIFICATION_TEXT,
|
|
7
|
+
getNotificationOpUserNickname,
|
|
8
|
+
} from '../../../utils/messageUtils';
|
|
9
|
+
import type { BaseLegendMessageProps } from '../types';
|
|
10
|
+
|
|
11
|
+
export const GroupNotificationMessage = memo(
|
|
12
|
+
({ message, isOutgoing }: BaseLegendMessageProps) => {
|
|
13
|
+
const notification = GROUP_NOTIFICATION_TEXT[message.contentType];
|
|
14
|
+
if (!notification) return null;
|
|
15
|
+
|
|
16
|
+
const sender = isOutgoing
|
|
17
|
+
? 'Bạn'
|
|
18
|
+
: message.senderNickname || getNotificationOpUserNickname(message) || '';
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<KLabel.Text typo="TextXsNormal" color={CHAT_BUBBLE_COLORS.dayLabel}>
|
|
22
|
+
{trans(notification.bySenderKey, { sender })}
|
|
23
|
+
</KLabel.Text>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
GroupNotificationMessage.displayName = 'GroupNotificationMessage';
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
useEffect,
|
|
6
6
|
useMemo,
|
|
7
7
|
useState,
|
|
8
|
+
type ComponentType,
|
|
8
9
|
} from 'react';
|
|
9
10
|
import { DeviceEventEmitter } from 'react-native';
|
|
10
11
|
import {
|
|
@@ -189,3 +190,17 @@ export const ChatDetailProvider = ({ children }: ChatDetailProviderProps) => {
|
|
|
189
190
|
</ChatDetailContext.Provider>
|
|
190
191
|
);
|
|
191
192
|
};
|
|
193
|
+
|
|
194
|
+
export function withChatDetailProvider<P extends object>(
|
|
195
|
+
Component: ComponentType<P>
|
|
196
|
+
): ComponentType<P> {
|
|
197
|
+
const WithChatDetailProvider = (props: P) => (
|
|
198
|
+
<ChatDetailProvider>
|
|
199
|
+
<Component {...props} />
|
|
200
|
+
</ChatDetailProvider>
|
|
201
|
+
);
|
|
202
|
+
WithChatDetailProvider.displayName = `withChatDetailProvider(${
|
|
203
|
+
Component.displayName || Component.name || 'Component'
|
|
204
|
+
})`;
|
|
205
|
+
return WithChatDetailProvider;
|
|
206
|
+
}
|
|
@@ -2,12 +2,15 @@ import OpenIMSDK, {
|
|
|
2
2
|
MessageReceiveOptType,
|
|
3
3
|
MessageType,
|
|
4
4
|
OpenIMEvent,
|
|
5
|
+
SessionType,
|
|
5
6
|
type ConversationItem,
|
|
7
|
+
type GroupItem,
|
|
6
8
|
type GroupMemberItem,
|
|
7
9
|
type MessageItem,
|
|
8
10
|
type MessagePinned,
|
|
9
11
|
type RevokedInfo,
|
|
10
12
|
} from '@droppii/openim-rn-client-sdk';
|
|
13
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
11
14
|
import { useCallback, useEffect } from 'react';
|
|
12
15
|
import { useConversationStore } from '../store/conversation';
|
|
13
16
|
import { ToastFlashMessage } from '../utils/toastFlashMessage';
|
|
@@ -18,22 +21,31 @@ import isEmpty from 'lodash/isEmpty';
|
|
|
18
21
|
import { markMessageRevoked, useMessageStore } from '../store/message';
|
|
19
22
|
import { syncPinnedMessagesOnEvent } from '../hooks/message/usePinMessage';
|
|
20
23
|
import { belongsToConversation } from '../utils/message';
|
|
24
|
+
import { getConversationID } from '../utils/conversation';
|
|
21
25
|
import { DeviceEventEmitter } from 'react-native';
|
|
22
26
|
import { ChatEvent } from '../types/events';
|
|
27
|
+
import { conversationQueryKeys } from '../hooks/query-keys';
|
|
23
28
|
|
|
24
29
|
export const useChatListener = () => {
|
|
25
30
|
const updateOneMessage = useMessageStore((state) => state.updateOneMessage);
|
|
26
31
|
const currentUserId = useUserStore((s) => s.user?.userID);
|
|
27
32
|
const onPressFlashMessage = useChatContext()?.onPressFlashMessage;
|
|
28
33
|
const isShowFLashMessage = useChatContext()?.isShowFLashMessage;
|
|
34
|
+
const queryClient = useQueryClient();
|
|
29
35
|
|
|
30
36
|
const onSendMessageProgress = useCallback(
|
|
31
|
-
({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
({
|
|
38
|
+
progress: _progress,
|
|
39
|
+
message,
|
|
40
|
+
}: {
|
|
41
|
+
progress: number;
|
|
42
|
+
message: MessageItem;
|
|
43
|
+
}) => {
|
|
44
|
+
// console.log('[Listener] SendMessageProgress', {
|
|
45
|
+
// clientMsgID: message.clientMsgID,
|
|
46
|
+
// status: message.status,
|
|
47
|
+
// progress,
|
|
48
|
+
// });
|
|
37
49
|
updateOneMessage(message);
|
|
38
50
|
},
|
|
39
51
|
[updateOneMessage]
|
|
@@ -41,6 +53,7 @@ export const useChatListener = () => {
|
|
|
41
53
|
|
|
42
54
|
const onConversationChanged = useCallback(
|
|
43
55
|
(conversations: ConversationItem[]) => {
|
|
56
|
+
// console.log('[Listener] OnConversationChanged', conversations);
|
|
44
57
|
const oldMap = useConversationStore.getState().map;
|
|
45
58
|
const visibleConversations: ConversationItem[] = [];
|
|
46
59
|
|
|
@@ -87,26 +100,156 @@ export const useChatListener = () => {
|
|
|
87
100
|
);
|
|
88
101
|
|
|
89
102
|
const onNewConversation = useCallback((conversations: ConversationItem[]) => {
|
|
90
|
-
console.log(
|
|
103
|
+
// console.log(
|
|
104
|
+
// '[Listener] OnNewConversation',
|
|
105
|
+
// conversations.map((c) => ({
|
|
106
|
+
// conversationID: c.conversationID,
|
|
107
|
+
// groupID: c.groupID,
|
|
108
|
+
// isNotInGroup: c.isNotInGroup,
|
|
109
|
+
// isGuardedRemoved: c.groupID
|
|
110
|
+
// ? useConversationStore.getState().removedGroupIds.has(c.groupID)
|
|
111
|
+
// : false,
|
|
112
|
+
// }))
|
|
113
|
+
// );
|
|
91
114
|
useConversationStore.getState().updateConversations(conversations);
|
|
92
115
|
}, []);
|
|
93
116
|
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
groupID:
|
|
98
|
-
|
|
99
|
-
|
|
117
|
+
const onGroupInfoChanged = useCallback(
|
|
118
|
+
(group: GroupItem) => {
|
|
119
|
+
// console.log('[Listener] OnGroupInfoChanged', {
|
|
120
|
+
// groupID: group.groupID,
|
|
121
|
+
// memberCount: group.memberCount,
|
|
122
|
+
// });
|
|
123
|
+
queryClient.setQueryData(
|
|
124
|
+
conversationQueryKeys.groupInfo(group.groupID),
|
|
125
|
+
group
|
|
126
|
+
);
|
|
127
|
+
},
|
|
128
|
+
[queryClient]
|
|
129
|
+
);
|
|
100
130
|
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
131
|
+
const onGroupMemberAdded = useCallback(
|
|
132
|
+
(member: GroupMemberItem) => {
|
|
133
|
+
// console.log('[Listener] OnGroupMemberAdded', {
|
|
134
|
+
// userID: member.userID,
|
|
135
|
+
// groupID: member.groupID,
|
|
136
|
+
// isCurrentUser: member.userID === currentUserId,
|
|
137
|
+
// });
|
|
138
|
+
queryClient.invalidateQueries({
|
|
139
|
+
queryKey: conversationQueryKeys.groupInfo(member.groupID),
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// The current user (re)joined this group — lift the removal guard so
|
|
143
|
+
// a future OnConversationChanged/OnNewConversation for it isn't dropped.
|
|
144
|
+
if (member.userID === currentUserId) {
|
|
145
|
+
useConversationStore
|
|
146
|
+
.getState()
|
|
147
|
+
.restoreGroupConversation(member.groupID);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
[queryClient, currentUserId]
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const removeGroupConversation = useCallback(
|
|
154
|
+
(
|
|
155
|
+
groupID: string,
|
|
156
|
+
groupName: string | undefined,
|
|
157
|
+
reason: 'left' | 'dismissed' | 'kicked'
|
|
158
|
+
) => {
|
|
159
|
+
// console.log('[Listener] removeGroupConversation', { groupID, reason });
|
|
160
|
+
|
|
161
|
+
// TEMPORARILY DISABLED: OnConversationChanged/OnNewConversation can
|
|
162
|
+
// still race this removal and resurrect the conversation before the
|
|
163
|
+
// removedGroupIds guard is proven reliable. Flip this back to `true`
|
|
164
|
+
// once that race is confirmed fixed.
|
|
165
|
+
const REMOVE_FLOW_ENABLED: boolean = false;
|
|
166
|
+
if (!REMOVE_FLOW_ENABLED) return;
|
|
167
|
+
|
|
168
|
+
const conversationID = getConversationID(SessionType.Group, groupID);
|
|
169
|
+
const conversation = useConversationStore.getState().map[conversationID];
|
|
170
|
+
const isCurrentConversation =
|
|
171
|
+
useConversationStore.getState().currentConversationId ===
|
|
172
|
+
conversationID;
|
|
173
|
+
|
|
174
|
+
// Marks groupID as removed so any late-arriving conversation-sync event
|
|
175
|
+
// for it (see onConversationChanged/onNewConversation) is dropped
|
|
176
|
+
// instead of silently resurrecting the conversation we just removed.
|
|
177
|
+
useConversationStore.getState().removeGroupConversation(groupID);
|
|
178
|
+
|
|
179
|
+
queryClient.removeQueries({
|
|
180
|
+
queryKey: conversationQueryKeys.groupInfo(groupID),
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
ToastFlashMessage.show({
|
|
184
|
+
key: `group-removed-${groupID}`,
|
|
185
|
+
title: groupName || conversation?.showName || 'Nhóm',
|
|
186
|
+
body:
|
|
187
|
+
reason === 'dismissed'
|
|
188
|
+
? 'Nhóm đã bị giải tán'
|
|
189
|
+
: reason === 'kicked'
|
|
190
|
+
? 'Bạn đã bị mời khỏi nhóm'
|
|
191
|
+
: 'Bạn không còn trong nhóm này',
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
if (isCurrentConversation) {
|
|
195
|
+
DeviceEventEmitter.emit(ChatEvent.GroupRemoved, {
|
|
196
|
+
groupID,
|
|
197
|
+
reason,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
[queryClient]
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const onGroupMemberDeleted = useCallback(
|
|
205
|
+
(member: GroupMemberItem) => {
|
|
206
|
+
// console.log('[Listener] OnGroupMemberDeleted', {
|
|
207
|
+
// userID: member.userID,
|
|
208
|
+
// groupID: member.groupID,
|
|
209
|
+
// isCurrentUser: member.userID === currentUserId,
|
|
210
|
+
// });
|
|
211
|
+
queryClient.invalidateQueries({
|
|
212
|
+
queryKey: conversationQueryKeys.groupInfo(member.groupID),
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// The removed member is the current user themselves — they were kicked,
|
|
216
|
+
// so their conversation for this group must be dropped like a leave/dismiss.
|
|
217
|
+
if (member.userID === currentUserId) {
|
|
218
|
+
removeGroupConversation(member.groupID, undefined, 'kicked');
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
[queryClient, currentUserId, removeGroupConversation]
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const onJoinedGroupDeleted = useCallback(
|
|
225
|
+
(group: GroupItem) => {
|
|
226
|
+
// console.log('[Listener] OnJoinedGroupDeleted', {
|
|
227
|
+
// groupID: group.groupID,
|
|
228
|
+
// groupName: group.groupName,
|
|
229
|
+
// });
|
|
230
|
+
removeGroupConversation(group.groupID, group.groupName, 'left');
|
|
231
|
+
},
|
|
232
|
+
[removeGroupConversation]
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
const onGroupDismissed = useCallback(
|
|
236
|
+
(group: GroupItem) => {
|
|
237
|
+
// console.log('[Listener] OnGroupDismissed', {
|
|
238
|
+
// groupID: group.groupID,
|
|
239
|
+
// groupName: group.groupName,
|
|
240
|
+
// });
|
|
241
|
+
removeGroupConversation(group.groupID, group.groupName, 'dismissed');
|
|
242
|
+
},
|
|
243
|
+
[removeGroupConversation]
|
|
244
|
+
);
|
|
107
245
|
|
|
108
246
|
const OnGroupMemberInfoChanged = useCallback(
|
|
109
247
|
(member: GroupMemberItem) => {
|
|
248
|
+
// console.log('[Listener] OnGroupMemberInfoChanged', {
|
|
249
|
+
// userID: member.userID,
|
|
250
|
+
// groupID: member.groupID,
|
|
251
|
+
// permissions: member.permissions,
|
|
252
|
+
// });
|
|
110
253
|
const conversation = useConversationStore
|
|
111
254
|
.getState()
|
|
112
255
|
.getCurrentConversation();
|
|
@@ -148,7 +291,7 @@ export const useChatListener = () => {
|
|
|
148
291
|
);
|
|
149
292
|
|
|
150
293
|
const onRecvNewMessages = useCallback((messages: MessageItem[]) => {
|
|
151
|
-
console.log('[Listener] OnRecvNewMessages', messages);
|
|
294
|
+
// console.log('[Listener] OnRecvNewMessages', messages);
|
|
152
295
|
const conversationId =
|
|
153
296
|
useConversationStore.getState().currentConversationId;
|
|
154
297
|
const targetUserId = useConversationStore.getState().currentUserId;
|
|
@@ -164,8 +307,8 @@ export const useChatListener = () => {
|
|
|
164
307
|
relevant.forEach((msg) => useMessageStore.getState().pushNewMessage(msg));
|
|
165
308
|
}, []);
|
|
166
309
|
|
|
167
|
-
const onRecvOfflineNewMessages = useCallback((
|
|
168
|
-
console.log('[Listener] onRecvOfflineNewMessages',
|
|
310
|
+
const onRecvOfflineNewMessages = useCallback((_messages: MessageItem[]) => {
|
|
311
|
+
// console.log('[Listener] onRecvOfflineNewMessages', _messages);
|
|
169
312
|
}, []);
|
|
170
313
|
|
|
171
314
|
useEffect(() => {
|
|
@@ -174,12 +317,15 @@ export const useChatListener = () => {
|
|
|
174
317
|
OpenIMSDK.on(OpenIMEvent.OnNewConversation, onNewConversation);
|
|
175
318
|
|
|
176
319
|
// Group members
|
|
320
|
+
OpenIMSDK.on(OpenIMEvent.OnGroupInfoChanged, onGroupInfoChanged);
|
|
177
321
|
OpenIMSDK.on(OpenIMEvent.OnGroupMemberAdded, onGroupMemberAdded);
|
|
178
322
|
OpenIMSDK.on(OpenIMEvent.OnGroupMemberDeleted, onGroupMemberDeleted);
|
|
179
323
|
OpenIMSDK.on(
|
|
180
324
|
OpenIMEvent.OnGroupMemberInfoChanged,
|
|
181
325
|
OnGroupMemberInfoChanged
|
|
182
326
|
);
|
|
327
|
+
OpenIMSDK.on(OpenIMEvent.OnJoinedGroupDeleted, onJoinedGroupDeleted);
|
|
328
|
+
OpenIMSDK.on(OpenIMEvent.OnGroupDismissed, onGroupDismissed);
|
|
183
329
|
|
|
184
330
|
// Message status
|
|
185
331
|
OpenIMSDK.on(OpenIMEvent.SendMessageProgress, onSendMessageProgress);
|
|
@@ -197,12 +343,15 @@ export const useChatListener = () => {
|
|
|
197
343
|
OpenIMSDK.off(OpenIMEvent.OnNewConversation, onNewConversation);
|
|
198
344
|
|
|
199
345
|
// Group members
|
|
346
|
+
OpenIMSDK.off(OpenIMEvent.OnGroupInfoChanged, onGroupInfoChanged);
|
|
200
347
|
OpenIMSDK.off(OpenIMEvent.OnGroupMemberAdded, onGroupMemberAdded);
|
|
201
348
|
OpenIMSDK.off(OpenIMEvent.OnGroupMemberDeleted, onGroupMemberDeleted);
|
|
202
|
-
OpenIMSDK.
|
|
349
|
+
OpenIMSDK.off(
|
|
203
350
|
OpenIMEvent.OnGroupMemberInfoChanged,
|
|
204
351
|
OnGroupMemberInfoChanged
|
|
205
352
|
);
|
|
353
|
+
OpenIMSDK.off(OpenIMEvent.OnJoinedGroupDeleted, onJoinedGroupDeleted);
|
|
354
|
+
OpenIMSDK.off(OpenIMEvent.OnGroupDismissed, onGroupDismissed);
|
|
206
355
|
|
|
207
356
|
// Message status
|
|
208
357
|
OpenIMSDK.off(OpenIMEvent.SendMessageProgress, onSendMessageProgress);
|
|
@@ -216,6 +365,7 @@ export const useChatListener = () => {
|
|
|
216
365
|
};
|
|
217
366
|
}, [
|
|
218
367
|
onConversationChanged,
|
|
368
|
+
onGroupInfoChanged,
|
|
219
369
|
onGroupMemberAdded,
|
|
220
370
|
onGroupMemberDeleted,
|
|
221
371
|
onMessagePinned,
|
|
@@ -225,5 +375,7 @@ export const useChatListener = () => {
|
|
|
225
375
|
onRecvNewMessages,
|
|
226
376
|
onRecvOfflineNewMessages,
|
|
227
377
|
OnGroupMemberInfoChanged,
|
|
378
|
+
onJoinedGroupDeleted,
|
|
379
|
+
onGroupDismissed,
|
|
228
380
|
]);
|
|
229
381
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import OpenIMSDK from '@droppii/openim-rn-client-sdk';
|
|
3
|
+
import { conversationQueryKeys } from '../query-keys';
|
|
4
|
+
|
|
5
|
+
export const useGetGroupInfo = (groupId = '') =>
|
|
6
|
+
useQuery({
|
|
7
|
+
queryKey: conversationQueryKeys.groupInfo(groupId),
|
|
8
|
+
queryFn: async () => {
|
|
9
|
+
try {
|
|
10
|
+
const res = await OpenIMSDK.getSpecifiedGroupsInfo([groupId]);
|
|
11
|
+
return res?.[0];
|
|
12
|
+
} catch (error) {
|
|
13
|
+
console.error('useGetGroupInfo error:', error);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
enabled: !!groupId,
|
|
18
|
+
staleTime: 0,
|
|
19
|
+
refetchOnMount: 'always',
|
|
20
|
+
});
|
|
@@ -268,14 +268,22 @@ export const generateOfflinePushInfo = (message: MessageItem) => {
|
|
|
268
268
|
const conversationData = useConversationStore
|
|
269
269
|
?.getState?.()
|
|
270
270
|
?.getCurrentConversation();
|
|
271
|
-
const
|
|
272
|
-
const
|
|
271
|
+
const operator = useUserStore.getState().user;
|
|
272
|
+
const operatorUserID = operator?.userID || '';
|
|
273
|
+
const isSingleChat =
|
|
274
|
+
conversationData?.conversationType === SessionType.Single;
|
|
275
|
+
const title = isSingleChat
|
|
276
|
+
? operator?.nickname || 'Droppii'
|
|
277
|
+
: conversationData?.showName || 'Droppii';
|
|
278
|
+
const icon = isSingleChat
|
|
279
|
+
? operator?.faceURL || ''
|
|
280
|
+
: conversationData?.faceURL || '';
|
|
273
281
|
const desc = getMessagePreview(message);
|
|
274
282
|
return {
|
|
275
283
|
title,
|
|
276
284
|
desc,
|
|
277
285
|
ex: JSON.stringify({
|
|
278
|
-
icon
|
|
286
|
+
icon,
|
|
279
287
|
conversationId: conversationData?.conversationID || '',
|
|
280
288
|
userId: operatorUserID,
|
|
281
289
|
groupId: conversationData?.groupID || '',
|
package/src/hooks/query-keys.ts
CHANGED
|
@@ -32,6 +32,7 @@ export const conversationQueryKeys = {
|
|
|
32
32
|
detailBySourceId: (sourceId: string) => ['detailBySourceId', sourceId],
|
|
33
33
|
joinedGroup: (groupId?: string) => [...conversationQueryKeys.all, groupId],
|
|
34
34
|
create: (userId?: string) => ['create', userId],
|
|
35
|
+
groupInfo: (groupId: string) => ['groupInfo', groupId] as const,
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
export const usersQueryKeys = {
|
|
@@ -25,14 +25,24 @@ export function useConversationList({
|
|
|
25
25
|
enabled: enabled !== false,
|
|
26
26
|
queryFn: async () => {
|
|
27
27
|
const offset = (page - 1) * 500;
|
|
28
|
-
const conversations = await
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
const [conversations, joinedGroups] = await Promise.all([
|
|
29
|
+
OpenIMSDK.getConversationListSplitApp({
|
|
30
|
+
offset,
|
|
31
|
+
count: 500,
|
|
32
|
+
applicationType,
|
|
33
|
+
}),
|
|
34
|
+
OpenIMSDK.getJoinedGroupList(),
|
|
35
|
+
]);
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
const joinedGroupIds = new Set(joinedGroups.map((g) => g.groupID));
|
|
38
|
+
const resolved = conversations.map((conversation) =>
|
|
39
|
+
conversation.groupID && !joinedGroupIds.has(conversation.groupID)
|
|
40
|
+
? { ...conversation, isNotInGroup: true }
|
|
41
|
+
: conversation
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
useConversationStore.getState().updateConversations(resolved);
|
|
45
|
+
return resolved;
|
|
36
46
|
},
|
|
37
47
|
});
|
|
38
48
|
|
|
@@ -2,12 +2,15 @@ import { memo } from 'react';
|
|
|
2
2
|
import { KContainer, KNavigation } from '@droppii/libs';
|
|
3
3
|
import { useNavigation } from '@react-navigation/native';
|
|
4
4
|
import { useGetConversationTarget } from '../../hooks/conversation/useGetConversationDetail';
|
|
5
|
+
import { useGetGroupInfo } from '../../hooks/conversation/useGetGroupInfo';
|
|
5
6
|
import { useConversation } from '../../store';
|
|
6
7
|
import ChatInfoProfile from './ChatInfoProfile';
|
|
7
8
|
import ChatInfoMediaRow from './ChatInfoMediaRow';
|
|
9
|
+
import ChatInfoDescriptionRow from './ChatInfoDescriptionRow';
|
|
8
10
|
import ChatInfoActions from './ChatInfoActions';
|
|
9
11
|
import type { ChatInfoProps } from './types';
|
|
10
12
|
import { trans } from '../../translation';
|
|
13
|
+
import { isGroupConversation } from '../../utils/conversation';
|
|
11
14
|
|
|
12
15
|
const ChatInfo = memo(
|
|
13
16
|
({
|
|
@@ -18,12 +21,17 @@ const ChatInfo = memo(
|
|
|
18
21
|
onPressOrders,
|
|
19
22
|
onPressCreateGroup,
|
|
20
23
|
onPressAddToGroup,
|
|
24
|
+
onPressLeaveGroup,
|
|
21
25
|
}: ChatInfoProps) => {
|
|
22
26
|
const navigation = useNavigation();
|
|
23
27
|
|
|
24
28
|
const conversation = useConversation(conversationId);
|
|
25
29
|
const { data: target } = useGetConversationTarget(conversationId);
|
|
26
30
|
const isTargetActive = target ? target.isActive : true;
|
|
31
|
+
const isGroup = isGroupConversation(conversation);
|
|
32
|
+
const { data: groupInfo } = useGetGroupInfo(
|
|
33
|
+
isGroup ? conversation?.groupID : undefined
|
|
34
|
+
);
|
|
27
35
|
|
|
28
36
|
return (
|
|
29
37
|
<KContainer.Page flex edges={['bottom']} background="#EBEDF2">
|
|
@@ -45,12 +53,20 @@ const ChatInfo = memo(
|
|
|
45
53
|
onPressSearch={onPressSearch}
|
|
46
54
|
/>
|
|
47
55
|
<ChatInfoMediaRow onPressMedia={onPressMedia} />
|
|
56
|
+
<KContainer.VisibleView visible={isGroup}>
|
|
57
|
+
<ChatInfoDescriptionRow
|
|
58
|
+
introduction={groupInfo?.introduction}
|
|
59
|
+
groupName={conversation?.showName}
|
|
60
|
+
/>
|
|
61
|
+
</KContainer.VisibleView>
|
|
48
62
|
<ChatInfoActions
|
|
49
63
|
conversation={conversation}
|
|
50
64
|
isTargetActive={isTargetActive}
|
|
65
|
+
isGroup={isGroup}
|
|
51
66
|
onPressOrders={onPressOrders}
|
|
52
67
|
onPressCreateGroup={onPressCreateGroup}
|
|
53
68
|
onPressAddToGroup={onPressAddToGroup}
|
|
69
|
+
onPressLeaveGroup={onPressLeaveGroup}
|
|
54
70
|
/>
|
|
55
71
|
</KContainer.ScrollView>
|
|
56
72
|
</KContainer.Page>
|