@droppii-org/chat-sdk 0.0.26 → 0.0.28
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/components/chatBubble/ChatBubble.d.ts.map +1 -1
- package/dist/components/chatBubble/ChatBubble.js +4 -5
- package/dist/components/conversation/DeskConversationList.d.ts.map +1 -1
- package/dist/components/conversation/DeskConversationList.js +14 -27
- package/dist/components/message/MessageHeader.d.ts +1 -3
- package/dist/components/message/MessageHeader.d.ts.map +1 -1
- package/dist/components/message/MessageHeader.js +7 -3
- package/dist/components/message/MessageList.d.ts +0 -2
- package/dist/components/message/MessageList.d.ts.map +1 -1
- package/dist/components/message/MessageList.js +5 -5
- package/dist/components/session/AssignedSessionFilter.d.ts.map +1 -1
- package/dist/components/session/AssignedSessionFilter.js +105 -51
- package/dist/constants/im.d.ts +3 -0
- package/dist/constants/im.d.ts.map +1 -0
- package/dist/constants/im.js +2 -0
- package/dist/constants/index.d.ts +12 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +12 -0
- package/dist/context/ChatContext.d.ts.map +1 -1
- package/dist/context/ChatContext.js +29 -39
- package/dist/hooks/conversation/useConversation.d.ts +5 -5
- package/dist/hooks/conversation/useConversation.d.ts.map +1 -1
- package/dist/hooks/conversation/useConversation.js +47 -52
- package/dist/hooks/global/useGlobalEvent.d.ts.map +1 -1
- package/dist/hooks/global/useGlobalEvent.js +66 -3
- package/dist/hooks/message/useSendMessage.d.ts.map +1 -1
- package/dist/hooks/message/useSendMessage.js +1 -1
- package/dist/hooks/user/useUsersInfo.d.ts +4 -0
- package/dist/hooks/user/useUsersInfo.d.ts.map +1 -0
- package/dist/hooks/user/useUsersInfo.js +44 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/layout/index.d.ts.map +1 -1
- package/dist/layout/index.js +8 -1
- package/dist/screens/chatBubble/index.d.ts +1 -3
- package/dist/screens/chatBubble/index.d.ts.map +1 -1
- package/dist/screens/chatBubble/index.js +13 -14
- package/dist/screens/deskMessage/index.d.ts.map +1 -1
- package/dist/screens/deskMessage/index.js +3 -4
- package/dist/store/conversation.d.ts +4 -0
- package/dist/store/conversation.d.ts.map +1 -0
- package/dist/store/conversation.js +119 -0
- package/dist/store/index.d.ts +3 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +2 -0
- package/dist/store/user.d.ts +4 -0
- package/dist/store/user.d.ts.map +1 -0
- package/dist/store/user.js +8 -0
- package/dist/store/usersInfo.d.ts +4 -0
- package/dist/store/usersInfo.d.ts.map +1 -0
- package/dist/store/usersInfo.js +12 -0
- package/dist/types/chat.d.ts +27 -0
- package/dist/types/chat.d.ts.map +1 -1
- package/dist/types/chat.js +6 -0
- package/dist/utils/imCommon.d.ts +26 -0
- package/dist/utils/imCommon.d.ts.map +1 -0
- package/dist/utils/imCommon.js +58 -0
- package/package.json +1 -1
- package/dist/hooks/zustand/useMessageStore.d.ts +0 -9
- package/dist/hooks/zustand/useMessageStore.d.ts.map +0 -1
- package/dist/hooks/zustand/useMessageStore.js +0 -8
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/sdk.d.ts +0 -1
- package/dist/types/sdk.d.ts.map +0 -1
- package/dist/types/sdk.js +0 -1
|
@@ -1,55 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useCallback, useEffect, useState } from "react";
|
|
1
|
+
import { SessionType } from "@openim/wasm-client-sdk";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { DChatSDK } from "../../constants/sdk";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
const markConversationMessageAsRead = useCallback((conversationId) => {
|
|
16
|
-
if (!conversationId)
|
|
17
|
-
return;
|
|
18
|
-
DChatSDK.markConversationMessageAsRead(conversationId)
|
|
19
|
-
.then()
|
|
20
|
-
.catch(({ errCode, errMsg }) => {
|
|
21
|
-
// Failed call
|
|
22
|
-
});
|
|
23
|
-
}, []);
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
getAllConversationList();
|
|
26
|
-
}, [getAllConversationList]);
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
const handler = ({ data }) => {
|
|
29
|
-
setConversationList((prev) => {
|
|
30
|
-
// Tạo map để cập nhật
|
|
31
|
-
const map = new Map(prev.map((c) => [c.conversationID, c]));
|
|
32
|
-
data.forEach((changed) => {
|
|
33
|
-
map.set(changed.conversationID, changed);
|
|
34
|
-
});
|
|
35
|
-
return Array.from(map.values());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
DChatSDK.on(CbEvents.OnConversationChanged, handler);
|
|
39
|
-
return () => {
|
|
40
|
-
DChatSDK.off(CbEvents.OnConversationChanged, handler);
|
|
41
|
-
};
|
|
42
|
-
}, []);
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (selectedThreadId) {
|
|
45
|
-
markConversationMessageAsRead(selectedThreadId);
|
|
46
|
-
}
|
|
47
|
-
}, [selectedThreadId, markConversationMessageAsRead]);
|
|
48
|
-
return {
|
|
49
|
-
conversationList,
|
|
50
|
-
getAllConversationList,
|
|
51
|
-
markConversationMessageAsRead,
|
|
52
|
-
};
|
|
4
|
+
import useUsersInfoStore from "../../store/usersInfo";
|
|
5
|
+
import { extractUserIdsFromConversations } from "../user/useUsersInfo";
|
|
6
|
+
import { useChatContext } from "../../context/ChatContext";
|
|
7
|
+
export const markConversationMessageAsRead = (conversationId) => {
|
|
8
|
+
if (!conversationId)
|
|
9
|
+
return;
|
|
10
|
+
DChatSDK.markConversationMessageAsRead(conversationId)
|
|
11
|
+
.then()
|
|
12
|
+
.catch(({ errCode, errMsg }) => {
|
|
13
|
+
console.error("markConversationMessageAsRead", errCode, errMsg);
|
|
14
|
+
});
|
|
53
15
|
};
|
|
54
16
|
export const useConversationDetail = ({ sourceID, sessionType, }) => {
|
|
55
17
|
const [conversationDetail, setConversationDetail] = useState(null);
|
|
@@ -62,7 +24,7 @@ export const useConversationDetail = ({ sourceID, sessionType, }) => {
|
|
|
62
24
|
setConversationDetail(data);
|
|
63
25
|
})
|
|
64
26
|
.catch((err) => {
|
|
65
|
-
console.
|
|
27
|
+
console.error("getOneConversation", err);
|
|
66
28
|
});
|
|
67
29
|
}, [sourceID, sessionType]);
|
|
68
30
|
useEffect(() => {
|
|
@@ -72,3 +34,36 @@ export const useConversationDetail = ({ sourceID, sessionType, }) => {
|
|
|
72
34
|
conversationDetail,
|
|
73
35
|
};
|
|
74
36
|
};
|
|
37
|
+
export const useConversationDisplayData = (conversation) => {
|
|
38
|
+
const { user } = useChatContext();
|
|
39
|
+
const usersInfo = useUsersInfoStore((state) => state.usersInfo);
|
|
40
|
+
const userInfo = useMemo(() => {
|
|
41
|
+
var _a;
|
|
42
|
+
if (!conversation)
|
|
43
|
+
return null;
|
|
44
|
+
const userId = (_a = extractUserIdsFromConversations([conversation])) === null || _a === void 0 ? void 0 : _a[0];
|
|
45
|
+
return usersInfo === null || usersInfo === void 0 ? void 0 : usersInfo[userId];
|
|
46
|
+
}, [conversation, usersInfo]);
|
|
47
|
+
const conversationDisplayData = useMemo(() => {
|
|
48
|
+
var _a, _b, _c, _d, _e;
|
|
49
|
+
if (!conversation)
|
|
50
|
+
return null;
|
|
51
|
+
const exConversationInfo = JSON.parse(conversation.ex || "{}");
|
|
52
|
+
const sessionInfo = exConversationInfo === null || exConversationInfo === void 0 ? void 0 : exConversationInfo.sessionInfo;
|
|
53
|
+
const isSupportGroup = conversation.conversationType === SessionType.Group &&
|
|
54
|
+
!!(sessionInfo === null || sessionInfo === void 0 ? void 0 : sessionInfo.data);
|
|
55
|
+
const isOwnerGroup = isSupportGroup && ((_a = sessionInfo === null || sessionInfo === void 0 ? void 0 : sessionInfo.data) === null || _a === void 0 ? void 0 : _a.ownerId) === (user === null || user === void 0 ? void 0 : user.userID);
|
|
56
|
+
const exUserInfo = JSON.parse((userInfo === null || userInfo === void 0 ? void 0 : userInfo.ex) || "{}");
|
|
57
|
+
return {
|
|
58
|
+
avatar: isSupportGroup && !isOwnerGroup
|
|
59
|
+
? userInfo === null || userInfo === void 0 ? void 0 : userInfo.faceURL
|
|
60
|
+
: conversation === null || conversation === void 0 ? void 0 : conversation.faceURL,
|
|
61
|
+
displayName: isSupportGroup && !isOwnerGroup
|
|
62
|
+
? `${userInfo === null || userInfo === void 0 ? void 0 : userInfo.nickname}${((_c = (_b = exUserInfo === null || exUserInfo === void 0 ? void 0 : exUserInfo.userInfo) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.username)
|
|
63
|
+
? ` (${(_e = (_d = exUserInfo === null || exUserInfo === void 0 ? void 0 : exUserInfo.userInfo) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.username})`
|
|
64
|
+
: ""}`
|
|
65
|
+
: conversation === null || conversation === void 0 ? void 0 : conversation.showName,
|
|
66
|
+
};
|
|
67
|
+
}, [conversation, userInfo]);
|
|
68
|
+
return Object.assign({}, conversationDisplayData);
|
|
69
|
+
};
|
|
@@ -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":"AAkBA,eAAO,MAAM,cAAc,YAmK1B,CAAC"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
2
|
import { DChatSDK } from "../../constants/sdk";
|
|
3
3
|
import { CbEvents, MessageType, SessionType, } from "@openim/wasm-client-sdk";
|
|
4
|
-
import { CustomType } from "../../types/chat";
|
|
4
|
+
import { ConnectStatus, CustomType, SyncStatus } from "../../types/chat";
|
|
5
5
|
import { pushNewMessage, updateOneMessage } from "../message/useMessage";
|
|
6
6
|
import { useChatContext } from "../../context/ChatContext";
|
|
7
|
-
import useConversationStore from "
|
|
7
|
+
import useConversationStore from "../../store/conversation";
|
|
8
8
|
const notPushType = [MessageType.TypingMessage, MessageType.RevokeMessage];
|
|
9
9
|
export const useGlobalEvent = () => {
|
|
10
10
|
const { user } = useChatContext();
|
|
11
|
-
const
|
|
11
|
+
const { updateConnectStatus, updateSyncStatus } = useChatContext();
|
|
12
|
+
const updateConversationList = useConversationStore((state) => state.updateConversationList);
|
|
13
|
+
const getConversationListByReq = useConversationStore((state) => state.getConversationListByReq);
|
|
12
14
|
const revokedMessageHandler = ({ data }) => {
|
|
13
15
|
updateOneMessage({
|
|
14
16
|
clientMsgID: data.clientMsgID,
|
|
@@ -19,6 +21,7 @@ export const useGlobalEvent = () => {
|
|
|
19
21
|
});
|
|
20
22
|
};
|
|
21
23
|
const inCurrentConversation = (newServerMsg) => {
|
|
24
|
+
const selectedSourceId = useConversationStore.getState().selectedSourceId;
|
|
22
25
|
switch (newServerMsg.sessionType) {
|
|
23
26
|
case SessionType.Single:
|
|
24
27
|
return (newServerMsg.sendID === selectedSourceId ||
|
|
@@ -52,14 +55,74 @@ export const useGlobalEvent = () => {
|
|
|
52
55
|
const loginCheck = async () => {
|
|
53
56
|
// check openIM token and user info
|
|
54
57
|
};
|
|
58
|
+
const connectingHandler = () => {
|
|
59
|
+
updateConnectStatus(ConnectStatus.Connecting);
|
|
60
|
+
};
|
|
61
|
+
const connectSuccessHandler = () => {
|
|
62
|
+
updateConnectStatus(ConnectStatus.Connected);
|
|
63
|
+
};
|
|
64
|
+
const connectFailedHandler = () => {
|
|
65
|
+
updateConnectStatus(ConnectStatus.Disconnected);
|
|
66
|
+
};
|
|
67
|
+
const userTokenHandler = () => {
|
|
68
|
+
useChatContext().userTokenHandler();
|
|
69
|
+
};
|
|
70
|
+
const syncStartHandler = ({ data }) => {
|
|
71
|
+
updateSyncStatus(SyncStatus.Loading);
|
|
72
|
+
};
|
|
73
|
+
const syncFinishHandler = () => {
|
|
74
|
+
updateSyncStatus(SyncStatus.Success);
|
|
75
|
+
// getFriendListByReq();
|
|
76
|
+
// getGroupListByReq();
|
|
77
|
+
getConversationListByReq(false);
|
|
78
|
+
// getUnReadCountByReq();
|
|
79
|
+
};
|
|
80
|
+
const syncFailedHandler = () => {
|
|
81
|
+
updateSyncStatus(SyncStatus.Failed);
|
|
82
|
+
};
|
|
55
83
|
const setIMListener = () => {
|
|
84
|
+
//account
|
|
85
|
+
DChatSDK.on(CbEvents.OnUserTokenExpired, userTokenHandler);
|
|
86
|
+
DChatSDK.on(CbEvents.OnUserTokenInvalid, userTokenHandler);
|
|
87
|
+
DChatSDK.on(CbEvents.OnConnecting, connectingHandler);
|
|
88
|
+
DChatSDK.on(CbEvents.OnConnectSuccess, connectSuccessHandler);
|
|
89
|
+
DChatSDK.on(CbEvents.OnConnectFailed, connectFailedHandler);
|
|
90
|
+
// sync
|
|
91
|
+
DChatSDK.on(CbEvents.OnSyncServerStart, syncStartHandler);
|
|
92
|
+
// DChatSDK.on(CbEvents.OnSyncServerProgress, syncProgressHandler);
|
|
93
|
+
DChatSDK.on(CbEvents.OnSyncServerFinish, syncFinishHandler);
|
|
94
|
+
DChatSDK.on(CbEvents.OnSyncServerFailed, syncFailedHandler);
|
|
56
95
|
// message
|
|
57
96
|
DChatSDK.on(CbEvents.OnRecvNewMessages, newMessageHandler);
|
|
58
97
|
DChatSDK.on(CbEvents.OnNewRecvMessageRevoked, revokedMessageHandler);
|
|
98
|
+
// conversation
|
|
99
|
+
DChatSDK.on(CbEvents.OnConversationChanged, conversationChangeHandler);
|
|
100
|
+
DChatSDK.on(CbEvents.OnNewConversation, newConversationHandler);
|
|
59
101
|
};
|
|
60
102
|
const disposeIMListener = () => {
|
|
103
|
+
//account
|
|
104
|
+
DChatSDK.off(CbEvents.OnUserTokenExpired, userTokenHandler);
|
|
105
|
+
DChatSDK.off(CbEvents.OnUserTokenInvalid, userTokenHandler);
|
|
106
|
+
DChatSDK.off(CbEvents.OnConnecting, connectingHandler);
|
|
107
|
+
DChatSDK.off(CbEvents.OnConnectSuccess, connectSuccessHandler);
|
|
108
|
+
DChatSDK.off(CbEvents.OnConnectFailed, connectFailedHandler);
|
|
109
|
+
// sync
|
|
110
|
+
DChatSDK.off(CbEvents.OnSyncServerStart, syncStartHandler);
|
|
111
|
+
// DChatSDK.off(CbEvents.OnSyncServerProgress, syncProgressHandler);
|
|
112
|
+
DChatSDK.off(CbEvents.OnSyncServerFinish, syncFinishHandler);
|
|
113
|
+
DChatSDK.off(CbEvents.OnSyncServerFailed, syncFailedHandler);
|
|
61
114
|
// message
|
|
62
115
|
DChatSDK.off(CbEvents.OnRecvNewMessages, newMessageHandler);
|
|
116
|
+
// conversation
|
|
117
|
+
DChatSDK.off(CbEvents.OnConversationChanged, conversationChangeHandler);
|
|
118
|
+
DChatSDK.off(CbEvents.OnNewConversation, newConversationHandler);
|
|
119
|
+
};
|
|
120
|
+
// conversation
|
|
121
|
+
const conversationChangeHandler = ({ data }) => {
|
|
122
|
+
updateConversationList(data, "filter");
|
|
123
|
+
};
|
|
124
|
+
const newConversationHandler = ({ data }) => {
|
|
125
|
+
updateConversationList(data, "push");
|
|
63
126
|
};
|
|
64
127
|
/** LIFE CYCLE */
|
|
65
128
|
useEffect(() => {
|
|
@@ -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;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;CAwIJ,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"}
|
|
@@ -6,7 +6,7 @@ import { useChatContext } from "../../context/ChatContext";
|
|
|
6
6
|
import { useCallback } from "react";
|
|
7
7
|
import { pushNewMessage, updateOneMessage } from "./useMessage";
|
|
8
8
|
import { emit } from "../../utils/events";
|
|
9
|
-
import useConversationStore from "
|
|
9
|
+
import useConversationStore from "../../store/conversation";
|
|
10
10
|
export const createTextMessage = async (text) => {
|
|
11
11
|
let textMessage = await DChatSDK.createTextMessage(text, new Date().getTime().toString())
|
|
12
12
|
.then(({ data }) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUsersInfo.d.ts","sourceRoot":"","sources":["../../../src/hooks/user/useUsersInfo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAe,MAAM,yBAAyB,CAAC;AAKxE,eAAO,MAAM,+BAA+B,GAC1C,eAAe,gBAAgB,EAAE,aAkBlC,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAyB5B,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useCallback, useEffect } from "react";
|
|
2
|
+
import useConversationStore from "../../store/conversation";
|
|
3
|
+
import { SessionType } from "@openim/wasm-client-sdk";
|
|
4
|
+
import useUsersInfoStore from "../../store/usersInfo";
|
|
5
|
+
import { DChatSDK } from "../../constants/sdk";
|
|
6
|
+
export const extractUserIdsFromConversations = (conversations) => {
|
|
7
|
+
const ids = conversations.reduce((acc, c) => {
|
|
8
|
+
var _a;
|
|
9
|
+
if (c.conversationType === SessionType.Single) {
|
|
10
|
+
acc.push(c.userID);
|
|
11
|
+
}
|
|
12
|
+
else if (c.conversationType === SessionType.Group) {
|
|
13
|
+
const exConversationInfo = JSON.parse(c.ex || "{}");
|
|
14
|
+
const sessionInfo = exConversationInfo === null || exConversationInfo === void 0 ? void 0 : exConversationInfo.sessionInfo;
|
|
15
|
+
if ((_a = sessionInfo === null || sessionInfo === void 0 ? void 0 : sessionInfo.data) === null || _a === void 0 ? void 0 : _a.ownerId) {
|
|
16
|
+
acc.push(sessionInfo.data.ownerId);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return acc;
|
|
20
|
+
}, []);
|
|
21
|
+
return Array.from(new Set(ids));
|
|
22
|
+
};
|
|
23
|
+
export const useSyncUsersInfo = () => {
|
|
24
|
+
const conversationList = useConversationStore((state) => state.conversationList);
|
|
25
|
+
const syncUsersInfo = useCallback(() => {
|
|
26
|
+
const userIds = extractUserIdsFromConversations(conversationList);
|
|
27
|
+
const { usersInfo, upsertUsers } = useUsersInfoStore.getState();
|
|
28
|
+
const needFetch = userIds.filter((id) => !usersInfo[id]);
|
|
29
|
+
if (needFetch.length > 0) {
|
|
30
|
+
DChatSDK.getUsersInfo(needFetch)
|
|
31
|
+
.then(({ data }) => {
|
|
32
|
+
upsertUsers(data);
|
|
33
|
+
})
|
|
34
|
+
.catch((error) => {
|
|
35
|
+
console.error("Error fetching users info:", error);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}, [conversationList]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!conversationList)
|
|
41
|
+
return;
|
|
42
|
+
syncUsersInfo();
|
|
43
|
+
}, [conversationList]);
|
|
44
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,12 @@ import DChatDeskMessage from "./screens/deskMessage";
|
|
|
2
2
|
import DChatBubble from "./screens/chatBubble";
|
|
3
3
|
import { Platform, LogLevel, SessionType, InitAndLoginConfig } from "@openim/wasm-client-sdk";
|
|
4
4
|
import { Icon } from "./components/icon";
|
|
5
|
+
import useUserStore from "./store/user";
|
|
6
|
+
import useConversationStore from "./store/conversation";
|
|
5
7
|
export { ChatProvider, useChatContext } from "./context/ChatContext";
|
|
6
8
|
export { DChatDeskMessage, DChatBubble, Icon };
|
|
7
9
|
export { useDChatAuth } from "./hooks/user/useAuth";
|
|
10
|
+
export { useUserStore, useConversationStore };
|
|
8
11
|
export { Platform as DChatPlatform, LogLevel as DChatLogLevel, SessionType as DChatSessionType, };
|
|
9
12
|
export type { InitAndLoginConfig as DChatInitAndLoginConfig };
|
|
10
13
|
//# 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,EACX,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;
|
|
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,EACX,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,oBAAoB,MAAM,sBAAsB,CAAC;AAGxD,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,kBAAkB,IAAI,uBAAuB,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,15 @@ import DChatDeskMessage from "./screens/deskMessage";
|
|
|
2
2
|
import DChatBubble from "./screens/chatBubble";
|
|
3
3
|
import { Platform, LogLevel, SessionType, } from "@openim/wasm-client-sdk";
|
|
4
4
|
import { Icon } from "./components/icon";
|
|
5
|
+
import useUserStore from "./store/user";
|
|
6
|
+
import useConversationStore from "./store/conversation";
|
|
5
7
|
// Main exports for the SDK
|
|
6
8
|
export { ChatProvider, useChatContext } from "./context/ChatContext";
|
|
7
9
|
//Components
|
|
8
10
|
export { DChatDeskMessage, DChatBubble, Icon };
|
|
9
11
|
//Hooks
|
|
10
12
|
export { useDChatAuth } from "./hooks/user/useAuth";
|
|
13
|
+
//Store
|
|
14
|
+
export { useUserStore, useConversationStore };
|
|
11
15
|
// export * from "./types/sdk";
|
|
12
16
|
export { Platform as DChatPlatform, LogLevel as DChatLogLevel, SessionType as DChatSessionType, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.tsx"],"names":[],"mappings":"
|
|
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,4CAehD,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
package/dist/layout/index.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Spin } from "antd";
|
|
3
4
|
import { useGlobalEvent } from "../hooks/global/useGlobalEvent";
|
|
4
5
|
import dayjs from "dayjs";
|
|
5
6
|
import "dayjs/locale/vi";
|
|
7
|
+
import { useChatContext } from "../context/ChatContext";
|
|
8
|
+
import { ConnectStatus, SyncStatus } from "../types/chat";
|
|
9
|
+
import { useSyncUsersInfo } from "../hooks/user/useUsersInfo";
|
|
6
10
|
dayjs.locale("vi");
|
|
7
11
|
const MainLayout = ({ children }) => {
|
|
12
|
+
const { syncStatus, connectStatus } = useChatContext();
|
|
8
13
|
useGlobalEvent();
|
|
9
|
-
|
|
14
|
+
useSyncUsersInfo();
|
|
15
|
+
return (_jsx(Spin, { spinning: syncStatus === SyncStatus.Loading &&
|
|
16
|
+
connectStatus === ConnectStatus.Connected, children: children }));
|
|
10
17
|
};
|
|
11
18
|
export default MainLayout;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { SessionType } from "@openim/wasm-client-sdk";
|
|
2
1
|
interface DChatBubbleProps {
|
|
3
|
-
|
|
4
|
-
sessionType: SessionType;
|
|
2
|
+
conversationID: string;
|
|
5
3
|
className?: string;
|
|
6
4
|
}
|
|
7
5
|
declare const DChatBubble: (props: DChatBubbleProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -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":"AAMA,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,WAAW,GAAI,OAAO,gBAAgB,mDA4B3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -2,26 +2,25 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import ChatBubble from "../../components/chatBubble/ChatBubble";
|
|
3
3
|
import { useChatContext } from "../../context/ChatContext";
|
|
4
4
|
import { ConnectStatus } from "../../types/chat";
|
|
5
|
-
import { useConversationDetail } from "../../hooks/conversation/useConversation";
|
|
6
|
-
import useConversationStore from "../../hooks/conversation/useConversationStore";
|
|
7
5
|
import { useEffect } from "react";
|
|
6
|
+
import useConversationStore from "../../store/conversation";
|
|
8
7
|
const DChatBubble = (props) => {
|
|
9
|
-
const {
|
|
8
|
+
const { conversationID, className } = props;
|
|
10
9
|
const { connectStatus } = useChatContext();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const setSelectedThreadId = useConversationStore((state) => state.setSelectedThreadId);
|
|
10
|
+
if (connectStatus !== ConnectStatus.Connected)
|
|
11
|
+
return null;
|
|
12
|
+
const conversationList = useConversationStore((state) => state.conversationList);
|
|
13
|
+
const setSelectedConversationId = useConversationStore((state) => state.setSelectedConversationId);
|
|
16
14
|
const setConversationData = useConversationStore((state) => state.setConversationData);
|
|
17
15
|
useEffect(() => {
|
|
18
|
-
if (!
|
|
16
|
+
if (!conversationList)
|
|
19
17
|
return;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
const conversation = conversationList.find((item) => item.conversationID === conversationID);
|
|
19
|
+
if (!conversation)
|
|
20
|
+
return;
|
|
21
|
+
setSelectedConversationId(conversation.conversationID);
|
|
22
|
+
setConversationData(conversation);
|
|
23
|
+
}, [conversationList, conversationID]);
|
|
25
24
|
return _jsx(ChatBubble, { className: className });
|
|
26
25
|
};
|
|
27
26
|
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,+CAqBrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -6,11 +6,10 @@ import AssignedSessionFilter from "../../components/session/AssignedSessionFilte
|
|
|
6
6
|
import { useChatContext } from "../../context/ChatContext";
|
|
7
7
|
import { Spin } from "antd";
|
|
8
8
|
import { ConnectStatus } from "../../types/chat";
|
|
9
|
-
import useConversationStore from "../../
|
|
9
|
+
import useConversationStore from "../../store/conversation";
|
|
10
10
|
const DChatDeskMessage = () => {
|
|
11
|
-
const
|
|
12
|
-
const selectedThreadId = useConversationStore((state) => state.selectedThreadId);
|
|
11
|
+
const selectedConversationId = useConversationStore((state) => state.selectedConversationId);
|
|
13
12
|
const { connectStatus } = useChatContext();
|
|
14
|
-
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:
|
|
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 }) })) }));
|
|
15
14
|
};
|
|
16
15
|
export default DChatDeskMessage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../src/store/conversation.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAmC,MAAM,QAAQ,CAAC;AAO5E,QAAA,MAAM,oBAAoB,gFA6IvB,CAAC;AAEJ,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { SessionType, } from "@openim/wasm-client-sdk";
|
|
2
|
+
import { create } from "zustand";
|
|
3
|
+
import { DChatSDK } from "../constants/sdk";
|
|
4
|
+
import { conversationSort, isGroupSession } from "../utils/imCommon";
|
|
5
|
+
import useUserStore from "./user";
|
|
6
|
+
import { markConversationMessageAsRead } from "../hooks/conversation/useConversation";
|
|
7
|
+
const CONVERSATION_SPLIT_COUNT = 500;
|
|
8
|
+
const useConversationStore = create((set, get) => ({
|
|
9
|
+
conversationData: null,
|
|
10
|
+
setConversationData: (data) => set({
|
|
11
|
+
conversationData: data,
|
|
12
|
+
selectedSourceId: (data === null || data === void 0 ? void 0 : data.conversationType) === SessionType.Group
|
|
13
|
+
? data === null || data === void 0 ? void 0 : data.groupID
|
|
14
|
+
: data === null || data === void 0 ? void 0 : data.userID,
|
|
15
|
+
}),
|
|
16
|
+
selectedConversationId: "",
|
|
17
|
+
setSelectedConversationId: (threadId) => set({ selectedConversationId: threadId }),
|
|
18
|
+
selectedSourceId: "",
|
|
19
|
+
// assigned session
|
|
20
|
+
summary: null,
|
|
21
|
+
setSummary: (summary) => set({ summary }),
|
|
22
|
+
filterSummary: {
|
|
23
|
+
status: undefined,
|
|
24
|
+
tag: undefined,
|
|
25
|
+
},
|
|
26
|
+
setFilterSummary: (filterSummary) => set({ filterSummary }),
|
|
27
|
+
// conversation
|
|
28
|
+
conversationList: [],
|
|
29
|
+
currentConversation: undefined,
|
|
30
|
+
unreadCount: 0,
|
|
31
|
+
currentGroupInfo: undefined,
|
|
32
|
+
currentMemberInGroup: undefined,
|
|
33
|
+
getConversationListByReq: async (isOffset) => {
|
|
34
|
+
let tmpConversationList = [];
|
|
35
|
+
try {
|
|
36
|
+
const { data } = await DChatSDK.getConversationListSplit({
|
|
37
|
+
offset: isOffset ? get().conversationList.length : 0,
|
|
38
|
+
count: CONVERSATION_SPLIT_COUNT,
|
|
39
|
+
});
|
|
40
|
+
tmpConversationList = data;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error("Error fetching conversation list:", error);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
set((state) => ({
|
|
47
|
+
conversationList: [
|
|
48
|
+
...(isOffset ? state.conversationList : []),
|
|
49
|
+
...tmpConversationList,
|
|
50
|
+
],
|
|
51
|
+
}));
|
|
52
|
+
return tmpConversationList.length === CONVERSATION_SPLIT_COUNT;
|
|
53
|
+
},
|
|
54
|
+
updateConversationList: (list, type) => {
|
|
55
|
+
const idx = list.findIndex((c) => { var _a; return c.conversationID === ((_a = get().currentConversation) === null || _a === void 0 ? void 0 : _a.conversationID); });
|
|
56
|
+
if (idx > -1) {
|
|
57
|
+
get().updateCurrentConversation(list[idx]);
|
|
58
|
+
markConversationMessageAsRead(list[idx].conversationID);
|
|
59
|
+
}
|
|
60
|
+
if (type === "filter") {
|
|
61
|
+
set((state) => ({
|
|
62
|
+
conversationList: conversationSort([...list, ...state.conversationList], state.conversationList),
|
|
63
|
+
}));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
let filterArr = [];
|
|
67
|
+
const chids = list.map((ch) => ch.conversationID);
|
|
68
|
+
filterArr = get().conversationList.filter((tc) => !chids.includes(tc.conversationID));
|
|
69
|
+
set(() => ({
|
|
70
|
+
conversationList: conversationSort([...list, ...filterArr]),
|
|
71
|
+
}));
|
|
72
|
+
},
|
|
73
|
+
updateCurrentConversation: async (conversation) => {
|
|
74
|
+
if (!conversation) {
|
|
75
|
+
set({ currentConversation: undefined });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const prevConversation = get().currentConversation;
|
|
79
|
+
const toggleNewConversation = conversation.conversationID !== (prevConversation === null || prevConversation === void 0 ? void 0 : prevConversation.conversationID);
|
|
80
|
+
if (toggleNewConversation &&
|
|
81
|
+
isGroupSession(conversation.conversationType)) {
|
|
82
|
+
get().getCurrentGroupInfoByReq(conversation.groupID);
|
|
83
|
+
await get().getCurrentMemberInGroupByReq(conversation.groupID);
|
|
84
|
+
}
|
|
85
|
+
set(() => ({ currentConversation: Object.assign({}, conversation) }));
|
|
86
|
+
},
|
|
87
|
+
getCurrentGroupInfoByReq: async (groupID) => {
|
|
88
|
+
let groupInfo;
|
|
89
|
+
try {
|
|
90
|
+
const { data } = await DChatSDK.getSpecifiedGroupsInfo([groupID]);
|
|
91
|
+
groupInfo = data[0];
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.error("Error fetching group info:", error);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
set(() => ({ currentGroupInfo: Object.assign({}, groupInfo) }));
|
|
98
|
+
},
|
|
99
|
+
getCurrentMemberInGroupByReq: async (groupID) => {
|
|
100
|
+
let memberInfo;
|
|
101
|
+
const selfID = useUserStore.getState().selfInfo.id;
|
|
102
|
+
try {
|
|
103
|
+
const { data } = await DChatSDK.getSpecifiedGroupMembersInfo({
|
|
104
|
+
groupID,
|
|
105
|
+
userIDList: [selfID],
|
|
106
|
+
});
|
|
107
|
+
memberInfo = data[0];
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
set(() => ({ currentMemberInGroup: undefined }));
|
|
111
|
+
console.error("Error fetching group members:", error);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
set(() => ({
|
|
115
|
+
currentMemberInGroup: memberInfo ? Object.assign({}, memberInfo) : undefined,
|
|
116
|
+
}));
|
|
117
|
+
},
|
|
118
|
+
}));
|
|
119
|
+
export default useConversationStore;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/store/user.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE9C,QAAA,MAAM,YAAY,wEAKf,CAAC;AAEJ,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usersInfo.d.ts","sourceRoot":"","sources":["../../src/store/usersInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC,QAAA,MAAM,iBAAiB,6EAUpB,CAAC;AAEJ,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
const useUsersInfoStore = create((set, get) => ({
|
|
3
|
+
usersInfo: {},
|
|
4
|
+
upsertUsers: (list) => set((state) => {
|
|
5
|
+
const next = Object.assign({}, state.usersInfo);
|
|
6
|
+
list.forEach((u) => {
|
|
7
|
+
next[u.userID] = Object.assign(Object.assign({}, next[u.userID]), u);
|
|
8
|
+
});
|
|
9
|
+
return { usersInfo: next };
|
|
10
|
+
}),
|
|
11
|
+
}));
|
|
12
|
+
export default useUsersInfoStore;
|