@droppii-org/chat-sdk 0.0.29 → 0.0.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/dist/assets/conversationBg.png +0 -0
- package/dist/assets/images/conversationBg.png +0 -0
- package/dist/assets/images/imageFailed.png +0 -0
- package/dist/assets/sdk/sql-wasm.wasm +0 -0
- package/dist/assets/sdk/version +1 -0
- package/dist/assets/sdk/wasm_exec.js +575 -0
- package/dist/assets/svg/document.d.ts +2 -0
- package/dist/assets/svg/document.d.ts.map +1 -0
- package/dist/assets/svg/document.js +2 -0
- package/dist/assets/svg/document.tsx +37 -0
- package/dist/assets/svg/index.d.ts +2 -0
- package/dist/assets/svg/index.d.ts.map +1 -0
- package/dist/assets/svg/index.js +1 -0
- package/dist/assets/svg/index.ts +1 -0
- package/dist/components/chatBubble/ChatBubble.d.ts.map +1 -1
- package/dist/components/chatBubble/ChatBubble.js +6 -11
- package/dist/components/conversation/ConversationItemList.d.ts +7 -0
- package/dist/components/conversation/ConversationItemList.d.ts.map +1 -0
- package/dist/components/conversation/ConversationItemList.js +20 -0
- package/dist/components/conversation/DeskConversationList.d.ts +1 -5
- package/dist/components/conversation/DeskConversationList.d.ts.map +1 -1
- package/dist/components/conversation/DeskConversationList.js +44 -29
- package/dist/components/mediaCollection/FileCollection.d.ts +3 -0
- package/dist/components/mediaCollection/FileCollection.d.ts.map +1 -0
- package/dist/components/mediaCollection/FileCollection.js +54 -0
- package/dist/components/mediaCollection/ImageCollection.d.ts +3 -0
- package/dist/components/mediaCollection/ImageCollection.d.ts.map +1 -0
- package/dist/components/mediaCollection/ImageCollection.js +37 -0
- package/dist/components/mediaCollection/LinkCollection.d.ts +3 -0
- package/dist/components/mediaCollection/LinkCollection.d.ts.map +1 -0
- package/dist/components/mediaCollection/LinkCollection.js +8 -0
- package/dist/components/mediaCollection/VideoCollection.d.ts +3 -0
- package/dist/components/mediaCollection/VideoCollection.d.ts.map +1 -0
- package/dist/components/mediaCollection/VideoCollection.js +53 -0
- package/dist/components/mediaCollection/index.d.ts +9 -0
- package/dist/components/mediaCollection/index.d.ts.map +1 -0
- package/dist/components/mediaCollection/index.js +54 -0
- package/dist/components/message/MessageHeader.d.ts.map +1 -1
- package/dist/components/message/MessageHeader.js +2 -1
- package/dist/components/message/MessageList.d.ts.map +1 -1
- package/dist/components/message/MessageList.js +15 -3
- package/dist/components/message/footer/FilePreview.d.ts +0 -1
- package/dist/components/message/footer/FilePreview.d.ts.map +1 -1
- package/dist/components/message/footer/FilePreview.js +4 -4
- package/dist/components/message/footer/ToolbarPlugin.js +1 -1
- package/dist/components/message/footer/index.js +1 -1
- package/dist/components/message/item/FileMessage.d.ts.map +1 -1
- package/dist/components/message/item/FileMessage.js +2 -1
- package/dist/components/message/item/ImageMessage.js +3 -3
- package/dist/components/message/item/TextMessage.js +2 -2
- package/dist/components/message/item/index.js +1 -1
- package/dist/components/session/AssignedSessionFilter.d.ts.map +1 -1
- package/dist/components/session/AssignedSessionFilter.js +20 -12
- package/dist/constants/images.d.ts +5 -0
- package/dist/constants/images.d.ts.map +1 -0
- package/dist/constants/images.js +7 -0
- package/dist/context/ChatContext.d.ts +2 -1
- package/dist/context/ChatContext.d.ts.map +1 -1
- package/dist/context/ChatContext.js +17 -24
- package/dist/hooks/collection/useMediaCollection.d.ts +229 -0
- package/dist/hooks/collection/useMediaCollection.d.ts.map +1 -0
- package/dist/hooks/collection/useMediaCollection.js +66 -0
- package/dist/hooks/common/useIsMobile.d.ts +2 -0
- package/dist/hooks/common/useIsMobile.d.ts.map +1 -0
- package/dist/hooks/common/useIsMobile.js +15 -0
- package/dist/hooks/global/useGlobalEvent.d.ts.map +1 -1
- package/dist/hooks/global/useGlobalEvent.js +55 -6
- package/dist/hooks/init/useChatToken.d.ts +2 -0
- package/dist/hooks/init/useChatToken.d.ts.map +1 -0
- package/dist/hooks/init/useChatToken.js +11 -0
- package/dist/hooks/message/useSendMessage.d.ts.map +1 -1
- package/dist/hooks/message/useSendMessage.js +31 -12
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/layout/index.d.ts.map +1 -1
- package/dist/layout/index.js +2 -5
- package/dist/locales/i18n.d.ts +3 -0
- package/dist/locales/i18n.d.ts.map +1 -0
- package/dist/locales/i18n.js +16 -0
- package/dist/locales/i18n.ts +18 -0
- package/dist/locales/vi/common.json +9 -0
- package/dist/screens/chatBubble/index.d.ts.map +1 -1
- package/dist/screens/chatBubble/index.js +4 -3
- package/dist/screens/deskMessage/index.d.ts.map +1 -1
- package/dist/screens/deskMessage/index.js +3 -3
- package/dist/services/api.d.ts +2 -0
- package/dist/services/api.d.ts.map +1 -0
- package/dist/services/api.js +16 -0
- package/dist/services/query.d.ts +5 -0
- package/dist/services/query.d.ts.map +1 -0
- package/dist/services/query.js +4 -0
- package/dist/services/routes.d.ts +15 -0
- package/dist/services/routes.d.ts.map +1 -0
- package/dist/services/routes.js +14 -0
- package/dist/store/auth.d.ts +4 -0
- package/dist/store/auth.d.ts.map +1 -0
- package/dist/store/auth.js +16 -0
- package/dist/store/conversation.d.ts.map +1 -1
- package/dist/store/conversation.js +4 -1
- package/dist/styles/global.css +1 -1
- package/dist/types/chat.d.ts +10 -4
- package/dist/types/chat.d.ts.map +1 -1
- package/dist/types/dto.d.ts +35 -0
- package/dist/types/dto.d.ts.map +1 -0
- package/dist/types/dto.js +1 -0
- package/dist/utils/common.d.ts +2 -0
- package/dist/utils/common.d.ts.map +1 -0
- package/dist/utils/common.js +12 -0
- package/package.json +15 -3
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
13
|
+
import { QUERY_KEYS } from "../../services/query";
|
|
14
|
+
import { apiInstance } from "../../services/api";
|
|
15
|
+
import { ENDPOINTS } from "../../services/routes";
|
|
16
|
+
import { useMemo } from "react";
|
|
17
|
+
import dayjs from "dayjs";
|
|
18
|
+
export const useMediaCollection = ({ recvID, contentType, }) => {
|
|
19
|
+
const _a = useInfiniteQuery({
|
|
20
|
+
initialPageParam: 1,
|
|
21
|
+
queryKey: [QUERY_KEYS.GET_IMAGE_COLLECTION, recvID, contentType],
|
|
22
|
+
queryFn: async ({ pageParam = 1 }) => {
|
|
23
|
+
const params = {
|
|
24
|
+
contentType,
|
|
25
|
+
recvID,
|
|
26
|
+
page: pageParam,
|
|
27
|
+
pageSize: 50,
|
|
28
|
+
};
|
|
29
|
+
const res = await apiInstance.post(ENDPOINTS.chatService.getMediaCollection, params);
|
|
30
|
+
return res.data;
|
|
31
|
+
},
|
|
32
|
+
getNextPageParam: (lastPage) => {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const currentPage = (_a = lastPage === null || lastPage === void 0 ? void 0 : lastPage.pageable) === null || _a === void 0 ? void 0 : _a.pageNumber;
|
|
35
|
+
const totalPages = (_b = lastPage === null || lastPage === void 0 ? void 0 : lastPage.pageable) === null || _b === void 0 ? void 0 : _b.totalPages;
|
|
36
|
+
return currentPage + 1 < totalPages ? currentPage + 1 : undefined;
|
|
37
|
+
},
|
|
38
|
+
enabled: !!recvID,
|
|
39
|
+
}), { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading } = _a, rest = __rest(_a, ["data", "fetchNextPage", "hasNextPage", "isFetchingNextPage", "isLoading"]);
|
|
40
|
+
const { groupedData, dataFlatten } = useMemo(() => {
|
|
41
|
+
if (!data)
|
|
42
|
+
return {
|
|
43
|
+
groupedData: {},
|
|
44
|
+
dataFlatten: [],
|
|
45
|
+
};
|
|
46
|
+
const allItems = data.pages.flatMap((page) => page.data);
|
|
47
|
+
const mGroupeddata = allItems.reduce((acc, item) => {
|
|
48
|
+
const dateKey = dayjs(item.chatLog.sendTime).format("YYYY-MM-DD");
|
|
49
|
+
if (!acc[dateKey])
|
|
50
|
+
acc[dateKey] = [];
|
|
51
|
+
acc[dateKey].push(item);
|
|
52
|
+
return acc;
|
|
53
|
+
}, {});
|
|
54
|
+
return {
|
|
55
|
+
groupedData: mGroupeddata,
|
|
56
|
+
dataFlatten: allItems,
|
|
57
|
+
};
|
|
58
|
+
}, [data]);
|
|
59
|
+
return Object.assign({ data,
|
|
60
|
+
fetchNextPage,
|
|
61
|
+
hasNextPage,
|
|
62
|
+
isFetchingNextPage,
|
|
63
|
+
isLoading,
|
|
64
|
+
groupedData,
|
|
65
|
+
dataFlatten }, rest);
|
|
66
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsMobile.d.ts","sourceRoot":"","sources":["../../../src/hooks/common/useIsMobile.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,WAAW,GAAI,aAAY,MAAY,YAanD,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
export const useIsMobile = (breakpoint = 768) => {
|
|
4
|
+
const [isMobile, setIsMobile] = useState(() => {
|
|
5
|
+
if (typeof window === "undefined")
|
|
6
|
+
return false;
|
|
7
|
+
return window.innerWidth < breakpoint;
|
|
8
|
+
});
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const handleResize = () => setIsMobile(window.innerWidth < breakpoint);
|
|
11
|
+
window.addEventListener("resize", handleResize);
|
|
12
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
13
|
+
}, [breakpoint]);
|
|
14
|
+
return isMobile;
|
|
15
|
+
};
|
|
@@ -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":"AAqBA,eAAO,MAAM,cAAc,YA0N1B,CAAC"}
|
|
@@ -5,12 +5,17 @@ import { ConnectStatus, CustomType, SyncStatus } from "../../types/chat";
|
|
|
5
5
|
import { pushNewMessage, updateOneMessage } from "../message/useMessage";
|
|
6
6
|
import { useChatContext } from "../../context/ChatContext";
|
|
7
7
|
import useConversationStore from "../../store/conversation";
|
|
8
|
+
import useAuthStore from "../../store/auth";
|
|
9
|
+
import { useRefetchChatToken } from "../../hooks/init/useChatToken";
|
|
8
10
|
const notPushType = [MessageType.TypingMessage, MessageType.RevokeMessage];
|
|
9
11
|
export const useGlobalEvent = () => {
|
|
10
12
|
const { user } = useChatContext();
|
|
11
|
-
const { updateConnectStatus, updateSyncStatus } = useChatContext();
|
|
13
|
+
const { updateConnectStatus, updateSyncStatus, getSelfUserInfo } = useChatContext();
|
|
12
14
|
const updateConversationList = useConversationStore((state) => state.updateConversationList);
|
|
13
15
|
const getConversationListByReq = useConversationStore((state) => state.getConversationListByReq);
|
|
16
|
+
const { mutate: refetchChatToken } = useRefetchChatToken();
|
|
17
|
+
const accessToken = useAuthStore((state) => state.accessToken);
|
|
18
|
+
const chatToken = useAuthStore((state) => state.chatToken);
|
|
14
19
|
const revokedMessageHandler = ({ data }) => {
|
|
15
20
|
updateOneMessage({
|
|
16
21
|
clientMsgID: data.clientMsgID,
|
|
@@ -52,8 +57,46 @@ export const useGlobalEvent = () => {
|
|
|
52
57
|
const newMessageHandler = ({ data }) => {
|
|
53
58
|
data.map((message) => handleNewMessage(message));
|
|
54
59
|
};
|
|
60
|
+
const userTokenHandler = () => {
|
|
61
|
+
refetchChatToken(undefined, {
|
|
62
|
+
onSettled(data) {
|
|
63
|
+
var _a;
|
|
64
|
+
if (data) {
|
|
65
|
+
useAuthStore.getState().setChatToken((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.token);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const initStore = () => {
|
|
71
|
+
getSelfUserInfo();
|
|
72
|
+
getConversationListByReq(false);
|
|
73
|
+
};
|
|
74
|
+
const tryLogin = async () => {
|
|
75
|
+
const { userID, chatToken, platformID, apiAddress, wsAddress } = useAuthStore.getState();
|
|
76
|
+
try {
|
|
77
|
+
await DChatSDK.login({
|
|
78
|
+
userID,
|
|
79
|
+
token: chatToken,
|
|
80
|
+
platformID,
|
|
81
|
+
apiAddr: `${apiAddress}/chat-service`,
|
|
82
|
+
wsAddr: `${wsAddress}/chat-service/ws`,
|
|
83
|
+
});
|
|
84
|
+
initStore();
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.error(error);
|
|
88
|
+
if (error.errCode !== 10102) {
|
|
89
|
+
//user has logged in
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
55
93
|
const loginCheck = async () => {
|
|
56
|
-
|
|
94
|
+
const chatToken = useAuthStore.getState().chatToken;
|
|
95
|
+
const userID = useAuthStore.getState().userID;
|
|
96
|
+
if (!chatToken || !userID) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
tryLogin();
|
|
57
100
|
};
|
|
58
101
|
const connectingHandler = () => {
|
|
59
102
|
updateConnectStatus(ConnectStatus.Connecting);
|
|
@@ -64,9 +107,6 @@ export const useGlobalEvent = () => {
|
|
|
64
107
|
const connectFailedHandler = () => {
|
|
65
108
|
updateConnectStatus(ConnectStatus.Disconnected);
|
|
66
109
|
};
|
|
67
|
-
const userTokenHandler = () => {
|
|
68
|
-
useChatContext().userTokenHandler();
|
|
69
|
-
};
|
|
70
110
|
const syncStartHandler = ({ data }) => {
|
|
71
111
|
updateSyncStatus(SyncStatus.Loading);
|
|
72
112
|
};
|
|
@@ -126,7 +166,6 @@ export const useGlobalEvent = () => {
|
|
|
126
166
|
};
|
|
127
167
|
/** LIFE CYCLE */
|
|
128
168
|
useEffect(() => {
|
|
129
|
-
loginCheck();
|
|
130
169
|
setIMListener();
|
|
131
170
|
window.addEventListener("online", () => {
|
|
132
171
|
DChatSDK.networkStatusChanged();
|
|
@@ -138,4 +177,14 @@ export const useGlobalEvent = () => {
|
|
|
138
177
|
disposeIMListener();
|
|
139
178
|
};
|
|
140
179
|
}, []);
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
if (!!accessToken) {
|
|
182
|
+
userTokenHandler();
|
|
183
|
+
}
|
|
184
|
+
}, [accessToken]);
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
if (!!chatToken) {
|
|
187
|
+
loginCheck();
|
|
188
|
+
}
|
|
189
|
+
}, [chatToken]);
|
|
141
190
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChatToken.d.ts","sourceRoot":"","sources":["../../../src/hooks/init/useChatToken.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,mBAAmB,oFAS5B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { QUERY_KEYS } from "../../services/query";
|
|
3
|
+
import { apiInstance } from "../../services/api";
|
|
4
|
+
import { ENDPOINTS } from "../../services/routes";
|
|
5
|
+
export const useRefetchChatToken = () => useMutation({
|
|
6
|
+
mutationKey: [QUERY_KEYS.REFRESH_CHAT_TOKEN],
|
|
7
|
+
mutationFn: async () => {
|
|
8
|
+
const res = await apiInstance.post(ENDPOINTS.chatService.getChatToken);
|
|
9
|
+
return res.data;
|
|
10
|
+
},
|
|
11
|
+
});
|
|
@@ -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;AAO1B,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAIlC,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,cAAc,GAAI,cAAc,WAAW;gDAiCjD;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;KAClB;wDAwBE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,UAAU,EAAE,CAAC;KACrB;
|
|
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;AAO1B,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAIlC,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,cAAc,GAAI,cAAc,WAAW;gDAiCjD;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;KAClB;wDAwBE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,UAAU,EAAE,CAAC;KACrB;CA+IJ,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,2CAIvC;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,KAoBM,iBACN,CAAC"}
|
|
@@ -136,7 +136,10 @@ export const useSendMessage = (lastMessage) => {
|
|
|
136
136
|
messageList.push(Object.assign(Object.assign({}, imageMessage), { ex: JSON.stringify(extendMessageInfo) || "{}" }));
|
|
137
137
|
}
|
|
138
138
|
else if (isVideo) {
|
|
139
|
-
const videoBaseInfo = await
|
|
139
|
+
const videoBaseInfo = await createVideoInfoWithThumbnail(file);
|
|
140
|
+
const thumbFile = new File([videoBaseInfo.thumbnail], file.name + "-thumb.jpg", {
|
|
141
|
+
type: "image/jpeg",
|
|
142
|
+
});
|
|
140
143
|
const videoMessage = await createVideoMessageByFile({
|
|
141
144
|
videoPath: "",
|
|
142
145
|
duration: videoBaseInfo.duration,
|
|
@@ -152,7 +155,7 @@ export const useSendMessage = (lastMessage) => {
|
|
|
152
155
|
snapshotHeight: videoBaseInfo.height,
|
|
153
156
|
snapShotType: file.type,
|
|
154
157
|
videoFile: file,
|
|
155
|
-
snapshotFile:
|
|
158
|
+
snapshotFile: thumbFile,
|
|
156
159
|
});
|
|
157
160
|
if (!videoMessage)
|
|
158
161
|
continue;
|
|
@@ -238,23 +241,39 @@ const createPicBaseInfoFromFile = (file) => new Promise((resolve, reject) => {
|
|
|
238
241
|
};
|
|
239
242
|
img.src = _URL.createObjectURL(file);
|
|
240
243
|
});
|
|
241
|
-
function
|
|
244
|
+
function createVideoInfoWithThumbnail(file) {
|
|
242
245
|
return new Promise((resolve, reject) => {
|
|
243
246
|
try {
|
|
244
247
|
const video = document.createElement("video");
|
|
245
248
|
video.preload = "metadata";
|
|
249
|
+
video.src = URL.createObjectURL(file);
|
|
246
250
|
video.onloadedmetadata = () => {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
});
|
|
251
|
+
const duration = Math.floor(video.duration * 1000);
|
|
252
|
+
const width = video.videoWidth;
|
|
253
|
+
const height = video.videoHeight;
|
|
254
|
+
// Seek tới giây 1 (nếu video dài hơn 1s) để lấy frame đẹp hơn
|
|
255
|
+
video.currentTime = Math.min(1, video.duration / 2);
|
|
253
256
|
};
|
|
254
|
-
video.
|
|
255
|
-
|
|
257
|
+
video.onseeked = () => {
|
|
258
|
+
const canvas = document.createElement("canvas");
|
|
259
|
+
canvas.width = video.videoWidth;
|
|
260
|
+
canvas.height = video.videoHeight;
|
|
261
|
+
const ctx = canvas.getContext("2d");
|
|
262
|
+
if (!ctx)
|
|
263
|
+
return reject("Canvas not supported");
|
|
264
|
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
265
|
+
canvas.toBlob((blob) => {
|
|
266
|
+
if (!blob)
|
|
267
|
+
return reject("Thumbnail capture failed");
|
|
268
|
+
resolve({
|
|
269
|
+
duration: Math.floor(video.duration * 1000),
|
|
270
|
+
width: video.videoWidth,
|
|
271
|
+
height: video.videoHeight,
|
|
272
|
+
thumbnail: blob,
|
|
273
|
+
});
|
|
274
|
+
}, "image/jpeg", 0.85);
|
|
256
275
|
};
|
|
257
|
-
video.
|
|
276
|
+
video.onerror = (err) => reject(err);
|
|
258
277
|
}
|
|
259
278
|
catch (e) {
|
|
260
279
|
reject(e);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import "./locales/i18n";
|
|
1
2
|
import DChatDeskMessage from "./screens/deskMessage";
|
|
2
3
|
import DChatBubble from "./screens/chatBubble";
|
|
3
|
-
import { Platform, LogLevel, SessionType
|
|
4
|
+
import { Platform, LogLevel, SessionType } from "@openim/wasm-client-sdk";
|
|
4
5
|
import { Icon } from "./components/icon";
|
|
5
6
|
import useUserStore from "./store/user";
|
|
6
7
|
import useConversationStore from "./store/conversation";
|
|
8
|
+
import { DChatInitAndLoginConfig } from "./types/chat";
|
|
7
9
|
export { ChatProvider, useChatContext } from "./context/ChatContext";
|
|
8
10
|
export { DChatDeskMessage, DChatBubble, Icon };
|
|
9
11
|
export { useDChatAuth } from "./hooks/user/useAuth";
|
|
10
12
|
export { useUserStore, useConversationStore };
|
|
11
13
|
export { Platform as DChatPlatform, LogLevel as DChatLogLevel, SessionType as DChatSessionType, };
|
|
12
|
-
export type {
|
|
14
|
+
export type { DChatInitAndLoginConfig };
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,WAAW,EAEZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,oBAAoB,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGrE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AAG/C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAI9C,OAAO,EACL,QAAQ,IAAI,aAAa,EACzB,QAAQ,IAAI,aAAa,EACzB,WAAW,IAAI,gBAAgB,GAChC,CAAC;AAEF,YAAY,EAAE,uBAAuB,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.tsx"],"names":[],"mappings":"AAKA,OAAO,iBAAiB,CAAC;AAOzB,UAAU,eAAe;IACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AACD,QAAA,MAAM,UAAU,GAAI,cAAc,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.tsx"],"names":[],"mappings":"AAKA,OAAO,iBAAiB,CAAC;AAOzB,UAAU,eAAe;IACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AACD,QAAA,MAAM,UAAU,GAAI,cAAc,eAAe,4CAMhD,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
package/dist/layout/index.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { Spin } from "antd";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
4
3
|
import { useGlobalEvent } from "../hooks/global/useGlobalEvent";
|
|
5
4
|
import dayjs from "dayjs";
|
|
6
5
|
import "dayjs/locale/vi";
|
|
7
6
|
import { useChatContext } from "../context/ChatContext";
|
|
8
|
-
import { ConnectStatus, SyncStatus } from "../types/chat";
|
|
9
7
|
import { useSyncUsersInfo } from "../hooks/user/useUsersInfo";
|
|
10
8
|
dayjs.locale("vi");
|
|
11
9
|
const MainLayout = ({ children }) => {
|
|
12
10
|
const { syncStatus, connectStatus } = useChatContext();
|
|
13
11
|
useGlobalEvent();
|
|
14
12
|
useSyncUsersInfo();
|
|
15
|
-
return
|
|
16
|
-
connectStatus === ConnectStatus.Connected, children: children }));
|
|
13
|
+
return _jsx(_Fragment, { children: children });
|
|
17
14
|
};
|
|
18
15
|
export default MainLayout;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../src/locales/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,SAAS,CAAC;AAiB3B,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import i18n from "i18next";
|
|
2
|
+
import { initReactI18next } from "react-i18next";
|
|
3
|
+
import vi from "./vi/common.json";
|
|
4
|
+
if (!i18n.isInitialized) {
|
|
5
|
+
i18n.use(initReactI18next).init({
|
|
6
|
+
resources: {
|
|
7
|
+
vi: { common: vi },
|
|
8
|
+
},
|
|
9
|
+
lng: "vi", // default
|
|
10
|
+
fallbackLng: "vi",
|
|
11
|
+
interpolation: { escapeValue: false },
|
|
12
|
+
ns: ["common"],
|
|
13
|
+
defaultNS: "common",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export default i18n;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import i18n from "i18next";
|
|
2
|
+
import { initReactI18next } from "react-i18next";
|
|
3
|
+
import vi from "./vi/common.json";
|
|
4
|
+
|
|
5
|
+
if (!i18n.isInitialized) {
|
|
6
|
+
i18n.use(initReactI18next).init({
|
|
7
|
+
resources: {
|
|
8
|
+
vi: { common: vi },
|
|
9
|
+
},
|
|
10
|
+
lng: "vi", // default
|
|
11
|
+
fallbackLng: "vi",
|
|
12
|
+
interpolation: { escapeValue: false },
|
|
13
|
+
ns: ["common"],
|
|
14
|
+
defaultNS: "common",
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default i18n;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screens/chatBubble/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screens/chatBubble/index.tsx"],"names":[],"mappings":"AAOA,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,WAAW,GAAI,OAAO,gBAAgB,mDAgC3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import ChatBubble from "../../components/chatBubble/ChatBubble";
|
|
3
3
|
import { useChatContext } from "../../context/ChatContext";
|
|
4
|
-
import { ConnectStatus } from "../../types/chat";
|
|
4
|
+
import { ConnectStatus, SyncStatus } from "../../types/chat";
|
|
5
5
|
import { useEffect } from "react";
|
|
6
6
|
import useConversationStore from "../../store/conversation";
|
|
7
|
+
import { Spin } from "antd";
|
|
7
8
|
const DChatBubble = (props) => {
|
|
8
9
|
const { conversationID, className } = props;
|
|
9
|
-
const { connectStatus } = useChatContext();
|
|
10
|
+
const { connectStatus, syncStatus } = useChatContext();
|
|
10
11
|
if (connectStatus !== ConnectStatus.Connected)
|
|
11
12
|
return null;
|
|
12
13
|
const conversationList = useConversationStore((state) => state.conversationList);
|
|
@@ -21,6 +22,6 @@ const DChatBubble = (props) => {
|
|
|
21
22
|
setSelectedConversationId(conversation.conversationID);
|
|
22
23
|
setConversationData(conversation);
|
|
23
24
|
}, [conversationList, conversationID]);
|
|
24
|
-
return _jsx(ChatBubble, { className: className });
|
|
25
|
+
return (_jsx(Spin, { spinning: syncStatus === SyncStatus.Loading, children: _jsx(ChatBubble, { className: className }) }));
|
|
25
26
|
};
|
|
26
27
|
export default DChatBubble;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screens/deskMessage/index.tsx"],"names":[],"mappings":"AAUA,QAAA,MAAM,gBAAgB,+
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screens/deskMessage/index.tsx"],"names":[],"mappings":"AAUA,QAAA,MAAM,gBAAgB,+CAuBrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -5,11 +5,11 @@ import DeskConversationList from "../../components/conversation/DeskConversation
|
|
|
5
5
|
import AssignedSessionFilter from "../../components/session/AssignedSessionFilter";
|
|
6
6
|
import { useChatContext } from "../../context/ChatContext";
|
|
7
7
|
import { Spin } from "antd";
|
|
8
|
-
import { ConnectStatus } from "../../types/chat";
|
|
8
|
+
import { ConnectStatus, SyncStatus } from "../../types/chat";
|
|
9
9
|
import useConversationStore from "../../store/conversation";
|
|
10
10
|
const DChatDeskMessage = () => {
|
|
11
11
|
const selectedConversationId = useConversationStore((state) => state.selectedConversationId);
|
|
12
|
-
const { connectStatus } = useChatContext();
|
|
13
|
-
return (_jsx(_Fragment, { children: connectStatus === ConnectStatus.Connected ? (_jsxs("div", { className: "flex flex-1 flex-row h-screen bg-gray-50", children: [_jsx(AssignedSessionFilter, {}), _jsx(DeskConversationList, {}), _jsx(MessageList, { conversationId: selectedConversationId })] })) : (_jsx("div", { className: "flex flex-1 flex-row h-screen bg-gray-50", children: connectStatus === ConnectStatus.Connecting && _jsx(Spin, { fullscreen: true }) })) }));
|
|
12
|
+
const { connectStatus, syncStatus } = useChatContext();
|
|
13
|
+
return (_jsx(_Fragment, { children: connectStatus === ConnectStatus.Connected ? (_jsx(Spin, { spinning: syncStatus === SyncStatus.Loading, children: _jsxs("div", { className: "flex flex-1 flex-row h-screen bg-gray-50", children: [_jsx(AssignedSessionFilter, {}), _jsx(DeskConversationList, {}), _jsx(MessageList, { conversationId: selectedConversationId })] }) })) : (_jsx("div", { className: "flex flex-1 flex-row h-screen bg-gray-50", children: connectStatus === ConnectStatus.Connecting && _jsx(Spin, { fullscreen: true }) })) }));
|
|
14
14
|
};
|
|
15
15
|
export default DChatDeskMessage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/services/api.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW,+BAMtB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import useAuthStore from "../store/auth";
|
|
3
|
+
const TIMEOUT = 90000;
|
|
4
|
+
export const apiInstance = axios.create({
|
|
5
|
+
headers: {
|
|
6
|
+
Accept: "application/json",
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
},
|
|
9
|
+
timeout: TIMEOUT,
|
|
10
|
+
});
|
|
11
|
+
apiInstance.interceptors.request.use((config) => {
|
|
12
|
+
return Object.assign(Object.assign({}, config), { baseURL: useAuthStore.getState().apiAddress, headers: Object.assign(Object.assign({}, config.headers), { Authorization: `Bearer ${useAuthStore.getState().accessToken}`, token: useAuthStore.getState().chatToken }) });
|
|
13
|
+
}, (error) => {
|
|
14
|
+
// Handle errors globally
|
|
15
|
+
return Promise.reject(error);
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/services/query.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;CAGtB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const ENDPOINTS: {
|
|
2
|
+
chatService: {
|
|
3
|
+
getChatToken: string;
|
|
4
|
+
getSessionSummary: string;
|
|
5
|
+
getSessionsByStatus: string;
|
|
6
|
+
getMediaCollection: string;
|
|
7
|
+
};
|
|
8
|
+
identityService: {
|
|
9
|
+
getToken: string;
|
|
10
|
+
};
|
|
11
|
+
userService: {
|
|
12
|
+
getCurrentUserInfo: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/services/routes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;;;;;;;;;;CAarB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const ENDPOINTS = {
|
|
2
|
+
chatService: {
|
|
3
|
+
getChatToken: "/chat-service/v1/auth/token",
|
|
4
|
+
getSessionSummary: "chat-service/v1/crm/sessions/assigned/summary",
|
|
5
|
+
getSessionsByStatus: "chat-service/v1/crm/sessions/assigned/query",
|
|
6
|
+
getMediaCollection: "chat-service/v1/messages/search/media",
|
|
7
|
+
},
|
|
8
|
+
identityService: {
|
|
9
|
+
getToken: "/identity-service/v1/identity/get-token",
|
|
10
|
+
},
|
|
11
|
+
userService: {
|
|
12
|
+
getCurrentUserInfo: "/user-service/v1/app/user",
|
|
13
|
+
},
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/store/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC,QAAA,MAAM,YAAY,wEAmBf,CAAC;AAEJ,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
import { Platform } from "@openim/wasm-client-sdk";
|
|
3
|
+
const useAuthStore = create((set, get) => ({
|
|
4
|
+
accessToken: "",
|
|
5
|
+
chatToken: "",
|
|
6
|
+
apiAddress: "",
|
|
7
|
+
wsAddress: "",
|
|
8
|
+
platformID: Platform.Web,
|
|
9
|
+
userID: "",
|
|
10
|
+
setAccessToken: (token) => set({ accessToken: token }),
|
|
11
|
+
setChatToken: (token) => set({ chatToken: token }),
|
|
12
|
+
initAuthStore: ({ accessToken, chatToken, apiAddress, wsAddress, platformID, userID, }) => {
|
|
13
|
+
set({ accessToken, chatToken, apiAddress, wsAddress, platformID, userID });
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
export default useAuthStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../src/store/conversation.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAmC,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../src/store/conversation.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAmC,MAAM,QAAQ,CAAC;AAQ5E,QAAA,MAAM,oBAAoB,gFAiJvB,CAAC;AAEJ,eAAe,oBAAoB,CAAC"}
|
|
@@ -4,6 +4,7 @@ import { DChatSDK } from "../constants/sdk";
|
|
|
4
4
|
import { conversationSort, isGroupSession } from "../utils/imCommon";
|
|
5
5
|
import useUserStore from "./user";
|
|
6
6
|
import { markConversationMessageAsRead } from "../hooks/conversation/useConversation";
|
|
7
|
+
import { SESSION_STATUS_ENUM } from "../constants";
|
|
7
8
|
const CONVERSATION_SPLIT_COUNT = 500;
|
|
8
9
|
const useConversationStore = create((set, get) => ({
|
|
9
10
|
conversationData: null,
|
|
@@ -20,10 +21,12 @@ const useConversationStore = create((set, get) => ({
|
|
|
20
21
|
summary: null,
|
|
21
22
|
setSummary: (summary) => set({ summary }),
|
|
22
23
|
filterSummary: {
|
|
23
|
-
status:
|
|
24
|
+
status: SESSION_STATUS_ENUM.UNASSIGNED,
|
|
24
25
|
tag: undefined,
|
|
25
26
|
},
|
|
26
27
|
setFilterSummary: (filterSummary) => set({ filterSummary }),
|
|
28
|
+
assignedSessionList: [],
|
|
29
|
+
setAssignedSessionList: (list) => set({ assignedSessionList: list }),
|
|
27
30
|
// conversation
|
|
28
31
|
conversationList: [],
|
|
29
32
|
currentConversation: undefined,
|