@droppii-org/chat-sdk 0.1.15 → 0.1.17
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/dist/assets/droppiiFontSelection.json +14521 -14521
- package/dist/assets/sdk/sql-wasm.wasm +0 -0
- package/dist/assets/svg/cannedResponse.tsx +48 -48
- package/dist/assets/svg/document.tsx +37 -37
- package/dist/assets/svg/index.ts +2 -2
- package/dist/components/message/GroupMembersDrawer.d.ts +7 -0
- package/dist/components/message/GroupMembersDrawer.d.ts.map +1 -0
- package/dist/components/message/GroupMembersDrawer.js +104 -0
- package/dist/components/message/MessageHeader.d.ts.map +1 -1
- package/dist/components/message/MessageHeader.js +4 -1
- package/dist/components/message/MessageList.d.ts.map +1 -1
- package/dist/components/message/MessageList.js +8 -7
- package/dist/components/message/footer/ComposerTabs.d.ts +2 -1
- package/dist/components/message/footer/ComposerTabs.d.ts.map +1 -1
- package/dist/components/message/footer/ComposerTabs.js +12 -4
- package/dist/components/message/footer/index.d.ts.map +1 -1
- package/dist/components/message/footer/index.js +15 -6
- package/dist/components/message/item/index.js +24 -20
- package/dist/components/thread/ManualAssignPopover.d.ts.map +1 -1
- package/dist/components/thread/ManualAssignPopover.js +16 -3
- package/dist/hooks/global/useGlobalEvent.d.ts.map +1 -1
- package/dist/hooks/global/useGlobalEvent.js +24 -1
- package/dist/hooks/group/useGroupMembers.d.ts +10 -0
- package/dist/hooks/group/useGroupMembers.d.ts.map +1 -0
- package/dist/hooks/group/useGroupMembers.js +44 -0
- package/dist/hooks/message/useConversationMessages.d.ts.map +1 -1
- package/dist/hooks/message/useConversationMessages.js +4 -3
- package/dist/hooks/message/useMessage.d.ts +1 -1
- package/dist/hooks/message/useMessage.d.ts.map +1 -1
- package/dist/hooks/message/useMessage.js +19 -6
- package/dist/hooks/message/useSendMessage.d.ts.map +1 -1
- package/dist/hooks/message/useSendMessage.js +42 -6
- package/dist/hooks/session/useCloseSession.d.ts.map +1 -1
- package/dist/hooks/session/useCloseSession.js +19 -12
- package/dist/hooks/session/useJoinGroupFlow.d.ts.map +1 -1
- package/dist/hooks/session/useJoinGroupFlow.js +27 -14
- package/dist/hooks/session/useUpdateSession.d.ts +1 -1
- package/dist/hooks/session/useUpdateSession.d.ts.map +1 -1
- package/dist/hooks/session/useUpdateSession.js +20 -12
- package/dist/locales/i18n.ts +18 -18
- package/dist/locales/vi/common.json +122 -113
- package/dist/store/conversation.d.ts.map +1 -1
- package/dist/store/conversation.js +7 -5
- package/dist/styles/global.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/messageEx.d.ts +5 -0
- package/dist/utils/messageEx.d.ts.map +1 -0
- package/dist/utils/messageEx.js +11 -0
- package/package.json +10 -11
|
@@ -11,19 +11,21 @@ import { message as antdMessage } from "antd";
|
|
|
11
11
|
import { invalidateSessionQueries } from "../../utils/queryHelpers";
|
|
12
12
|
import AssignConfirmModal from "./AssignConfirmModal";
|
|
13
13
|
import { useDebounce } from "ahooks";
|
|
14
|
+
import useAuthStore from "../../store/auth";
|
|
14
15
|
const SEARCH_DEBOUNCE_WAIT = 300;
|
|
15
|
-
const SupporterItem = ({ supporter, onClick, isCurrentAssignee, }) => {
|
|
16
|
+
const SupporterItem = ({ supporter, onClick, isCurrentAssignee, isCurrentUser, }) => {
|
|
16
17
|
var _a;
|
|
17
18
|
const { t } = useTranslation();
|
|
18
19
|
const isOnline = supporter.status === "ONLINE";
|
|
19
20
|
return (_jsxs("div", { role: "option", tabIndex: 0, "aria-selected": isCurrentAssignee, className: clsx("flex items-center gap-3 px-3 py-2 rounded-md transition-colors", isCurrentAssignee
|
|
20
21
|
? "bg-blue-50 border border-blue-200 pointer-events-none"
|
|
21
|
-
: "cursor-pointer hover:bg-gray-50"), onClick: () => onClick(supporter), children: [_jsx(Badge, { dot: true, color: isOnline ? "#52c41a" : "#d9d9d9", offset: [-2, 24], children: _jsx(Avatar, { src: supporter.avatar, size: 32, children: ((_a = supporter.displayName) === null || _a === void 0 ? void 0 : _a.charAt(0)) || "A" }) }), _jsx("span", { className: "text-sm truncate
|
|
22
|
+
: "cursor-pointer hover:bg-gray-50"), onClick: () => onClick(supporter), children: [_jsx(Badge, { dot: true, color: isOnline ? "#52c41a" : "#d9d9d9", offset: [-2, 24], children: _jsx(Avatar, { src: supporter.avatar, size: 32, children: ((_a = supporter.displayName) === null || _a === void 0 ? void 0 : _a.charAt(0)) || "A" }) }), _jsxs("div", { className: "flex items-center gap-2 min-w-0 flex-1", children: [_jsx("span", { className: "text-sm truncate", children: supporter.displayName }), isCurrentUser && (_jsx("span", { className: "text-xs text-blue-500 shrink-0", children: t("current_account") }))] }), _jsx("div", { className: "flex items-center gap-2 shrink-0", children: isCurrentAssignee && (_jsx("span", { className: "text-xs text-blue-500 shrink-0", children: t("manual_assign_current") })) })] }));
|
|
22
23
|
};
|
|
23
24
|
const ManualAssignPopover = ({ sessionId, supporter, teamId: propTeamId, }) => {
|
|
24
25
|
var _a, _b;
|
|
25
26
|
const { t } = useTranslation();
|
|
26
27
|
const queryClient = useQueryClient();
|
|
28
|
+
const authUserID = useAuthStore((state) => state.userID);
|
|
27
29
|
const [open, setOpen] = useState(false);
|
|
28
30
|
const [searchText, setSearchText] = useState("");
|
|
29
31
|
const [selectedAgent, setSelectedAgent] = useState(null);
|
|
@@ -75,7 +77,18 @@ const ManualAssignPopover = ({ sessionId, supporter, teamId: propTeamId, }) => {
|
|
|
75
77
|
setSearchText("");
|
|
76
78
|
}
|
|
77
79
|
};
|
|
78
|
-
const popoverContent = (_jsxs("div", { className: "w-64", children: [_jsx("div", { className: "mb-2", children: _jsx(Input, { autoFocus: true, placeholder: t("manual_assign_search_placeholder"), value: searchText, onChange: (e) => setSearchText(e.target.value), prefix: _jsx(Icon, { icon: "search-o", size: 16, className: "text-gray-400" }), className: "rounded-lg border-gray-300 focus-within:border-[#3278f7] focus-within:shadow-[0_0_0_2px_rgba(50,120,247,0.12)]", allowClear: true }) }), _jsx("div", { className: "max-h-72 overflow-y-auto", role: "listbox", children: isLoading ? (_jsx("div", { className: "flex items-center justify-center py-8", children: _jsx(Spin, {}) })) : supporters && supporters.length > 0 ? (_jsx("div", { className: clsx("flex flex-col transition-opacity duration-200", isFetching && "opacity-50 pointer-events-none"), children: supporters
|
|
80
|
+
const popoverContent = (_jsxs("div", { className: "w-64", children: [_jsx("div", { className: "mb-2", children: _jsx(Input, { autoFocus: true, placeholder: t("manual_assign_search_placeholder"), value: searchText, onChange: (e) => setSearchText(e.target.value), prefix: _jsx(Icon, { icon: "search-o", size: 16, className: "text-gray-400" }), className: "rounded-lg border-gray-300 focus-within:border-[#3278f7] focus-within:shadow-[0_0_0_2px_rgba(50,120,247,0.12)]", allowClear: true }) }), _jsx("div", { className: "max-h-72 overflow-y-auto", role: "listbox", children: isLoading ? (_jsx("div", { className: "flex items-center justify-center py-8", children: _jsx(Spin, {}) })) : supporters && supporters.length > 0 ? (_jsx("div", { className: clsx("flex flex-col transition-opacity duration-200", isFetching && "opacity-50 pointer-events-none"), children: [...supporters]
|
|
81
|
+
.sort((supporterA, supporterB) => {
|
|
82
|
+
const isSupporterACurrentUser = supporterA.memberId === authUserID;
|
|
83
|
+
const isSupporterBCurrentUser = supporterB.memberId === authUserID;
|
|
84
|
+
if (isSupporterACurrentUser !== isSupporterBCurrentUser) {
|
|
85
|
+
return isSupporterACurrentUser ? -1 : 1;
|
|
86
|
+
}
|
|
87
|
+
return supporterA.displayName.localeCompare(supporterB.displayName, "vi", {
|
|
88
|
+
sensitivity: "base",
|
|
89
|
+
});
|
|
90
|
+
})
|
|
91
|
+
.map((item) => (_jsx(SupporterItem, { supporter: item, onClick: handleSelectAgent, isCurrentAssignee: item.memberId === (supporter === null || supporter === void 0 ? void 0 : supporter.id), isCurrentUser: item.memberId === authUserID }, item.memberId))) })) : (_jsx("div", { className: "flex items-center justify-center py-8", children: _jsx("span", { className: "text-sm text-gray-400", children: t("manual_assign_no_results") }) })) })] }));
|
|
79
92
|
return (_jsxs(_Fragment, { children: [_jsx(Popover, { content: popoverContent, trigger: "click", open: open, onOpenChange: handleOpenChange, placement: "topLeft", arrow: false, children: _jsxs("div", { role: "button", tabIndex: 0, "aria-label": t("manual_assign_button_reassign"), className: clsx("flex items-center border border-gray-200 rounded-lg p-1 gap-1 transition-opacity", isAssigning
|
|
80
93
|
? "opacity-50 pointer-events-none"
|
|
81
94
|
: "cursor-pointer hover:opacity-80"), children: [_jsx(Avatar, { src: supporter === null || supporter === void 0 ? void 0 : supporter.avatar, size: 28, children: ((_b = (_a = supporter === null || supporter === void 0 ? void 0 : supporter.fullName) === null || _a === void 0 ? void 0 : _a.charAt) === null || _b === void 0 ? void 0 : _b.call(_a, 0)) || "A" }), _jsx("span", { className: "text-purple-500", children: _jsx(Icon, { icon: "shuffle-b", size: 20 }) })] }) }), _jsx(AssignConfirmModal, { open: confirmModalOpen, agent: selectedAgent, loading: isAssigning, onCancel: handleCancelConfirm, onConfirm: handleConfirmAssign, afterClose: handleAfterClose })] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGlobalEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/global/useGlobalEvent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGlobalEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/global/useGlobalEvent.ts"],"names":[],"mappings":"AAgCA,eAAO,MAAM,cAAc,YAuS1B,CAAC"}
|
|
@@ -10,6 +10,8 @@ import { useRefetchChatToken } from "../../hooks/init/useChatToken";
|
|
|
10
10
|
import { updateSession } from "../session/useUpdateSession";
|
|
11
11
|
import { QUERY_KEYS } from "../../services/query";
|
|
12
12
|
import { useQueryClient } from "@tanstack/react-query";
|
|
13
|
+
import { isGroupSession } from "../../utils/imCommon";
|
|
14
|
+
import { invalidateSessionQueries } from "../../utils/queryHelpers";
|
|
13
15
|
const notPushType = [MessageType.TypingMessage, MessageType.RevokeMessage];
|
|
14
16
|
export const useGlobalEvent = () => {
|
|
15
17
|
const { user } = useChatContext();
|
|
@@ -17,12 +19,25 @@ export const useGlobalEvent = () => {
|
|
|
17
19
|
const { updateConnectStatus, updateSyncStatus, getSelfUserInfo } = useChatContext();
|
|
18
20
|
const updateConversationList = useConversationStore((state) => state.updateConversationList);
|
|
19
21
|
const getConversationListByReq = useConversationStore((state) => state.getConversationListByReq);
|
|
22
|
+
const getCurrentGroupInfoByReq = useConversationStore((state) => state.getCurrentGroupInfoByReq);
|
|
23
|
+
const getCurrentMemberInGroupByReq = useConversationStore((state) => state.getCurrentMemberInGroupByReq);
|
|
20
24
|
const { mutate: refetchChatToken } = useRefetchChatToken();
|
|
21
25
|
const accessToken = useAuthStore((state) => state.accessToken);
|
|
22
26
|
const chatToken = useAuthStore((state) => state.chatToken);
|
|
23
27
|
const apiAddress = useAuthStore((state) => {
|
|
24
28
|
return state.apiAddress;
|
|
25
29
|
});
|
|
30
|
+
const refreshCurrentGroupState = async () => {
|
|
31
|
+
const currentConversation = useConversationStore.getState().currentConversation;
|
|
32
|
+
if (!(currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.groupID) ||
|
|
33
|
+
!isGroupSession(currentConversation.conversationType)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
await Promise.all([
|
|
37
|
+
getCurrentGroupInfoByReq(currentConversation.groupID),
|
|
38
|
+
getCurrentMemberInGroupByReq(currentConversation.groupID),
|
|
39
|
+
]);
|
|
40
|
+
};
|
|
26
41
|
const revokedMessageHandler = ({ data }) => {
|
|
27
42
|
updateOneMessage({
|
|
28
43
|
clientMsgID: data.clientMsgID,
|
|
@@ -67,6 +82,12 @@ export const useGlobalEvent = () => {
|
|
|
67
82
|
if (!notPushType.includes(newServerMsg.contentType)) {
|
|
68
83
|
pushNewMessage(newServerMsg);
|
|
69
84
|
}
|
|
85
|
+
if (newServerMsg.sendID !== (user === null || user === void 0 ? void 0 : user.userID)) {
|
|
86
|
+
queryClient.invalidateQueries({
|
|
87
|
+
queryKey: [QUERY_KEYS.GET_LIST_SESSION_BY_CONVERSATION],
|
|
88
|
+
});
|
|
89
|
+
void invalidateSessionQueries(queryClient);
|
|
90
|
+
}
|
|
70
91
|
};
|
|
71
92
|
const newMessageHandler = ({ data }) => {
|
|
72
93
|
var _a;
|
|
@@ -119,7 +140,6 @@ export const useGlobalEvent = () => {
|
|
|
119
140
|
};
|
|
120
141
|
const connectSuccessHandler = () => {
|
|
121
142
|
updateConnectStatus(ConnectStatus.Connected);
|
|
122
|
-
getConversationListByReq(false);
|
|
123
143
|
};
|
|
124
144
|
const connectFailedHandler = () => {
|
|
125
145
|
updateConnectStatus(ConnectStatus.Disconnected);
|
|
@@ -132,6 +152,7 @@ export const useGlobalEvent = () => {
|
|
|
132
152
|
// getFriendListByReq();
|
|
133
153
|
// getGroupListByReq();
|
|
134
154
|
getConversationListByReq(false);
|
|
155
|
+
void refreshCurrentGroupState();
|
|
135
156
|
// getUnReadCountByReq();
|
|
136
157
|
};
|
|
137
158
|
const syncFailedHandler = () => {
|
|
@@ -197,9 +218,11 @@ export const useGlobalEvent = () => {
|
|
|
197
218
|
// conversation
|
|
198
219
|
const conversationChangeHandler = ({ data }) => {
|
|
199
220
|
updateConversationList(data, "filter");
|
|
221
|
+
void refreshCurrentGroupState();
|
|
200
222
|
};
|
|
201
223
|
const newConversationHandler = ({ data }) => {
|
|
202
224
|
updateConversationList(data, "push");
|
|
225
|
+
void refreshCurrentGroupState();
|
|
203
226
|
};
|
|
204
227
|
/** LIFE CYCLE */
|
|
205
228
|
useEffect(() => {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GroupMemberItem } from "@openim/wasm-client-sdk";
|
|
2
|
+
interface UseGroupMembersResult {
|
|
3
|
+
members: GroupMemberItem[];
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
error?: string;
|
|
6
|
+
refetch: () => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare const useGroupMembers: (groupID?: string) => UseGroupMembersResult;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=useGroupMembers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGroupMembers.d.ts","sourceRoot":"","sources":["../../../src/hooks/group/useGroupMembers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAM1D,UAAU,qBAAqB;IAC7B,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED,eAAO,MAAM,eAAe,GAC1B,UAAU,MAAM,KACf,qBA2CF,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { DChatSDK } from "../../constants/sdk";
|
|
3
|
+
const GROUP_MEMBER_LIST_OFFSET = 0;
|
|
4
|
+
const GROUP_MEMBER_LIST_COUNT = 999;
|
|
5
|
+
export const useGroupMembers = (groupID) => {
|
|
6
|
+
const [members, setMembers] = useState([]);
|
|
7
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
8
|
+
const [error, setError] = useState(undefined);
|
|
9
|
+
const fetchMembers = useCallback(async () => {
|
|
10
|
+
if (!groupID) {
|
|
11
|
+
setMembers([]);
|
|
12
|
+
setError(undefined);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
setIsLoading(true);
|
|
16
|
+
setError(undefined);
|
|
17
|
+
try {
|
|
18
|
+
const { data } = await DChatSDK.getGroupMemberList({
|
|
19
|
+
groupID,
|
|
20
|
+
filter: 0,
|
|
21
|
+
offset: GROUP_MEMBER_LIST_OFFSET,
|
|
22
|
+
count: GROUP_MEMBER_LIST_COUNT,
|
|
23
|
+
});
|
|
24
|
+
setMembers(data !== null && data !== void 0 ? data : []);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
console.error("Error fetching group member list:", err);
|
|
28
|
+
setMembers([]);
|
|
29
|
+
setError("load_group_member_list_failed");
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
setIsLoading(false);
|
|
33
|
+
}
|
|
34
|
+
}, [groupID]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
void fetchMembers();
|
|
37
|
+
}, [fetchMembers]);
|
|
38
|
+
return {
|
|
39
|
+
members,
|
|
40
|
+
isLoading,
|
|
41
|
+
error,
|
|
42
|
+
refetch: fetchMembers,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConversationMessages.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useConversationMessages.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,UAAU,6BAA6B;IACrC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,uBAAuB,GAAI,+EAKrC,6BAA6B;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useConversationMessages.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useConversationMessages.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,UAAU,6BAA6B;IACrC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,uBAAuB,GAAI,+EAKrC,6BAA6B;;;;;;;;;;;;;;;;;CAwC/B,CAAC"}
|
|
@@ -3,11 +3,12 @@ import { useMemo } from "react";
|
|
|
3
3
|
import { useMessage } from "./useMessage";
|
|
4
4
|
import { usePullSessionMessages } from "./usePullSessionMessages";
|
|
5
5
|
export const useConversationMessages = ({ conversationId, searchClientMsgID, restrictToLastSession = false, customerUserID, }) => {
|
|
6
|
-
const
|
|
6
|
+
const isPreviewMessagesBeforeJoin = restrictToLastSession;
|
|
7
|
+
const sdkMessages = useMessage(conversationId, searchClientMsgID, !isPreviewMessagesBeforeJoin);
|
|
7
8
|
const { data: pulledMessages, isLoading: isPullLoading, isFetching: isPullFetching, } = usePullSessionMessages({
|
|
8
9
|
conversationID: conversationId,
|
|
9
10
|
userID: customerUserID,
|
|
10
|
-
enabled:
|
|
11
|
+
enabled: isPreviewMessagesBeforeJoin,
|
|
11
12
|
});
|
|
12
13
|
const lastSessionState = useMemo(() => ({
|
|
13
14
|
initLoading: isPullLoading || isPullFetching,
|
|
@@ -15,7 +16,7 @@ export const useConversationMessages = ({ conversationId, searchClientMsgID, res
|
|
|
15
16
|
hasMoreNew: false,
|
|
16
17
|
messageList: pulledMessages !== null && pulledMessages !== void 0 ? pulledMessages : [],
|
|
17
18
|
}), [isPullLoading, isPullFetching, pulledMessages]);
|
|
18
|
-
if (
|
|
19
|
+
if (isPreviewMessagesBeforeJoin) {
|
|
19
20
|
return {
|
|
20
21
|
loadState: lastSessionState,
|
|
21
22
|
latestLoadState: { current: lastSessionState },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MessageItem, MessageType } from "@openim/wasm-client-sdk";
|
|
2
2
|
export declare const visibleTypeMessage: MessageType[];
|
|
3
|
-
export declare const useMessage: (conversationId?: string, searchClientMsgID?: string) => {
|
|
3
|
+
export declare const useMessage: (conversationId?: string, searchClientMsgID?: string, enabled?: boolean) => {
|
|
4
4
|
loadState: {
|
|
5
5
|
initLoading: boolean;
|
|
6
6
|
hasMoreOld: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,WAAW,EACX,WAAW,EAEZ,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"useMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,WAAW,EACX,WAAW,EAEZ,MAAM,yBAAyB,CAAC;AAOjC,eAAO,MAAM,kBAAkB,eAgB9B,CAAC;AAEF,eAAO,MAAM,UAAU,GACrB,iBAAiB,MAAM,EACvB,oBAAoB,MAAM,EAC1B,iBAAc;;;;;qBAMO,WAAW,EAAE;;;;;;qBAAb,WAAW,EAAE;;;;;;CA8PnC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,SAAS,WAAW,SACpB,CAAC;AAChC,eAAO,MAAM,gBAAgB,GAAI,SAAS,WAAW,SACpB,CAAC;AAClC,eAAO,MAAM,gBAAgB,GAAI,aAAa,MAAM,SACf,CAAC;AAEtC,eAAO,MAAM,kBAAkB,GAC7B,aAAa,WAAW,EAAE,EAC1B,SAAS,WAAW,EACpB,WAAW,MAAM,GAAG,MAAM,KACzB,WAAW,GAAG,SAkBhB,CAAC"}
|
|
@@ -4,8 +4,6 @@ import { DChatSDK } from "../../constants/sdk";
|
|
|
4
4
|
import { useLatest, useRequest } from "ahooks";
|
|
5
5
|
import emitter, { emit } from "../../utils/events";
|
|
6
6
|
import isEmpty from "lodash/isEmpty";
|
|
7
|
-
import { useChatContext } from "../../context/ChatContext";
|
|
8
|
-
import { SyncStatus } from "../../types/chat";
|
|
9
7
|
const PAGE_SIZE = 50;
|
|
10
8
|
export const visibleTypeMessage = [
|
|
11
9
|
MessageType.TextMessage,
|
|
@@ -24,8 +22,7 @@ export const visibleTypeMessage = [
|
|
|
24
22
|
MessageType.RevokeMessage,
|
|
25
23
|
MessageType.LogTextMessage,
|
|
26
24
|
];
|
|
27
|
-
export const useMessage = (conversationId, searchClientMsgID) => {
|
|
28
|
-
const { syncStatus } = useChatContext();
|
|
25
|
+
export const useMessage = (conversationId, searchClientMsgID, enabled = true) => {
|
|
29
26
|
const [loadState, setLoadState] = useState({
|
|
30
27
|
initLoading: true,
|
|
31
28
|
hasMoreOld: true,
|
|
@@ -33,6 +30,7 @@ export const useMessage = (conversationId, searchClientMsgID) => {
|
|
|
33
30
|
messageList: [],
|
|
34
31
|
});
|
|
35
32
|
const latestLoadState = useLatest(loadState);
|
|
33
|
+
const enabledRef = useLatest(enabled);
|
|
36
34
|
const { loading: moreOldLoading, runAsync: getMoreOldMessages } = useRequest(async (loadMore = true) => {
|
|
37
35
|
var _a, _b, _c, _d, _e;
|
|
38
36
|
const reqConversationID = conversationId;
|
|
@@ -129,6 +127,8 @@ export const useMessage = (conversationId, searchClientMsgID) => {
|
|
|
129
127
|
useEffect(() => {
|
|
130
128
|
const pushNewMessage = (message) => {
|
|
131
129
|
var _a, _b;
|
|
130
|
+
if (!enabledRef.current)
|
|
131
|
+
return;
|
|
132
132
|
if ((_b = (_a = latestLoadState.current) === null || _a === void 0 ? void 0 : _a.messageList) === null || _b === void 0 ? void 0 : _b.find((item) => item.clientMsgID === message.clientMsgID)) {
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
@@ -138,6 +138,8 @@ export const useMessage = (conversationId, searchClientMsgID) => {
|
|
|
138
138
|
});
|
|
139
139
|
};
|
|
140
140
|
const updateOneMessage = (message) => {
|
|
141
|
+
if (!enabledRef.current)
|
|
142
|
+
return;
|
|
141
143
|
setLoadState((preState) => {
|
|
142
144
|
var _a, _b, _c, _d;
|
|
143
145
|
const tmpList = [...preState.messageList];
|
|
@@ -165,6 +167,8 @@ export const useMessage = (conversationId, searchClientMsgID) => {
|
|
|
165
167
|
});
|
|
166
168
|
};
|
|
167
169
|
const removeOneMessage = (clientMsgID) => {
|
|
170
|
+
if (!enabledRef.current)
|
|
171
|
+
return;
|
|
168
172
|
setLoadState((preState) => (Object.assign(Object.assign({}, preState), { messageList: preState.messageList.filter((msg) => msg.clientMsgID !== clientMsgID) })));
|
|
169
173
|
};
|
|
170
174
|
emitter.on("PUSH_NEW_MSG", pushNewMessage);
|
|
@@ -177,7 +181,16 @@ export const useMessage = (conversationId, searchClientMsgID) => {
|
|
|
177
181
|
};
|
|
178
182
|
}, []);
|
|
179
183
|
useEffect(() => {
|
|
180
|
-
if (!
|
|
184
|
+
if (!enabled) {
|
|
185
|
+
setLoadState({
|
|
186
|
+
initLoading: true,
|
|
187
|
+
hasMoreOld: true,
|
|
188
|
+
hasMoreNew: false,
|
|
189
|
+
messageList: [],
|
|
190
|
+
});
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (!conversationId)
|
|
181
194
|
return;
|
|
182
195
|
if (!isEmpty(searchClientMsgID)) {
|
|
183
196
|
searchMessages();
|
|
@@ -193,7 +206,7 @@ export const useMessage = (conversationId, searchClientMsgID) => {
|
|
|
193
206
|
messageList: [],
|
|
194
207
|
}));
|
|
195
208
|
};
|
|
196
|
-
}, [conversationId, searchClientMsgID,
|
|
209
|
+
}, [conversationId, searchClientMsgID, enabled]);
|
|
197
210
|
return {
|
|
198
211
|
loadState,
|
|
199
212
|
latestLoadState,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSendMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useSendMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,WAAW,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"useSendMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useSendMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,WAAW,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAY1B,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAUlC,OAAO,EAAgB,gBAAgB,EAAyB,MAAM,iBAAiB,CAAC;AAkBxF,eAAO,MAAM,iBAAiB,GAAI,SAAS;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB,YAE0C,CAAC;AAE5C,eAAO,MAAM,iBAAiB,GAAU,MAAM,MAAM,gCAanD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAU,MAAM,oBAAoB,gCAaxE,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAU,iBAAiB,eAAe,gCAazE,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAU,MAAM,oBAAoB,gCAaxE,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAU,MAAM,mBAAmB,gCAatE,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAU,MAAM,MAAM,EAAE,MAAM,MAAM,EAAE,gCActE,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,MAAM,MAAM,EACZ,eAAe,WAAW,gCAc3B,CAAC;AAEF,eAAO,MAAM,cAAc;4EA0NpB;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,cAAc,CAAC,EAAE,gBAAgB,CAAC;QAClC,UAAU,EAAE,OAAO,CAAC;KACrB;oFAoCE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,UAAU,EAAE,CAAC;QACpB,cAAc,CAAC,EAAE,gBAAgB,CAAC;QAClC,UAAU,EAAE,OAAO,CAAC;KACrB;mCA5JqB,WAAW;CA6RpC,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,+BAGvC;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,gBAAgB,CAAC;CACnC,KAWM,iBACN,CAAC"}
|
|
@@ -3,12 +3,18 @@ import { DChatSDK } from "../../constants/sdk";
|
|
|
3
3
|
import { v4 as uuidv4 } from "uuid";
|
|
4
4
|
import { useChatContext } from "../../context/ChatContext";
|
|
5
5
|
import { useCallback } from "react";
|
|
6
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
6
7
|
import { useTranslation } from "react-i18next";
|
|
7
8
|
import { pushNewMessage, removeOneMessage, updateOneMessage, } from "./useMessage";
|
|
8
9
|
import { emit } from "../../utils/events";
|
|
9
10
|
import useConversationStore from "../../store/conversation";
|
|
10
11
|
import useAuthStore from "../../store/auth";
|
|
12
|
+
import { apiInstance } from "../../services/api";
|
|
13
|
+
import { ENDPOINTS } from "../../services/routes";
|
|
11
14
|
import { extractLinks, generateContentBasedOnMessageType, } from "../../utils/common";
|
|
15
|
+
import { SessionStatus, SessionTag } from "../../types/chat";
|
|
16
|
+
import { updateSession } from "../session/useUpdateSession";
|
|
17
|
+
import { invalidateSessionQueries } from "../../utils/queryHelpers";
|
|
12
18
|
const messageFileStore = new Map();
|
|
13
19
|
const MEDIA_CONTENT_TYPES = new Set([
|
|
14
20
|
MessageType.PictureMessage,
|
|
@@ -100,11 +106,38 @@ export const createQuoteMessage = async (text, quotedMessage) => {
|
|
|
100
106
|
export const useSendMessage = () => {
|
|
101
107
|
const { user } = useChatContext();
|
|
102
108
|
const { t } = useTranslation("common");
|
|
109
|
+
const queryClient = useQueryClient();
|
|
103
110
|
const conversationData = useConversationStore((state) => state.conversationData);
|
|
104
111
|
const quotedMessage = useConversationStore((state) => state.quotedMessage);
|
|
105
112
|
const setQuotedMessage = useConversationStore((state) => state.setQuotedMessage);
|
|
106
113
|
const { userID: recvID, groupID } = conversationData || {};
|
|
107
|
-
const
|
|
114
|
+
const syncSessionAfterPublicMessage = useCallback(async (currentSession) => {
|
|
115
|
+
if (!(currentSession === null || currentSession === void 0 ? void 0 : currentSession.id)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const shouldUpdateStatus = currentSession.status === SessionStatus.WAITING_PROCESS ||
|
|
119
|
+
currentSession.tag === SessionTag.AWAITING_REPLY ||
|
|
120
|
+
currentSession.tag === SessionTag.TEMPORARILY_PAUSED;
|
|
121
|
+
if (!shouldUpdateStatus) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const response = await apiInstance.put(ENDPOINTS.chatService.updateSession(currentSession.id), {
|
|
126
|
+
status: SessionStatus.IN_PROCESS,
|
|
127
|
+
applicationType: useAuthStore.getState().applicationType,
|
|
128
|
+
});
|
|
129
|
+
const updatedSession = response.data.data;
|
|
130
|
+
if (!updatedSession) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
updateSession(updatedSession);
|
|
134
|
+
await invalidateSessionQueries(queryClient);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error("syncSessionAfterPublicMessage", error);
|
|
138
|
+
}
|
|
139
|
+
}, [queryClient]);
|
|
140
|
+
const dispatchMessage = useCallback(async (message, currentSession) => {
|
|
108
141
|
var _a, _b;
|
|
109
142
|
const desc = generateContentBasedOnMessageType(message.contentType, ((_a = message === null || message === void 0 ? void 0 : message.textElem) === null || _a === void 0 ? void 0 : _a.content) || "") || t("new_message");
|
|
110
143
|
const { data: successMessage } = await DChatSDK.sendMessage({
|
|
@@ -125,13 +158,16 @@ export const useSendMessage = () => {
|
|
|
125
158
|
},
|
|
126
159
|
});
|
|
127
160
|
updateOneMessage(Object.assign(Object.assign({}, successMessage), { ex: successMessage.ex || message.ex || "{}", isInternal: (_b = successMessage.isInternal) !== null && _b !== void 0 ? _b : message.isInternal }));
|
|
161
|
+
if (!message.isInternal) {
|
|
162
|
+
await syncSessionAfterPublicMessage(currentSession);
|
|
163
|
+
}
|
|
128
164
|
messageFileStore.delete(message.clientMsgID);
|
|
129
|
-
}, [recvID,
|
|
130
|
-
const sendMessage = useCallback(async (message) => {
|
|
165
|
+
}, [groupID, recvID, syncSessionAfterPublicMessage, t, conversationData === null || conversationData === void 0 ? void 0 : conversationData.showName, conversationData === null || conversationData === void 0 ? void 0 : conversationData.faceURL, conversationData === null || conversationData === void 0 ? void 0 : conversationData.conversationID]);
|
|
166
|
+
const sendMessage = useCallback(async (message, currentSession) => {
|
|
131
167
|
pushNewMessage(message);
|
|
132
168
|
emit("CHAT_LIST_SCROLL_TO_BOTTOM");
|
|
133
169
|
try {
|
|
134
|
-
await dispatchMessage(message);
|
|
170
|
+
await dispatchMessage(message, currentSession);
|
|
135
171
|
}
|
|
136
172
|
catch (error) {
|
|
137
173
|
console.error("sendMessage", error);
|
|
@@ -242,7 +278,7 @@ export const useSendMessage = () => {
|
|
|
242
278
|
currentSession,
|
|
243
279
|
});
|
|
244
280
|
let messageItem = Object.assign(Object.assign({}, message), { ex: JSON.stringify(extendMessageInfo) || "{}", isInternal });
|
|
245
|
-
sendMessage(messageItem);
|
|
281
|
+
sendMessage(messageItem, currentSession);
|
|
246
282
|
}, [recvID, groupID, user, sendMessage, quotedMessage, setQuotedMessage]);
|
|
247
283
|
const sendMergeMessage = useCallback(async ({ richText, plainText, files, currentSession, isInternal, }) => {
|
|
248
284
|
if (!recvID && !groupID)
|
|
@@ -356,7 +392,7 @@ export const useSendMessage = () => {
|
|
|
356
392
|
currentSession,
|
|
357
393
|
});
|
|
358
394
|
const mMessage = Object.assign(Object.assign({}, message), { ex: JSON.stringify(extendMessageInfo) || "{}", isInternal });
|
|
359
|
-
await sendMessage(mMessage);
|
|
395
|
+
await sendMessage(mMessage, currentSession);
|
|
360
396
|
}
|
|
361
397
|
}, [recvID, groupID, sendMessage, quotedMessage, setQuotedMessage]);
|
|
362
398
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCloseSession.d.ts","sourceRoot":"","sources":["../../../src/hooks/session/useCloseSession.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"useCloseSession.d.ts","sourceRoot":"","sources":["../../../src/hooks/session/useCloseSession.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI/C,eAAO,MAAM,eAAe,wGAqB3B,CAAC"}
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
import { useMutation } from "@tanstack/react-query";
|
|
1
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
2
2
|
import { QUERY_KEYS } from "../../services/query";
|
|
3
3
|
import { apiInstance } from "../../services/api";
|
|
4
4
|
import { ENDPOINTS } from "../../services/routes";
|
|
5
5
|
import useAuthStore from "../../store/auth";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
6
|
+
import { invalidateSessionQueries } from "../../utils/queryHelpers";
|
|
7
|
+
export const useCloseSession = () => {
|
|
8
|
+
const queryClient = useQueryClient();
|
|
9
|
+
return useMutation({
|
|
10
|
+
mutationKey: [QUERY_KEYS.CLOSE_SESSION],
|
|
11
|
+
mutationFn: async (sessionId) => {
|
|
12
|
+
const res = await apiInstance.post(ENDPOINTS.chatService.closeSession(sessionId), null, {
|
|
13
|
+
params: {
|
|
14
|
+
applicationType: useAuthStore.getState().applicationType,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
return res === null || res === void 0 ? void 0 : res.data;
|
|
18
|
+
},
|
|
19
|
+
onSuccess: async () => {
|
|
20
|
+
await invalidateSessionQueries(queryClient);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useJoinGroupFlow.d.ts","sourceRoot":"","sources":["../../../src/hooks/session/useJoinGroupFlow.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useJoinGroupFlow.d.ts","sourceRoot":"","sources":["../../../src/hooks/session/useJoinGroupFlow.ts"],"names":[],"mappings":"AAUA,UAAU,sBAAsB;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,eAAe,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,2BAA2B,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CACrD;AAED,eAAO,MAAM,gBAAgB,GAAI,yFAK9B,sBAAsB;;;CA4ExB,CAAC"}
|
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { message } from "antd";
|
|
3
|
-
import { useCallback, useEffect, useRef } from "react";
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
4
|
import { useTranslation } from "react-i18next";
|
|
5
5
|
import useConversationStore from "../../store/conversation";
|
|
6
6
|
import { useJoinSession } from "./useJoinSession";
|
|
7
|
+
const POST_JOIN_SYNC_DELAY = 500;
|
|
7
8
|
export const useJoinGroupFlow = ({ groupId, latestConversationSessionId, refetchIsJoined, refetchConversationSessions, }) => {
|
|
8
9
|
const { t } = useTranslation();
|
|
9
10
|
const joinSyncTimerRef = useRef(null);
|
|
11
|
+
const [isWaitingForSync, setIsWaitingForSync] = useState(false);
|
|
10
12
|
const getCurrentGroupInfoByReq = useConversationStore((state) => state.getCurrentGroupInfoByReq);
|
|
11
13
|
const { mutateAsync: joinSession, isPending: isJoining } = useJoinSession();
|
|
12
14
|
const syncGroupStateAfterJoin = useCallback(async () => {
|
|
13
|
-
await refetchIsJoined();
|
|
14
|
-
await refetchConversationSessions();
|
|
15
|
-
if (!groupId)
|
|
16
|
-
return;
|
|
17
|
-
await getCurrentGroupInfoByReq(groupId);
|
|
18
15
|
if (joinSyncTimerRef.current) {
|
|
19
16
|
clearTimeout(joinSyncTimerRef.current);
|
|
20
17
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
setIsWaitingForSync(true);
|
|
19
|
+
try {
|
|
20
|
+
await refetchIsJoined();
|
|
21
|
+
await refetchConversationSessions();
|
|
22
|
+
if (!groupId)
|
|
23
|
+
return;
|
|
24
|
+
await getCurrentGroupInfoByReq(groupId);
|
|
25
|
+
await new Promise((resolve) => {
|
|
26
|
+
joinSyncTimerRef.current = setTimeout(() => {
|
|
27
|
+
resolve();
|
|
28
|
+
}, POST_JOIN_SYNC_DELAY);
|
|
29
|
+
});
|
|
30
|
+
await refetchIsJoined();
|
|
31
|
+
await refetchConversationSessions();
|
|
32
|
+
await getCurrentGroupInfoByReq(groupId);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
setIsWaitingForSync(false);
|
|
36
|
+
joinSyncTimerRef.current = null;
|
|
37
|
+
}
|
|
24
38
|
}, [
|
|
25
39
|
getCurrentGroupInfoByReq,
|
|
26
40
|
groupId,
|
|
@@ -33,17 +47,16 @@ export const useJoinGroupFlow = ({ groupId, latestConversationSessionId, refetch
|
|
|
33
47
|
return;
|
|
34
48
|
try {
|
|
35
49
|
await joinSession(latestConversationSessionId);
|
|
36
|
-
message.success(t("join_group_success"));
|
|
37
50
|
}
|
|
38
51
|
catch (error) {
|
|
39
52
|
const isDuplicate = (_d = (_c = (_b = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.includes) === null || _d === void 0 ? void 0 : _d.call(_c, "Duplicate key");
|
|
40
53
|
if (!isDuplicate) {
|
|
41
54
|
message.error(t("join_group_failed"));
|
|
42
55
|
}
|
|
56
|
+
return;
|
|
43
57
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
58
|
+
await syncGroupStateAfterJoin();
|
|
59
|
+
message.success(t("join_group_success"));
|
|
47
60
|
}, [joinSession, latestConversationSessionId, syncGroupStateAfterJoin, t]);
|
|
48
61
|
useEffect(() => {
|
|
49
62
|
return () => {
|
|
@@ -54,6 +67,6 @@ export const useJoinGroupFlow = ({ groupId, latestConversationSessionId, refetch
|
|
|
54
67
|
}, []);
|
|
55
68
|
return {
|
|
56
69
|
handleJoinGroup,
|
|
57
|
-
isJoining,
|
|
70
|
+
isJoining: isJoining || isWaitingForSync,
|
|
58
71
|
};
|
|
59
72
|
};
|
|
@@ -4,7 +4,7 @@ interface UpdateSessionParams {
|
|
|
4
4
|
status?: string;
|
|
5
5
|
tag?: string;
|
|
6
6
|
}
|
|
7
|
-
export declare const useUpdateSession: () => import("@tanstack/react-query").UseMutationResult<
|
|
7
|
+
export declare const useUpdateSession: () => import("@tanstack/react-query").UseMutationResult<UpdateSessionResponse, Error, UpdateSessionParams, unknown>;
|
|
8
8
|
export declare const updateSession: (data: UpdateSessionResponse) => void;
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=useUpdateSession.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUpdateSession.d.ts","sourceRoot":"","sources":["../../../src/hooks/session/useUpdateSession.ts"],"names":[],"mappings":"AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"useUpdateSession.d.ts","sourceRoot":"","sources":["../../../src/hooks/session/useUpdateSession.ts"],"names":[],"mappings":"AAMA,OAAO,EAAgB,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAItE,UAAU,mBAAmB;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,gBAAgB,qHAqB5B,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,MAAM,qBAAqB,SAC3B,CAAC"}
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
3
|
import { QUERY_KEYS } from "../../services/query";
|
|
4
4
|
import { apiInstance } from "../../services/api";
|
|
5
5
|
import { ENDPOINTS } from "../../services/routes";
|
|
6
6
|
import useAuthStore from "../../store/auth";
|
|
7
7
|
import { emit } from "../../utils/events";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
8
|
+
import { invalidateSessionQueries } from "../../utils/queryHelpers";
|
|
9
|
+
export const useUpdateSession = () => {
|
|
10
|
+
const queryClient = useQueryClient();
|
|
11
|
+
return useMutation({
|
|
12
|
+
mutationKey: [QUERY_KEYS.UPDATE_SESSION],
|
|
13
|
+
mutationFn: async ({ sessionId, status, tag }) => {
|
|
14
|
+
const res = await apiInstance.put(ENDPOINTS.chatService.updateSession(sessionId), {
|
|
15
|
+
status,
|
|
16
|
+
tag,
|
|
17
|
+
applicationType: useAuthStore.getState().applicationType,
|
|
18
|
+
});
|
|
19
|
+
return res.data.data;
|
|
20
|
+
},
|
|
21
|
+
onSuccess: async (data) => {
|
|
22
|
+
updateSession(data);
|
|
23
|
+
await invalidateSessionQueries(queryClient);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
};
|
|
19
27
|
export const updateSession = (data) => emit("UPDATE_SESSION", data);
|