@droppii-org/chat-sdk 0.1.35 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"BizThreadCard.d.ts","sourceRoot":"","sources":["../../../src/components/biz-inbox/BizThreadCard.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAavF,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,uBAAuB,KAAK,IAAI,CAAC;CAClD;AAwBD,QAAA,MAAM,aAAa,GAAI,mBAAmB,kBAAkB,4CAkE3D,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"BizThreadCard.d.ts","sourceRoot":"","sources":["../../../src/components/biz-inbox/BizThreadCard.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAYvF,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,uBAAuB,KAAK,IAAI,CAAC;CAClD;AAwBD,QAAA,MAAM,aAAa,GAAI,mBAAmB,kBAAkB,4CA+D3D,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -3,10 +3,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import clsx from "clsx";
4
4
  import dayjs from "dayjs";
5
5
  import { useTranslation } from "react-i18next";
6
- import { useChatContext } from "../../context/ChatContext";
6
+ import useAuthStore from "../../store/auth";
7
7
  import { formatTimestamp } from "../../utils/common";
8
8
  import { parseBizLatestMessage } from "../../utils/bizMessage";
9
- import { isBizGroupChat, resolveBizAvatarUrl, resolveBizBadgeLabel, resolveBizDisplayName, } from "../../utils/bizConversation";
9
+ import { resolveBizAvatarUrl, resolveBizBadgeLabel, resolveBizDisplayName, } from "../../utils/bizConversation";
10
10
  import BizThreadAvatar from "./BizThreadAvatar";
11
11
  import BizThreadTitle from "./BizThreadTitle";
12
12
  const formatLatestMessageTime = (sendTime) => {
@@ -25,14 +25,11 @@ const BizThreadCard = ({ item, onClick }) => {
25
25
  var _a;
26
26
  const { t } = useTranslation("biz-inbox");
27
27
  const { t: tCommon } = useTranslation("common");
28
- const { user } = useChatContext();
28
+ const currentUserId = useAuthStore((state) => state.userID);
29
29
  const displayName = resolveBizDisplayName(item, t);
30
30
  const avatarUrl = resolveBizAvatarUrl(item);
31
31
  const badgeLabel = resolveBizBadgeLabel(item.chatCategory, t);
32
- const latestMessagePreview = parseBizLatestMessage(item.latestMsg, user === null || user === void 0 ? void 0 : user.userID, tCommon, {
33
- peerFullName: item.peer.fullName,
34
- isGroupChat: isBizGroupChat(item),
35
- });
32
+ const latestMessagePreview = parseBizLatestMessage(item.latestMsg, currentUserId, tCommon, item.peer.fullName);
36
33
  const latestMessageTime = formatLatestMessageTime(item.latestMsgSendTime || null);
37
34
  const unreadCount = (_a = item.unreadCount) !== null && _a !== void 0 ? _a : 0;
38
35
  return (_jsxs("button", { type: "button", onClick: () => onClick(item), "data-testid": "biz-inbox-thread-card", className: "flex w-full shrink-0 items-start gap-2 border-b border-[#EFEFEF] bg-white p-3 text-left transition-colors hover:bg-gray-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-[#1677ff]", children: [_jsx(BizThreadAvatar, { chatCategory: item.chatCategory, displayName: displayName, avatarUrl: avatarUrl, badgeLabel: badgeLabel }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsxs("div", { className: "flex min-h-[25.6px] items-center justify-between gap-1", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx(BizThreadTitle, { chatCategory: item.chatCategory, displayName: displayName, hasUnread: unreadCount > 0 }) }), latestMessageTime && (_jsx("span", { className: "shrink-0 text-[12px] font-normal leading-[160%] text-[#747B7E] [font-feature-settings:'liga'_off,'clig'_off]", children: latestMessageTime }))] }), _jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("p", { className: clsx("min-w-0 flex-1 truncate text-[14px] leading-[160%] [font-feature-settings:'liga'_off,'clig'_off]", unreadCount > 0
@@ -42,8 +42,9 @@ export declare const useSendMessage: (options?: UseSendMessageOptions) => {
42
42
  }) => Promise<void>;
43
43
  resendMessage: (failedMessage: MessageItem) => Promise<void>;
44
44
  };
45
- export declare const generateExtendMessageInfo: ({ richText, currentSession, }: {
45
+ export declare const generateExtendMessageInfo: ({ richText, plainText, currentSession, }: {
46
46
  richText?: string;
47
+ plainText?: string;
47
48
  currentSession?: ISessionResponse;
48
49
  }) => ExtendMessageInfo;
49
50
  //# sourceMappingURL=useSendMessage.d.ts.map
@@ -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,cAAc,CAAC;AAWtB,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAUlC,OAAO,EAAgB,gBAAgB,EAAyB,MAAM,aAAa,CAAC;AAkBpF,eAAO,MAAM,iBAAiB,GAAI,SAAS;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB,YAE0C,CAAC;AAE5C,eAAO,MAAM,iBAAiB,GAAU,MAAM,MAAM,gCAanD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAU,MAAM,oBAAoB,gCAaxE,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAU,iBAAiB,eAAe,gCAazE,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAU,MAAM,oBAAoB,gCAaxE,CAAC;AAEF,eAAO,MAAM,uBAAuB,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,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,eAAe,CAAC;CACxE;AAED,eAAO,MAAM,cAAc,GAAI,UAAU,qBAAqB;4EA+OvD;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,cAAc,CAAC,EAAE,gBAAgB,CAAC;QAClC,UAAU,EAAE,OAAO,CAAC;KACrB,KAAG,OAAO,CAAC,OAAO,CAAC;oFA6CjB;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,UAAU,EAAE,CAAC;QACpB,cAAc,CAAC,EAAE,gBAAgB,CAAC;QAClC,UAAU,EAAE,OAAO,CAAC;KACrB;mCArKqB,WAAW;CA6SpC,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,0CAIvC;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,gBAAgB,CAAC;CACnC,sBA4BA,CAAC"}
@@ -292,6 +292,7 @@ export const useSendMessage = (options) => {
292
292
  return false;
293
293
  const extendMessageInfo = generateExtendMessageInfo({
294
294
  richText,
295
+ plainText,
295
296
  currentSession,
296
297
  });
297
298
  let messageItem = Object.assign(Object.assign({}, message), { ex: JSON.stringify(extendMessageInfo) || "{}", isInternal });
@@ -306,6 +307,7 @@ export const useSendMessage = (options) => {
306
307
  setQuotedMessage,
307
308
  ]);
308
309
  const sendMergeMessage = useCallback(async ({ richText, plainText, files, currentSession, isInternal, }) => {
310
+ var _a, _b;
309
311
  if (!recvID && !groupID)
310
312
  return;
311
313
  const messageList = [];
@@ -414,6 +416,12 @@ export const useSendMessage = (options) => {
414
416
  for (const message of messageList) {
415
417
  const extendMessageInfo = generateExtendMessageInfo({
416
418
  richText: (message === null || message === void 0 ? void 0 : message.contentType) === MessageType.TextMessage ? richText : "",
419
+ plainText: (message === null || message === void 0 ? void 0 : message.contentType) === MessageType.TextMessage ||
420
+ (message === null || message === void 0 ? void 0 : message.contentType) === MessageType.UrlTextMessage
421
+ ? ((_a = message.textElem) === null || _a === void 0 ? void 0 : _a.content) ||
422
+ ((_b = message.urlTextElem) === null || _b === void 0 ? void 0 : _b.content) ||
423
+ plainText
424
+ : "",
417
425
  currentSession,
418
426
  });
419
427
  const mMessage = Object.assign(Object.assign({}, message), { ex: JSON.stringify(extendMessageInfo) || "{}", isInternal });
@@ -426,18 +434,32 @@ export const useSendMessage = (options) => {
426
434
  resendMessage,
427
435
  };
428
436
  };
429
- export const generateExtendMessageInfo = ({ richText, currentSession, }) => {
430
- return {
431
- messageInfo: {
437
+ export const generateExtendMessageInfo = ({ richText, plainText, currentSession, }) => {
438
+ const extendMessageInfo = {
439
+ sessionId: (currentSession === null || currentSession === void 0 ? void 0 : currentSession.id) || "",
440
+ applicationType: useAuthStore.getState().applicationType,
441
+ };
442
+ const trimmedRichText = richText === null || richText === void 0 ? void 0 : richText.trim();
443
+ const trimmedPlainText = plainText === null || plainText === void 0 ? void 0 : plainText.trim();
444
+ if (trimmedRichText) {
445
+ extendMessageInfo.messageInfo = {
432
446
  type: "MESSAGE_INFO",
433
447
  data: {
434
448
  type: "rich_text",
435
- content: richText || "",
449
+ content: trimmedRichText,
436
450
  },
437
- },
438
- sessionId: (currentSession === null || currentSession === void 0 ? void 0 : currentSession.id) || "",
439
- applicationType: useAuthStore.getState().applicationType,
440
- };
451
+ };
452
+ }
453
+ else if (trimmedPlainText) {
454
+ extendMessageInfo.messageInfo = {
455
+ type: "MESSAGE_INFO",
456
+ data: {
457
+ type: "plain_text",
458
+ content: trimmedPlainText,
459
+ },
460
+ };
461
+ }
462
+ return extendMessageInfo;
441
463
  };
442
464
  const createPicBaseInfoFromFile = (file) => new Promise((resolve, reject) => {
443
465
  const _URL = window.URL || window.webkitURL;
@@ -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
  };