@droppii-org/chat-sdk 0.1.29 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/svg/index.ts +1 -1
- package/dist/components/biz-inbox/BizThreadAvatar.d.ts.map +1 -1
- package/dist/components/biz-inbox/BizThreadAvatar.js +6 -1
- package/dist/components/biz-inbox/BizThreadCard.d.ts +3 -3
- package/dist/components/biz-inbox/BizThreadCard.d.ts.map +1 -1
- package/dist/components/biz-inbox/BizThreadCard.js +20 -8
- package/dist/components/biz-inbox/BizThreadList.d.ts +5 -4
- package/dist/components/biz-inbox/BizThreadList.d.ts.map +1 -1
- package/dist/components/biz-inbox/BizThreadList.js +29 -6
- package/dist/components/biz-inbox/BizThreadTitle.d.ts +2 -1
- package/dist/components/biz-inbox/BizThreadTitle.d.ts.map +1 -1
- package/dist/components/biz-inbox/BizThreadTitle.js +2 -1
- package/dist/components/biz-thread-detail/BizMessageList.d.ts.map +1 -1
- package/dist/components/biz-thread-detail/BizMessageList.js +15 -7
- package/dist/components/biz-thread-detail/BizThreadDetailHeader.d.ts.map +1 -1
- package/dist/components/biz-thread-detail/BizThreadDetailHeader.js +3 -4
- package/dist/components/biz-thread-detail/item/BizMessageItem.d.ts +2 -1
- package/dist/components/biz-thread-detail/item/BizMessageItem.d.ts.map +1 -1
- package/dist/components/biz-thread-detail/item/BizMessageItem.js +11 -5
- package/dist/components/message/MessageInfiniteScroll.d.ts +2 -1
- package/dist/components/message/MessageInfiniteScroll.d.ts.map +1 -1
- package/dist/components/message/MessageInfiniteScroll.js +2 -15
- package/dist/components/message/MessageList.d.ts.map +1 -1
- package/dist/components/message/MessageList.js +2 -2
- package/dist/hooks/biz/index.d.ts +4 -0
- package/dist/hooks/biz/index.d.ts.map +1 -1
- package/dist/hooks/biz/index.js +3 -0
- package/dist/hooks/biz/useBizActiveConversation.d.ts +3 -0
- package/dist/hooks/biz/useBizActiveConversation.d.ts.map +1 -0
- package/dist/hooks/biz/useBizActiveConversation.js +59 -0
- package/dist/hooks/biz/useBizConversationList.d.ts +3 -2
- package/dist/hooks/biz/useBizConversationList.d.ts.map +1 -1
- package/dist/hooks/biz/useBizConversationList.js +4 -1
- package/dist/hooks/biz/useBizConversationListItems.d.ts +8 -0
- package/dist/hooks/biz/useBizConversationListItems.d.ts.map +1 -0
- package/dist/hooks/biz/useBizConversationListItems.js +10 -0
- package/dist/hooks/biz/useBizGlobalEvent.d.ts +2 -0
- package/dist/hooks/biz/useBizGlobalEvent.d.ts.map +1 -0
- package/dist/hooks/biz/useBizGlobalEvent.js +44 -0
- package/dist/hooks/biz/useBizSendMessage.d.ts.map +1 -1
- package/dist/hooks/biz/useBizSendMessage.js +7 -6
- package/dist/hooks/message/useMessageListScroll.d.ts.map +1 -1
- package/dist/hooks/message/useMessageListScroll.js +10 -0
- package/dist/locales/vi/biz-inbox.json +1 -0
- package/dist/screens/biz-message/index.d.ts.map +1 -1
- package/dist/screens/biz-message/index.js +7 -28
- package/dist/store/bizConversation.d.ts +4 -0
- package/dist/store/bizConversation.d.ts.map +1 -1
- package/dist/store/bizConversation.js +9 -0
- package/dist/styles/global.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/biz.d.ts +5 -2
- package/dist/types/biz.d.ts.map +1 -1
- package/dist/types/biz.js +2 -0
- package/dist/utils/bizConversation.d.ts +3 -5
- package/dist/utils/bizConversation.d.ts.map +1 -1
- package/dist/utils/bizConversation.js +18 -40
- package/dist/utils/bizMessage.d.ts +8 -2
- package/dist/utils/bizMessage.d.ts.map +1 -1
- package/dist/utils/bizMessage.js +60 -3
- package/package.json +1 -1
package/dist/assets/svg/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./document";
|
|
2
|
-
export * from "./canned-response";
|
|
2
|
+
export * from "./canned-response";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BizThreadAvatar.d.ts","sourceRoot":"","sources":["../../../src/components/biz-inbox/BizThreadAvatar.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,eAAe,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,eAAe,GAAI,uDAKtB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"BizThreadAvatar.d.ts","sourceRoot":"","sources":["../../../src/components/biz-inbox/BizThreadAvatar.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,eAAe,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,eAAe,GAAI,uDAKtB,oBAAoB,4CAwCtB,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -4,5 +4,10 @@ import clsx from "clsx";
|
|
|
4
4
|
import { Icon } from "../../components/icon";
|
|
5
5
|
import { BizChatCategory } from "../../types/biz";
|
|
6
6
|
import { resolveBizBadgeColor } from "../../utils/bizConversation";
|
|
7
|
-
const BizThreadAvatar = ({ chatCategory, displayName, avatarUrl, badgeLabel, }) =>
|
|
7
|
+
const BizThreadAvatar = ({ chatCategory, displayName, avatarUrl, badgeLabel, }) => {
|
|
8
|
+
if (chatCategory === BizChatCategory.BIZ_BOT_CRM) {
|
|
9
|
+
return (_jsx("div", { className: "flex h-12 w-12 shrink-0 items-center justify-center rounded-xl bg-[#607CFB] p-2.5 shadow-[inset_2px_3px_8px_0_rgba(0,0,0,0.40)]", children: _jsx(Icon, { icon: "head-phone-o1", size: 28, className: "text-white" }) }));
|
|
10
|
+
}
|
|
11
|
+
return (_jsxs("div", { className: "relative h-12 w-12 shrink-0", children: [avatarUrl ? (_jsx("img", { src: avatarUrl, alt: displayName, className: "h-12 w-12 rounded-full object-cover" })) : (_jsx("div", { className: "flex h-12 w-12 items-center justify-center rounded-full bg-[#0C5CFF] text-white", children: chatCategory === BizChatCategory.GROUP ? (_jsx(Icon, { icon: "user-two-b", size: 20 })) : chatCategory === BizChatCategory.BIZ_BOT_PDP ? (_jsx(Icon, { icon: "droppii-o-1", size: 20 })) : (_jsx(Icon, { icon: "user-o", size: 20 })) })), badgeLabel && (_jsx("span", { className: clsx("absolute -bottom-px -right-px flex h-[17px] items-center justify-center gap-2 rounded-md border border-white px-1 text-[10px] font-semibold leading-3 text-white shadow-[inset_2px_6px_8px_0_rgba(0,0,0,0.40)]", resolveBizBadgeColor(chatCategory)), children: badgeLabel }))] }));
|
|
12
|
+
};
|
|
8
13
|
export default BizThreadAvatar;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BizConversationListItem } from "../../hooks/biz/useBizConversationListItems";
|
|
2
2
|
export interface BizThreadCardProps {
|
|
3
|
-
item:
|
|
4
|
-
onClick: (item:
|
|
3
|
+
item: BizConversationListItem;
|
|
4
|
+
onClick: (item: BizConversationListItem) => void;
|
|
5
5
|
}
|
|
6
6
|
declare const BizThreadCard: ({ item, onClick }: BizThreadCardProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export default BizThreadCard;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BizThreadCard.d.ts","sourceRoot":"","sources":["../../../src/components/biz-inbox/BizThreadCard.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BizThreadCard.d.ts","sourceRoot":"","sources":["../../../src/components/biz-inbox/BizThreadCard.tsx"],"names":[],"mappings":"AAIA,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;AAuBD,QAAA,MAAM,aAAa,GAAI,mBAAmB,kBAAkB,4CA+D3D,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import clsx from "clsx";
|
|
3
4
|
import { useTranslation } from "react-i18next";
|
|
5
|
+
import { useChatContext } from "../../context/ChatContext";
|
|
4
6
|
import { formatTimestamp } from "../../utils/common";
|
|
5
|
-
import {
|
|
7
|
+
import { parseBizLatestMessage } from "../../utils/bizMessage";
|
|
8
|
+
import { isBizGroupChat, resolveBizAvatarUrl, resolveBizBadgeLabel, resolveBizDisplayName, } from "../../utils/bizConversation";
|
|
6
9
|
import BizThreadAvatar from "./BizThreadAvatar";
|
|
7
10
|
import BizThreadTitle from "./BizThreadTitle";
|
|
8
11
|
const formatLatestMessageTime = (sendTime) => {
|
|
@@ -10,16 +13,25 @@ const formatLatestMessageTime = (sendTime) => {
|
|
|
10
13
|
return "";
|
|
11
14
|
return formatTimestamp(sendTime, { hasTime: true });
|
|
12
15
|
};
|
|
16
|
+
const formatUnreadCount = (count) => (count > 99 ? "99+" : count);
|
|
17
|
+
const UnreadBadge = ({ count }) => {
|
|
18
|
+
const label = String(formatUnreadCount(count));
|
|
19
|
+
const isWide = label.length > 1;
|
|
20
|
+
return (_jsx("span", { className: `inline-flex h-5 shrink-0 items-center justify-center rounded-[32px] border-2 border-white bg-[linear-gradient(93deg,#FF7D74_0%,#F04438_100%)] text-center text-[12px] font-semibold leading-[160%] text-white px-[3px] ${isWide ? "min-w-8" : "min-w-5"}`, children: label }));
|
|
21
|
+
};
|
|
13
22
|
const BizThreadCard = ({ item, onClick }) => {
|
|
23
|
+
var _a;
|
|
14
24
|
const { t } = useTranslation("biz-inbox");
|
|
15
|
-
const
|
|
25
|
+
const { t: tCommon } = useTranslation("common");
|
|
26
|
+
const { user } = useChatContext();
|
|
27
|
+
const displayName = resolveBizDisplayName(item, t);
|
|
16
28
|
const avatarUrl = resolveBizAvatarUrl(item);
|
|
17
29
|
const badgeLabel = resolveBizBadgeLabel(item.chatCategory, t);
|
|
18
|
-
const latestMessagePreview =
|
|
19
|
-
const latestMessageTime = formatLatestMessageTime(
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
const latestMessagePreview = parseBizLatestMessage(item.latestMsg, user === null || user === void 0 ? void 0 : user.userID, tCommon, isBizGroupChat(item));
|
|
31
|
+
const latestMessageTime = formatLatestMessageTime(item.latestMsgSendTime || null);
|
|
32
|
+
const unreadCount = (_a = item.unreadCount) !== null && _a !== void 0 ? _a : 0;
|
|
33
|
+
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
|
|
34
|
+
? "font-[510] text-black"
|
|
35
|
+
: "font-normal tracking-[0.14px] text-[#5C6366]"), children: latestMessagePreview }), unreadCount > 0 && _jsx(UnreadBadge, { count: unreadCount })] })] })] }));
|
|
24
36
|
};
|
|
25
37
|
export default BizThreadCard;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BizConversationListItem } from "../../hooks/biz/useBizConversationListItems";
|
|
2
2
|
export interface BizThreadListProps {
|
|
3
|
-
items:
|
|
3
|
+
items: BizConversationListItem[];
|
|
4
|
+
isLoading: boolean;
|
|
4
5
|
isFetchingNextPage: boolean;
|
|
5
6
|
hasNextPage: boolean;
|
|
6
7
|
onLoadMore: () => void;
|
|
7
|
-
onSelectThread?: (item:
|
|
8
|
+
onSelectThread?: (item: BizConversationListItem) => void;
|
|
8
9
|
}
|
|
9
|
-
declare const BizThreadList: ({ items, isFetchingNextPage, hasNextPage, onLoadMore, onSelectThread, }: BizThreadListProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
declare const BizThreadList: ({ items, isLoading, isFetchingNextPage, hasNextPage, onLoadMore, onSelectThread, }: BizThreadListProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
11
|
export default BizThreadList;
|
|
11
12
|
//# sourceMappingURL=BizThreadList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BizThreadList.d.ts","sourceRoot":"","sources":["../../../src/components/biz-inbox/BizThreadList.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BizThreadList.d.ts","sourceRoot":"","sources":["../../../src/components/biz-inbox/BizThreadList.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAMvF,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,uBAAuB,EAAE,CAAC;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,uBAAuB,KAAK,IAAI,CAAC;CAC1D;AAYD,QAAA,MAAM,aAAa,GAAI,oFAOpB,kBAAkB,4CAwGpB,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -2,27 +2,47 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
|
4
4
|
import { useTranslation } from "react-i18next";
|
|
5
|
-
import { Empty } from "antd";
|
|
5
|
+
import { Empty, Spin } from "antd";
|
|
6
6
|
import InfiniteScroll from "react-infinite-scroll-component";
|
|
7
|
+
import { DChatSDK } from "../../constants/sdk";
|
|
7
8
|
import useBizConversationStore from "../../store/bizConversation";
|
|
9
|
+
import useConversationStore from "../../store/conversation";
|
|
8
10
|
import { Icon } from "../../components/icon";
|
|
9
11
|
import BizThreadCard from "./BizThreadCard";
|
|
10
12
|
const FooterSkeleton = () => (_jsxs("div", { className: "flex items-center gap-3 p-3", children: [_jsx("div", { className: "h-10 w-10 animate-pulse rounded-full bg-neutral-200" }), _jsxs("div", { className: "flex flex-1 flex-col gap-2", children: [_jsx("div", { className: "h-3 w-1/2 animate-pulse rounded bg-neutral-200" }), _jsx("div", { className: "h-2.5 w-1/3 animate-pulse rounded bg-neutral-200" })] })] }));
|
|
11
|
-
const BizThreadList = ({ items, isFetchingNextPage, hasNextPage, onLoadMore, onSelectThread, }) => {
|
|
13
|
+
const BizThreadList = ({ items, isLoading, isFetchingNextPage, hasNextPage, onLoadMore, onSelectThread, }) => {
|
|
12
14
|
const { t } = useTranslation("biz-inbox");
|
|
13
15
|
const router = useRouter();
|
|
14
16
|
const pathname = usePathname();
|
|
15
17
|
const searchParams = useSearchParams();
|
|
18
|
+
const sdkConversations = useBizConversationStore((state) => state.sdkConversations);
|
|
16
19
|
const selectConversation = useBizConversationStore((state) => state.selectConversation);
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const setConversationData = useConversationStore((state) => state.setConversationData);
|
|
21
|
+
const setSelectedConversationId = useConversationStore((state) => state.setSelectedConversationId);
|
|
22
|
+
const syncSdkConversation = (conversationId) => {
|
|
23
|
+
const cachedConversation = sdkConversations[conversationId];
|
|
24
|
+
if (cachedConversation) {
|
|
25
|
+
setConversationData(cachedConversation);
|
|
26
|
+
setSelectedConversationId(conversationId);
|
|
21
27
|
return;
|
|
22
28
|
}
|
|
29
|
+
DChatSDK.getMultipleConversation([conversationId])
|
|
30
|
+
.then((res) => {
|
|
31
|
+
if (res.data.length > 0) {
|
|
32
|
+
setConversationData(res.data[0]);
|
|
33
|
+
setSelectedConversationId(conversationId);
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
.catch((error) => {
|
|
37
|
+
console.error("getMultipleConversation", error);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const handleSelectThread = (item) => {
|
|
23
41
|
const newSearchParams = new URLSearchParams(searchParams);
|
|
24
42
|
newSearchParams.set("threadId", item.conversationId);
|
|
25
43
|
router.push(`${pathname}?${newSearchParams.toString()}`);
|
|
44
|
+
selectConversation(item);
|
|
45
|
+
syncSdkConversation(item.conversationId);
|
|
26
46
|
onSelectThread === null || onSelectThread === void 0 ? void 0 : onSelectThread(item);
|
|
27
47
|
};
|
|
28
48
|
const handleEndReached = () => {
|
|
@@ -30,6 +50,9 @@ const BizThreadList = ({ items, isFetchingNextPage, hasNextPage, onLoadMore, onS
|
|
|
30
50
|
onLoadMore();
|
|
31
51
|
}
|
|
32
52
|
};
|
|
53
|
+
if (isLoading) {
|
|
54
|
+
return (_jsx("div", { "data-testid": "biz-inbox-thread-list", className: "flex flex-1 items-center justify-center py-12", children: _jsx(Spin, {}) }));
|
|
55
|
+
}
|
|
33
56
|
return (_jsx("div", { id: "scrollableBizThreadsDiv", "data-testid": "biz-inbox-thread-list", className: "min-h-0 w-full flex-1 overflow-auto", children: _jsx(InfiniteScroll, { dataLength: items.length, next: handleEndReached, hasMore: hasNextPage, loader: isFetchingNextPage ? _jsx(FooterSkeleton, {}) : null, scrollableTarget: "scrollableBizThreadsDiv", children: items.length === 0 ? (_jsx("div", { className: "flex items-center justify-center py-12", children: _jsx(Empty, { image: _jsx(Icon, { icon: "chat-square-b", size: 80, className: "text-gray-300" }), description: t("empty.no_conversations") }) })) : (items.map((item) => (_jsx(BizThreadCard, { item: item, onClick: handleSelectThread }, item.conversationId)))) }) }));
|
|
34
57
|
};
|
|
35
58
|
export default BizThreadList;
|
|
@@ -2,7 +2,8 @@ import { BizChatCategory } from "../../types/biz";
|
|
|
2
2
|
export interface BizThreadTitleProps {
|
|
3
3
|
chatCategory: BizChatCategory;
|
|
4
4
|
displayName: string;
|
|
5
|
+
hasUnread?: boolean;
|
|
5
6
|
}
|
|
6
|
-
declare const BizThreadTitle: ({ chatCategory, displayName }: BizThreadTitleProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
declare const BizThreadTitle: ({ chatCategory, displayName, hasUnread, }: BizThreadTitleProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export default BizThreadTitle;
|
|
8
9
|
//# sourceMappingURL=BizThreadTitle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BizThreadTitle.d.ts","sourceRoot":"","sources":["../../../src/components/biz-inbox/BizThreadTitle.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BizThreadTitle.d.ts","sourceRoot":"","sources":["../../../src/components/biz-inbox/BizThreadTitle.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,eAAe,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,QAAA,MAAM,cAAc,GAAI,2CAIrB,mBAAmB,4CAwBrB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import clsx from "clsx";
|
|
3
4
|
import { Icon } from "../../components/icon";
|
|
4
5
|
import { BizChatCategory } from "../../types/biz";
|
|
5
|
-
const BizThreadTitle = ({ chatCategory, displayName }) => (_jsxs("div", { className: "flex min-w-0 items-center gap-1", children: [chatCategory === BizChatCategory.GROUP && (_jsx(Icon, { icon: "user-two-b", size: 12, className: "shrink-0 text-black" })), chatCategory === BizChatCategory.BIZ_BOT_PDP && (_jsx("span", { className: "flex h-4 w-4 shrink-0 items-center justify-center gap-0.5 rounded-full border border-white bg-[linear-gradient(93deg,#607CFB_0%,#1B3FE4_100%)] px-1 py-0.5 text-white", children: _jsx(Icon, { icon: "shield-done-b", size: 8 }) })), _jsx("span", { className: "truncate text-[16px]
|
|
6
|
+
const BizThreadTitle = ({ chatCategory, displayName, hasUnread = false, }) => (_jsxs("div", { className: "flex min-w-0 items-center gap-1", children: [chatCategory === BizChatCategory.GROUP && (_jsx(Icon, { icon: "user-two-b", size: 12, className: "shrink-0 text-black" })), chatCategory === BizChatCategory.BIZ_BOT_PDP && (_jsx("span", { className: "flex h-4 w-4 shrink-0 items-center justify-center gap-0.5 rounded-full border border-white bg-[linear-gradient(93deg,#607CFB_0%,#1B3FE4_100%)] px-1 py-0.5 text-white", children: _jsx(Icon, { icon: "shield-done-b", size: 8 }) })), chatCategory === BizChatCategory.BIZ_BOT_CRM && (_jsx("span", { className: "flex h-4 w-4 shrink-0 items-center justify-center rounded-full bg-black text-white", children: _jsx(Icon, { icon: "droppii-o-1", size: 8 }) })), _jsx("span", { className: clsx("min-w-0 truncate text-[16px] leading-[160%] text-black [font-feature-settings:'liga'_off,'clig'_off]", hasUnread ? "font-bold tracking-[0.16px]" : "font-[510]"), children: displayName })] }));
|
|
6
7
|
export default BizThreadTitle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BizMessageList.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizMessageList.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BizMessageList.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizMessageList.tsx"],"names":[],"mappings":"AAgBA,QAAA,MAAM,cAAc,+CA8EnB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect } from "react";
|
|
4
4
|
import { Empty, Spin } from "antd";
|
|
5
5
|
import { useTranslation } from "react-i18next";
|
|
@@ -8,21 +8,29 @@ import MessageInfiniteScroll from "../../components/message/MessageInfiniteScrol
|
|
|
8
8
|
import { useMessage } from "../../hooks/message/useMessage";
|
|
9
9
|
import { useMessageListScroll } from "../../hooks/message/useMessageListScroll";
|
|
10
10
|
import useBizConversationStore from "../../store/bizConversation";
|
|
11
|
+
import useConversationStore from "../../store/conversation";
|
|
12
|
+
import { ConnectStatus, SyncStatus } from "../../types/chat";
|
|
13
|
+
import { isBizGroupChat } from "../../utils/bizConversation";
|
|
11
14
|
import emitter from "../../utils/events";
|
|
12
15
|
import BizMessageItem from "./item/BizMessageItem";
|
|
13
16
|
const BizMessageList = () => {
|
|
14
17
|
const { t } = useTranslation("biz-inbox");
|
|
15
|
-
const { user } = useChatContext();
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
18
|
+
const { user, connectStatus, syncStatus } = useChatContext();
|
|
19
|
+
const conversation = useBizConversationStore((state) => state.conversationData);
|
|
20
|
+
const selectedConversationId = useConversationStore((state) => state.selectedConversationId);
|
|
21
|
+
const isGroupChat = conversation ? isBizGroupChat(conversation) : false;
|
|
22
|
+
const isSdkReady = connectStatus === ConnectStatus.Connected &&
|
|
23
|
+
syncStatus !== SyncStatus.Loading;
|
|
24
|
+
const messageController = useMessage(selectedConversationId, undefined, isSdkReady && !!selectedConversationId);
|
|
25
|
+
const { scrollRef, loadMoreOldMessage, handleInfiniteScroll, scrollToBottomIfAtBottom, } = useMessageListScroll(Object.assign({ conversationId: selectedConversationId, userId: user === null || user === void 0 ? void 0 : user.userID }, messageController));
|
|
26
|
+
const { loadState, moreOldLoading } = messageController;
|
|
27
|
+
const isMessageLoading = !isSdkReady || !selectedConversationId || loadState.initLoading;
|
|
20
28
|
useEffect(() => {
|
|
21
29
|
emitter.on("BIZ_CHAT_SCROLL_TO_BOTTOM_IF_AT_BOTTOM", scrollToBottomIfAtBottom);
|
|
22
30
|
return () => {
|
|
23
31
|
emitter.off("BIZ_CHAT_SCROLL_TO_BOTTOM_IF_AT_BOTTOM", scrollToBottomIfAtBottom);
|
|
24
32
|
};
|
|
25
33
|
}, [scrollToBottomIfAtBottom]);
|
|
26
|
-
return (
|
|
34
|
+
return (_jsx("div", { "data-testid": "biz-message-list", className: "relative flex min-h-0 min-w-0 flex-1 flex-col overflow-x-hidden bg-white", children: isMessageLoading ? (_jsx("div", { className: "flex flex-1 items-center justify-center py-12", children: _jsx(Spin, {}) })) : (_jsx(MessageInfiniteScroll, { scrollRef: scrollRef, scrollableTargetId: "scrollableBizMessagesDiv", loadState: loadState, moreOldLoading: moreOldLoading, onLoadMoreOld: loadMoreOldMessage, onScroll: handleInfiniteScroll, containerClassName: "h-full", empty: _jsx("div", { className: "flex flex-1 items-center justify-center py-12", children: _jsx(Empty, { description: t("empty.no_messages") }) }), children: loadState.messageList.map((message, _, array) => (_jsx(BizMessageItem, { message: message, allMessages: array, isGroupChat: isGroupChat }, message.clientMsgID))) })) }));
|
|
27
35
|
};
|
|
28
36
|
export default BizMessageList;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BizThreadDetailHeader.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizThreadDetailHeader.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"BizThreadDetailHeader.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizThreadDetailHeader.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAOvD,MAAM,WAAW,0BAA0B;IACzC,YAAY,EAAE,mBAAmB,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAqBD,QAAA,MAAM,qBAAqB,GAAI,2BAG5B,0BAA0B,4CA0C5B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
@@ -4,15 +4,14 @@ import { useTranslation } from "react-i18next";
|
|
|
4
4
|
import { Icon } from "../../components/icon";
|
|
5
5
|
import BizThreadAvatar from "../../components/biz-inbox/BizThreadAvatar";
|
|
6
6
|
import BizThreadTitle from "../../components/biz-inbox/BizThreadTitle";
|
|
7
|
-
import {
|
|
7
|
+
import { resolveBizAvatarUrl, resolveBizBadgeLabel, resolveBizDisplayName, } from "../../utils/bizConversation";
|
|
8
8
|
const HeaderIconButton = ({ icon, onClick, testId, }) => (_jsx("button", { type: "button", onClick: onClick, "data-testid": testId, className: "flex shrink-0 cursor-pointer items-center justify-center p-2 text-[#1B3FE4]", children: _jsx(Icon, { icon: icon, size: 24 }) }));
|
|
9
9
|
const BizThreadDetailHeader = ({ conversation, onBack, }) => {
|
|
10
10
|
const { t } = useTranslation("biz-inbox");
|
|
11
|
-
const
|
|
12
|
-
const displayName = resolveBizDisplayName(conversation, t("thread_card.fallback_name"));
|
|
11
|
+
const displayName = resolveBizDisplayName(conversation, t);
|
|
13
12
|
const avatarUrl = resolveBizAvatarUrl(conversation);
|
|
14
13
|
const badgeLabel = resolveBizBadgeLabel(conversation.chatCategory, t);
|
|
15
|
-
const subtitle =
|
|
14
|
+
const subtitle = t("thread_detail.profile_hint");
|
|
16
15
|
return (_jsxs("div", { "data-testid": "biz-thread-detail-header", className: "flex w-full cursor-default items-center border-b border-[#EFEFEF] bg-white p-2 shadow-[inset_0px_-1px_0px_0px_rgba(61,63,64,0.1)]", children: [_jsx(HeaderIconButton, { icon: "arrow-left-o", onClick: onBack, testId: "biz-thread-detail-back" }), _jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-2 px-1", "data-testid": "biz-thread-detail-profile", children: [_jsx(BizThreadAvatar, { chatCategory: conversation.chatCategory, displayName: displayName, avatarUrl: avatarUrl, badgeLabel: badgeLabel }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx(BizThreadTitle, { chatCategory: conversation.chatCategory, displayName: displayName }), _jsx("p", { className: "truncate text-[10px] font-normal leading-[160%] tracking-[0.1px] text-[#5C6366] [font-feature-settings:'liga'_off,'clig'_off]", children: subtitle })] })] })] }));
|
|
17
16
|
};
|
|
18
17
|
export default BizThreadDetailHeader;
|
|
@@ -2,7 +2,8 @@ import { MessageItem } from "@openim/wasm-client-sdk";
|
|
|
2
2
|
export interface BizMessageItemProps {
|
|
3
3
|
message: MessageItem;
|
|
4
4
|
allMessages: MessageItem[];
|
|
5
|
+
isGroupChat?: boolean;
|
|
5
6
|
}
|
|
6
|
-
declare const BizMessageItem: ({ message, allMessages }: BizMessageItemProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
7
|
+
declare const BizMessageItem: ({ message, allMessages, isGroupChat, }: BizMessageItemProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
7
8
|
export default BizMessageItem;
|
|
8
9
|
//# sourceMappingURL=BizMessageItem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BizMessageItem.d.ts","sourceRoot":"","sources":["../../../../src/components/biz-thread-detail/item/BizMessageItem.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"BizMessageItem.d.ts","sourceRoot":"","sources":["../../../../src/components/biz-thread-detail/item/BizMessageItem.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAQtD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,WAAW,CAAC;IACrB,WAAW,EAAE,WAAW,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAyBD,QAAA,MAAM,cAAc,GAAI,wCAIrB,mBAAmB,mDA0DrB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -2,18 +2,24 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Icon } from "../../../components/icon";
|
|
4
4
|
import useAuthStore from "../../../store/auth";
|
|
5
|
+
import { visibleTypeMessage } from "../../../hooks/message/useMessage";
|
|
5
6
|
import { formatTimestamp } from "../../../utils/common";
|
|
6
|
-
import { getBizMessageDisplay } from "../../../utils/bizMessage";
|
|
7
|
+
import { getBizMessageDisplay, shouldHideBizMessage } from "../../../utils/bizMessage";
|
|
7
8
|
import BizMessageBubble from "../BizMessageBubble";
|
|
8
|
-
const BizMessageAvatar = ({ avatarUrl }) =>
|
|
9
|
+
const BizMessageAvatar = ({ avatarUrl }) => avatarUrl ? (_jsx("img", { src: avatarUrl, alt: "", className: "h-6 w-6 shrink-0 self-end rounded-full object-cover" })) : (_jsx("div", { className: "flex h-6 w-6 shrink-0 items-center justify-center self-end rounded-full bg-[#0C5CFF]", children: _jsx(Icon, { icon: "droppii-o-1", size: 14, className: "text-white" }) }));
|
|
9
10
|
const BizMessageTime = ({ sendTime }) => (_jsx("div", { className: "flex w-full items-center px-4 py-1", children: _jsx("div", { className: "flex min-w-0 flex-1 flex-col items-start", children: _jsx("p", { className: "w-full break-words text-center text-[12px] font-normal leading-[160%] tracking-normal text-[#747B7E]", children: formatTimestamp(sendTime, { hasTime: true }) }) }) }));
|
|
10
|
-
const BizMessageItem = ({ message, allMessages }) => {
|
|
11
|
+
const BizMessageItem = ({ message, allMessages, isGroupChat = false, }) => {
|
|
11
12
|
const userID = useAuthStore((state) => state.userID);
|
|
12
13
|
if (!userID)
|
|
13
14
|
return null;
|
|
14
|
-
|
|
15
|
+
if (shouldHideBizMessage(message) ||
|
|
16
|
+
!visibleTypeMessage.includes(message.contentType)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const display = getBizMessageDisplay(message, allMessages, userID, isGroupChat);
|
|
15
20
|
if (!display.isMine) {
|
|
16
|
-
return (_jsxs("div", { className: "flex w-full flex-col pb-1", "data-testid": "biz-message-item", children: [display.showTimeBreak && _jsx(BizMessageTime, { sendTime: display.sendTime }), _jsxs("div", { className: "flex w-full items-end pl-3 pr-12", children: [
|
|
21
|
+
return (_jsxs("div", { className: "flex w-full flex-col pb-1", "data-testid": "biz-message-item", children: [display.showTimeBreak && _jsx(BizMessageTime, { sendTime: display.sendTime }), _jsxs("div", { className: "flex w-full items-end gap-1 pl-3 pr-12", children: [isGroupChat &&
|
|
22
|
+
(display.showAvatar ? (_jsx(BizMessageAvatar, { avatarUrl: display.senderFaceUrl })) : (_jsx("div", { className: "h-6 w-6 shrink-0 self-end" }))), _jsx("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: _jsx(BizMessageBubble, { isMine: display.isMine, content: display.content, senderName: display.senderName, showSenderName: display.showSenderName, showTip: display.showTip }) })] })] }));
|
|
17
23
|
}
|
|
18
24
|
return (_jsxs("div", { className: "flex w-full flex-col pb-1", "data-testid": "biz-message-item", children: [display.showTimeBreak && _jsx(BizMessageTime, { sendTime: display.sendTime }), _jsx("div", { className: "flex w-full justify-end pl-12 pr-3", children: _jsx("div", { className: "flex min-w-0 max-w-[calc(100%-48px)] flex-col items-end gap-1", children: _jsx(BizMessageBubble, { isMine: display.isMine, content: display.content, showTip: display.showTip }) }) })] }));
|
|
19
25
|
};
|
|
@@ -4,12 +4,13 @@ export interface MessageInfiniteScrollProps {
|
|
|
4
4
|
scrollRef: Ref<HTMLDivElement>;
|
|
5
5
|
scrollableTargetId: string;
|
|
6
6
|
loadState: MessageListLoadState;
|
|
7
|
+
moreOldLoading?: boolean;
|
|
7
8
|
onLoadMoreOld: () => void;
|
|
8
9
|
onScroll: (e: React.UIEvent<HTMLDivElement>) => void;
|
|
9
10
|
children: ReactNode;
|
|
10
11
|
empty?: ReactNode;
|
|
11
12
|
containerClassName?: string;
|
|
12
13
|
}
|
|
13
|
-
declare const MessageInfiniteScroll: ({ scrollRef, scrollableTargetId, loadState, onLoadMoreOld, onScroll, children, empty, containerClassName, }: MessageInfiniteScrollProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
declare const MessageInfiniteScroll: ({ scrollRef, scrollableTargetId, loadState, moreOldLoading, onLoadMoreOld, onScroll, children, empty, containerClassName, }: MessageInfiniteScrollProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
15
|
export default MessageInfiniteScroll;
|
|
15
16
|
//# sourceMappingURL=MessageInfiniteScroll.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageInfiniteScroll.d.ts","sourceRoot":"","sources":["../../../src/components/message/MessageInfiniteScroll.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"MessageInfiniteScroll.d.ts","sourceRoot":"","sources":["../../../src/components/message/MessageInfiniteScroll.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAIvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAEjF,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;IAC/B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,oBAAoB,CAAC;IAChC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,QAAQ,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;IACrD,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,QAAA,MAAM,qBAAqB,GAAI,6HAU5B,0BAA0B,4CAoC5B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { Spin } from "antd";
|
|
4
|
+
import clsx from "clsx";
|
|
4
5
|
import InfiniteScroll from "react-infinite-scroll-component";
|
|
5
|
-
const
|
|
6
|
-
height: "100%",
|
|
7
|
-
overflowY: "auto",
|
|
8
|
-
overflowX: "hidden",
|
|
9
|
-
display: "flex",
|
|
10
|
-
flexDirection: "column-reverse",
|
|
11
|
-
paddingBottom: 12,
|
|
12
|
-
};
|
|
13
|
-
const infiniteScrollStyle = {
|
|
14
|
-
display: "flex",
|
|
15
|
-
flexDirection: "column-reverse",
|
|
16
|
-
minWidth: 0,
|
|
17
|
-
width: "100%",
|
|
18
|
-
};
|
|
19
|
-
const MessageInfiniteScroll = ({ scrollRef, scrollableTargetId, loadState, onLoadMoreOld, onScroll, children, empty, containerClassName, }) => (_jsx("div", { id: scrollableTargetId, ref: scrollRef, className: containerClassName, style: scrollContainerStyle, children: empty && loadState.messageList.length === 0 ? (empty) : (_jsx(InfiniteScroll, { dataLength: loadState.messageList.length, next: onLoadMoreOld, style: infiniteScrollStyle, inverse: true, hasMore: loadState.hasMoreOld, loader: _jsx("div", { className: "flex items-center justify-center py-2", children: _jsx(Spin, {}) }), scrollableTarget: scrollableTargetId, onScroll: (e) => onScroll(e), children: children })) }));
|
|
6
|
+
const MessageInfiniteScroll = ({ scrollRef, scrollableTargetId, loadState, moreOldLoading = false, onLoadMoreOld, onScroll, children, empty, containerClassName, }) => (_jsx("div", { id: scrollableTargetId, ref: scrollRef, className: clsx("flex h-full flex-col-reverse overflow-x-hidden overflow-y-auto pb-3", containerClassName), children: empty && loadState.messageList.length === 0 ? (empty) : (_jsx(InfiniteScroll, { dataLength: loadState.messageList.length, next: onLoadMoreOld, className: "flex w-full min-w-0 flex-col-reverse", inverse: true, hasMore: loadState.hasMoreOld, loader: moreOldLoading ? (_jsx("div", { className: "flex w-full items-center justify-center py-2", children: _jsx(Spin, { size: "small" }) })) : (_jsx("span", { className: "sr-only" })), scrollableTarget: scrollableTargetId, onScroll: (e) => onScroll(e), children: children })) }));
|
|
20
7
|
export default MessageInfiniteScroll;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageList.d.ts","sourceRoot":"","sources":["../../../src/components/message/MessageList.tsx"],"names":[],"mappings":"AA2BA,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,qBAAqB,CAAC,EAAE,MAAM,IAAI,CAAC;CACpC;AAED,QAAA,MAAM,WAAW,GAAI,OAAO,gBAAgB,
|
|
1
|
+
{"version":3,"file":"MessageList.d.ts","sourceRoot":"","sources":["../../../src/components/message/MessageList.tsx"],"names":[],"mappings":"AA2BA,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,qBAAqB,CAAC,EAAE,MAAM,IAAI,CAAC;CACpC;AAED,QAAA,MAAM,WAAW,GAAI,OAAO,gBAAgB,4CAqQ3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -49,7 +49,7 @@ const MessageList = (props) => {
|
|
|
49
49
|
restrictToLastSession: shouldRestrictToLastSession,
|
|
50
50
|
customerUserID,
|
|
51
51
|
});
|
|
52
|
-
const { loadState, moreNewLoading } = messageController;
|
|
52
|
+
const { loadState, moreOldLoading, moreNewLoading } = messageController;
|
|
53
53
|
const { scrollRef, loadMoreOldMessage, handleInfiniteScroll, scrollToBottom } = useMessageListScroll(Object.assign({ conversationId, userId: user === null || user === void 0 ? void 0 : user.userID }, messageController));
|
|
54
54
|
const handleOpenRevoke = useCallback((clientMsgID) => {
|
|
55
55
|
setSelectedItem(clientMsgID);
|
|
@@ -135,6 +135,6 @@ const MessageList = (props) => {
|
|
|
135
135
|
backgroundSize: "cover",
|
|
136
136
|
backgroundPosition: "center",
|
|
137
137
|
overflowX: "hidden",
|
|
138
|
-
}, children: [_jsx(MessageHeader, { onClose: onClose, currentSession: latestConversationSession, isJoined: isJoined }), _jsx(MessageInfiniteScroll, { scrollRef: scrollRef, scrollableTargetId: "scrollableMessagesDiv", loadState: loadState, onLoadMoreOld: loadMoreOldMessage, onScroll: handleInfiniteScroll, children: loadState.messageList.map((message, _, array) => (_jsx(MessageItem, { message: message, allMessages: array, contextMenuOpen: openMenuId === message.clientMsgID, onContextMenuOpenChange: (open) => setOpenMenuId(open ? message.clientMsgID : null), onRevokeMessage: handleOpenRevoke, onQuoteMessage: setQuotedMessage, onPressQuoteMessage: onPressQuoteMessage }, message.clientMsgID))) }), moreNewLoading && (_jsx("div", { className: "flex items-center justify-center py-2", children: _jsx(Spin, {}) })), isCheckingMembership ? (_jsx("div", { className: "border-t bg-white py-4 flex items-center justify-center", children: _jsx(Spin, {}) })) : (latestConversationSession === null || latestConversationSession === void 0 ? void 0 : latestConversationSession.status) === SessionStatus.UNASSIGNED ? (_jsx(UnassignedSessionFooter, { sessionId: latestConversationSession.id, teamId: latestConversationSession.teamId })) : shouldRestrictToLastSession ? (_jsxs("div", { className: "border-t bg-white py-4 flex flex-col items-center gap-2", children: [_jsx("p", { className: "text-sm text-gray-500", children: t("join_group_required") }), _jsx(Button, { type: "primary", onClick: joinGroup, loading: isJoining, children: t("join_group") })] })) : (_jsx(MessageFooter, { currentSession: latestConversationSession, openCreateCannedModal: openCreateCannedModal })), _jsx(Modal, { centered: true, open: showConfirmRevoke, onOk: onRevokeMessage, onCancel: handleCloseRevoke, title: t("revoke_message_confirm_title"), okText: t("revoke"), cancelText: t("cancel"), okType: "danger", confirmLoading: isRevoking, getContainer: false, forceRender: true, children: _jsx("p", { children: t("revoke_message_confirm_message") }) })] }));
|
|
138
|
+
}, children: [_jsx(MessageHeader, { onClose: onClose, currentSession: latestConversationSession, isJoined: isJoined }), _jsx(MessageInfiniteScroll, { scrollRef: scrollRef, scrollableTargetId: "scrollableMessagesDiv", loadState: loadState, moreOldLoading: moreOldLoading, onLoadMoreOld: loadMoreOldMessage, onScroll: handleInfiniteScroll, children: loadState.messageList.map((message, _, array) => (_jsx(MessageItem, { message: message, allMessages: array, contextMenuOpen: openMenuId === message.clientMsgID, onContextMenuOpenChange: (open) => setOpenMenuId(open ? message.clientMsgID : null), onRevokeMessage: handleOpenRevoke, onQuoteMessage: setQuotedMessage, onPressQuoteMessage: onPressQuoteMessage }, message.clientMsgID))) }), moreNewLoading && (_jsx("div", { className: "flex items-center justify-center py-2", children: _jsx(Spin, {}) })), isCheckingMembership ? (_jsx("div", { className: "border-t bg-white py-4 flex items-center justify-center", children: _jsx(Spin, {}) })) : (latestConversationSession === null || latestConversationSession === void 0 ? void 0 : latestConversationSession.status) === SessionStatus.UNASSIGNED ? (_jsx(UnassignedSessionFooter, { sessionId: latestConversationSession.id, teamId: latestConversationSession.teamId })) : shouldRestrictToLastSession ? (_jsxs("div", { className: "border-t bg-white py-4 flex flex-col items-center gap-2", children: [_jsx("p", { className: "text-sm text-gray-500", children: t("join_group_required") }), _jsx(Button, { type: "primary", onClick: joinGroup, loading: isJoining, children: t("join_group") })] })) : (_jsx(MessageFooter, { currentSession: latestConversationSession, openCreateCannedModal: openCreateCannedModal })), _jsx(Modal, { centered: true, open: showConfirmRevoke, onOk: onRevokeMessage, onCancel: handleCloseRevoke, title: t("revoke_message_confirm_title"), okText: t("revoke"), cancelText: t("cancel"), okType: "danger", confirmLoading: isRevoking, getContainer: false, forceRender: true, children: _jsx("p", { children: t("revoke_message_confirm_message") }) })] }));
|
|
139
139
|
};
|
|
140
140
|
export default MessageList;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export { useBizConversationList } from "./useBizConversationList";
|
|
2
|
+
export { useBizConversationListItems } from "./useBizConversationListItems";
|
|
2
3
|
export { useCreateBizConversation } from "./useCreateBizConversation";
|
|
3
4
|
export { useBizSendMessage } from "./useBizSendMessage";
|
|
5
|
+
export { useBizGlobalEvent } from "./useBizGlobalEvent";
|
|
6
|
+
export { useBizActiveConversation } from "./useBizActiveConversation";
|
|
7
|
+
export type { BizConversationListItem } from "./useBizConversationListItems";
|
|
4
8
|
export type { CreateBizConversationInput } from "./useCreateBizConversation";
|
|
5
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/biz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/biz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,YAAY,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAC7E,YAAY,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/hooks/biz/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { useBizConversationList } from "./useBizConversationList";
|
|
2
|
+
export { useBizConversationListItems } from "./useBizConversationListItems";
|
|
2
3
|
export { useCreateBizConversation } from "./useCreateBizConversation";
|
|
3
4
|
export { useBizSendMessage } from "./useBizSendMessage";
|
|
5
|
+
export { useBizGlobalEvent } from "./useBizGlobalEvent";
|
|
6
|
+
export { useBizActiveConversation } from "./useBizActiveConversation";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBizActiveConversation.d.ts","sourceRoot":"","sources":["../../../src/hooks/biz/useBizActiveConversation.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAE7E,eAAO,MAAM,wBAAwB,GACnC,mBAAmB,uBAAuB,EAAE,SAwE7C,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useSearchParams } from "next/navigation";
|
|
3
|
+
import { DChatSDK } from "../../constants/sdk";
|
|
4
|
+
import { useChatContext } from "../../context/ChatContext";
|
|
5
|
+
import { ConnectStatus } from "../../types/chat";
|
|
6
|
+
import useBizConversationStore from "../../store/bizConversation";
|
|
7
|
+
import useConversationStore from "../../store/conversation";
|
|
8
|
+
export const useBizActiveConversation = (conversationItems) => {
|
|
9
|
+
const searchParams = useSearchParams();
|
|
10
|
+
const threadId = searchParams.get("threadId");
|
|
11
|
+
const { connectStatus } = useChatContext();
|
|
12
|
+
const sdkConversations = useBizConversationStore((state) => state.sdkConversations);
|
|
13
|
+
const selectConversation = useBizConversationStore((state) => state.selectConversation);
|
|
14
|
+
const clearBizConversation = useBizConversationStore((state) => state.clearSelectedConversation);
|
|
15
|
+
const setSelectedConversationId = useConversationStore((state) => state.setSelectedConversationId);
|
|
16
|
+
const setConversationData = useConversationStore((state) => state.setConversationData);
|
|
17
|
+
const clearSdkConversation = useConversationStore((state) => state.clearSelectedConversation);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!threadId) {
|
|
20
|
+
clearBizConversation();
|
|
21
|
+
clearSdkConversation();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
setSelectedConversationId(threadId);
|
|
25
|
+
const currentBizData = useBizConversationStore.getState().conversationData;
|
|
26
|
+
if ((currentBizData === null || currentBizData === void 0 ? void 0 : currentBizData.conversationId) !== threadId) {
|
|
27
|
+
const matchedThread = conversationItems.find((item) => item.conversationId === threadId);
|
|
28
|
+
if (matchedThread) {
|
|
29
|
+
selectConversation(matchedThread);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (connectStatus !== ConnectStatus.Connected)
|
|
33
|
+
return;
|
|
34
|
+
const cachedConversation = sdkConversations[threadId];
|
|
35
|
+
if (cachedConversation) {
|
|
36
|
+
setConversationData(cachedConversation);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
DChatSDK.getMultipleConversation([threadId])
|
|
40
|
+
.then((res) => {
|
|
41
|
+
if (res.data.length > 0) {
|
|
42
|
+
setConversationData(res.data[0]);
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
.catch((error) => {
|
|
46
|
+
console.error("getMultipleConversation", error);
|
|
47
|
+
});
|
|
48
|
+
}, [
|
|
49
|
+
threadId,
|
|
50
|
+
conversationItems,
|
|
51
|
+
sdkConversations,
|
|
52
|
+
connectStatus,
|
|
53
|
+
selectConversation,
|
|
54
|
+
clearBizConversation,
|
|
55
|
+
clearSdkConversation,
|
|
56
|
+
setSelectedConversationId,
|
|
57
|
+
setConversationData,
|
|
58
|
+
]);
|
|
59
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type BizConversationListItem } from "./useBizConversationListItems";
|
|
2
2
|
interface UseBizConversationListParams {
|
|
3
3
|
enabled: boolean;
|
|
4
4
|
pageSize?: number;
|
|
5
5
|
}
|
|
6
6
|
interface UseBizConversationListResult {
|
|
7
|
-
items:
|
|
7
|
+
items: BizConversationListItem[];
|
|
8
|
+
isLoading: boolean;
|
|
8
9
|
isFetchingNextPage: boolean;
|
|
9
10
|
hasNextPage: boolean;
|
|
10
11
|
fetchNextPage: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBizConversationList.d.ts","sourceRoot":"","sources":["../../../src/hooks/biz/useBizConversationList.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useBizConversationList.d.ts","sourceRoot":"","sources":["../../../src/hooks/biz/useBizConversationList.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,+BAA+B,CAAC;AAEvC,UAAU,4BAA4B;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,4BAA4B;IACpC,KAAK,EAAE,uBAAuB,EAAE,CAAC;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,eAAO,MAAM,sBAAsB,GACjC,QAAQ,4BAA4B,KACnC,4BA+CF,CAAC"}
|
|
@@ -5,6 +5,7 @@ import { ENDPOINTS } from "../../services/routes";
|
|
|
5
5
|
import { QUERY_KEYS } from "../../services/query";
|
|
6
6
|
import { PAGE_SIZE } from "../../constants";
|
|
7
7
|
import { DChatApplicationType } from "../../types/chat";
|
|
8
|
+
import { useBizConversationListItems, } from "./useBizConversationListItems";
|
|
8
9
|
export const useBizConversationList = (params) => {
|
|
9
10
|
var _a, _b, _c;
|
|
10
11
|
const applicationType = useAuthStore((state) => state.applicationType);
|
|
@@ -33,9 +34,11 @@ export const useBizConversationList = (params) => {
|
|
|
33
34
|
return pageNumber + 1;
|
|
34
35
|
},
|
|
35
36
|
});
|
|
36
|
-
const
|
|
37
|
+
const apiItems = ((_c = (_b = query.data) === null || _b === void 0 ? void 0 : _b.pages) !== null && _c !== void 0 ? _c : []).flatMap((page) => page.data);
|
|
38
|
+
const items = useBizConversationListItems(apiItems);
|
|
37
39
|
return {
|
|
38
40
|
items,
|
|
41
|
+
isLoading: query.isLoading,
|
|
39
42
|
isFetchingNextPage: query.isFetchingNextPage,
|
|
40
43
|
hasNextPage: !!query.hasNextPage,
|
|
41
44
|
fetchNextPage: () => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BizConversationItem } from "../../types/biz";
|
|
2
|
+
export interface BizConversationListItem extends BizConversationItem {
|
|
3
|
+
latestMsg: string;
|
|
4
|
+
unreadCount: number;
|
|
5
|
+
latestMsgSendTime: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const useBizConversationListItems: (apiItems: BizConversationItem[]) => BizConversationListItem[];
|
|
8
|
+
//# sourceMappingURL=useBizConversationListItems.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBizConversationListItems.d.ts","sourceRoot":"","sources":["../../../src/hooks/biz/useBizConversationListItems.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,2BAA2B,GACtC,UAAU,mBAAmB,EAAE,KAC9B,uBAAuB,EAmBzB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import useBizConversationStore from "../../store/bizConversation";
|
|
3
|
+
export const useBizConversationListItems = (apiItems) => {
|
|
4
|
+
const sdkConversations = useBizConversationStore((state) => state.sdkConversations);
|
|
5
|
+
return useMemo(() => apiItems.map((item) => {
|
|
6
|
+
var _a, _b, _c;
|
|
7
|
+
const sdkConversation = sdkConversations[item.conversationId];
|
|
8
|
+
return Object.assign(Object.assign({}, item), { latestMsg: (_a = sdkConversation === null || sdkConversation === void 0 ? void 0 : sdkConversation.latestMsg) !== null && _a !== void 0 ? _a : "", unreadCount: (_b = sdkConversation === null || sdkConversation === void 0 ? void 0 : sdkConversation.unreadCount) !== null && _b !== void 0 ? _b : 0, latestMsgSendTime: (_c = sdkConversation === null || sdkConversation === void 0 ? void 0 : sdkConversation.latestMsgSendTime) !== null && _c !== void 0 ? _c : 0 });
|
|
9
|
+
}), [apiItems, sdkConversations]);
|
|
10
|
+
};
|