@droppii-org/chat-sdk 0.0.38 → 0.0.39
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/conversation/ConversationBySessionItem.js +1 -1
- package/dist/components/mediaCollection/FileCollection.d.ts.map +1 -1
- package/dist/components/mediaCollection/ImageCollection.d.ts.map +1 -1
- package/dist/components/mediaCollection/VideoCollection.d.ts.map +1 -1
- package/dist/components/mediaCollection/index.d.ts +0 -1
- package/dist/components/mediaCollection/index.d.ts.map +1 -1
- package/dist/components/mediaCollection/index.js +0 -1
- package/dist/components/message/MessageHeader.d.ts +3 -1
- package/dist/components/message/MessageHeader.d.ts.map +1 -1
- package/dist/components/message/MessageHeader.js +1 -23
- package/dist/components/message/MessageList.d.ts.map +1 -1
- package/dist/components/message/MessageList.js +22 -3
- package/dist/components/message/footer/index.d.ts +5 -1
- package/dist/components/message/footer/index.d.ts.map +1 -1
- package/dist/components/message/footer/index.js +9 -4
- package/dist/components/message/item/index.d.ts.map +1 -1
- package/dist/components/message/item/index.js +4 -4
- package/dist/components/searchConversation/item/SearchItemAsMessage.js +1 -1
- package/dist/hooks/message/useMessage.d.ts.map +1 -1
- package/dist/hooks/message/useMessage.js +1 -0
- package/dist/hooks/message/useSendMessage.d.ts +7 -3
- package/dist/hooks/message/useSendMessage.d.ts.map +1 -1
- package/dist/hooks/message/useSendMessage.js +12 -9
- package/dist/types/chat.d.ts +1 -7
- package/dist/types/chat.d.ts.map +1 -1
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/common.js +8 -4
- package/package.json +1 -1
|
@@ -29,7 +29,7 @@ const ConversationBySessionItem = ({ sessionItem, }) => {
|
|
|
29
29
|
if (!conversation)
|
|
30
30
|
return null;
|
|
31
31
|
return (_jsxs("div", { onClick: () => handleConversationClick(conversation), className: `relative p-3 border-b border-gray-100 hover:bg-gray-100 cursor-pointer transition-colors ${isSelected ? "bg-blue-50" : "bg-white"}`, children: [isSelected && (_jsx("div", { className: "absolute left-0 top-0 bottom-0 w-1 bg-blue-500" })), _jsxs("div", { className: "flex items-start gap-3", children: [_jsx("div", { className: "relative flex-shrink-0", children: _jsx(Badge, { dot: true, status: "success", offset: [-2, 36], children: _jsx(Avatar, { size: 48, src: avatar, children: ((_a = displayName === null || displayName === void 0 ? void 0 : displayName.charAt) === null || _a === void 0 ? void 0 : _a.call(displayName, 0)) || "A" }) }) }), _jsx("div", { className: "flex-1 min-w-0", children: _jsxs("div", { className: "flex items-start justify-between", children: [_jsxs("div", { className: "flex-1 min-w-0", children: [_jsx("h3", { className: "font-semibold text-gray-900 text-sm truncate", children: displayName }), _jsx("p", { className: "text-xs text-gray-500 truncate mt-0.5", children: parseLatestMessage(conversation.latestMsg, user === null || user === void 0 ? void 0 : user.userID, t) })] }), _jsxs("div", { className: "flex flex-col items-end gap-1 ml-2", children: [_jsx("span", { className: "text-xs text-gray-400", children: formatTimestamp(conversation.latestMsgSendTime, {
|
|
32
|
-
hasTime:
|
|
32
|
+
hasTime: true,
|
|
33
33
|
}) }), _jsx("div", { className: "flex items-center gap-1", children: conversation.unreadCount > 0 && (_jsx(Badge, { count: conversation.unreadCount })) })] })] }) })] })] }, conversation.conversationID));
|
|
34
34
|
};
|
|
35
35
|
export default ConversationBySessionItem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileCollection.d.ts","sourceRoot":"","sources":["../../../src/components/mediaCollection/FileCollection.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FileCollection.d.ts","sourceRoot":"","sources":["../../../src/components/mediaCollection/FileCollection.tsx"],"names":[],"mappings":"AAaA,QAAA,MAAM,cAAc,+CAqGnB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageCollection.d.ts","sourceRoot":"","sources":["../../../src/components/mediaCollection/ImageCollection.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ImageCollection.d.ts","sourceRoot":"","sources":["../../../src/components/mediaCollection/ImageCollection.tsx"],"names":[],"mappings":"AAYA,QAAA,MAAM,eAAe,+CA+GpB,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VideoCollection.d.ts","sourceRoot":"","sources":["../../../src/components/mediaCollection/VideoCollection.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"VideoCollection.d.ts","sourceRoot":"","sources":["../../../src/components/mediaCollection/VideoCollection.tsx"],"names":[],"mappings":"AAaA,QAAA,MAAM,eAAe,+CAyHpB,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -4,7 +4,6 @@ export declare enum MediaCollectionTabKey {
|
|
|
4
4
|
File = "file",
|
|
5
5
|
Link = "link"
|
|
6
6
|
}
|
|
7
|
-
export declare const TOP_OFFSET = 128;
|
|
8
7
|
declare const MediaCollection: () => import("react/jsx-runtime").JSX.Element;
|
|
9
8
|
export default MediaCollection;
|
|
10
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/mediaCollection/index.tsx"],"names":[],"mappings":"AAaA,oBAAY,qBAAqB;IAC/B,KAAK,UAAU;IACf,KAAK,UAAU;IACf,IAAI,SAAS;IACb,IAAI,SAAS;CACd;AAED,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/mediaCollection/index.tsx"],"names":[],"mappings":"AAaA,oBAAY,qBAAqB;IAC/B,KAAK,UAAU;IACf,KAAK,UAAU;IACf,IAAI,SAAS;IACb,IAAI,SAAS;CACd;AAED,QAAA,MAAM,eAAe,+CA8EpB,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -17,7 +17,6 @@ export var MediaCollectionTabKey;
|
|
|
17
17
|
MediaCollectionTabKey["File"] = "file";
|
|
18
18
|
MediaCollectionTabKey["Link"] = "link";
|
|
19
19
|
})(MediaCollectionTabKey || (MediaCollectionTabKey = {}));
|
|
20
|
-
export const TOP_OFFSET = 128; /// HEADER + TAB HEIGHT
|
|
21
20
|
const MediaCollection = () => {
|
|
22
21
|
const { t } = useTranslation();
|
|
23
22
|
const [isOpen, { toggle }] = useBoolean(false);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { SessionStatus, SessionTag } from "../../types/chat";
|
|
2
|
+
import { ISessionByStatus } from "../../store/type";
|
|
2
3
|
interface MessageHeaderProps {
|
|
3
4
|
onClose?: () => void;
|
|
5
|
+
currentSession?: ISessionByStatus;
|
|
4
6
|
}
|
|
5
7
|
type SelectSessionValueType = SessionStatus | SessionTag;
|
|
6
8
|
export interface SelectSessionOption {
|
|
@@ -10,6 +12,6 @@ export interface SelectSessionOption {
|
|
|
10
12
|
tintColorClassnameBg: string;
|
|
11
13
|
bgTintColorClassname: string;
|
|
12
14
|
}
|
|
13
|
-
declare const MessageHeader: ({ onClose }: MessageHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
declare const MessageHeader: ({ onClose, currentSession }: MessageHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
16
|
export default MessageHeader;
|
|
15
17
|
//# sourceMappingURL=MessageHeader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageHeader.d.ts","sourceRoot":"","sources":["../../../src/components/message/MessageHeader.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MessageHeader.d.ts","sourceRoot":"","sources":["../../../src/components/message/MessageHeader.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,UAAU,kBAAkB;IAC1B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,cAAc,CAAC,EAAE,gBAAgB,CAAC;CACnC;AAED,KAAK,sBAAsB,GAAG,aAAa,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,sBAAsB,CAAC;IAC9B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED,QAAA,MAAM,aAAa,GAAI,6BAA6B,kBAAkB,4CAmKrE,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -5,32 +5,22 @@ import { Icon } from "../icon";
|
|
|
5
5
|
import { useConversationDisplayData } from "../../hooks/conversation/useConversation";
|
|
6
6
|
import useConversationStore from "../../store/conversation";
|
|
7
7
|
import MediaCollection from "../mediaCollection";
|
|
8
|
-
import { useGetSession } from "../../hooks/session/useGetSession";
|
|
9
8
|
import { useEffect, useMemo, useState } from "react";
|
|
10
9
|
import { useTranslation } from "react-i18next";
|
|
11
10
|
import { SessionStatus, SessionTag } from "../../types/chat";
|
|
12
11
|
import SelectSession from "./SelectSession";
|
|
13
12
|
import { useUpdateSession } from "../../hooks/session/useUpdateSession";
|
|
14
|
-
import emitter from "../../utils/events";
|
|
15
13
|
import { useChatContext } from "../../context/ChatContext";
|
|
16
14
|
import { adminUserId } from "../../constants";
|
|
17
|
-
const MessageHeader = ({ onClose }) => {
|
|
15
|
+
const MessageHeader = ({ onClose, currentSession }) => {
|
|
18
16
|
var _a;
|
|
19
17
|
const { t } = useTranslation();
|
|
20
18
|
const { user } = useChatContext();
|
|
21
19
|
const conversationData = useConversationStore((state) => state.conversationData);
|
|
22
|
-
const { dataFlatten: sessions, refetch: refetchSession } = useGetSession({
|
|
23
|
-
conversationIds: (conversationData === null || conversationData === void 0 ? void 0 : conversationData.conversationID)
|
|
24
|
-
? [conversationData.conversationID]
|
|
25
|
-
: [],
|
|
26
|
-
});
|
|
27
20
|
const { mutate: updateSession } = useUpdateSession();
|
|
28
21
|
const { avatar, displayName } = useConversationDisplayData(conversationData);
|
|
29
22
|
const [currentSessionStatus, setCurrentSessionStatus] = useState(SessionStatus.UNASSIGNED);
|
|
30
23
|
const [currentSessionTag, setCurrentSessionTag] = useState(SessionTag.NONE);
|
|
31
|
-
const currentSession = useMemo(() => {
|
|
32
|
-
return sessions === null || sessions === void 0 ? void 0 : sessions.find((session) => session.conversationId === (conversationData === null || conversationData === void 0 ? void 0 : conversationData.conversationID));
|
|
33
|
-
}, [sessions, conversationData]);
|
|
34
24
|
const statusOptions = useMemo(() => {
|
|
35
25
|
return [
|
|
36
26
|
{
|
|
@@ -116,18 +106,6 @@ const MessageHeader = ({ onClose }) => {
|
|
|
116
106
|
setCurrentSessionStatus(currentSession.status);
|
|
117
107
|
}
|
|
118
108
|
}, [currentSession]);
|
|
119
|
-
useEffect(() => {
|
|
120
|
-
emitter.on("UPDATE_SESSION", (sessionUpdated) => {
|
|
121
|
-
if (sessionUpdated.conversationId === (conversationData === null || conversationData === void 0 ? void 0 : conversationData.conversationID)) {
|
|
122
|
-
refetchSession();
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
return () => {
|
|
126
|
-
emitter.off("UPDATE_SESSION", () => {
|
|
127
|
-
refetchSession();
|
|
128
|
-
});
|
|
129
|
-
};
|
|
130
|
-
}, [conversationData === null || conversationData === void 0 ? void 0 : conversationData.conversationID]);
|
|
131
109
|
return (_jsxs("div", { className: "px-4 py-3 flex items-center border-b gap-3 bg-white no-transform", children: [_jsx(Avatar, { src: avatar, size: "large", children: ((_a = displayName === null || displayName === void 0 ? void 0 : displayName.charAt) === null || _a === void 0 ? void 0 : _a.call(displayName, 0)) || "A" }), _jsxs("div", { className: "flex flex-col", children: [_jsx("p", { className: "text-base truncate", children: displayName || "" }), _jsx("p", { className: "text-xs text-gray-500", children: "2 thành viên" })] }), _jsxs("div", { className: "flex items-center gap-2 flex-1 justify-end", children: [currentSessionTag !== SessionTag.NONE &&
|
|
132
110
|
(user === null || user === void 0 ? void 0 : user.userID) === adminUserId && (_jsx(SelectSession, { options: tagOptions, value: currentSessionTag, onChange: (value) => handleUpdateSession(value, "tag") })), (user === null || user === void 0 ? void 0 : user.userID) === adminUserId && (_jsx(SelectSession, { options: statusOptions, value: currentSessionStatus, onChange: (value) => handleUpdateSession(value, "status") })), _jsx(Button, { type: "text", shape: "default", className: "text-gray-500 w-8 h-8 p-0", children: _jsx(Icon, { icon: "search-o", size: 22 }) }), _jsx(MediaCollection, {}), _jsx(Button, { type: "text", shape: "default", className: "text-gray-500 w-8 h-8 p-0", children: _jsx(Icon, { icon: "align-justify-o", size: 22 }) }), !!onClose && (_jsx(Button, { type: "text", shape: "default", className: "text-gray-500 w-8 h-8 p-0", onClick: onClose, children: _jsx(Icon, { icon: "close-b", size: 22 }) }))] })] }));
|
|
133
111
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageList.d.ts","sourceRoot":"","sources":["../../../src/components/message/MessageList.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MessageList.d.ts","sourceRoot":"","sources":["../../../src/components/message/MessageList.tsx"],"names":[],"mappings":"AAwBA,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;CACtB;AAGD,QAAA,MAAM,WAAW,GAAI,OAAO,gBAAgB,4CAgM3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useMessage } from "../../hooks/message/useMessage";
|
|
4
4
|
import { Empty, Spin } from "antd";
|
|
5
|
-
import { useEffect, useRef } from "react";
|
|
5
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
6
6
|
import dayjs from "dayjs";
|
|
7
7
|
import isToday from "dayjs/plugin/isToday";
|
|
8
8
|
import emitter from "../../utils/events";
|
|
@@ -18,6 +18,7 @@ import { useDebounceFn } from "ahooks";
|
|
|
18
18
|
import { MSG_ITEM_CONTENT_PREFIX, MSG_ITEM_PREFIX } from "../../constants";
|
|
19
19
|
import { markConversationMessageAsRead } from "../../hooks/conversation/useConversation";
|
|
20
20
|
import { useChatContext } from "../../context/ChatContext";
|
|
21
|
+
import { useGetSession } from "../../hooks/session/useGetSession";
|
|
21
22
|
dayjs.extend(isToday);
|
|
22
23
|
const BOTTOM_THRESHOLD = -5;
|
|
23
24
|
const MessageList = (props) => {
|
|
@@ -28,6 +29,12 @@ const MessageList = (props) => {
|
|
|
28
29
|
const scrollRef = useRef(null);
|
|
29
30
|
const { getMoreOldMessages, moreOldLoading, loadState, getMoreNewMessages, moreNewLoading, latestLoadState, } = useMessage(conversationId, searchClientMsgID);
|
|
30
31
|
const conversationData = useConversationStore((state) => state.conversationData);
|
|
32
|
+
const { dataFlatten: sessions, refetch: refetchSession } = useGetSession({
|
|
33
|
+
conversationIds: !!conversationId ? [conversationId] : [],
|
|
34
|
+
});
|
|
35
|
+
const currentSession = useMemo(() => {
|
|
36
|
+
return sessions === null || sessions === void 0 ? void 0 : sessions.find((session) => session.conversationId === conversationId);
|
|
37
|
+
}, [sessions, conversationId]);
|
|
31
38
|
const handleMarkConversationMessageAsRead = () => {
|
|
32
39
|
var _a, _b, _c;
|
|
33
40
|
const lastMessage = (_b = (_a = latestLoadState === null || latestLoadState === void 0 ? void 0 : latestLoadState.current) === null || _a === void 0 ? void 0 : _a.messageList) === null || _b === void 0 ? void 0 : _b[0];
|
|
@@ -91,6 +98,18 @@ const MessageList = (props) => {
|
|
|
91
98
|
emitter.off("CHAT_LIST_SCROLL_TO_MESSAGE", scrollToMessage);
|
|
92
99
|
};
|
|
93
100
|
}, []);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
emitter.on("UPDATE_SESSION", (sessionUpdated) => {
|
|
103
|
+
if (sessionUpdated.conversationId === conversationId) {
|
|
104
|
+
refetchSession();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return () => {
|
|
108
|
+
emitter.off("UPDATE_SESSION", () => {
|
|
109
|
+
refetchSession();
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
}, [conversationId]);
|
|
94
113
|
if (!conversationData) {
|
|
95
114
|
return (_jsx("div", { className: "flex flex-1 items-center justify-center h-full", children: _jsx(Empty, { description: t("no_conversation_data") }) }));
|
|
96
115
|
}
|
|
@@ -98,7 +117,7 @@ const MessageList = (props) => {
|
|
|
98
117
|
backgroundImage: `url(${images.conversationBg})`,
|
|
99
118
|
backgroundSize: "cover",
|
|
100
119
|
backgroundPosition: "center",
|
|
101
|
-
}, children: [_jsx(MessageHeader, { onClose: onClose }), _jsx("div", { id: "scrollableMessagesDiv", ref: scrollRef, style: {
|
|
120
|
+
}, children: [_jsx(MessageHeader, { onClose: onClose, currentSession: currentSession }), _jsx("div", { id: "scrollableMessagesDiv", ref: scrollRef, style: {
|
|
102
121
|
height: "100%",
|
|
103
122
|
overflow: "auto",
|
|
104
123
|
display: "flex",
|
|
@@ -110,6 +129,6 @@ const MessageList = (props) => {
|
|
|
110
129
|
handleMarkConversationMessageAsRead();
|
|
111
130
|
loadMoreNewMessage();
|
|
112
131
|
}
|
|
113
|
-
}, children: loadState.messageList.map((message, _, array) => (_jsx(MessageItem, { message: message, allMessages: array }, message.clientMsgID))) }) }), moreNewLoading && (_jsx("div", { className: "flex items-center justify-center py-2", children: _jsx(Spin, {}) })), _jsx(MessageFooter, {})] }));
|
|
132
|
+
}, children: loadState.messageList.map((message, _, array) => (_jsx(MessageItem, { message: message, allMessages: array }, message.clientMsgID))) }) }), moreNewLoading && (_jsx("div", { className: "flex items-center justify-center py-2", children: _jsx(Spin, {}) })), _jsx(MessageFooter, { currentSession: currentSession })] }));
|
|
114
133
|
};
|
|
115
134
|
export default MessageList;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { MessageFooterContextType } from "../../../types/chat";
|
|
2
|
+
import { ISessionByStatus } from "../../../store/type";
|
|
3
|
+
interface MessageFooterProps {
|
|
4
|
+
currentSession?: ISessionByStatus;
|
|
5
|
+
}
|
|
2
6
|
export declare const MessageFooterContext: import("react").Context<MessageFooterContextType>;
|
|
3
7
|
export declare const useMessageFooterContext: () => MessageFooterContextType;
|
|
4
|
-
declare const MessageFooterProvider: () => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
declare const MessageFooterProvider: ({ currentSession }: MessageFooterProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
9
|
export default MessageFooterProvider;
|
|
6
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/message/footer/index.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/message/footer/index.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAK/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,UAAU,kBAAkB;IAC1B,cAAc,CAAC,EAAE,gBAAgB,CAAC;CACnC;AA+BD,eAAO,MAAM,oBAAoB,mDAI/B,CAAC;AAEH,eAAO,MAAM,uBAAuB,gCAAyC,CAAC;AAE9E,QAAA,MAAM,qBAAqB,GAAI,oBAAoB,kBAAkB,4CA4DpE,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
@@ -48,19 +48,24 @@ export const MessageFooterContext = createContext({
|
|
|
48
48
|
setListUploadFiles: () => { },
|
|
49
49
|
});
|
|
50
50
|
export const useMessageFooterContext = () => useContext(MessageFooterContext);
|
|
51
|
-
const MessageFooterProvider = () => {
|
|
51
|
+
const MessageFooterProvider = ({ currentSession }) => {
|
|
52
52
|
const { t } = useTranslation();
|
|
53
53
|
const { sendTextMessage, sendMergeMessage } = useSendMessage();
|
|
54
54
|
const [listUploadFiles, setListUploadFiles] = useState([]);
|
|
55
55
|
const onSendMessage = useCallback(async ({ plainText, richText, type, }) => {
|
|
56
56
|
if (type === "text") {
|
|
57
|
-
sendTextMessage({ plainText, richText });
|
|
57
|
+
sendTextMessage({ plainText, richText, currentSession });
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
|
-
sendMergeMessage({
|
|
60
|
+
sendMergeMessage({
|
|
61
|
+
plainText,
|
|
62
|
+
richText,
|
|
63
|
+
files: listUploadFiles,
|
|
64
|
+
currentSession,
|
|
65
|
+
});
|
|
61
66
|
}
|
|
62
67
|
setListUploadFiles([]);
|
|
63
|
-
}, [sendMergeMessage, sendTextMessage, listUploadFiles]);
|
|
68
|
+
}, [sendMergeMessage, sendTextMessage, listUploadFiles, currentSession]);
|
|
64
69
|
return (_jsx(MessageFooterContext.Provider, { value: { onSendMessage, listUploadFiles, setListUploadFiles }, children: _jsxs(LexicalComposer, { initialConfig: initialConfig, children: [_jsxs("div", { className: "border-t pb-2 flex flex-col gap-1 bg-white", children: [listUploadFiles.length > 0 && _jsx(FilePreview, {}), _jsx(ToolbarPlugin, {}), _jsx("div", { className: "relative px-4", children: _jsx(RichTextPlugin, { contentEditable: _jsx(ContentEditable, { className: "border border-indigo-500 rounded-md bg-blue-100 min-h-[64px] max-h-[140px] overflow-y-auto px-3 py-2 text-sm" }), ErrorBoundary: LexicalErrorBoundary, "aria-placeholder": t("enter_message"), placeholder: _jsx("div", { className: "absolute top-2 left-7 pointer-events-none", children: _jsx("p", { className: "text-gray-500 text-sm", children: t("enter_message") }) }) }) }), _jsx(ActionBar, {})] }), _jsx(LinkPlugin, {}), _jsx(ListPlugin, {}), _jsx(EnterHandler, {})] }) }));
|
|
65
70
|
};
|
|
66
71
|
export default MessageFooterProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/message/item/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EACL,WAAW,IAAI,eAAe,EAE/B,MAAM,yBAAyB,CAAC;AAYjC,UAAU,gBAAgB;IACxB,OAAO,EAAE,eAAe,CAAC;IACzB,WAAW,EAAE,eAAe,EAAE,CAAC;CAChC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/message/item/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EACL,WAAW,IAAI,eAAe,EAE/B,MAAM,yBAAyB,CAAC;AAYjC,UAAU,gBAAgB;IACxB,OAAO,EAAE,eAAe,CAAC;IACzB,WAAW,EAAE,eAAe,EAAE,CAAC;CAChC;AAED,QAAA,MAAM,WAAW,GAAI,0BAA0B,gBAAgB,mDAkH9D,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -11,7 +11,6 @@ import VideoMessageItem from "./VideoMessage";
|
|
|
11
11
|
import { getVisibleNeighbor, visibleTypeMessage, } from "../../../hooks/message/useMessage";
|
|
12
12
|
import { MSG_ITEM_CONTENT_PREFIX, MSG_ITEM_PREFIX } from "../../../constants";
|
|
13
13
|
import { formatTimestamp } from "../../../utils/common";
|
|
14
|
-
const BREAK_TIME = 5;
|
|
15
14
|
const MessageItem = ({ message, allMessages }) => {
|
|
16
15
|
var _a, _b, _c, _d;
|
|
17
16
|
const { user } = useChatContext();
|
|
@@ -40,12 +39,13 @@ const MessageItem = ({ message, allMessages }) => {
|
|
|
40
39
|
const prevSameUser = (previousMessage === null || previousMessage === void 0 ? void 0 : previousMessage.sendID) === (message === null || message === void 0 ? void 0 : message.sendID);
|
|
41
40
|
const nextSameUser = (nextMessage === null || nextMessage === void 0 ? void 0 : nextMessage.sendID) === (message === null || message === void 0 ? void 0 : message.sendID);
|
|
42
41
|
const prevTimeBreak = !previousMessage ||
|
|
43
|
-
dayjs(message.sendTime).
|
|
44
|
-
BREAK_TIME;
|
|
42
|
+
!dayjs(message.sendTime).isSame(previousMessage.sendTime, "days");
|
|
45
43
|
const showTimeBreak = prevTimeBreak;
|
|
46
44
|
const showSenderAvatar = !nextSameUser;
|
|
47
45
|
const showSenderName = !prevSameUser && !isMine;
|
|
48
|
-
return (_jsxs("div", { className: "flex flex-col gap-2 py-1 px-3 sm:p x-4", id: `${MSG_ITEM_PREFIX}${message === null || message === void 0 ? void 0 : message.clientMsgID}`, children: [showTimeBreak && (_jsx("div", { className: "flex justify-center", children: _jsx("span", { className: "text-xs text-gray-600 text-center bg-neutral-100 px-2 py-1 rounded-full", children: formatTimestamp(message.sendTime
|
|
46
|
+
return (_jsxs("div", { className: "flex flex-col gap-2 py-1 px-3 sm:p x-4", id: `${MSG_ITEM_PREFIX}${message === null || message === void 0 ? void 0 : message.clientMsgID}`, children: [showTimeBreak && (_jsx("div", { className: "flex justify-center", children: _jsx("span", { className: "text-xs text-gray-600 text-center bg-neutral-100 px-2 py-1 rounded-full", children: formatTimestamp(message.sendTime, {
|
|
47
|
+
dateMonthFormat: "DD MMMM",
|
|
48
|
+
}) }) })), _jsx("div", { className: clsx("flex", isMine ? "justify-end" : "justify-start"), children: _jsxs("div", { className: clsx("flex flex-1 items-end gap-2", isMine ? "justify-end" : "justify-start"), children: [!isMine && (_jsx("div", { className: "flex items-center justify-center w-[32px] h-[32px]", children: showSenderAvatar && (_jsx(Avatar, { src: message === null || message === void 0 ? void 0 : message.senderFaceUrl, children: ((_b = (_a = message === null || message === void 0 ? void 0 : message.senderNickname) === null || _a === void 0 ? void 0 : _a.charAt) === null || _b === void 0 ? void 0 : _b.call(_a, 0)) || "A" })) })), _jsxs("div", { className: clsx("flex flex-col flex-[0.8]", isMine ? "items-end" : "items-start"), children: [showSenderName && (_jsx("span", { className: "text-xs text-gray-500 mb-1 px-3", children: message === null || message === void 0 ? void 0 : message.senderNickname })), _jsxs("div", { className: clsx("px-3 py-2 rounded-2xl max-w-full break-words flex flex-col flex-1 text-gray-900 gap-1", isMine ? "bg-blue-100" : "bg-white"), id: `${MSG_ITEM_CONTENT_PREFIX}${message === null || message === void 0 ? void 0 : message.clientMsgID}`, children: [(message === null || message === void 0 ? void 0 : message.contentType) === MessageType.MergeMessage ? (_jsxs("div", { children: [(_d = (_c = message === null || message === void 0 ? void 0 : message.mergeElem) === null || _c === void 0 ? void 0 : _c.multiMessage) === null || _d === void 0 ? void 0 : _d.map((item) => {
|
|
49
49
|
return renderMessageByType(item);
|
|
50
50
|
}), (message === null || message === void 0 ? void 0 : message.textElem) && _jsx(TextMessageItem, { message: message })] })) : (renderMessageByType(message)), _jsx("span", { className: clsx("text-xs text-gray-500 text-right text-gray-500"), children: dayjs(message === null || message === void 0 ? void 0 : message.sendTime).format("HH:mm") })] })] })] }) }, message === null || message === void 0 ? void 0 : message.clientMsgID)] }, message === null || message === void 0 ? void 0 : message.clientMsgID));
|
|
51
51
|
};
|
|
@@ -43,7 +43,7 @@ const SearchItemAsMessage = (props) => {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
return (_jsxs("div", { className: "py-3 px-2 flex items-center gap-3 hover:bg-gray-100 hover:rounded-sm cursor-pointer border-b mx-1", onClick: onPressItem, children: [_jsx("div", { children: _jsx(Avatar, { size: "large", src: message.senderFaceUrl, alt: message.senderNickname, children: message.senderNickname.charAt(0).toUpperCase() }) }), _jsxs("div", { className: "flex flex-col flex-1 min-w-0 gap-1", children: [_jsxs("div", { className: "flex flex-1 items-center justify-between", children: [_jsx("span", { className: "text-sm flex-1 font-semibold truncate", children: message.senderNickname }), _jsx("span", { className: "text-xs text-gray-500", children: formatTimestamp(message.sendTime, {
|
|
46
|
-
hasTime:
|
|
46
|
+
hasTime: true,
|
|
47
47
|
}) })] }), _jsx("div", { className: "flex flex-col flex-1 min-w-0", children: _jsx("span", { className: "text-xs flex-1 text-gray-500 truncate", dangerouslySetInnerHTML: {
|
|
48
48
|
__html: highlightSearch(msgContent, searchTerm),
|
|
49
49
|
} }) })] })] }, message.clientMsgID));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,WAAW,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAQ7E,eAAO,MAAM,kBAAkB,eAc9B,CAAC;AAEF,eAAO,MAAM,UAAU,GACrB,gBAAgB,MAAM,EACtB,oBAAoB,MAAM;;;;;qBAML,WAAW,EAAE;;;;;;qBAAb,WAAW,EAAE;;;;;;
|
|
1
|
+
{"version":3,"file":"useMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,WAAW,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAQ7E,eAAO,MAAM,kBAAkB,eAc9B,CAAC;AAEF,eAAO,MAAM,UAAU,GACrB,gBAAgB,MAAM,EACtB,oBAAoB,MAAM;;;;;qBAML,WAAW,EAAE;;;;;;qBAAb,WAAW,EAAE;;;;;;CAuMnC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,SAAS,WAAW,SACpB,CAAC;AAChC,eAAO,MAAM,gBAAgB,GAAI,SAAS,WAAW,SACpB,CAAC;AAElC,eAAO,MAAM,kBAAkB,GAC7B,aAAa,WAAW,EAAE,EAC1B,SAAS,WAAW,EACpB,WAAW,MAAM,GAAG,MAAM,KACzB,WAAW,GAAG,SAkBhB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MergerMsgParams, MessageItem } from "@openim/wasm-client-sdk";
|
|
2
2
|
import { ExtendMessageInfo, FileMsgParamsByFile, ImageMsgParamsByFile, VideoMsgParamsByFile } from "../../types/chat";
|
|
3
3
|
import { UploadFile } from "antd";
|
|
4
|
+
import { ISessionByStatus } from "../../store/type";
|
|
4
5
|
export declare const createTextMessage: (text: string) => Promise<MessageItem | null>;
|
|
5
6
|
export declare const createImageMessageByFile: (file: ImageMsgParamsByFile) => Promise<MessageItem | null>;
|
|
6
7
|
export declare const createMergerMessage: (mergerMsgParams: MergerMsgParams) => Promise<MessageItem | null>;
|
|
@@ -8,17 +9,20 @@ export declare const createVideoMessageByFile: (file: VideoMsgParamsByFile) => P
|
|
|
8
9
|
export declare const createFileMessageByFile: (file: FileMsgParamsByFile) => Promise<MessageItem | null>;
|
|
9
10
|
export declare const createUrlTextMessage: (text: string, urls: string[]) => Promise<MessageItem | null>;
|
|
10
11
|
export declare const useSendMessage: () => {
|
|
11
|
-
sendTextMessage: ({ plainText, richText, }: {
|
|
12
|
+
sendTextMessage: ({ plainText, richText, currentSession, }: {
|
|
12
13
|
plainText: string;
|
|
13
14
|
richText: string;
|
|
15
|
+
currentSession?: ISessionByStatus;
|
|
14
16
|
}) => Promise<void>;
|
|
15
|
-
sendMergeMessage: ({ richText, plainText, files, }: {
|
|
17
|
+
sendMergeMessage: ({ richText, plainText, files, currentSession, }: {
|
|
16
18
|
richText: string;
|
|
17
19
|
plainText: string;
|
|
18
20
|
files: UploadFile[];
|
|
21
|
+
currentSession?: ISessionByStatus;
|
|
19
22
|
}) => Promise<void>;
|
|
20
23
|
};
|
|
21
|
-
export declare const generateExtendMessageInfo: ({ richText, }: {
|
|
24
|
+
export declare const generateExtendMessageInfo: ({ richText, currentSession, }: {
|
|
22
25
|
richText?: string;
|
|
26
|
+
currentSession?: ISessionByStatus;
|
|
23
27
|
}) => ExtendMessageInfo;
|
|
24
28
|
//# sourceMappingURL=useSendMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSendMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useSendMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,WAAW,EAIZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAEL,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AA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
|
@@ -93,7 +93,7 @@ export const useSendMessage = () => {
|
|
|
93
93
|
updateOneMessage(Object.assign(Object.assign({}, message), { status: MessageStatus.Failed }));
|
|
94
94
|
}
|
|
95
95
|
}, [recvID, groupID]);
|
|
96
|
-
const sendTextMessage = useCallback(async ({ plainText, richText, }) => {
|
|
96
|
+
const sendTextMessage = useCallback(async ({ plainText, richText, currentSession, }) => {
|
|
97
97
|
if (!recvID && !groupID)
|
|
98
98
|
return;
|
|
99
99
|
const urls = extractLinks(plainText);
|
|
@@ -109,11 +109,12 @@ export const useSendMessage = () => {
|
|
|
109
109
|
return;
|
|
110
110
|
const extendMessageInfo = generateExtendMessageInfo({
|
|
111
111
|
richText,
|
|
112
|
+
currentSession,
|
|
112
113
|
});
|
|
113
114
|
let messageItem = Object.assign(Object.assign({}, message), { ex: JSON.stringify(extendMessageInfo) || "{}" });
|
|
114
115
|
sendMessage(messageItem);
|
|
115
116
|
}, [recvID, groupID, user, sendMessage]);
|
|
116
|
-
const sendMergeMessage = useCallback(async ({ richText, plainText, files, }) => {
|
|
117
|
+
const sendMergeMessage = useCallback(async ({ richText, plainText, files, currentSession, }) => {
|
|
117
118
|
if (!recvID && !groupID)
|
|
118
119
|
return;
|
|
119
120
|
const messageList = [];
|
|
@@ -193,17 +194,18 @@ export const useSendMessage = () => {
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
if (!!plainText && plainText.trim() !== "") {
|
|
196
|
-
const extendMessageInfo = generateExtendMessageInfo({
|
|
197
|
-
richText,
|
|
198
|
-
});
|
|
199
197
|
const textMessage = await createTextMessage(plainText);
|
|
200
198
|
if (!textMessage)
|
|
201
199
|
return;
|
|
202
|
-
|
|
203
|
-
messageList.push(messageItem);
|
|
200
|
+
messageList.push(textMessage);
|
|
204
201
|
}
|
|
205
202
|
for (const message of messageList) {
|
|
206
|
-
|
|
203
|
+
const extendMessageInfo = generateExtendMessageInfo({
|
|
204
|
+
richText,
|
|
205
|
+
currentSession,
|
|
206
|
+
});
|
|
207
|
+
const mMessage = Object.assign(Object.assign({}, message), { ex: JSON.stringify(extendMessageInfo) || "{}" });
|
|
208
|
+
await sendMessage(mMessage);
|
|
207
209
|
}
|
|
208
210
|
}, [recvID, groupID, sendMessage]);
|
|
209
211
|
return {
|
|
@@ -211,7 +213,7 @@ export const useSendMessage = () => {
|
|
|
211
213
|
sendMergeMessage,
|
|
212
214
|
};
|
|
213
215
|
};
|
|
214
|
-
export const generateExtendMessageInfo = ({ richText, }) => {
|
|
216
|
+
export const generateExtendMessageInfo = ({ richText, currentSession, }) => {
|
|
215
217
|
return {
|
|
216
218
|
messageInfo: {
|
|
217
219
|
type: "MESSAGE_INFO",
|
|
@@ -220,6 +222,7 @@ export const generateExtendMessageInfo = ({ richText, }) => {
|
|
|
220
222
|
content: richText || "",
|
|
221
223
|
},
|
|
222
224
|
},
|
|
225
|
+
sessionId: (currentSession === null || currentSession === void 0 ? void 0 : currentSession.id) || "",
|
|
223
226
|
applicationType: useAuthStore.getState().applicationType,
|
|
224
227
|
};
|
|
225
228
|
};
|
package/dist/types/chat.d.ts
CHANGED
|
@@ -44,13 +44,7 @@ export interface ExtendMessageInfo {
|
|
|
44
44
|
content: string;
|
|
45
45
|
};
|
|
46
46
|
};
|
|
47
|
-
|
|
48
|
-
type: "SESSION_INFO";
|
|
49
|
-
data: {
|
|
50
|
-
sessionId: string;
|
|
51
|
-
applicationType: DChatApplicationType;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
47
|
+
sessionId: string;
|
|
54
48
|
applicationType: DChatApplicationType;
|
|
55
49
|
}
|
|
56
50
|
export interface MessageFooterContextType {
|
package/dist/types/chat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/types/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,mBAAmB,EACpB,MAAM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B;AAED,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,eAAe,oBAAoB;IACnC,cAAc,mBAAmB;IACjC,kBAAkB,uBAAuB;CAC1C;AAED,oBAAY,wBAAwB;IAClC,qBAAqB,0BAA0B;CAChD"}
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare const parseLatestMessage: (latestMsg: string, currentUserId?: str
|
|
|
3
3
|
export declare const highlightSearch: (text: string, keyword: string, maxLength?: number) => string;
|
|
4
4
|
interface FormatOptions {
|
|
5
5
|
hasTime?: boolean;
|
|
6
|
+
dateMonthFormat?: string;
|
|
6
7
|
}
|
|
7
8
|
export declare function formatTimestamp(timestamp: number, options?: FormatOptions): string;
|
|
8
9
|
export declare function extractLinks(text: string): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAapD;AAED,eAAO,MAAM,kBAAkB,GAC7B,WAAW,MAAM,EACjB,gBAAgB,MAAM,EACtB,IAAI,GAAG,WAgCR,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,MAAM,MAAM,EACZ,SAAS,MAAM,EACf,kBAAc,WA2Cf,CAAC;AAEF,UAAU,aAAa;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAapD;AAED,eAAO,MAAM,kBAAkB,GAC7B,WAAW,MAAM,EACjB,gBAAgB,MAAM,EACtB,IAAI,GAAG,WAgCR,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,MAAM,MAAM,EACZ,SAAS,MAAM,EACf,kBAAc,WA2Cf,CAAC;AAEF,UAAU,aAAa;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,CAqBR;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAKnD"}
|
package/dist/utils/common.js
CHANGED
|
@@ -79,19 +79,23 @@ export const highlightSearch = (text, keyword, maxLength = 30) => {
|
|
|
79
79
|
return `${displayedBefore}<mark>${match}</mark>${displayedAfter}`;
|
|
80
80
|
};
|
|
81
81
|
export function formatTimestamp(timestamp, options) {
|
|
82
|
-
const { hasTime =
|
|
82
|
+
const { hasTime = false, dateMonthFormat = "DD/MM" } = options || {};
|
|
83
83
|
const date = dayjs(timestamp);
|
|
84
84
|
const now = dayjs();
|
|
85
85
|
if (date.isSame(now, "day")) {
|
|
86
86
|
// hôm nay
|
|
87
|
-
return date.format("HH:mm");
|
|
87
|
+
return hasTime ? date.format("HH:mm") : date.format(dateMonthFormat);
|
|
88
88
|
}
|
|
89
89
|
if (date.isSame(now, "year")) {
|
|
90
90
|
// cùng năm
|
|
91
|
-
return hasTime
|
|
91
|
+
return hasTime
|
|
92
|
+
? date.format(`HH:mm ${dateMonthFormat}`)
|
|
93
|
+
: date.format(dateMonthFormat);
|
|
92
94
|
}
|
|
93
95
|
// khác năm
|
|
94
|
-
return hasTime
|
|
96
|
+
return hasTime
|
|
97
|
+
? date.format(`HH:mm ${dateMonthFormat} YYYY`)
|
|
98
|
+
: date.format(`${dateMonthFormat} YYYY`);
|
|
95
99
|
}
|
|
96
100
|
export function extractLinks(text) {
|
|
97
101
|
// Regex match http:// hoặc https:// và domain
|