@droppii-org/chat-sdk 0.1.55 → 0.1.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/biz-inbox/BizThreadAvatar.d.ts +3 -3
- package/dist/components/biz-inbox/BizThreadAvatar.d.ts.map +1 -1
- package/dist/components/biz-inbox/BizThreadAvatar.js +5 -5
- 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 +7 -8
- package/dist/components/biz-inbox/BizThreadList.d.ts +3 -3
- package/dist/components/biz-inbox/BizThreadList.d.ts.map +1 -1
- package/dist/components/biz-inbox/BizThreadList.js +4 -8
- package/dist/components/biz-inbox/BizThreadTitle.d.ts +3 -3
- package/dist/components/biz-inbox/BizThreadTitle.d.ts.map +1 -1
- package/dist/components/biz-inbox/BizThreadTitle.js +5 -5
- package/dist/components/biz-thread-detail/BizMessageList.d.ts.map +1 -1
- package/dist/components/biz-thread-detail/BizMessageList.js +4 -5
- package/dist/components/biz-thread-detail/BizThreadDetailHeader.d.ts +2 -2
- package/dist/components/biz-thread-detail/BizThreadDetailHeader.d.ts.map +1 -1
- package/dist/components/biz-thread-detail/BizThreadDetailHeader.js +7 -5
- package/dist/components/biz-thread-detail/BizThreadDetailInput.d.ts.map +1 -1
- package/dist/components/biz-thread-detail/BizThreadDetailInput.js +8 -13
- package/dist/components/biz-thread-detail/bot/BotButtonMessage.d.ts +1 -1
- package/dist/components/biz-thread-detail/bot/BotButtonMessage.d.ts.map +1 -1
- package/dist/components/conversation-detail/ConversationDetailHeader.d.ts +8 -0
- package/dist/components/conversation-detail/ConversationDetailHeader.d.ts.map +1 -0
- package/dist/components/conversation-detail/ConversationDetailHeader.js +18 -0
- package/dist/components/conversation-detail/ConversationDetailInput.d.ts +8 -0
- package/dist/components/conversation-detail/ConversationDetailInput.d.ts.map +1 -0
- package/dist/components/conversation-detail/ConversationDetailInput.js +258 -0
- package/dist/components/conversation-detail/ConversationMessageList.d.ts +7 -0
- package/dist/components/conversation-detail/ConversationMessageList.d.ts.map +1 -0
- package/dist/components/conversation-detail/ConversationMessageList.js +35 -0
- package/dist/components/conversation-detail/ConversationMoreOptionItem.d.ts +8 -0
- package/dist/components/conversation-detail/ConversationMoreOptionItem.d.ts.map +1 -0
- package/dist/components/conversation-detail/ConversationMoreOptionItem.js +19 -0
- package/dist/components/conversation-detail/ConversationMoreOptionPanel.d.ts +10 -0
- package/dist/components/conversation-detail/ConversationMoreOptionPanel.d.ts.map +1 -0
- package/dist/components/conversation-detail/ConversationMoreOptionPanel.js +20 -0
- package/dist/components/conversation-detail/bot/BotButtonMessage.d.ts +10 -0
- package/dist/components/conversation-detail/bot/BotButtonMessage.d.ts.map +1 -0
- package/dist/components/conversation-detail/bot/BotButtonMessage.js +30 -0
- package/dist/components/conversation-detail/bot/BotStartButton.d.ts +8 -0
- package/dist/components/conversation-detail/bot/BotStartButton.d.ts.map +1 -0
- package/dist/components/conversation-detail/bot/BotStartButton.js +11 -0
- package/dist/components/conversation-detail/bot/BotSuggest.d.ts +7 -0
- package/dist/components/conversation-detail/bot/BotSuggest.d.ts.map +1 -0
- package/dist/components/conversation-detail/bot/BotSuggest.js +11 -0
- package/dist/components/conversation-detail/bot/index.d.ts +7 -0
- package/dist/components/conversation-detail/bot/index.d.ts.map +1 -0
- package/dist/components/conversation-detail/bot/index.js +3 -0
- package/dist/components/conversation-detail/index.d.ts +10 -0
- package/dist/components/conversation-detail/index.d.ts.map +1 -0
- package/dist/components/conversation-detail/index.js +5 -0
- package/dist/components/conversation-inbox/ConversationInboxHeader.d.ts +3 -0
- package/dist/components/conversation-inbox/ConversationInboxHeader.d.ts.map +1 -0
- package/dist/components/conversation-inbox/ConversationInboxHeader.js +8 -0
- package/dist/components/conversation-inbox/ConversationInboxItem.d.ts +8 -0
- package/dist/components/conversation-inbox/ConversationInboxItem.d.ts.map +1 -0
- package/dist/components/conversation-inbox/ConversationInboxItem.js +30 -0
- package/dist/components/conversation-inbox/ConversationInboxList.d.ts +12 -0
- package/dist/components/conversation-inbox/ConversationInboxList.d.ts.map +1 -0
- package/dist/components/conversation-inbox/ConversationInboxList.js +36 -0
- package/dist/components/conversation-inbox/ConversationInboxTitle.d.ts +9 -0
- package/dist/components/conversation-inbox/ConversationInboxTitle.d.ts.map +1 -0
- package/dist/components/conversation-inbox/ConversationInboxTitle.js +7 -0
- package/dist/components/conversation-inbox/ConversationPeerAvatar.d.ts +10 -0
- package/dist/components/conversation-inbox/ConversationPeerAvatar.d.ts.map +1 -0
- package/dist/components/conversation-inbox/ConversationPeerAvatar.js +10 -0
- package/dist/components/conversation-inbox/index.d.ts +10 -0
- package/dist/components/conversation-inbox/index.d.ts.map +1 -0
- package/dist/components/conversation-inbox/index.js +5 -0
- package/dist/components/message/footer/LinkInputPreview.js +1 -1
- package/dist/components/message/item/ImageMessage.js +1 -1
- package/dist/components/message/item/LinkCard.js +1 -1
- package/dist/components/message/item/LinkText.js +1 -1
- package/dist/components/message/item/VideoMessage.js +1 -1
- package/dist/components/message/item/mediaSize.d.ts.map +1 -1
- package/dist/components/message/item/mediaSize.js +8 -8
- package/dist/constants/moreOption.d.ts +9 -0
- package/dist/constants/moreOption.d.ts.map +1 -0
- package/dist/constants/moreOption.js +37 -0
- package/dist/hooks/conversation/useActiveConversation.d.ts +3 -0
- package/dist/hooks/conversation/useActiveConversation.d.ts.map +1 -0
- package/dist/hooks/conversation/useActiveConversation.js +31 -0
- package/dist/hooks/conversation/useBotConversationDetail.d.ts +3 -0
- package/dist/hooks/conversation/useBotConversationDetail.d.ts.map +1 -0
- package/dist/hooks/conversation/useBotConversationDetail.js +18 -0
- package/dist/hooks/conversation/useBotFlow.d.ts +18 -0
- package/dist/hooks/conversation/useBotFlow.d.ts.map +1 -0
- package/dist/hooks/conversation/useBotFlow.js +150 -0
- package/dist/hooks/conversation/useConversationList.d.ts +15 -0
- package/dist/hooks/conversation/useConversationList.d.ts.map +1 -0
- package/dist/hooks/conversation/useConversationList.js +70 -0
- package/dist/hooks/conversation/useCreateConversation.d.ts +8 -0
- package/dist/hooks/conversation/useCreateConversation.d.ts.map +1 -0
- package/dist/hooks/conversation/useCreateConversation.js +15 -0
- package/dist/hooks/conversation/useResetBotFlow.d.ts +3 -0
- package/dist/hooks/conversation/useResetBotFlow.d.ts.map +1 -0
- package/dist/hooks/conversation/useResetBotFlow.js +14 -0
- package/dist/hooks/conversation/useRunBotFlow.d.ts +7 -0
- package/dist/hooks/conversation/useRunBotFlow.d.ts.map +1 -0
- package/dist/hooks/conversation/useRunBotFlow.js +14 -0
- package/dist/hooks/global/useGlobalEvent.d.ts.map +1 -1
- package/dist/hooks/global/useGlobalEvent.js +15 -7
- package/dist/hooks/message/useSendMessage.d.ts +1 -1
- package/dist/hooks/message/useSendMessage.d.ts.map +1 -1
- package/dist/hooks/user/useAuth.js +2 -2
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/locales/i18n.js +3 -3
- package/dist/locales/i18n.ts +3 -3
- package/dist/locales/vi/biz-inbox.json +39 -39
- package/dist/locales/vi/conversation-inbox.json +39 -0
- package/dist/screens/biz-message/index.d.ts +3 -4
- package/dist/screens/biz-message/index.d.ts.map +1 -1
- package/dist/screens/biz-message/index.js +5 -9
- package/dist/screens/biz-thread-detail/index.js +6 -6
- package/dist/screens/conversation-detail/index.d.ts +9 -0
- package/dist/screens/conversation-detail/index.d.ts.map +1 -0
- package/dist/screens/conversation-detail/index.js +53 -0
- package/dist/screens/conversation-inbox/index.d.ts +8 -0
- package/dist/screens/conversation-inbox/index.d.ts.map +1 -0
- package/dist/screens/conversation-inbox/index.js +30 -0
- package/dist/services/query.d.ts +0 -1
- package/dist/services/query.d.ts.map +1 -1
- package/dist/services/query.js +0 -1
- package/dist/services/routes.d.ts +0 -1
- package/dist/services/routes.d.ts.map +1 -1
- package/dist/services/routes.js +0 -1
- package/dist/store/conversation.d.ts.map +1 -1
- package/dist/store/conversation.js +14 -5
- package/dist/store/messageDraft.d.ts +9 -0
- package/dist/store/messageDraft.d.ts.map +1 -0
- package/dist/store/messageDraft.js +35 -0
- package/dist/store/type.d.ts +6 -1
- package/dist/store/type.d.ts.map +1 -1
- package/dist/styles/global.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/conversation.d.ts +116 -0
- package/dist/types/conversation.d.ts.map +1 -0
- package/dist/types/conversation.js +33 -0
- package/dist/utils/common.d.ts +1 -1
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/common.js +5 -3
- package/dist/utils/conversation.d.ts +12 -0
- package/dist/utils/conversation.d.ts.map +1 -0
- package/dist/utils/conversation.js +53 -0
- package/dist/utils/events.d.ts +1 -1
- package/dist/utils/events.d.ts.map +1 -1
- package/dist/utils/fileValidation.d.ts +2 -1
- package/dist/utils/fileValidation.d.ts.map +1 -1
- package/dist/utils/fileValidation.js +10 -1
- package/dist/utils/imCommon.d.ts +1 -0
- package/dist/utils/imCommon.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
|
4
|
+
import { useTranslation } from "react-i18next";
|
|
5
|
+
import { Empty, Spin } from "antd";
|
|
6
|
+
import InfiniteScroll from "react-infinite-scroll-component";
|
|
7
|
+
import useConversationStore from "../../store/conversation";
|
|
8
|
+
import { Icon } from "../../components/icon";
|
|
9
|
+
import ConversationInboxItem from "./ConversationInboxItem";
|
|
10
|
+
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 ConversationInboxList = ({ items, isLoading, isFetchingNextPage, hasNextPage, onLoadMore, onSelectThread, }) => {
|
|
12
|
+
const { t } = useTranslation("conversation-inbox");
|
|
13
|
+
const router = useRouter();
|
|
14
|
+
const pathname = usePathname();
|
|
15
|
+
const searchParams = useSearchParams();
|
|
16
|
+
const setConversationData = useConversationStore((state) => state.setConversationData);
|
|
17
|
+
const setSelectedConversationId = useConversationStore((state) => state.setSelectedConversationId);
|
|
18
|
+
const handleSelectThread = (item) => {
|
|
19
|
+
const newSearchParams = new URLSearchParams(searchParams);
|
|
20
|
+
newSearchParams.set("threadId", item.conversationID);
|
|
21
|
+
router.push(`${pathname}?${newSearchParams.toString()}`);
|
|
22
|
+
setSelectedConversationId(item.conversationID);
|
|
23
|
+
setConversationData(item);
|
|
24
|
+
onSelectThread === null || onSelectThread === void 0 ? void 0 : onSelectThread(item);
|
|
25
|
+
};
|
|
26
|
+
const handleEndReached = () => {
|
|
27
|
+
if (hasNextPage && !isFetchingNextPage) {
|
|
28
|
+
onLoadMore();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
if (isLoading) {
|
|
32
|
+
return (_jsx("div", { "data-testid": "conversation-inbox-thread-list", className: "flex flex-1 items-center justify-center py-12", children: _jsx(Spin, {}) }));
|
|
33
|
+
}
|
|
34
|
+
return (_jsx("div", { id: "scrollableConversationThreadsDiv", "data-testid": "conversation-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: "scrollableConversationThreadsDiv", 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(ConversationInboxItem, { item: item, onClick: handleSelectThread }, item.conversationID)))) }) }));
|
|
35
|
+
};
|
|
36
|
+
export default ConversationInboxList;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PeerType } from "../../types/conversation";
|
|
2
|
+
export interface ConversationInboxTitleProps {
|
|
3
|
+
peerType: PeerType;
|
|
4
|
+
displayName: string;
|
|
5
|
+
hasUnread?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare const ConversationInboxTitle: ({ peerType, displayName, hasUnread, }: ConversationInboxTitleProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default ConversationInboxTitle;
|
|
9
|
+
//# sourceMappingURL=ConversationInboxTitle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConversationInboxTitle.d.ts","sourceRoot":"","sources":["../../../src/components/conversation-inbox/ConversationInboxTitle.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,QAAA,MAAM,sBAAsB,GAAI,uCAI7B,2BAA2B,4CAmB7B,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { Icon } from "../../components/icon";
|
|
5
|
+
import { PeerType } from "../../types/conversation";
|
|
6
|
+
const ConversationInboxTitle = ({ peerType, displayName, hasUnread = false, }) => (_jsxs("div", { className: "flex min-w-0 items-center gap-1", children: [peerType === PeerType.GROUP && (_jsx(Icon, { icon: "user-two-b", size: 12, className: "shrink-0 text-black" })), peerType === PeerType.BOT && (_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 })] }));
|
|
7
|
+
export default ConversationInboxTitle;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PeerType } from "../../types/conversation";
|
|
2
|
+
export interface ConversationPeerAvatarProps {
|
|
3
|
+
peerType: PeerType;
|
|
4
|
+
displayName: string;
|
|
5
|
+
avatarUrl: string | null;
|
|
6
|
+
badgeLabel: string;
|
|
7
|
+
}
|
|
8
|
+
declare const ConversationPeerAvatar: ({ peerType, displayName, avatarUrl, badgeLabel, }: ConversationPeerAvatarProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default ConversationPeerAvatar;
|
|
10
|
+
//# sourceMappingURL=ConversationPeerAvatar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConversationPeerAvatar.d.ts","sourceRoot":"","sources":["../../../src/components/conversation-inbox/ConversationPeerAvatar.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,sBAAsB,GAAI,mDAK7B,2BAA2B,4CAyB7B,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { Avatar } from "antd";
|
|
5
|
+
import { resolvePeerBadgeColor } from "../../utils/conversation";
|
|
6
|
+
const ConversationPeerAvatar = ({ peerType, displayName, avatarUrl, badgeLabel, }) => {
|
|
7
|
+
const badge = 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-badge-inset", resolvePeerBadgeColor(peerType)), children: badgeLabel })) : null;
|
|
8
|
+
return (_jsxs("div", { className: "relative h-12 w-12 shrink-0", children: [_jsx(Avatar, { size: 48, src: avatarUrl || undefined, alt: displayName, className: "uppercase", children: (displayName === null || displayName === void 0 ? void 0 : displayName.charAt(0)) || "A" }), badge] }));
|
|
9
|
+
};
|
|
10
|
+
export default ConversationPeerAvatar;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as ConversationInboxHeader } from "./ConversationInboxHeader";
|
|
2
|
+
export { default as ConversationPeerAvatar } from "./ConversationPeerAvatar";
|
|
3
|
+
export type { ConversationPeerAvatarProps } from "./ConversationPeerAvatar";
|
|
4
|
+
export { default as ConversationInboxTitle } from "./ConversationInboxTitle";
|
|
5
|
+
export type { ConversationInboxTitleProps } from "./ConversationInboxTitle";
|
|
6
|
+
export { default as ConversationInboxItem } from "./ConversationInboxItem";
|
|
7
|
+
export type { ConversationInboxItemProps } from "./ConversationInboxItem";
|
|
8
|
+
export { default as ConversationInboxList } from "./ConversationInboxList";
|
|
9
|
+
export type { ConversationInboxListProps } from "./ConversationInboxList";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/conversation-inbox/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAE/E,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,YAAY,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAE5E,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,YAAY,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAE5E,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,YAAY,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAE1E,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,YAAY,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as ConversationInboxHeader } from "./ConversationInboxHeader";
|
|
2
|
+
export { default as ConversationPeerAvatar } from "./ConversationPeerAvatar";
|
|
3
|
+
export { default as ConversationInboxTitle } from "./ConversationInboxTitle";
|
|
4
|
+
export { default as ConversationInboxItem } from "./ConversationInboxItem";
|
|
5
|
+
export { default as ConversationInboxList } from "./ConversationInboxList";
|
|
@@ -6,7 +6,7 @@ import { getHostLabel } from "../../../utils/link";
|
|
|
6
6
|
import { openLink } from "../../../utils/openLink";
|
|
7
7
|
import { useTranslation } from "react-i18next";
|
|
8
8
|
const LinkInputPreview = ({ url, onRemove }) => {
|
|
9
|
-
const { t } = useTranslation("
|
|
9
|
+
const { t } = useTranslation("conversation-inbox");
|
|
10
10
|
const { data, isLoading, isError } = useFetchUrlMetadata(url);
|
|
11
11
|
const handleOpen = () => {
|
|
12
12
|
openLink(url, t);
|
|
@@ -17,7 +17,7 @@ const ImageMessageItem = (props) => {
|
|
|
17
17
|
snapshotHeight: (_k = pictureElem === null || pictureElem === void 0 ? void 0 : pictureElem.snapshotPicture) === null || _k === void 0 ? void 0 : _k.height,
|
|
18
18
|
});
|
|
19
19
|
const isSending = message.status === MessageStatus.Sending;
|
|
20
|
-
return (_jsx(Spin, { spinning: isSending, children: _jsx("div", { className: "relative max-w-[200px]", style: minStyle, children: _jsx(Image, { src: sourceUrl, width: minStyle.width, className: "cursor-pointer rounded-xl object-
|
|
20
|
+
return (_jsx(Spin, { spinning: isSending, children: _jsx("div", { className: "relative flex max-w-[200px] overflow-hidden rounded-xl", style: minStyle, children: _jsx(Image, { src: sourceUrl, width: minStyle.width, className: "block cursor-pointer rounded-xl object-cover", preview: {
|
|
21
21
|
src: bigUrl,
|
|
22
22
|
toolbarRender: (originalNode, info) => { var _a; return renderImagePreviewToolbar(originalNode, (_a = info === null || info === void 0 ? void 0 : info.image) === null || _a === void 0 ? void 0 : _a.url, t); },
|
|
23
23
|
}, placeholder: _jsx("div", { className: "flex items-center justify-center rounded-xl bg-black/10", style: minStyle, children: _jsx(Spin, {}) }) }) }) }));
|
|
@@ -4,7 +4,7 @@ import { useTranslation } from "react-i18next";
|
|
|
4
4
|
import { getHostLabel } from "../../../utils/link";
|
|
5
5
|
import { openLink } from "../../../utils/openLink";
|
|
6
6
|
const LinkCard = ({ metadata, url }) => {
|
|
7
|
-
const { t } = useTranslation("
|
|
7
|
+
const { t } = useTranslation("conversation-inbox");
|
|
8
8
|
const { title, description, image } = metadata;
|
|
9
9
|
if (!title && !description && !image) {
|
|
10
10
|
return null;
|
|
@@ -6,7 +6,7 @@ import { parseTextWithLinks } from "../../../utils/link";
|
|
|
6
6
|
import { openLink } from "../../../utils/openLink";
|
|
7
7
|
import { MESSAGE_TEXT_CLASS } from "./textStyle";
|
|
8
8
|
const LinkText = ({ text }) => {
|
|
9
|
-
const { t } = useTranslation("
|
|
9
|
+
const { t } = useTranslation("conversation-inbox");
|
|
10
10
|
const segments = parseTextWithLinks(text);
|
|
11
11
|
return (_jsx("span", { className: clsx("min-w-0 whitespace-pre-wrap text-left [overflow-wrap:anywhere]", MESSAGE_TEXT_CLASS), children: segments.map((segment, index) => segment.type === "link" ? (_jsx("button", { type: "button", onClick: () => openLink(segment.url, t), className: "inline text-left font-medium text-primary-400 underline-offset-2 hover:underline", children: segment.value }, `${segment.url}-${index}`)) : (_jsx("span", { children: segment.value }, `text-${index}`))) }));
|
|
12
12
|
};
|
|
@@ -13,6 +13,6 @@ const VideoMessageItem = (props) => {
|
|
|
13
13
|
snapshotHeight: videoElem === null || videoElem === void 0 ? void 0 : videoElem.snapshotHeight,
|
|
14
14
|
});
|
|
15
15
|
const isSending = message.status === MessageStatus.Sending;
|
|
16
|
-
return (_jsx(Spin, { spinning: isSending, children: _jsx("div", { className: "relative max-w-[200px]", style: minStyle, children: _jsx("video", { src: videoUrl, poster: posterUrl, controls: true, className: "rounded-xl object-cover", style: { width: minStyle.width } }) }) }));
|
|
16
|
+
return (_jsx(Spin, { spinning: isSending, children: _jsx("div", { className: "relative max-w-[200px] overflow-hidden rounded-xl", style: minStyle, children: _jsx("video", { src: videoUrl, poster: posterUrl, controls: true, className: "block rounded-xl object-cover", style: { width: minStyle.width } }) }) }));
|
|
17
17
|
};
|
|
18
18
|
export default VideoMessageItem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mediaSize.d.ts","sourceRoot":"","sources":["../../../../src/components/message/item/mediaSize.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,2BAA2B;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,uBAAuB,GAAI,8CAIrC,2BAA2B;;;;
|
|
1
|
+
{"version":3,"file":"mediaSize.d.ts","sourceRoot":"","sources":["../../../../src/components/message/item/mediaSize.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,2BAA2B;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,uBAAuB,GAAI,8CAIrC,2BAA2B;;;;CAmB7B,CAAC;AAEF,eAAO,MAAM,uBAAuB,iDArBjC,2BAA2B;;;;CAqBgC,CAAC"}
|
|
@@ -2,19 +2,19 @@ const IMAGE_MAX_WIDTH = 200;
|
|
|
2
2
|
export const getImageMessageMinStyle = ({ imageWidth, imageHeight, snapshotHeight, }) => {
|
|
3
3
|
if (!imageWidth || !imageHeight || imageWidth <= 0 || imageHeight <= 0) {
|
|
4
4
|
return {
|
|
5
|
-
minHeight:
|
|
6
|
-
minWidth:
|
|
5
|
+
minHeight: `${IMAGE_MAX_WIDTH}px`,
|
|
6
|
+
minWidth: `${IMAGE_MAX_WIDTH}px`,
|
|
7
7
|
width: IMAGE_MAX_WIDTH,
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
const snapshotMaxHeight = snapshotHeight !== null && snapshotHeight !== void 0 ? snapshotHeight : imageHeight;
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
11
|
+
const displayWidth = Math.min(imageWidth, IMAGE_MAX_WIDTH);
|
|
12
|
+
const aspectHeight = displayWidth * (imageHeight / imageWidth);
|
|
13
|
+
const displayHeight = Math.min(aspectHeight, snapshotMaxHeight);
|
|
14
14
|
return {
|
|
15
|
-
minHeight: `${
|
|
16
|
-
minWidth: `${
|
|
17
|
-
width:
|
|
15
|
+
minHeight: `${displayHeight}px`,
|
|
16
|
+
minWidth: `${displayWidth}px`,
|
|
17
|
+
width: displayWidth,
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
export const getVideoMessageMinStyle = getImageMessageMinStyle;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface MoreOptionConfig {
|
|
2
|
+
icon: string;
|
|
3
|
+
labelKey: string;
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const DEFAULT_MORE_OPTIONS: MoreOptionConfig[];
|
|
7
|
+
export declare function createMoreOptions(extraOptions?: MoreOptionConfig[]): MoreOptionConfig[];
|
|
8
|
+
export declare const MORE_OPTIONS: MoreOptionConfig[];
|
|
9
|
+
//# sourceMappingURL=moreOption.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moreOption.d.ts","sourceRoot":"","sources":["../../src/constants/moreOption.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,EAgBlD,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,YAAY,GAAE,gBAAgB,EAAO,GACpC,gBAAgB,EAAE,CAEpB;AAED,eAAO,MAAM,YAAY,EAAE,gBAAgB,EAgBzC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const DEFAULT_MORE_OPTIONS = [
|
|
2
|
+
{
|
|
3
|
+
icon: "image-02-o",
|
|
4
|
+
labelKey: "thread_detail.more_option.media",
|
|
5
|
+
enabled: true,
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
icon: "camera-o",
|
|
9
|
+
labelKey: "thread_detail.more_option.camera",
|
|
10
|
+
enabled: false,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
icon: "paperclip-o",
|
|
14
|
+
labelKey: "thread_detail.more_option.document",
|
|
15
|
+
enabled: true,
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
export function createMoreOptions(extraOptions = []) {
|
|
19
|
+
return [...DEFAULT_MORE_OPTIONS, ...extraOptions];
|
|
20
|
+
}
|
|
21
|
+
export const MORE_OPTIONS = createMoreOptions([
|
|
22
|
+
{
|
|
23
|
+
icon: "receipt-o",
|
|
24
|
+
labelKey: "thread_detail.more_option.order",
|
|
25
|
+
enabled: false,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
icon: "shopping-basket-o",
|
|
29
|
+
labelKey: "thread_detail.more_option.product",
|
|
30
|
+
enabled: false,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
icon: "calendar-active-o",
|
|
34
|
+
labelKey: "thread_detail.more_option.appointment",
|
|
35
|
+
enabled: false,
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useActiveConversation.d.ts","sourceRoot":"","sources":["../../../src/hooks/conversation/useActiveConversation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,eAAO,MAAM,qBAAqB,GAChC,mBAAmB,oBAAoB,EAAE,SAuC1C,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { useSearchParams } from "next/navigation";
|
|
4
|
+
import useConversationStore from "../../store/conversation";
|
|
5
|
+
export const useActiveConversation = (conversationItems) => {
|
|
6
|
+
const searchParams = useSearchParams();
|
|
7
|
+
const threadId = searchParams.get("threadId");
|
|
8
|
+
const setSelectedConversationId = useConversationStore((state) => state.setSelectedConversationId);
|
|
9
|
+
const setConversationData = useConversationStore((state) => state.setConversationData);
|
|
10
|
+
const clearSelectedConversation = useConversationStore((state) => state.clearSelectedConversation);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!threadId) {
|
|
13
|
+
clearSelectedConversation();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
setSelectedConversationId(threadId);
|
|
17
|
+
const matchedThread = conversationItems.find((item) => item.conversationID === threadId);
|
|
18
|
+
if (!matchedThread)
|
|
19
|
+
return;
|
|
20
|
+
const currentData = useConversationStore.getState().conversationData;
|
|
21
|
+
if ((currentData === null || currentData === void 0 ? void 0 : currentData.conversationID) !== threadId) {
|
|
22
|
+
setConversationData(matchedThread);
|
|
23
|
+
}
|
|
24
|
+
}, [
|
|
25
|
+
threadId,
|
|
26
|
+
conversationItems,
|
|
27
|
+
setSelectedConversationId,
|
|
28
|
+
setConversationData,
|
|
29
|
+
clearSelectedConversation,
|
|
30
|
+
]);
|
|
31
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BotConversationDetail } from "../../types/conversation";
|
|
2
|
+
export declare const useBotConversationDetail: (conversationId: string, enabled: boolean) => import("@tanstack/react-query").UseQueryResult<BotConversationDetail, Error>;
|
|
3
|
+
//# sourceMappingURL=useBotConversationDetail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBotConversationDetail.d.ts","sourceRoot":"","sources":["../../../src/hooks/conversation/useBotConversationDetail.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAElE,eAAO,MAAM,wBAAwB,GACnC,gBAAgB,MAAM,EACtB,SAAS,OAAO,iFAejB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { apiInstance } from "../../services/api";
|
|
4
|
+
import { ENDPOINTS } from "../../services/routes";
|
|
5
|
+
import { QUERY_KEYS } from "../../services/query";
|
|
6
|
+
export const useBotConversationDetail = (conversationId, enabled) => {
|
|
7
|
+
return useQuery({
|
|
8
|
+
queryKey: [QUERY_KEYS.GET_BIZ_CONVERSATION_DETAIL, conversationId],
|
|
9
|
+
queryFn: async () => {
|
|
10
|
+
const res = await apiInstance.get(ENDPOINTS.chatService.getBizConversationDetail(conversationId));
|
|
11
|
+
return res.data.data;
|
|
12
|
+
},
|
|
13
|
+
enabled: enabled && !!conversationId,
|
|
14
|
+
staleTime: 0,
|
|
15
|
+
refetchOnWindowFocus: false,
|
|
16
|
+
refetchOnReconnect: false,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type BotInputButtonsBlock } from "../../types/conversation";
|
|
2
|
+
export type BotFlowStatus = "running" | "not_started";
|
|
3
|
+
interface UseBotFlowParams {
|
|
4
|
+
conversationId: string;
|
|
5
|
+
isBotThread: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const useBotFlow: ({ conversationId, isBotThread, }: UseBotFlowParams) => {
|
|
8
|
+
status: BotFlowStatus;
|
|
9
|
+
flowIsEnd: boolean;
|
|
10
|
+
isProcessing: boolean;
|
|
11
|
+
shouldShowButtons: boolean;
|
|
12
|
+
currentButtonsBlock: BotInputButtonsBlock | null;
|
|
13
|
+
start: () => Promise<void>;
|
|
14
|
+
selectButton: (actionId: string) => Promise<void>;
|
|
15
|
+
restart: () => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=useBotFlow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBotFlow.d.ts","sourceRoot":"","sources":["../../../src/hooks/conversation/useBotFlow.ts"],"names":[],"mappings":"AAKA,OAAO,EAIL,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;AAU9B,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,aAAa,CAAC;AAEtD,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;CACtB;AAsBD,eAAO,MAAM,UAAU,GAAI,kCAGxB,gBAAgB;;;;;;;6BA0GqB,MAAM;;CAiD7C,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useTranslation } from "react-i18next";
|
|
4
|
+
import { BotBlockType, BotFlowNodeType, } from "../../types/conversation";
|
|
5
|
+
import { BOT_DEFAULT_BUTTON_ID } from "../../constants/botFlow";
|
|
6
|
+
import { useSendMessage } from "../../hooks/message/useSendMessage";
|
|
7
|
+
import useAuthStore from "../../store/auth";
|
|
8
|
+
import emitter from "../../utils/events";
|
|
9
|
+
import { useBotConversationDetail } from "./useBotConversationDetail";
|
|
10
|
+
import { useRunBotFlow } from "./useRunBotFlow";
|
|
11
|
+
import { useResetBotFlow } from "./useResetBotFlow";
|
|
12
|
+
const INITIAL_BOT_FLOW_STATE = {
|
|
13
|
+
conversationId: "",
|
|
14
|
+
flowCurrentStep: null,
|
|
15
|
+
flowIsEnd: false,
|
|
16
|
+
};
|
|
17
|
+
const parseMessageFlowGroupId = (ex) => {
|
|
18
|
+
var _a;
|
|
19
|
+
try {
|
|
20
|
+
return (_a = JSON.parse(ex || "{}").flow) === null || _a === void 0 ? void 0 : _a.groupId;
|
|
21
|
+
}
|
|
22
|
+
catch (_b) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const useBotFlow = ({ conversationId, isBotThread, }) => {
|
|
27
|
+
var _a;
|
|
28
|
+
const [botFlowState, setBotFlowState] = useState(INITIAL_BOT_FLOW_STATE);
|
|
29
|
+
const { conversationId: storedConversationId, flowCurrentStep } = botFlowState;
|
|
30
|
+
const isActiveConversation = storedConversationId === conversationId;
|
|
31
|
+
const flowIsEnd = isActiveConversation && botFlowState.flowIsEnd;
|
|
32
|
+
const [pendingGroupId, setPendingGroupId] = useState(null);
|
|
33
|
+
const latestBotFlowGroupIdRef = useRef(null);
|
|
34
|
+
const authUserID = useAuthStore((state) => state.userID);
|
|
35
|
+
const { t } = useTranslation("conversation-inbox");
|
|
36
|
+
const detailQuery = useBotConversationDetail(conversationId, isBotThread);
|
|
37
|
+
const runMutation = useRunBotFlow();
|
|
38
|
+
const resetMutation = useResetBotFlow();
|
|
39
|
+
const { sendMergeMessage } = useSendMessage({
|
|
40
|
+
scrollEvent: "CONVERSATION_CHAT_SCROLL_TO_BOTTOM_IF_AT_BOTTOM",
|
|
41
|
+
});
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!isBotThread) {
|
|
44
|
+
setBotFlowState(INITIAL_BOT_FLOW_STATE);
|
|
45
|
+
setPendingGroupId(null);
|
|
46
|
+
latestBotFlowGroupIdRef.current = null;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (detailQuery.data) {
|
|
50
|
+
setBotFlowState({
|
|
51
|
+
conversationId,
|
|
52
|
+
flowCurrentStep: detailQuery.data.flowCurrentStep,
|
|
53
|
+
flowIsEnd: detailQuery.data.flowIsEnd,
|
|
54
|
+
});
|
|
55
|
+
setPendingGroupId(null);
|
|
56
|
+
latestBotFlowGroupIdRef.current = null;
|
|
57
|
+
}
|
|
58
|
+
}, [isBotThread, conversationId, detailQuery.data]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const handleNewMessage = (message) => {
|
|
61
|
+
if (message.sendID === authUserID)
|
|
62
|
+
return;
|
|
63
|
+
const groupId = parseMessageFlowGroupId(message.ex);
|
|
64
|
+
if (!groupId)
|
|
65
|
+
return;
|
|
66
|
+
latestBotFlowGroupIdRef.current = groupId;
|
|
67
|
+
setPendingGroupId((currentGroupId) => currentGroupId === groupId ? null : currentGroupId);
|
|
68
|
+
};
|
|
69
|
+
emitter.on("PUSH_NEW_MSG", handleNewMessage);
|
|
70
|
+
return () => {
|
|
71
|
+
emitter.off("PUSH_NEW_MSG", handleNewMessage);
|
|
72
|
+
};
|
|
73
|
+
}, [authUserID]);
|
|
74
|
+
const activeStep = storedConversationId === conversationId ? flowCurrentStep : null;
|
|
75
|
+
const currentButtonsBlock = (_a = activeStep === null || activeStep === void 0 ? void 0 : activeStep.data.children.find((child) => child.type === BotBlockType.InputButtons)) !== null && _a !== void 0 ? _a : null;
|
|
76
|
+
const isProcessing = runMutation.isPending || resetMutation.isPending;
|
|
77
|
+
const shouldShowButtons = !!currentButtonsBlock && !isProcessing && !pendingGroupId;
|
|
78
|
+
const status = (activeStep === null || activeStep === void 0 ? void 0 : activeStep.type) === BotFlowNodeType.Start ? "not_started" : "running";
|
|
79
|
+
const runStep = async (step, actionId = null) => {
|
|
80
|
+
var _a;
|
|
81
|
+
latestBotFlowGroupIdRef.current = null;
|
|
82
|
+
const result = await runMutation.mutateAsync({
|
|
83
|
+
conversationId,
|
|
84
|
+
groupId: step.id,
|
|
85
|
+
childId: null,
|
|
86
|
+
actionId,
|
|
87
|
+
});
|
|
88
|
+
setBotFlowState({
|
|
89
|
+
conversationId,
|
|
90
|
+
flowCurrentStep: result.flowNextStep,
|
|
91
|
+
flowIsEnd: result.isEnd,
|
|
92
|
+
});
|
|
93
|
+
const nextGroupId = (_a = result.flowNextStep) === null || _a === void 0 ? void 0 : _a.id;
|
|
94
|
+
setPendingGroupId(result.havingBotMessage &&
|
|
95
|
+
nextGroupId &&
|
|
96
|
+
latestBotFlowGroupIdRef.current !== nextGroupId
|
|
97
|
+
? nextGroupId
|
|
98
|
+
: null);
|
|
99
|
+
};
|
|
100
|
+
const start = async () => {
|
|
101
|
+
if (!activeStep)
|
|
102
|
+
return;
|
|
103
|
+
await runStep(activeStep);
|
|
104
|
+
};
|
|
105
|
+
const selectButton = async (actionId) => {
|
|
106
|
+
if (!activeStep)
|
|
107
|
+
return;
|
|
108
|
+
const flow = {
|
|
109
|
+
groupId: activeStep.id,
|
|
110
|
+
childId: null,
|
|
111
|
+
actionId,
|
|
112
|
+
};
|
|
113
|
+
const selectedButton = currentButtonsBlock === null || currentButtonsBlock === void 0 ? void 0 : currentButtonsBlock.data.buttons.find((button) => button.id === actionId);
|
|
114
|
+
if (selectedButton) {
|
|
115
|
+
await sendMergeMessage({
|
|
116
|
+
plainText: selectedButton.label,
|
|
117
|
+
richText: "",
|
|
118
|
+
isInternal: false,
|
|
119
|
+
flow,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
await runStep(activeStep, actionId);
|
|
123
|
+
};
|
|
124
|
+
const restart = async () => {
|
|
125
|
+
var _a;
|
|
126
|
+
const flow = {
|
|
127
|
+
groupId: (_a = activeStep === null || activeStep === void 0 ? void 0 : activeStep.id) !== null && _a !== void 0 ? _a : "",
|
|
128
|
+
childId: null,
|
|
129
|
+
actionId: BOT_DEFAULT_BUTTON_ID,
|
|
130
|
+
};
|
|
131
|
+
await sendMergeMessage({
|
|
132
|
+
plainText: t("thread_detail.bot.restart"),
|
|
133
|
+
richText: "",
|
|
134
|
+
isInternal: false,
|
|
135
|
+
flow,
|
|
136
|
+
});
|
|
137
|
+
const resetDetail = await resetMutation.mutateAsync(conversationId);
|
|
138
|
+
await runStep(resetDetail.flowCurrentStep);
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
status,
|
|
142
|
+
flowIsEnd,
|
|
143
|
+
isProcessing,
|
|
144
|
+
shouldShowButtons,
|
|
145
|
+
currentButtonsBlock,
|
|
146
|
+
start,
|
|
147
|
+
selectButton,
|
|
148
|
+
restart,
|
|
149
|
+
};
|
|
150
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ChatCategory, type ConversationListItem } from "../../types/conversation";
|
|
2
|
+
interface UseConversationListParams {
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
chatCategory?: ChatCategory;
|
|
5
|
+
}
|
|
6
|
+
interface UseConversationListResult {
|
|
7
|
+
items: ConversationListItem[];
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
isFetchingNextPage: boolean;
|
|
10
|
+
hasNextPage: boolean;
|
|
11
|
+
fetchNextPage: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const useConversationList: (params: UseConversationListParams) => UseConversationListResult;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=useConversationList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConversationList.d.ts","sourceRoot":"","sources":["../../../src/hooks/conversation/useConversationList.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAI/E,UAAU,yBAAyB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED,UAAU,yBAAyB;IACjC,KAAK,EAAE,oBAAoB,EAAE,CAAC;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AASD,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,yBAAyB,KAChC,yBAuFF,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { CbEvents, } from "@openim/wasm-client-sdk";
|
|
4
|
+
import { DChatSDK } from "../../constants/sdk";
|
|
5
|
+
import { useChatContext } from "../../context/ChatContext";
|
|
6
|
+
import { ConnectStatus, DChatApplicationType } from "../../types/chat";
|
|
7
|
+
import useAuthStore from "../../store/auth";
|
|
8
|
+
import useConversationStore from "../../store/conversation";
|
|
9
|
+
const toConversationListItem = (conversation) => (Object.assign(Object.assign({}, conversation), { peerType: conversation.peerType }));
|
|
10
|
+
export const useConversationList = (params) => {
|
|
11
|
+
const { enabled, chatCategory } = params;
|
|
12
|
+
const { connectStatus } = useChatContext();
|
|
13
|
+
const applicationType = useAuthStore((state) => state.applicationType);
|
|
14
|
+
const conversationList = useConversationStore((state) => state.conversationList);
|
|
15
|
+
const getConversationListByReq = useConversationStore((state) => state.getConversationListByReq);
|
|
16
|
+
const updateConversationList = useConversationStore((state) => state.updateConversationList);
|
|
17
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
18
|
+
const [isFetchingNextPage, setIsFetchingNextPage] = useState(false);
|
|
19
|
+
const [hasNextPage, setHasNextPage] = useState(false);
|
|
20
|
+
const isApplicationTypeValid = Object.values(DChatApplicationType).includes(applicationType);
|
|
21
|
+
const queryEnabled = enabled &&
|
|
22
|
+
isApplicationTypeValid &&
|
|
23
|
+
connectStatus === ConnectStatus.Connected;
|
|
24
|
+
const appParams = useMemo(() => ({ applicationType, chatCategory }), [applicationType, chatCategory]);
|
|
25
|
+
const loadInitial = useCallback(async () => {
|
|
26
|
+
setIsLoading(true);
|
|
27
|
+
try {
|
|
28
|
+
const hasMore = await getConversationListByReq(false, appParams);
|
|
29
|
+
setHasNextPage(hasMore);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
setIsLoading(false);
|
|
33
|
+
}
|
|
34
|
+
}, [getConversationListByReq, appParams]);
|
|
35
|
+
const fetchNextPage = useCallback(() => {
|
|
36
|
+
if (!hasNextPage || isFetchingNextPage)
|
|
37
|
+
return;
|
|
38
|
+
setIsFetchingNextPage(true);
|
|
39
|
+
void getConversationListByReq(true, appParams)
|
|
40
|
+
.then((hasMore) => setHasNextPage(hasMore))
|
|
41
|
+
.finally(() => setIsFetchingNextPage(false));
|
|
42
|
+
}, [hasNextPage, isFetchingNextPage, getConversationListByReq, appParams]);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!queryEnabled)
|
|
45
|
+
return;
|
|
46
|
+
void loadInitial();
|
|
47
|
+
const onSyncFinish = () => {
|
|
48
|
+
void loadInitial();
|
|
49
|
+
};
|
|
50
|
+
const conversationChangeHandler = ({ data, }) => {
|
|
51
|
+
updateConversationList(data, "push");
|
|
52
|
+
};
|
|
53
|
+
DChatSDK.on(CbEvents.OnSyncServerFinish, onSyncFinish);
|
|
54
|
+
DChatSDK.on(CbEvents.OnConversationChanged, conversationChangeHandler);
|
|
55
|
+
DChatSDK.on(CbEvents.OnNewConversation, conversationChangeHandler);
|
|
56
|
+
return () => {
|
|
57
|
+
DChatSDK.off(CbEvents.OnSyncServerFinish, onSyncFinish);
|
|
58
|
+
DChatSDK.off(CbEvents.OnConversationChanged, conversationChangeHandler);
|
|
59
|
+
DChatSDK.off(CbEvents.OnNewConversation, conversationChangeHandler);
|
|
60
|
+
};
|
|
61
|
+
}, [queryEnabled, loadInitial, updateConversationList]);
|
|
62
|
+
const items = useMemo(() => conversationList.map(toConversationListItem), [conversationList]);
|
|
63
|
+
return {
|
|
64
|
+
items,
|
|
65
|
+
isLoading,
|
|
66
|
+
isFetchingNextPage,
|
|
67
|
+
hasNextPage,
|
|
68
|
+
fetchNextPage,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ChatCategory, ChatType, CreateConversationData } from "../../types/conversation";
|
|
2
|
+
export interface CreateConversationInput {
|
|
3
|
+
peerUserId: string;
|
|
4
|
+
chatCategory: ChatCategory;
|
|
5
|
+
chatType: ChatType;
|
|
6
|
+
}
|
|
7
|
+
export declare const useCreateConversation: () => import("@tanstack/react-query").UseMutationResult<CreateConversationData, Error, CreateConversationInput, unknown>;
|
|
8
|
+
//# sourceMappingURL=useCreateConversation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateConversation.d.ts","sourceRoot":"","sources":["../../../src/hooks/conversation/useCreateConversation.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,eAAO,MAAM,qBAAqB,0HAejC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMutation } from "@tanstack/react-query";
|
|
3
|
+
import useAuthStore from "../../store/auth";
|
|
4
|
+
import { apiInstance } from "../../services/api";
|
|
5
|
+
import { ENDPOINTS } from "../../services/routes";
|
|
6
|
+
import { QUERY_KEYS } from "../../services/query";
|
|
7
|
+
export const useCreateConversation = () => {
|
|
8
|
+
return useMutation({
|
|
9
|
+
mutationKey: [QUERY_KEYS.CREATE_BIZ_CONVERSATION],
|
|
10
|
+
mutationFn: async (input) => {
|
|
11
|
+
const res = await apiInstance.post(ENDPOINTS.chatService.createBizConversation, Object.assign(Object.assign({}, input), { applicationType: useAuthStore.getState().applicationType }));
|
|
12
|
+
return res.data.data;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useResetBotFlow.d.ts","sourceRoot":"","sources":["../../../src/hooks/conversation/useResetBotFlow.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAElE,eAAO,MAAM,eAAe,wGAY3B,CAAC"}
|