@droppii-org/chat-sdk 0.1.34 → 0.1.36

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 (42) hide show
  1. package/dist/components/biz-inbox/BizThreadAvatar.d.ts.map +1 -1
  2. package/dist/components/biz-inbox/BizThreadAvatar.js +3 -0
  3. package/dist/components/biz-inbox/BizThreadCard.d.ts.map +1 -1
  4. package/dist/components/biz-inbox/BizThreadCard.js +7 -5
  5. package/dist/components/biz-thread-detail/BizMessageList.d.ts.map +1 -1
  6. package/dist/components/biz-thread-detail/BizMessageList.js +7 -7
  7. package/dist/components/biz-thread-detail/BizThreadDetailInput.d.ts.map +1 -1
  8. package/dist/components/biz-thread-detail/BizThreadDetailInput.js +39 -12
  9. package/dist/context/ChatContext.d.ts.map +1 -1
  10. package/dist/context/ChatContext.js +2 -0
  11. package/dist/hooks/biz/index.d.ts +0 -1
  12. package/dist/hooks/biz/index.d.ts.map +1 -1
  13. package/dist/hooks/biz/index.js +0 -1
  14. package/dist/hooks/biz/useBizConversationListItems.d.ts.map +1 -1
  15. package/dist/hooks/biz/useBizConversationListItems.js +27 -2
  16. package/dist/hooks/biz/useBizGlobalEvent.d.ts.map +1 -1
  17. package/dist/hooks/biz/useBizGlobalEvent.js +17 -5
  18. package/dist/hooks/global/useGlobalEvent.d.ts.map +1 -1
  19. package/dist/hooks/global/useGlobalEvent.js +7 -4
  20. package/dist/hooks/message/useSendMessage.d.ts +17 -3
  21. package/dist/hooks/message/useSendMessage.d.ts.map +1 -1
  22. package/dist/hooks/message/useSendMessage.js +73 -26
  23. package/dist/hooks/user/useAuth.d.ts.map +1 -1
  24. package/dist/hooks/user/useAuth.js +3 -0
  25. package/dist/hooks/user/useUsersInfo.d.ts.map +1 -1
  26. package/dist/hooks/user/useUsersInfo.js +30 -18
  27. package/dist/store/bizMessageDraft.d.ts +3 -2
  28. package/dist/store/bizMessageDraft.d.ts.map +1 -1
  29. package/dist/store/bizMessageDraft.js +19 -7
  30. package/dist/tsconfig.tsbuildinfo +1 -1
  31. package/dist/types/biz.d.ts +2 -1
  32. package/dist/types/biz.d.ts.map +1 -1
  33. package/dist/types/biz.js +1 -0
  34. package/dist/types/chat.d.ts +1 -1
  35. package/dist/types/chat.d.ts.map +1 -1
  36. package/dist/utils/bizConversation.d.ts +1 -0
  37. package/dist/utils/bizConversation.d.ts.map +1 -1
  38. package/dist/utils/bizConversation.js +15 -8
  39. package/dist/utils/bizMessage.d.ts +1 -1
  40. package/dist/utils/bizMessage.d.ts.map +1 -1
  41. package/dist/utils/bizMessage.js +6 -5
  42. package/package.json +126 -127
@@ -1 +1 @@
1
- {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../../src/hooks/user/useAuth.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY;;CAwBxB,CAAC"}
1
+ {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../../src/hooks/user/useAuth.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY;;CA4BxB,CAAC"}
@@ -2,13 +2,16 @@ import { Platform } from "@openim/wasm-client-sdk";
2
2
  import { DChatSDK } from "../../constants/sdk";
3
3
  import useAuthStore from "../../store/auth";
4
4
  import useConversationStore from "../../store/conversation";
5
+ import useBizMessageDraftStore from "../../store/bizMessageDraft";
5
6
  export const useDChatAuth = () => {
6
7
  const initAuthStore = useAuthStore((state) => state.initAuthStore);
7
8
  const resetConversationStore = useConversationStore((state) => state.resetConversationStore);
9
+ const clearAllDrafts = useBizMessageDraftStore((state) => state.clearAllDrafts);
8
10
  const logout = async () => {
9
11
  const res = await DChatSDK.logout();
10
12
  const applicationType = useAuthStore.getState().applicationType;
11
13
  resetConversationStore();
14
+ clearAllDrafts();
12
15
  initAuthStore({
13
16
  chatToken: "",
14
17
  accessToken: "",
@@ -1 +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"}
1
+ {"version":3,"file":"useUsersInfo.d.ts","sourceRoot":"","sources":["../../../src/hooks/user/useUsersInfo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAe,MAAM,yBAAyB,CAAC;AASxE,eAAO,MAAM,+BAA+B,GAC1C,eAAe,gBAAgB,EAAE,aAwBlC,CAAC;AAEF,eAAO,MAAM,gBAAgB,YA4B5B,CAAC"}
@@ -2,18 +2,27 @@ import { useCallback, useEffect } from "react";
2
2
  import useConversationStore from "../../store/conversation";
3
3
  import { SessionType } from "@openim/wasm-client-sdk";
4
4
  import useUsersInfoStore from "../../store/usersInfo";
5
+ import useAuthStore from "../../store/auth";
5
6
  import { DChatSDK } from "../../constants/sdk";
7
+ const isValidUserId = (userId) => !!(userId === null || userId === void 0 ? void 0 : userId.trim());
6
8
  export const extractUserIdsFromConversations = (conversations) => {
7
9
  const ids = conversations.reduce((acc, c) => {
8
- var _a;
10
+ var _a, _b;
9
11
  if (c.conversationType === SessionType.Single) {
10
- acc.push(c.userID);
12
+ if (isValidUserId(c.userID)) {
13
+ acc.push(c.userID.trim());
14
+ }
11
15
  }
12
16
  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
+ try {
18
+ const exConversationInfo = JSON.parse(c.ex || "{}");
19
+ const ownerId = (_b = (_a = exConversationInfo === null || exConversationInfo === void 0 ? void 0 : exConversationInfo.sessionInfo) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.ownerId;
20
+ if (isValidUserId(ownerId)) {
21
+ acc.push(ownerId.trim());
22
+ }
23
+ }
24
+ catch (_c) {
25
+ // ignore malformed conversation ex
17
26
  }
18
27
  }
19
28
  return acc;
@@ -22,23 +31,26 @@ export const extractUserIdsFromConversations = (conversations) => {
22
31
  };
23
32
  export const useSyncUsersInfo = () => {
24
33
  const conversationList = useConversationStore((state) => state.conversationList);
34
+ const isCrm = useAuthStore((state) => state.isCrm);
25
35
  const syncUsersInfo = useCallback(() => {
36
+ if (!isCrm)
37
+ return;
26
38
  const userIds = extractUserIdsFromConversations(conversationList);
27
39
  const { usersInfo, upsertUsers } = useUsersInfoStore.getState();
28
40
  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]);
41
+ if (needFetch.length === 0)
42
+ return;
43
+ DChatSDK.getUsersInfo(needFetch)
44
+ .then(({ data }) => {
45
+ upsertUsers(data);
46
+ })
47
+ .catch((error) => {
48
+ console.error("Error fetching users info:", error);
49
+ });
50
+ }, [conversationList, isCrm]);
39
51
  useEffect(() => {
40
- if (!conversationList)
52
+ if (!isCrm || !conversationList.length)
41
53
  return;
42
54
  syncUsersInfo();
43
- }, [conversationList]);
55
+ }, [conversationList, isCrm, syncUsersInfo]);
44
56
  };
@@ -1,7 +1,8 @@
1
1
  interface BizMessageDraftStore {
2
2
  drafts: Record<string, string>;
3
- setDraft: (conversationId: string, text: string) => void;
4
- clearDraft: (conversationId: string) => void;
3
+ setDraft: (userId: string, conversationId: string, text: string) => void;
4
+ clearDraft: (userId: string, conversationId: string) => void;
5
+ clearAllDrafts: () => void;
5
6
  }
6
7
  declare const useBizMessageDraftStore: import("zustand").UseBoundStore<import("zustand").StoreApi<BizMessageDraftStore>>;
7
8
  export default useBizMessageDraftStore;
@@ -1 +1 @@
1
- {"version":3,"file":"bizMessageDraft.d.ts","sourceRoot":"","sources":["../../src/store/bizMessageDraft.ts"],"names":[],"mappings":"AAEA,UAAU,oBAAoB;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,QAAQ,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACzD,UAAU,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C;AAED,QAAA,MAAM,uBAAuB,mFAW1B,CAAC;AAEJ,eAAe,uBAAuB,CAAC"}
1
+ {"version":3,"file":"bizMessageDraft.d.ts","sourceRoot":"","sources":["../../src/store/bizMessageDraft.ts"],"names":[],"mappings":"AAKA,UAAU,oBAAoB;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACzE,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7D,cAAc,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED,QAAA,MAAM,uBAAuB,mFAkB1B,CAAC;AAEJ,eAAe,uBAAuB,CAAC"}
@@ -10,14 +10,26 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { create } from "zustand";
13
+ const createDraftKey = (userId, conversationId) => `${userId}:${conversationId}`;
13
14
  const useBizMessageDraftStore = create((set) => ({
14
15
  drafts: {},
15
- setDraft: (conversationId, text) => set((state) => ({
16
- drafts: Object.assign(Object.assign({}, state.drafts), { [conversationId]: text }),
17
- })),
18
- clearDraft: (conversationId) => set((state) => {
19
- const _a = state.drafts, _b = conversationId, _ = _a[_b], drafts = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
20
- return { drafts };
21
- }),
16
+ setDraft: (userId, conversationId, text) => {
17
+ if (!userId || !conversationId)
18
+ return;
19
+ const key = createDraftKey(userId, conversationId);
20
+ set((state) => ({
21
+ drafts: Object.assign(Object.assign({}, state.drafts), { [key]: text }),
22
+ }));
23
+ },
24
+ clearDraft: (userId, conversationId) => {
25
+ if (!userId || !conversationId)
26
+ return;
27
+ const key = createDraftKey(userId, conversationId);
28
+ set((state) => {
29
+ const _a = state.drafts, _b = key, _ = _a[_b], drafts = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
30
+ return { drafts };
31
+ });
32
+ },
33
+ clearAllDrafts: () => set({ drafts: {} }),
22
34
  }));
23
35
  export default useBizMessageDraftStore;