@droppii-org/chat-sdk 0.0.27 → 0.0.29

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.
Files changed (68) hide show
  1. package/dist/components/chatBubble/ChatBubble.d.ts.map +1 -1
  2. package/dist/components/chatBubble/ChatBubble.js +4 -5
  3. package/dist/components/conversation/DeskConversationList.d.ts.map +1 -1
  4. package/dist/components/conversation/DeskConversationList.js +10 -29
  5. package/dist/components/message/MessageHeader.d.ts +1 -3
  6. package/dist/components/message/MessageHeader.d.ts.map +1 -1
  7. package/dist/components/message/MessageHeader.js +7 -3
  8. package/dist/components/message/MessageList.d.ts +0 -2
  9. package/dist/components/message/MessageList.d.ts.map +1 -1
  10. package/dist/components/message/MessageList.js +5 -5
  11. package/dist/components/session/AssignedSessionFilter.d.ts.map +1 -1
  12. package/dist/components/session/AssignedSessionFilter.js +105 -51
  13. package/dist/constants/im.d.ts +3 -0
  14. package/dist/constants/im.d.ts.map +1 -0
  15. package/dist/constants/im.js +2 -0
  16. package/dist/constants/index.d.ts +12 -0
  17. package/dist/constants/index.d.ts.map +1 -1
  18. package/dist/constants/index.js +12 -0
  19. package/dist/context/ChatContext.d.ts.map +1 -1
  20. package/dist/context/ChatContext.js +29 -39
  21. package/dist/hooks/conversation/useConversation.d.ts +5 -5
  22. package/dist/hooks/conversation/useConversation.d.ts.map +1 -1
  23. package/dist/hooks/conversation/useConversation.js +47 -52
  24. package/dist/hooks/global/useGlobalEvent.d.ts.map +1 -1
  25. package/dist/hooks/global/useGlobalEvent.js +66 -3
  26. package/dist/hooks/message/useSendMessage.d.ts.map +1 -1
  27. package/dist/hooks/message/useSendMessage.js +1 -1
  28. package/dist/hooks/user/useUsersInfo.d.ts +4 -0
  29. package/dist/hooks/user/useUsersInfo.d.ts.map +1 -0
  30. package/dist/hooks/user/useUsersInfo.js +44 -0
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +4 -0
  34. package/dist/layout/index.d.ts.map +1 -1
  35. package/dist/layout/index.js +8 -1
  36. package/dist/screens/chatBubble/index.d.ts.map +1 -1
  37. package/dist/screens/chatBubble/index.js +4 -11
  38. package/dist/screens/deskMessage/index.d.ts.map +1 -1
  39. package/dist/screens/deskMessage/index.js +3 -4
  40. package/dist/store/conversation.d.ts +4 -0
  41. package/dist/store/conversation.d.ts.map +1 -0
  42. package/dist/store/conversation.js +121 -0
  43. package/dist/store/index.d.ts +3 -0
  44. package/dist/store/index.d.ts.map +1 -0
  45. package/dist/store/index.js +2 -0
  46. package/dist/store/user.d.ts +4 -0
  47. package/dist/store/user.d.ts.map +1 -0
  48. package/dist/store/user.js +8 -0
  49. package/dist/store/usersInfo.d.ts +4 -0
  50. package/dist/store/usersInfo.d.ts.map +1 -0
  51. package/dist/store/usersInfo.js +12 -0
  52. package/dist/types/chat.d.ts +27 -0
  53. package/dist/types/chat.d.ts.map +1 -1
  54. package/dist/types/chat.js +6 -0
  55. package/dist/utils/imCommon.d.ts +26 -0
  56. package/dist/utils/imCommon.d.ts.map +1 -0
  57. package/dist/utils/imCommon.js +58 -0
  58. package/package.json +1 -1
  59. package/dist/hooks/zustand/useMessageStore.d.ts +0 -9
  60. package/dist/hooks/zustand/useMessageStore.d.ts.map +0 -1
  61. package/dist/hooks/zustand/useMessageStore.js +0 -8
  62. package/dist/tsconfig.tsbuildinfo +0 -1
  63. package/dist/types/index.d.ts +0 -1
  64. package/dist/types/index.d.ts.map +0 -1
  65. package/dist/types/index.js +0 -1
  66. package/dist/types/sdk.d.ts +0 -1
  67. package/dist/types/sdk.d.ts.map +0 -1
  68. package/dist/types/sdk.js +0 -1
@@ -1,55 +1,17 @@
1
- import { CbEvents, } from "@openim/wasm-client-sdk";
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
- export const useConversationList = (selectedThreadId) => {
5
- const [conversationList, setConversationList] = useState([]);
6
- const getAllConversationList = useCallback(async () => {
7
- DChatSDK.getAllConversationList()
8
- .then(({ data }) => {
9
- setConversationList(data);
10
- })
11
- .catch((err) => {
12
- console.log("getAllConversationList", err);
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.log("getOneConversation", err);
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":"AAiBA,eAAO,MAAM,cAAc,YAqF1B,CAAC"}
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 "../conversation/useConversationStore";
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 selectedSourceId = useConversationStore((state) => state.selectedSourceId);
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;AAQ1B,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGlC,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"}
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 "../conversation/useConversationStore";
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,4 @@
1
+ import { ConversationItem } from "@openim/wasm-client-sdk";
2
+ export declare const extractUserIdsFromConversations: (conversations: ConversationItem[]) => string[];
3
+ export declare const useSyncUsersInfo: () => void;
4
+ //# sourceMappingURL=useUsersInfo.d.ts.map
@@ -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
@@ -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;AAGzC,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;AAIpD,OAAO,EACL,QAAQ,IAAI,aAAa,EACzB,QAAQ,IAAI,aAAa,EACzB,WAAW,IAAI,gBAAgB,GAChC,CAAC;AAEF,YAAY,EAAE,kBAAkB,IAAI,uBAAuB,EAAE,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":"AAIA,OAAO,iBAAiB,CAAC;AAIzB,UAAU,eAAe;IACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AACD,QAAA,MAAM,UAAU,GAAI,cAAc,eAAe,4CAGhD,CAAC;AAEF,eAAe,UAAU,CAAC"}
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"}
@@ -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
- return _jsx("div", { children: children });
14
+ useSyncUsersInfo();
15
+ return (_jsx(Spin, { spinning: syncStatus === SyncStatus.Loading &&
16
+ connectStatus === ConnectStatus.Connected, children: children }));
10
17
  };
11
18
  export default MainLayout;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screens/chatBubble/index.tsx"],"names":[],"mappings":"AAQA,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,WAAW,GAAI,OAAO,gBAAgB,mDAkC3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
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,31 +2,24 @@ 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 { useConversationList } from "../../hooks/conversation/useConversation";
6
- import useConversationStore from "../../hooks/conversation/useConversationStore";
7
5
  import { useEffect } from "react";
8
- import { SessionType } from "@openim/wasm-client-sdk";
6
+ import useConversationStore from "../../store/conversation";
9
7
  const DChatBubble = (props) => {
10
8
  const { conversationID, className } = props;
11
9
  const { connectStatus } = useChatContext();
12
10
  if (connectStatus !== ConnectStatus.Connected)
13
11
  return null;
14
- const { conversationList } = useConversationList();
15
- const setSelectedThreadId = useConversationStore((state) => state.setSelectedThreadId);
12
+ const conversationList = useConversationStore((state) => state.conversationList);
13
+ const setSelectedConversationId = useConversationStore((state) => state.setSelectedConversationId);
16
14
  const setConversationData = useConversationStore((state) => state.setConversationData);
17
- const setSelectedSourceId = useConversationStore((state) => state.setSelectedSourceId);
18
15
  useEffect(() => {
19
16
  if (!conversationList)
20
17
  return;
21
18
  const conversation = conversationList.find((item) => item.conversationID === conversationID);
22
19
  if (!conversation)
23
20
  return;
24
- const sourceId = (conversation === null || conversation === void 0 ? void 0 : conversation.conversationType) === SessionType.Group
25
- ? conversation === null || conversation === void 0 ? void 0 : conversation.groupID
26
- : conversation === null || conversation === void 0 ? void 0 : conversation.userID;
27
- setSelectedThreadId(conversation.conversationID);
21
+ setSelectedConversationId(conversation.conversationID);
28
22
  setConversationData(conversation);
29
- setSelectedSourceId(sourceId);
30
23
  }, [conversationList, conversationID]);
31
24
  return _jsx(ChatBubble, { className: className });
32
25
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screens/deskMessage/index.tsx"],"names":[],"mappings":"AAUA,QAAA,MAAM,gBAAgB,+CA2BrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
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 "../../hooks/conversation/useConversationStore";
9
+ import useConversationStore from "../../store/conversation";
10
10
  const DChatDeskMessage = () => {
11
- const conversationData = useConversationStore((state) => state.conversationData);
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: selectedThreadId, conversationData: conversationData })] })) : (_jsx("div", { className: "flex flex-1 flex-row h-screen bg-gray-50", children: connectStatus === ConnectStatus.Connecting && _jsx(Spin, { fullscreen: true }) })) }));
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,4 @@
1
+ import { ConversationStore } from "./type";
2
+ declare const useConversationStore: import("zustand").UseBoundStore<import("zustand").StoreApi<ConversationStore>>;
3
+ export default useConversationStore;
4
+ //# sourceMappingURL=conversation.d.ts.map
@@ -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,gFA+IvB,CAAC;AAEJ,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,121 @@
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
+ if (type === "filter" && list[idx].unreadCount > 0) {
59
+ markConversationMessageAsRead(list[idx].conversationID);
60
+ }
61
+ }
62
+ if (type === "filter") {
63
+ set((state) => ({
64
+ conversationList: conversationSort([...list, ...state.conversationList], state.conversationList),
65
+ }));
66
+ return;
67
+ }
68
+ let filterArr = [];
69
+ const chids = list.map((ch) => ch.conversationID);
70
+ filterArr = get().conversationList.filter((tc) => !chids.includes(tc.conversationID));
71
+ set(() => ({
72
+ conversationList: conversationSort([...list, ...filterArr]),
73
+ }));
74
+ },
75
+ updateCurrentConversation: async (conversation) => {
76
+ if (!conversation) {
77
+ set({ currentConversation: undefined });
78
+ return;
79
+ }
80
+ const prevConversation = get().currentConversation;
81
+ const toggleNewConversation = conversation.conversationID !== (prevConversation === null || prevConversation === void 0 ? void 0 : prevConversation.conversationID);
82
+ if (toggleNewConversation &&
83
+ isGroupSession(conversation.conversationType)) {
84
+ get().getCurrentGroupInfoByReq(conversation.groupID);
85
+ await get().getCurrentMemberInGroupByReq(conversation.groupID);
86
+ }
87
+ set(() => ({ currentConversation: Object.assign({}, conversation) }));
88
+ },
89
+ getCurrentGroupInfoByReq: async (groupID) => {
90
+ let groupInfo;
91
+ try {
92
+ const { data } = await DChatSDK.getSpecifiedGroupsInfo([groupID]);
93
+ groupInfo = data[0];
94
+ }
95
+ catch (error) {
96
+ console.error("Error fetching group info:", error);
97
+ return;
98
+ }
99
+ set(() => ({ currentGroupInfo: Object.assign({}, groupInfo) }));
100
+ },
101
+ getCurrentMemberInGroupByReq: async (groupID) => {
102
+ let memberInfo;
103
+ const selfID = useUserStore.getState().selfInfo.id;
104
+ try {
105
+ const { data } = await DChatSDK.getSpecifiedGroupMembersInfo({
106
+ groupID,
107
+ userIDList: [selfID],
108
+ });
109
+ memberInfo = data[0];
110
+ }
111
+ catch (error) {
112
+ set(() => ({ currentMemberInGroup: undefined }));
113
+ console.error("Error fetching group members:", error);
114
+ return;
115
+ }
116
+ set(() => ({
117
+ currentMemberInGroup: memberInfo ? Object.assign({}, memberInfo) : undefined,
118
+ }));
119
+ },
120
+ }));
121
+ export default useConversationStore;
@@ -0,0 +1,3 @@
1
+ export * from "./conversation";
2
+ export * from "./user";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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,2 @@
1
+ export * from "./conversation";
2
+ export * from "./user";
@@ -0,0 +1,4 @@
1
+ import { UserStore } from "./type";
2
+ declare const useUserStore: import("zustand").UseBoundStore<import("zustand").StoreApi<UserStore>>;
3
+ export default useUserStore;
4
+ //# sourceMappingURL=user.d.ts.map
@@ -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,8 @@
1
+ import { create } from "zustand";
2
+ const useUserStore = create((set, get) => ({
3
+ selfInfo: {},
4
+ getSelfInfo: (data) => {
5
+ set({ selfInfo: data });
6
+ },
7
+ }));
8
+ export default useUserStore;
@@ -0,0 +1,4 @@
1
+ import { UsersInfoStore } from "./type";
2
+ declare const useUsersInfoStore: import("zustand").UseBoundStore<import("zustand").StoreApi<UsersInfoStore>>;
3
+ export default useUsersInfoStore;
4
+ //# sourceMappingURL=usersInfo.d.ts.map
@@ -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;