@droppii-org/chat-mobile 0.2.29 → 0.2.31
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/assets/images/index.js +1 -0
- package/lib/module/assets/images/index.js.map +1 -1
- package/lib/module/assets/images/notification-warning.png +0 -0
- package/lib/module/components/ThreadCard/MuteThread.js +71 -31
- package/lib/module/components/ThreadCard/MuteThread.js.map +1 -1
- package/lib/module/components/ThreadCard/ThreadCard.js +9 -4
- package/lib/module/components/ThreadCard/ThreadCard.js.map +1 -1
- package/lib/module/components/flows/inputButtons/index.js +6 -3
- package/lib/module/components/flows/inputButtons/index.js.map +1 -1
- package/lib/module/components/messages/fileMessage/index.js +2 -1
- package/lib/module/components/messages/fileMessage/index.js.map +1 -1
- package/lib/module/config/api-endpoints.js +2 -1
- package/lib/module/config/api-endpoints.js.map +1 -1
- package/lib/module/context/ChatDetailContext.js +35 -2
- package/lib/module/context/ChatDetailContext.js.map +1 -1
- package/lib/module/context/index.js +1 -0
- package/lib/module/context/index.js.map +1 -1
- package/lib/module/hooks/conversation/useGetConversationDetail.js +58 -0
- package/lib/module/hooks/conversation/useGetConversationDetail.js.map +1 -0
- package/lib/module/hooks/flows/useFlow.js +1 -1
- package/lib/module/hooks/flows/useFlow.js.map +1 -1
- package/lib/module/hooks/flows/useGetConversationFlowMainMenu.js +17 -0
- package/lib/module/hooks/flows/useGetConversationFlowMainMenu.js.map +1 -0
- package/lib/module/hooks/message/useSendMessage.js +32 -7
- package/lib/module/hooks/message/useSendMessage.js.map +1 -1
- package/lib/module/hooks/query-keys.js +5 -1
- package/lib/module/hooks/query-keys.js.map +1 -1
- package/lib/module/hooks/useChatCompose.js +0 -1
- package/lib/module/hooks/useChatCompose.js.map +1 -1
- package/lib/module/hooks/useIsJoinedGroup.js +15 -0
- package/lib/module/hooks/useIsJoinedGroup.js.map +1 -0
- package/lib/module/index.js +4 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatAttachmentPanel.js +4 -14
- package/lib/module/screens/chat-detail/ChatAttachmentPanel.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatComposer.js +26 -15
- package/lib/module/screens/chat-detail/ChatComposer.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatDetail.js +58 -71
- package/lib/module/screens/chat-detail/ChatDetail.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatDetailHeader.js +7 -10
- package/lib/module/screens/chat-detail/ChatDetailHeader.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatListLegend.js +1 -1
- package/lib/module/screens/chat-detail/ChatListLegend.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatLoadEarlier.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatQuickActions.js +2 -1
- package/lib/module/screens/chat-detail/ChatQuickActions.js.map +1 -1
- package/lib/module/screens/chat-detail/constants.js +30 -24
- package/lib/module/screens/chat-detail/constants.js.map +1 -1
- package/lib/module/screens/chat-detail/index.js +2 -2
- package/lib/module/screens/chat-detail/index.js.map +1 -1
- package/lib/module/screens/chat-detail/legend/LegendChatMessage.js +1 -4
- package/lib/module/screens/chat-detail/legend/LegendChatMessage.js.map +1 -1
- package/lib/module/screens/chat-detail/types.js +15 -1
- package/lib/module/screens/chat-detail/types.js.map +1 -1
- package/lib/module/services/attachmentHandlers/imageAttachmentHandler.js +2 -2
- package/lib/module/services/attachmentHandlers/imageAttachmentHandler.js.map +1 -1
- package/lib/module/services/endpoints.js +3 -1
- package/lib/module/services/endpoints.js.map +1 -1
- package/lib/module/translation/resources/i18n.js +8 -2
- package/lib/module/translation/resources/i18n.js.map +1 -1
- package/lib/module/types/chat.js +9 -0
- package/lib/module/types/chat.js.map +1 -1
- package/lib/module/types/flows.js +5 -0
- package/lib/module/types/flows.js.map +1 -1
- package/lib/module/utils/device.js +1 -1
- package/lib/module/utils/device.js.map +1 -1
- package/lib/module/utils/flows.js +5 -0
- package/lib/module/utils/flows.js.map +1 -1
- package/lib/module/utils/imageUtils.js +0 -3
- package/lib/module/utils/imageUtils.js.map +1 -1
- package/lib/module/utils/messageUtils.js +5 -19
- package/lib/module/utils/messageUtils.js.map +1 -1
- package/lib/typescript/src/assets/images/index.d.ts +1 -0
- package/lib/typescript/src/assets/images/index.d.ts.map +1 -1
- package/lib/typescript/src/components/ThreadCard/MuteThread.d.ts.map +1 -1
- package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts.map +1 -1
- package/lib/typescript/src/components/flows/inputButtons/index.d.ts.map +1 -1
- package/lib/typescript/src/config/api-endpoints.d.ts +1 -0
- package/lib/typescript/src/config/api-endpoints.d.ts.map +1 -1
- package/lib/typescript/src/context/ChatDetailContext.d.ts +1 -1
- package/lib/typescript/src/context/ChatDetailContext.d.ts.map +1 -1
- package/lib/typescript/src/context/index.d.ts +1 -0
- package/lib/typescript/src/context/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/conversation/useGetConversationDetail.d.ts +17 -0
- package/lib/typescript/src/hooks/conversation/useGetConversationDetail.d.ts.map +1 -0
- package/lib/typescript/src/hooks/flows/useGetConversationFlowMainMenu.d.ts +3 -0
- package/lib/typescript/src/hooks/flows/useGetConversationFlowMainMenu.d.ts.map +1 -0
- package/lib/typescript/src/hooks/message/useSendMessage.d.ts +5 -4
- package/lib/typescript/src/hooks/message/useSendMessage.d.ts.map +1 -1
- package/lib/typescript/src/hooks/query-keys.d.ts +4 -0
- package/lib/typescript/src/hooks/query-keys.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useIsJoinedGroup.d.ts +2 -0
- package/lib/typescript/src/hooks/useIsJoinedGroup.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -4
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts +2 -2
- package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts +3 -1
- package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts +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 +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts +3 -2
- package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/constants.d.ts +3 -3
- package/lib/typescript/src/screens/chat-detail/constants.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/index.d.ts +3 -3
- package/lib/typescript/src/screens/chat-detail/index.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatMessage.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatMessage.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/types.d.ts +28 -19
- package/lib/typescript/src/screens/chat-detail/types.d.ts.map +1 -1
- package/lib/typescript/src/services/endpoints.d.ts +2 -0
- package/lib/typescript/src/services/endpoints.d.ts.map +1 -1
- package/lib/typescript/src/store/conversation.d.ts +1 -1
- 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/chat.d.ts +26 -2
- package/lib/typescript/src/types/chat.d.ts.map +1 -1
- package/lib/typescript/src/types/flows.d.ts +3 -0
- package/lib/typescript/src/types/flows.d.ts.map +1 -1
- package/lib/typescript/src/utils/flows.d.ts +2 -0
- package/lib/typescript/src/utils/flows.d.ts.map +1 -1
- package/lib/typescript/src/utils/imageUtils.d.ts +0 -1
- package/lib/typescript/src/utils/imageUtils.d.ts.map +1 -1
- package/lib/typescript/src/utils/messageUtils.d.ts +1 -1
- package/lib/typescript/src/utils/messageUtils.d.ts.map +1 -1
- package/package.json +4 -6
- package/src/assets/images/index.ts +1 -0
- package/src/assets/images/notification-warning.png +0 -0
- package/src/components/ThreadCard/MuteThread.tsx +70 -36
- package/src/components/ThreadCard/ThreadCard.tsx +7 -3
- package/src/components/flows/inputButtons/index.tsx +11 -3
- package/src/components/messages/fileMessage/index.tsx +1 -0
- package/src/config/api-endpoints.ts +2 -0
- package/src/context/ChatDetailContext.tsx +57 -4
- package/src/context/index.ts +1 -0
- package/src/hooks/conversation/useGetConversationDetail.ts +78 -0
- package/src/hooks/flows/useFlow.ts +1 -1
- package/src/hooks/flows/useGetConversationFlowMainMenu.ts +19 -0
- package/src/hooks/message/useSendMessage.ts +43 -14
- package/src/hooks/query-keys.ts +7 -0
- package/src/hooks/useChatCompose.ts +1 -1
- package/src/hooks/useIsJoinedGroup.ts +13 -0
- package/src/index.tsx +15 -6
- package/src/screens/chat-detail/ChatAttachmentPanel.tsx +8 -25
- package/src/screens/chat-detail/ChatComposer.tsx +26 -21
- package/src/screens/chat-detail/ChatDetail.tsx +61 -77
- package/src/screens/chat-detail/ChatDetailHeader.tsx +7 -18
- package/src/screens/chat-detail/ChatListLegend.tsx +1 -1
- package/src/screens/chat-detail/ChatLoadEarlier.tsx +1 -2
- package/src/screens/chat-detail/ChatQuickActions.tsx +6 -2
- package/src/screens/chat-detail/constants.ts +33 -27
- package/src/screens/chat-detail/index.ts +5 -8
- package/src/screens/chat-detail/legend/LegendChatMessage.tsx +1 -5
- package/src/screens/chat-detail/types.ts +30 -28
- package/src/services/attachmentHandlers/imageAttachmentHandler.ts +2 -2
- package/src/services/endpoints.ts +4 -0
- package/src/store/conversation.ts +1 -1
- package/src/translation/resources/i18n.ts +7 -1
- package/src/types/chat.ts +31 -1
- package/src/types/flows.ts +4 -0
- package/src/utils/device.ts +1 -1
- package/src/utils/flows.ts +7 -0
- package/src/utils/imageUtils.ts +0 -4
- package/src/utils/messageUtils.ts +7 -22
- package/lib/module/screens/chat-detail/ChatDay.js +0 -65
- package/lib/module/screens/chat-detail/ChatDay.js.map +0 -1
- package/lib/module/types/message.js +0 -17
- package/lib/module/types/message.js.map +0 -1
- package/lib/module/utils/resolveMessageType.js +0 -47
- package/lib/module/utils/resolveMessageType.js.map +0 -1
- package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts +0 -3
- package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts.map +0 -1
- package/lib/typescript/src/types/message.d.ts +0 -16
- package/lib/typescript/src/types/message.d.ts.map +0 -1
- package/lib/typescript/src/utils/resolveMessageType.d.ts +0 -4
- package/lib/typescript/src/utils/resolveMessageType.d.ts.map +0 -1
- package/src/screens/chat-detail/ChatDay.tsx +0 -73
- package/src/types/message.ts +0 -18
- package/src/utils/resolveMessageType.ts +0 -51
|
@@ -15,12 +15,14 @@ export interface ApiEndpoints {
|
|
|
15
15
|
conversationFlow: string;
|
|
16
16
|
// Image upload service (relative path - full URL constructed in imageUpload service)
|
|
17
17
|
imageUpload: string;
|
|
18
|
+
bot: string;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
const DEFAULT_ENDPOINTS: ApiEndpoints = {
|
|
21
22
|
urlMetadata: '/chat-service/v1/utils/url-metadata',
|
|
22
23
|
conversationFlow: '/chat-service/v1/app/conversations',
|
|
23
24
|
imageUpload: '/uploader-service/v1/uploader/permanently',
|
|
25
|
+
bot: '/chat-service/v1/app/bots/',
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
let endpoints: ApiEndpoints = { ...DEFAULT_ENDPOINTS };
|
|
@@ -6,20 +6,32 @@ import {
|
|
|
6
6
|
useMemo,
|
|
7
7
|
useState,
|
|
8
8
|
} from 'react';
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
import {
|
|
10
|
+
DFlowState,
|
|
11
|
+
type ChatDetailContextType,
|
|
12
|
+
type ChatDetailProviderProps,
|
|
12
13
|
} from '../types/chat';
|
|
13
14
|
import { fechtCurrentConversationFlow } from '../hooks/flows/useCurrentConversationFlow';
|
|
14
15
|
import { useConversationStore } from '../store';
|
|
15
16
|
import { PeerType } from '@droppii/openim-rn-client-sdk';
|
|
16
|
-
import
|
|
17
|
+
import {
|
|
18
|
+
DFlowContext,
|
|
19
|
+
NodeTypes,
|
|
20
|
+
type IConversationFlow,
|
|
21
|
+
type IConversationFlowStep,
|
|
22
|
+
} from '../types/flows';
|
|
23
|
+
import { useGetConversationFlowMainMenu } from '../hooks/flows/useGetConversationFlowMainMenu';
|
|
24
|
+
import { useRunFlow } from '../hooks/flows/useFlow';
|
|
25
|
+
import { CONTEXT_BUTTON_PREFIX, isContextButton } from '../utils/flows';
|
|
17
26
|
|
|
18
27
|
export const ChatDetailContext = createContext<ChatDetailContextType>({
|
|
19
28
|
isBotConversation: false,
|
|
20
29
|
conversationFlow: undefined,
|
|
21
30
|
refetchConversationFlow: () => {},
|
|
22
31
|
setConverationFlowStep: () => {},
|
|
32
|
+
flowState: undefined,
|
|
33
|
+
runButtonContext: () => Promise.resolve(false),
|
|
34
|
+
conversation: undefined,
|
|
23
35
|
});
|
|
24
36
|
|
|
25
37
|
export const useChatDetailContext = (): ChatDetailContextType => {
|
|
@@ -43,10 +55,26 @@ export const ChatDetailProvider = ({ children }: ChatDetailProviderProps) => {
|
|
|
43
55
|
IConversationFlow | undefined
|
|
44
56
|
>(undefined);
|
|
45
57
|
|
|
58
|
+
const flowState = useMemo(() => {
|
|
59
|
+
return conversationFlow
|
|
60
|
+
? conversationFlow?.flowCurrentStep?.data?.children?.some(
|
|
61
|
+
(n) => n.type === NodeTypes.LogicCsTeam
|
|
62
|
+
)
|
|
63
|
+
? DFlowState.CS
|
|
64
|
+
: DFlowState.BOT
|
|
65
|
+
: undefined;
|
|
66
|
+
}, [conversationFlow]);
|
|
67
|
+
|
|
46
68
|
const isBotConversation = useMemo(() => {
|
|
47
69
|
return conversation?.peerType === PeerType.Bot;
|
|
48
70
|
}, [conversation]);
|
|
49
71
|
|
|
72
|
+
const { data: conversationFlowMainMenu } = useGetConversationFlowMainMenu(
|
|
73
|
+
isBotConversation ? conversationId : ''
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const { mutateAsync: runFlow } = useRunFlow();
|
|
77
|
+
|
|
50
78
|
const setConverationFlowStep = useCallback((step?: IConversationFlowStep) => {
|
|
51
79
|
setConverationFlow(
|
|
52
80
|
(prev) =>
|
|
@@ -64,6 +92,28 @@ export const ChatDetailProvider = ({ children }: ChatDetailProviderProps) => {
|
|
|
64
92
|
}
|
|
65
93
|
}, [conversationId]);
|
|
66
94
|
|
|
95
|
+
const runButtonContext = useCallback(
|
|
96
|
+
async (stringContext: DFlowContext) => {
|
|
97
|
+
const actionItem = conversationFlowMainMenu?.find(
|
|
98
|
+
(f) =>
|
|
99
|
+
isContextButton(f.label) &&
|
|
100
|
+
f.label.trim().slice(CONTEXT_BUTTON_PREFIX.length) ===
|
|
101
|
+
stringContext?.trim()
|
|
102
|
+
);
|
|
103
|
+
if (actionItem) {
|
|
104
|
+
const res = await runFlow({
|
|
105
|
+
actionId: actionItem.id,
|
|
106
|
+
groupId: '',
|
|
107
|
+
childId: '',
|
|
108
|
+
});
|
|
109
|
+
setConverationFlowStep(res?.flowNextStep || undefined);
|
|
110
|
+
return res ? true : false;
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
},
|
|
114
|
+
[runFlow, conversationFlowMainMenu, setConverationFlowStep]
|
|
115
|
+
);
|
|
116
|
+
|
|
67
117
|
useEffect(() => {
|
|
68
118
|
if (!!conversationId && !!isBotConversation) {
|
|
69
119
|
getConversationFlow();
|
|
@@ -77,6 +127,9 @@ export const ChatDetailProvider = ({ children }: ChatDetailProviderProps) => {
|
|
|
77
127
|
refetchConversationFlow: () => {},
|
|
78
128
|
setConverationFlowStep,
|
|
79
129
|
isBotConversation,
|
|
130
|
+
flowState,
|
|
131
|
+
runButtonContext,
|
|
132
|
+
conversation,
|
|
80
133
|
}}
|
|
81
134
|
>
|
|
82
135
|
{children}
|
package/src/context/index.ts
CHANGED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import OpenIMSDK, { SessionType } from '@droppii/openim-rn-client-sdk';
|
|
3
|
+
import { useConversationStore } from '../../store/conversation';
|
|
4
|
+
import { apiInstance } from '../../services/apis';
|
|
5
|
+
import type { BaseResponse } from '../../types/auth';
|
|
6
|
+
import { conversationQueryKeys } from '../query-keys';
|
|
7
|
+
import { ENDPOINTS } from '../../services/endpoints';
|
|
8
|
+
|
|
9
|
+
interface UseGetConversationDetailParams {
|
|
10
|
+
targetConversationId?: string;
|
|
11
|
+
targetUserId?: string;
|
|
12
|
+
targetGroupId?: string;
|
|
13
|
+
targetBotId?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface UseGetConversationDetailResult {
|
|
17
|
+
conversationId: string;
|
|
18
|
+
isLoading: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const useBotConversationData = (botId?: string) =>
|
|
22
|
+
useQuery({
|
|
23
|
+
queryKey: conversationQueryKeys.detailByBotId(botId || ''),
|
|
24
|
+
queryFn: async () => {
|
|
25
|
+
const res = await apiInstance?.get<
|
|
26
|
+
BaseResponse<{ groupId: string; conversationId: string }>
|
|
27
|
+
>(ENDPOINTS.chatService.getConversationByBotId(botId || ''));
|
|
28
|
+
return res?.data?.data || undefined;
|
|
29
|
+
},
|
|
30
|
+
enabled: !!botId,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const useGetOneConversation = ({
|
|
34
|
+
targetUserId,
|
|
35
|
+
targetGroupId,
|
|
36
|
+
}: {
|
|
37
|
+
targetUserId?: string;
|
|
38
|
+
targetGroupId?: string;
|
|
39
|
+
}) => {
|
|
40
|
+
return useQuery({
|
|
41
|
+
queryKey: conversationQueryKeys.detailBySourceId(
|
|
42
|
+
targetUserId || targetGroupId || ''
|
|
43
|
+
),
|
|
44
|
+
queryFn: async () => {
|
|
45
|
+
const res = await OpenIMSDK.getOneConversation({
|
|
46
|
+
sourceID: targetUserId || targetGroupId || '',
|
|
47
|
+
sessionType: targetUserId ? SessionType.Single : SessionType.Group,
|
|
48
|
+
});
|
|
49
|
+
if (res?.conversationID) {
|
|
50
|
+
useConversationStore.getState().updateConversations([res]);
|
|
51
|
+
}
|
|
52
|
+
return res || undefined;
|
|
53
|
+
},
|
|
54
|
+
enabled: !!targetUserId || !!targetGroupId,
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const useGetConversationDetail = ({
|
|
59
|
+
targetConversationId,
|
|
60
|
+
targetUserId,
|
|
61
|
+
targetGroupId,
|
|
62
|
+
targetBotId,
|
|
63
|
+
}: UseGetConversationDetailParams): UseGetConversationDetailResult => {
|
|
64
|
+
const { data: botData, isLoading: botIdLoading } =
|
|
65
|
+
useBotConversationData(targetBotId);
|
|
66
|
+
|
|
67
|
+
const { data: conversationData, isLoading: conversationLoading } =
|
|
68
|
+
useGetOneConversation({
|
|
69
|
+
targetUserId,
|
|
70
|
+
targetGroupId: targetGroupId || botData?.groupId,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
conversationId:
|
|
75
|
+
targetConversationId || conversationData?.conversationID || '',
|
|
76
|
+
isLoading: botIdLoading || conversationLoading,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
@@ -20,7 +20,7 @@ export const useResetFlow = () => {
|
|
|
20
20
|
const { sendMessage } = useSendMessage();
|
|
21
21
|
const conversationFlow = useChatDetailContext().conversationFlow;
|
|
22
22
|
return useMutation({
|
|
23
|
-
mutationKey: conversationQueryKeys.
|
|
23
|
+
mutationKey: conversationQueryKeys.resetFlow(conversationId),
|
|
24
24
|
mutationFn: async () => {
|
|
25
25
|
await sendMessage({
|
|
26
26
|
plainText: trans('restart'),
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { conversationQueryKeys } from '../query-keys';
|
|
3
|
+
import { apiInstance } from '../../services/apis';
|
|
4
|
+
import type { BaseResponse } from '../../types/auth';
|
|
5
|
+
import type { InputButtonItem } from '../../types/flows';
|
|
6
|
+
import { ENDPOINTS } from '../../services/endpoints';
|
|
7
|
+
|
|
8
|
+
export const useGetConversationFlowMainMenu = (conversationId?: string) => {
|
|
9
|
+
return useQuery({
|
|
10
|
+
queryKey: [conversationQueryKeys.flowMainMenu(conversationId || '')],
|
|
11
|
+
queryFn: async () => {
|
|
12
|
+
const res = await apiInstance?.get<BaseResponse<InputButtonItem[]>>(
|
|
13
|
+
ENDPOINTS.chatService.conversationFlowMainMenu(conversationId || '')
|
|
14
|
+
);
|
|
15
|
+
return res?.data?.data || undefined;
|
|
16
|
+
},
|
|
17
|
+
enabled: !!conversationId,
|
|
18
|
+
});
|
|
19
|
+
};
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
import type { UploadFileItem } from 'react-native-fs';
|
|
3
2
|
import { useConversationStore } from '../../store/conversation';
|
|
4
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
CustomMsgParams,
|
|
5
|
+
MessageItem,
|
|
6
|
+
OfflinePush,
|
|
7
|
+
} from '@droppii/openim-rn-client-sdk';
|
|
5
8
|
import { MessageStatus, MessageType } from '@droppii/openim-rn-client-sdk';
|
|
6
9
|
import { extractUrls } from '../../utils/url';
|
|
7
10
|
import OpenIMSDK from '@droppii/openim-rn-client-sdk';
|
|
8
|
-
import
|
|
11
|
+
import {
|
|
12
|
+
CustomMessageType,
|
|
13
|
+
type CustomMessagePayload,
|
|
14
|
+
type IMessageItemEx,
|
|
15
|
+
} from '../../types/chat';
|
|
9
16
|
import { useChatContext } from '../../context';
|
|
10
17
|
import { generateContentBasedOnMessageType } from '../../utils/conversation';
|
|
11
18
|
import { markMessageRevoked, useMessageStore } from '../../store/message';
|
|
19
|
+
import uuid from 'react-native-uuid';
|
|
12
20
|
|
|
13
21
|
import type { IUrlMetadata } from '../../types/common';
|
|
14
22
|
import type { IRunConversationFlowPayload } from '../../types/flows';
|
|
@@ -63,14 +71,14 @@ export const useSendMessage = () => {
|
|
|
63
71
|
const sendMessage = useCallback(
|
|
64
72
|
async ({
|
|
65
73
|
plainText,
|
|
66
|
-
files,
|
|
67
74
|
urlMetadata,
|
|
68
75
|
flow,
|
|
76
|
+
customMessage,
|
|
69
77
|
}: {
|
|
70
78
|
plainText?: string;
|
|
71
|
-
files?: UploadFileItem[];
|
|
72
79
|
urlMetadata?: IUrlMetadata;
|
|
73
80
|
flow?: IRunConversationFlowPayload;
|
|
81
|
+
customMessage?: CustomMessagePayload;
|
|
74
82
|
}) => {
|
|
75
83
|
const { userID: recvID, groupID } =
|
|
76
84
|
useConversationStore.getState().getCurrentConversation() || {};
|
|
@@ -78,13 +86,10 @@ export const useSendMessage = () => {
|
|
|
78
86
|
|
|
79
87
|
const messageList: MessageItem[] = [];
|
|
80
88
|
|
|
81
|
-
for (const file of files || []) {
|
|
82
|
-
if (!file) continue;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
89
|
const hasText = !!plainText && plainText.trim() !== '';
|
|
86
90
|
const hasPreview = !!urlMetadata?.url;
|
|
87
91
|
|
|
92
|
+
//text msg
|
|
88
93
|
if (hasText || hasPreview) {
|
|
89
94
|
const urls = hasText ? extractUrls(plainText) : [];
|
|
90
95
|
const isUrlMessage = urls.length > 0 || hasPreview;
|
|
@@ -100,6 +105,21 @@ export const useSendMessage = () => {
|
|
|
100
105
|
messageList.push(message);
|
|
101
106
|
}
|
|
102
107
|
|
|
108
|
+
//custom msg
|
|
109
|
+
if (customMessage) {
|
|
110
|
+
let customElem: CustomMsgParams = {
|
|
111
|
+
data: JSON.stringify(customMessage.data),
|
|
112
|
+
extension: customMessage.type,
|
|
113
|
+
description:
|
|
114
|
+
customMessage?.type === CustomMessageType.Order
|
|
115
|
+
? customMessage?.data?.orderCode
|
|
116
|
+
: '',
|
|
117
|
+
};
|
|
118
|
+
const message = await createCustomMessage(customElem);
|
|
119
|
+
if (!message) return;
|
|
120
|
+
messageList.push(message);
|
|
121
|
+
}
|
|
122
|
+
|
|
103
123
|
for (const message of messageList) {
|
|
104
124
|
const extendMessageInfo: IMessageItemEx = {
|
|
105
125
|
applicationType,
|
|
@@ -212,10 +232,7 @@ const generateOfflinePushInfo = (
|
|
|
212
232
|
};
|
|
213
233
|
|
|
214
234
|
export const createTextMessage = async (text: string) => {
|
|
215
|
-
let textMessage = await OpenIMSDK.createTextMessage(
|
|
216
|
-
text,
|
|
217
|
-
new Date().getTime().toString()
|
|
218
|
-
)
|
|
235
|
+
let textMessage = await OpenIMSDK.createTextMessage(text, uuid.v4())
|
|
219
236
|
.then((data) => {
|
|
220
237
|
return data;
|
|
221
238
|
})
|
|
@@ -230,7 +247,7 @@ export const createUrlTextMessage = async (text: string, urls: string[]) => {
|
|
|
230
247
|
let urlTextMessage = await OpenIMSDK.createUrlTextMessage(
|
|
231
248
|
text,
|
|
232
249
|
urls,
|
|
233
|
-
|
|
250
|
+
uuid.v4()
|
|
234
251
|
)
|
|
235
252
|
.then((data) => {
|
|
236
253
|
return data;
|
|
@@ -241,3 +258,15 @@ export const createUrlTextMessage = async (text: string, urls: string[]) => {
|
|
|
241
258
|
});
|
|
242
259
|
return urlTextMessage;
|
|
243
260
|
};
|
|
261
|
+
|
|
262
|
+
export const createCustomMessage = async (params: CustomMsgParams) => {
|
|
263
|
+
let customMessage = await OpenIMSDK.createCustomMessage(params, uuid.v4())
|
|
264
|
+
.then((data) => {
|
|
265
|
+
return data;
|
|
266
|
+
})
|
|
267
|
+
.catch(({ errCode, errMsg }) => {
|
|
268
|
+
console.error('createUrlTextMessage', errCode, errMsg);
|
|
269
|
+
return null;
|
|
270
|
+
});
|
|
271
|
+
return customMessage;
|
|
272
|
+
};
|
package/src/hooks/query-keys.ts
CHANGED
|
@@ -12,11 +12,18 @@ export const conversationQueryKeys = {
|
|
|
12
12
|
detail: (conversationId: string) =>
|
|
13
13
|
[...conversationQueryKeys.details(), conversationId] as const,
|
|
14
14
|
flow: (conversationId: string) => ['conversationFlow', conversationId],
|
|
15
|
+
flowMainMenu: (conversationId: string) => [
|
|
16
|
+
'conversationFlowMainMenu',
|
|
17
|
+
conversationId,
|
|
18
|
+
],
|
|
15
19
|
resetFlow: (conversationId: string) => [
|
|
16
20
|
'resetConversationFlow',
|
|
17
21
|
conversationId,
|
|
18
22
|
],
|
|
19
23
|
runFlow: (conversationId: string) => ['runConversationFlow', conversationId],
|
|
24
|
+
detailByBotId: (botId: string) => ['conversationByBotId', botId],
|
|
25
|
+
detailBySourceId: (sourceId: string) => ['detailBySourceId', sourceId],
|
|
26
|
+
joinedGroup: (groupId?: string) => [...conversationQueryKeys.all, groupId],
|
|
20
27
|
};
|
|
21
28
|
|
|
22
29
|
export type ConversationQueryKeys = typeof conversationQueryKeys;
|
|
@@ -151,7 +151,7 @@ export function useChatCompose() {
|
|
|
151
151
|
// Clear composer immediately — message is already in chat list with Sending status.
|
|
152
152
|
// User retries from the bubble, not the composer.
|
|
153
153
|
setText('');
|
|
154
|
-
await sendMessage({
|
|
154
|
+
await sendMessage({ plainText, urlMetadata: urlMeta });
|
|
155
155
|
}
|
|
156
156
|
}, [
|
|
157
157
|
imageAttachment,
|
|
@@ -0,0 +1,13 @@
|
|
|
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 useIsJoinedGroup = (groupId?: string) => {
|
|
6
|
+
return useQuery({
|
|
7
|
+
queryKey: conversationQueryKeys.joinedGroup(groupId),
|
|
8
|
+
enabled: Boolean(groupId),
|
|
9
|
+
queryFn: async () => {
|
|
10
|
+
return await OpenIMSDK.isJoinGroup(groupId!);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -14,6 +14,7 @@ export * from './store';
|
|
|
14
14
|
export * from './context';
|
|
15
15
|
export * from './hooks/useConversationList';
|
|
16
16
|
export * from './hooks/useChatMessages';
|
|
17
|
+
export * from './hooks/message/useSendMessage';
|
|
17
18
|
export { useImageAttachment } from './hooks/useImageAttachment';
|
|
18
19
|
export { useMediaViewer } from './hooks/useMediaViewer';
|
|
19
20
|
export type { MediaItem } from './hooks/useMediaViewer';
|
|
@@ -34,24 +35,32 @@ export {
|
|
|
34
35
|
ChatComposer,
|
|
35
36
|
ChatQuickActions,
|
|
36
37
|
ChatAttachmentPanel,
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
DEFAULT_QUICK_ACTIONS,
|
|
39
|
+
DEFAULT_PANNEL_ACTIONS,
|
|
40
|
+
DChatPannelActionItemType,
|
|
41
|
+
DChatQuickActionItemType,
|
|
39
42
|
} from './screens/chat-detail';
|
|
40
43
|
export type {
|
|
41
44
|
DChatActionItem,
|
|
42
45
|
DChatActionIconProvider,
|
|
43
46
|
DChatQuickAction,
|
|
44
|
-
|
|
47
|
+
DChatPannelAction,
|
|
45
48
|
ChatDetailProps,
|
|
46
49
|
ChatDetailHeaderProps,
|
|
47
50
|
ChatListProps,
|
|
48
51
|
ChatComposerProps,
|
|
49
52
|
ChatQuickActionsProps,
|
|
50
53
|
ChatQuickActionsRenderParams,
|
|
51
|
-
|
|
54
|
+
ChatPanelProps,
|
|
52
55
|
} from './screens/chat-detail';
|
|
53
56
|
|
|
54
|
-
export
|
|
55
|
-
export {
|
|
57
|
+
export { LoginStatus, MessageType } from '@droppii/openim-rn-client-sdk';
|
|
58
|
+
export type {
|
|
59
|
+
PeerType,
|
|
60
|
+
ConversationItem,
|
|
61
|
+
MessageItem,
|
|
62
|
+
} from '@droppii/openim-rn-client-sdk';
|
|
56
63
|
|
|
57
64
|
export { registerUIUtils, UIUtils } from './utils/UIUtils';
|
|
65
|
+
|
|
66
|
+
export { DFlowContext } from './types/flows';
|
|
@@ -8,8 +8,7 @@ import {
|
|
|
8
8
|
KSpacingValue,
|
|
9
9
|
} from '@droppii/libs';
|
|
10
10
|
import { ATTACHMENT_PANEL_COLUMNS } from './constants';
|
|
11
|
-
import {
|
|
12
|
-
import type { DChatAttachmentAction, ChatAttachmentPanelProps } from './types';
|
|
11
|
+
import type { DChatPannelAction, ChatPanelProps } from './types';
|
|
13
12
|
|
|
14
13
|
const AttachmentActionItem = memo(
|
|
15
14
|
({
|
|
@@ -17,9 +16,9 @@ const AttachmentActionItem = memo(
|
|
|
17
16
|
itemWidth,
|
|
18
17
|
onPress,
|
|
19
18
|
}: {
|
|
20
|
-
action:
|
|
19
|
+
action: DChatPannelAction;
|
|
21
20
|
itemWidth: `${number}%`;
|
|
22
|
-
onPress: (action:
|
|
21
|
+
onPress: (action: DChatPannelAction) => void;
|
|
23
22
|
}) => {
|
|
24
23
|
const handlePress = useCallback(() => {
|
|
25
24
|
onPress(action);
|
|
@@ -61,42 +60,26 @@ const AttachmentActionItem = memo(
|
|
|
61
60
|
AttachmentActionItem.displayName = 'AttachmentActionItem';
|
|
62
61
|
|
|
63
62
|
export const ChatAttachmentPanel = memo(
|
|
64
|
-
({
|
|
65
|
-
actions,
|
|
66
|
-
columns = ATTACHMENT_PANEL_COLUMNS,
|
|
67
|
-
onActionPress,
|
|
68
|
-
renderAction,
|
|
69
|
-
}: ChatAttachmentPanelProps) => {
|
|
70
|
-
const handleActionPress = useChatActionPress(onActionPress);
|
|
71
|
-
|
|
63
|
+
({ actions, columns = ATTACHMENT_PANEL_COLUMNS }: ChatPanelProps) => {
|
|
72
64
|
const itemWidth = useMemo(
|
|
73
65
|
() => `${100 / columns}%` as `${number}%`,
|
|
74
66
|
[columns]
|
|
75
67
|
);
|
|
76
68
|
|
|
77
|
-
const renderItem = useCallback<ListRenderItem<
|
|
69
|
+
const renderItem = useCallback<ListRenderItem<DChatPannelAction>>(
|
|
78
70
|
({ item }) => {
|
|
79
|
-
const onPress = () => handleActionPress(item);
|
|
80
|
-
|
|
81
|
-
if (renderAction) {
|
|
82
|
-
return <>{renderAction(item, onPress)}</>;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
71
|
return (
|
|
86
72
|
<AttachmentActionItem
|
|
87
73
|
action={item}
|
|
88
74
|
itemWidth={itemWidth}
|
|
89
|
-
onPress={
|
|
75
|
+
onPress={() => item?.onPress?.()}
|
|
90
76
|
/>
|
|
91
77
|
);
|
|
92
78
|
},
|
|
93
|
-
[
|
|
79
|
+
[itemWidth]
|
|
94
80
|
);
|
|
95
81
|
|
|
96
|
-
const keyExtractor = useCallback(
|
|
97
|
-
(item: DChatAttachmentAction) => item.id,
|
|
98
|
-
[]
|
|
99
|
-
);
|
|
82
|
+
const keyExtractor = useCallback((item: DChatPannelAction) => item.id, []);
|
|
100
83
|
|
|
101
84
|
if (!actions?.length) {
|
|
102
85
|
return null;
|
|
@@ -18,11 +18,11 @@ import { ChatMessageInput } from './components/ChatMessageInput';
|
|
|
18
18
|
import { AttachmentPreview } from '../../components/AttachmentPreview';
|
|
19
19
|
|
|
20
20
|
import {
|
|
21
|
-
|
|
22
|
-
DEFAULT_Chat_QUICK_ACTIONS,
|
|
21
|
+
DEFAULT_QUICK_ACTIONS,
|
|
23
22
|
getAttachmentPanelHeight,
|
|
23
|
+
DEFAULT_PANNEL_ACTIONS,
|
|
24
24
|
} from './constants';
|
|
25
|
-
import type
|
|
25
|
+
import { DChatPannelActionItemType, type DChatPannelAction } from './types';
|
|
26
26
|
import { useChatComposerState } from './hooks/useChatComposerState';
|
|
27
27
|
import { useChatComposerAnimation } from './hooks/useChatComposerAnimation';
|
|
28
28
|
import { useChatDetailContext } from '../../context/ChatDetailContext';
|
|
@@ -35,10 +35,11 @@ import { useChatCompose } from '../../hooks/useChatCompose';
|
|
|
35
35
|
|
|
36
36
|
interface ChatComposerInternalProps {
|
|
37
37
|
isEmptyMessage?: boolean;
|
|
38
|
+
pannelActions?: DChatPannelAction[];
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export const ChatComposer = memo(
|
|
41
|
-
({ isEmptyMessage = false }: ChatComposerInternalProps) => {
|
|
42
|
+
({ isEmptyMessage = false, pannelActions }: ChatComposerInternalProps) => {
|
|
42
43
|
const insets = useSafeAreaInsets();
|
|
43
44
|
|
|
44
45
|
const { isBotConversation, conversationFlow } = useChatDetailContext();
|
|
@@ -57,7 +58,7 @@ export const ChatComposer = memo(
|
|
|
57
58
|
} = useChatComposerState(compose.text);
|
|
58
59
|
|
|
59
60
|
const panelHeight = useMemo(
|
|
60
|
-
() => getAttachmentPanelHeight(
|
|
61
|
+
() => getAttachmentPanelHeight(DEFAULT_PANNEL_ACTIONS.length),
|
|
61
62
|
[]
|
|
62
63
|
);
|
|
63
64
|
|
|
@@ -132,18 +133,25 @@ export const ChatComposer = memo(
|
|
|
132
133
|
})
|
|
133
134
|
);
|
|
134
135
|
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
136
|
+
const resolvedPannelActons = useMemo(() => {
|
|
137
|
+
return (pannelActions || DEFAULT_PANNEL_ACTIONS)?.map((p) => {
|
|
138
|
+
let onPress;
|
|
139
|
+
switch (p.id) {
|
|
140
|
+
case DChatPannelActionItemType.Gallery:
|
|
141
|
+
onPress = debouncedImagePickerRef.current;
|
|
142
|
+
break;
|
|
143
|
+
case DChatPannelActionItemType.Documents:
|
|
144
|
+
onPress = debouncedFilePickerRef.current;
|
|
145
|
+
break;
|
|
146
|
+
default:
|
|
147
|
+
break;
|
|
143
148
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
return {
|
|
150
|
+
...p,
|
|
151
|
+
onPress: p.onPress || onPress,
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
}, [pannelActions]);
|
|
147
155
|
|
|
148
156
|
const inputRowStyle = useMemo(
|
|
149
157
|
() => ({ paddingBottom: isAttachmentOpen ? 8 : insets.bottom + 12 }),
|
|
@@ -186,7 +194,7 @@ export const ChatComposer = memo(
|
|
|
186
194
|
<KContainer.View background={'rgba(131, 137, 157, 0.05)'}>
|
|
187
195
|
<ChatQuickActions
|
|
188
196
|
visible
|
|
189
|
-
actions={
|
|
197
|
+
actions={DEFAULT_QUICK_ACTIONS}
|
|
190
198
|
onActionPress={(action) =>
|
|
191
199
|
console.log('[ChatComposer] quick action:', action.id)
|
|
192
200
|
}
|
|
@@ -272,10 +280,7 @@ export const ChatComposer = memo(
|
|
|
272
280
|
style={[styles.accessorySlot, accessorySlotStyle]}
|
|
273
281
|
pointerEvents={isAttachmentOpen ? 'auto' : 'none'}
|
|
274
282
|
>
|
|
275
|
-
<ChatAttachmentPanel
|
|
276
|
-
actions={DEFAULT_ATTACHMENT_ACTIONS}
|
|
277
|
-
onActionPress={handleAttachmentAction}
|
|
278
|
-
/>
|
|
283
|
+
<ChatAttachmentPanel actions={resolvedPannelActons} />
|
|
279
284
|
</Reanimated.View>
|
|
280
285
|
</KContainer.View>
|
|
281
286
|
);
|