@scalemule/chat 0.0.7 → 0.0.8
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/react.cjs +159 -111
- package/dist/react.js +83 -35
- package/package.json +1 -1
- package/dist/ChatClient-DQPHdUHX.d.cts +0 -107
- package/dist/ChatClient-DtUKF-4c.d.ts +0 -107
- package/dist/constants.d.ts +0 -9
- package/dist/constants.d.ts.map +0 -1
- package/dist/core/ChatClient.d.ts +0 -96
- package/dist/core/ChatClient.d.ts.map +0 -1
- package/dist/core/EventEmitter.d.ts +0 -11
- package/dist/core/EventEmitter.d.ts.map +0 -1
- package/dist/core/MessageCache.d.ts +0 -18
- package/dist/core/MessageCache.d.ts.map +0 -1
- package/dist/core/OfflineQueue.d.ts +0 -19
- package/dist/core/OfflineQueue.d.ts.map +0 -1
- package/dist/element.d.cts +0 -2
- package/dist/element.d.ts +0 -2
- package/dist/element.d.ts.map +0 -1
- package/dist/embed/index.d.ts +0 -2
- package/dist/embed/index.d.ts.map +0 -1
- package/dist/factory.d.ts +0 -8
- package/dist/factory.d.ts.map +0 -1
- package/dist/iframe.d.cts +0 -17
- package/dist/iframe.d.ts +0 -15
- package/dist/iframe.d.ts.map +0 -1
- package/dist/index.d.cts +0 -166
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +0 -1
- package/dist/react-components/ChatInput.d.ts +0 -16
- package/dist/react-components/ChatInput.d.ts.map +0 -1
- package/dist/react-components/ChatMessageItem.d.ts +0 -13
- package/dist/react-components/ChatMessageItem.d.ts.map +0 -1
- package/dist/react-components/ChatMessageList.d.ts +0 -15
- package/dist/react-components/ChatMessageList.d.ts.map +0 -1
- package/dist/react-components/ChatThread.d.ts +0 -12
- package/dist/react-components/ChatThread.d.ts.map +0 -1
- package/dist/react-components/ConversationList.d.ts +0 -13
- package/dist/react-components/ConversationList.d.ts.map +0 -1
- package/dist/react-components/EmojiPicker.d.ts +0 -8
- package/dist/react-components/EmojiPicker.d.ts.map +0 -1
- package/dist/react-components/index.d.ts +0 -8
- package/dist/react-components/index.d.ts.map +0 -1
- package/dist/react-components/theme.d.ts +0 -19
- package/dist/react-components/theme.d.ts.map +0 -1
- package/dist/react-components/utils.d.ts +0 -4
- package/dist/react-components/utils.d.ts.map +0 -1
- package/dist/react.d.cts +0 -145
- package/dist/react.d.ts +0 -72
- package/dist/react.d.ts.map +0 -1
- package/dist/shared/ChatController.d.ts +0 -65
- package/dist/shared/ChatController.d.ts.map +0 -1
- package/dist/shared/upload.d.ts +0 -3
- package/dist/shared/upload.d.ts.map +0 -1
- package/dist/support.d.ts +0 -99
- package/dist/support.d.ts.map +0 -1
- package/dist/transport/HttpTransport.d.ts +0 -20
- package/dist/transport/HttpTransport.d.ts.map +0 -1
- package/dist/transport/WebSocketTransport.d.ts +0 -78
- package/dist/transport/WebSocketTransport.d.ts.map +0 -1
- package/dist/types-COPVrm3K.d.cts +0 -256
- package/dist/types-COPVrm3K.d.ts +0 -256
- package/dist/types.d.ts +0 -271
- package/dist/types.d.ts.map +0 -1
- package/dist/umd.d.ts +0 -6
- package/dist/umd.d.ts.map +0 -1
- package/dist/version.d.ts +0 -2
- package/dist/version.d.ts.map +0 -1
- package/dist/widget/icons.d.ts +0 -8
- package/dist/widget/icons.d.ts.map +0 -1
- package/dist/widget/index.d.ts +0 -2
- package/dist/widget/index.d.ts.map +0 -1
- package/dist/widget/storage.d.ts +0 -5
- package/dist/widget/storage.d.ts.map +0 -1
- package/dist/widget/styles.d.ts +0 -3
- package/dist/widget/styles.d.ts.map +0 -1
package/dist/react.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkW2PWFS3E_cjs = require('./chunk-W2PWFS3E.cjs');
|
|
4
|
-
var
|
|
4
|
+
var React4 = require('react');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var reactDom = require('react-dom');
|
|
6
7
|
|
|
7
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
+
var React4__default = /*#__PURE__*/_interopDefault(React4);
|
|
10
11
|
|
|
11
12
|
function ChatInput({
|
|
12
13
|
onSend,
|
|
@@ -14,13 +15,13 @@ function ChatInput({
|
|
|
14
15
|
onUploadAttachment,
|
|
15
16
|
placeholder = "Type a message..."
|
|
16
17
|
}) {
|
|
17
|
-
const [content, setContent] =
|
|
18
|
-
const [attachments, setAttachments] =
|
|
19
|
-
const [isSending, setIsSending] =
|
|
20
|
-
const [isDragging, setIsDragging] =
|
|
21
|
-
const fileInputRef =
|
|
22
|
-
const typingTimeoutRef =
|
|
23
|
-
const readyAttachments =
|
|
18
|
+
const [content, setContent] = React4.useState("");
|
|
19
|
+
const [attachments, setAttachments] = React4.useState([]);
|
|
20
|
+
const [isSending, setIsSending] = React4.useState(false);
|
|
21
|
+
const [isDragging, setIsDragging] = React4.useState(false);
|
|
22
|
+
const fileInputRef = React4.useRef(null);
|
|
23
|
+
const typingTimeoutRef = React4.useRef(null);
|
|
24
|
+
const readyAttachments = React4.useMemo(
|
|
24
25
|
() => attachments.filter((attachment) => attachment.attachment).map((attachment) => attachment.attachment),
|
|
25
26
|
[attachments]
|
|
26
27
|
);
|
|
@@ -235,43 +236,90 @@ function ChatInput({
|
|
|
235
236
|
}
|
|
236
237
|
);
|
|
237
238
|
}
|
|
238
|
-
var
|
|
239
|
+
var QUICK_REACTIONS = ["\u2764\uFE0F", "\u{1F602}", "\u{1F44D}", "\u{1F525}", "\u{1F62E}", "\u{1F622}", "\u{1F44F}", "\u{1F64C}"];
|
|
239
240
|
function EmojiPicker({
|
|
240
241
|
onSelect,
|
|
241
|
-
|
|
242
|
+
onClose,
|
|
243
|
+
anchorRef,
|
|
244
|
+
emojis = QUICK_REACTIONS
|
|
242
245
|
}) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
style: {
|
|
262
|
-
width: 32,
|
|
263
|
-
height: 32,
|
|
264
|
-
border: "none",
|
|
265
|
-
background: "transparent",
|
|
266
|
-
borderRadius: 999,
|
|
267
|
-
cursor: "pointer",
|
|
268
|
-
fontSize: 18
|
|
269
|
-
},
|
|
270
|
-
children: emoji
|
|
271
|
-
},
|
|
272
|
-
emoji
|
|
273
|
-
))
|
|
246
|
+
const ref = React4.useRef(null);
|
|
247
|
+
const [position, setPosition] = React4.useState(null);
|
|
248
|
+
React4.useEffect(() => {
|
|
249
|
+
const anchor = anchorRef.current;
|
|
250
|
+
if (!anchor) return;
|
|
251
|
+
const rect = anchor.getBoundingClientRect();
|
|
252
|
+
const pickerWidth = emojis.length * 36 + 16;
|
|
253
|
+
let left = rect.left + rect.width / 2 - pickerWidth / 2;
|
|
254
|
+
if (left < 8) left = 8;
|
|
255
|
+
if (left + pickerWidth > window.innerWidth - 8)
|
|
256
|
+
left = window.innerWidth - 8 - pickerWidth;
|
|
257
|
+
setPosition({ top: rect.top - 8, left });
|
|
258
|
+
}, [anchorRef, emojis.length]);
|
|
259
|
+
React4.useEffect(() => {
|
|
260
|
+
function handleClickOutside(e) {
|
|
261
|
+
if (ref.current && !ref.current.contains(e.target) && anchorRef.current && !anchorRef.current.contains(e.target)) {
|
|
262
|
+
onClose();
|
|
263
|
+
}
|
|
274
264
|
}
|
|
265
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
266
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
267
|
+
}, [onClose, anchorRef]);
|
|
268
|
+
if (!position) return null;
|
|
269
|
+
return reactDom.createPortal(
|
|
270
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
271
|
+
"div",
|
|
272
|
+
{
|
|
273
|
+
ref,
|
|
274
|
+
style: {
|
|
275
|
+
position: "fixed",
|
|
276
|
+
top: position.top,
|
|
277
|
+
left: position.left,
|
|
278
|
+
transform: "translateY(-100%)",
|
|
279
|
+
background: "var(--sm-surface, #fff)",
|
|
280
|
+
border: "1px solid var(--sm-border-color, #e5e7eb)",
|
|
281
|
+
borderRadius: 12,
|
|
282
|
+
boxShadow: "0 10px 25px rgba(15, 23, 42, 0.12)",
|
|
283
|
+
padding: 8,
|
|
284
|
+
display: "flex",
|
|
285
|
+
gap: 4,
|
|
286
|
+
zIndex: 9999
|
|
287
|
+
},
|
|
288
|
+
children: emojis.map((emoji) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
289
|
+
"button",
|
|
290
|
+
{
|
|
291
|
+
onClick: () => {
|
|
292
|
+
onSelect(emoji);
|
|
293
|
+
onClose();
|
|
294
|
+
},
|
|
295
|
+
type: "button",
|
|
296
|
+
"aria-label": `React with ${emoji}`,
|
|
297
|
+
style: {
|
|
298
|
+
width: 32,
|
|
299
|
+
height: 32,
|
|
300
|
+
display: "flex",
|
|
301
|
+
alignItems: "center",
|
|
302
|
+
justifyContent: "center",
|
|
303
|
+
borderRadius: 8,
|
|
304
|
+
border: "none",
|
|
305
|
+
background: "transparent",
|
|
306
|
+
cursor: "pointer",
|
|
307
|
+
fontSize: 18,
|
|
308
|
+
transition: "background 0.15s ease"
|
|
309
|
+
},
|
|
310
|
+
onMouseEnter: (e) => {
|
|
311
|
+
e.target.style.background = "var(--sm-surface-muted, #f8fafc)";
|
|
312
|
+
},
|
|
313
|
+
onMouseLeave: (e) => {
|
|
314
|
+
e.target.style.background = "transparent";
|
|
315
|
+
},
|
|
316
|
+
children: emoji
|
|
317
|
+
},
|
|
318
|
+
emoji
|
|
319
|
+
))
|
|
320
|
+
}
|
|
321
|
+
),
|
|
322
|
+
document.body
|
|
275
323
|
);
|
|
276
324
|
}
|
|
277
325
|
|
|
@@ -391,10 +439,10 @@ function ChatMessageItem({
|
|
|
391
439
|
onReport,
|
|
392
440
|
highlight = false
|
|
393
441
|
}) {
|
|
394
|
-
const [showPicker, setShowPicker] =
|
|
442
|
+
const [showPicker, setShowPicker] = React4.useState(false);
|
|
395
443
|
const isOwn = Boolean(currentUserId && message.sender_id === currentUserId);
|
|
396
444
|
const canReact = Boolean(onAddReaction || onRemoveReaction);
|
|
397
|
-
const reactionEntries =
|
|
445
|
+
const reactionEntries = React4.useMemo(() => message.reactions ?? [], [message.reactions]);
|
|
398
446
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
399
447
|
"div",
|
|
400
448
|
{
|
|
@@ -529,13 +577,13 @@ function ChatMessageList({
|
|
|
529
577
|
onReport,
|
|
530
578
|
emptyState
|
|
531
579
|
}) {
|
|
532
|
-
const containerRef =
|
|
533
|
-
const unreadMarkerRef =
|
|
534
|
-
const lastMessageCountRef =
|
|
535
|
-
const didScrollToUnreadRef =
|
|
536
|
-
const [showJumpToLatest, setShowJumpToLatest] =
|
|
537
|
-
const unreadIndex =
|
|
538
|
-
|
|
580
|
+
const containerRef = React4.useRef(null);
|
|
581
|
+
const unreadMarkerRef = React4.useRef(null);
|
|
582
|
+
const lastMessageCountRef = React4.useRef(messages.length);
|
|
583
|
+
const didScrollToUnreadRef = React4.useRef(false);
|
|
584
|
+
const [showJumpToLatest, setShowJumpToLatest] = React4.useState(false);
|
|
585
|
+
const unreadIndex = React4.useMemo(() => getUnreadIndex(messages, unreadSince), [messages, unreadSince]);
|
|
586
|
+
React4.useEffect(() => {
|
|
539
587
|
const container = containerRef.current;
|
|
540
588
|
if (!container) return;
|
|
541
589
|
const distanceFromBottom = container.scrollHeight - container.scrollTop - container.clientHeight;
|
|
@@ -548,7 +596,7 @@ function ChatMessageList({
|
|
|
548
596
|
}
|
|
549
597
|
lastMessageCountRef.current = messages.length;
|
|
550
598
|
}, [messages]);
|
|
551
|
-
|
|
599
|
+
React4.useEffect(() => {
|
|
552
600
|
if (!scrollToUnreadOnMount || unreadIndex < 0 || didScrollToUnreadRef.current) {
|
|
553
601
|
return;
|
|
554
602
|
}
|
|
@@ -595,7 +643,7 @@ function ChatMessageList({
|
|
|
595
643
|
const previousMessage = messages[index - 1];
|
|
596
644
|
const showDateDivider = !previousMessage || !isSameDay(previousMessage.created_at, message.created_at);
|
|
597
645
|
const showUnreadDivider = unreadIndex === index;
|
|
598
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
646
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(React4__default.default.Fragment, { children: [
|
|
599
647
|
showDateDivider ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
600
648
|
"div",
|
|
601
649
|
{
|
|
@@ -720,19 +768,19 @@ function ChatThread({
|
|
|
720
768
|
} = useChat(conversationId);
|
|
721
769
|
const { typingUsers, sendTyping } = useTyping(conversationId);
|
|
722
770
|
const { members } = usePresence(conversationId);
|
|
723
|
-
const ownReadStatus =
|
|
771
|
+
const ownReadStatus = React4.useMemo(
|
|
724
772
|
() => resolvedUserId ? readStatuses.find((status) => status.user_id === resolvedUserId)?.last_read_at : void 0,
|
|
725
773
|
[readStatuses, resolvedUserId]
|
|
726
774
|
);
|
|
727
|
-
const otherTypingUsers =
|
|
775
|
+
const otherTypingUsers = React4.useMemo(
|
|
728
776
|
() => typingUsers.filter((userId) => userId !== resolvedUserId),
|
|
729
777
|
[typingUsers, resolvedUserId]
|
|
730
778
|
);
|
|
731
|
-
const activeMembers =
|
|
779
|
+
const activeMembers = React4.useMemo(
|
|
732
780
|
() => members.filter((member) => member.userId !== resolvedUserId),
|
|
733
781
|
[members, resolvedUserId]
|
|
734
782
|
);
|
|
735
|
-
|
|
783
|
+
React4.useEffect(() => {
|
|
736
784
|
if (!messages.length) return;
|
|
737
785
|
void markRead();
|
|
738
786
|
}, [markRead, messages.length, messages[messages.length - 1]?.id]);
|
|
@@ -871,8 +919,8 @@ function ConversationList({
|
|
|
871
919
|
const { conversations, isLoading } = useConversations({
|
|
872
920
|
conversationType
|
|
873
921
|
});
|
|
874
|
-
const [search, setSearch] =
|
|
875
|
-
const filtered =
|
|
922
|
+
const [search, setSearch] = React4.useState("");
|
|
923
|
+
const filtered = React4.useMemo(() => {
|
|
876
924
|
const query = search.trim().toLowerCase();
|
|
877
925
|
if (!query) return conversations;
|
|
878
926
|
return conversations.filter((conversation) => {
|
|
@@ -1019,15 +1067,15 @@ function ConversationList({
|
|
|
1019
1067
|
}
|
|
1020
1068
|
);
|
|
1021
1069
|
}
|
|
1022
|
-
var ChatContext =
|
|
1070
|
+
var ChatContext = React4.createContext(null);
|
|
1023
1071
|
function useChatContext() {
|
|
1024
|
-
const ctx =
|
|
1072
|
+
const ctx = React4.useContext(ChatContext);
|
|
1025
1073
|
if (!ctx) throw new Error("useChatContext must be used within a ChatProvider");
|
|
1026
1074
|
return ctx;
|
|
1027
1075
|
}
|
|
1028
1076
|
function ChatProvider({ config, children }) {
|
|
1029
|
-
const [client] =
|
|
1030
|
-
|
|
1077
|
+
const [client] = React4.useState(() => new chunkW2PWFS3E_cjs.ChatClient(config));
|
|
1078
|
+
React4.useEffect(() => {
|
|
1031
1079
|
return () => {
|
|
1032
1080
|
client.destroy();
|
|
1033
1081
|
};
|
|
@@ -1042,28 +1090,28 @@ function useChatConfig() {
|
|
|
1042
1090
|
}
|
|
1043
1091
|
function useConnection() {
|
|
1044
1092
|
const { client } = useChatContext();
|
|
1045
|
-
const [status, setStatus] =
|
|
1046
|
-
|
|
1093
|
+
const [status, setStatus] = React4.useState(client.status);
|
|
1094
|
+
React4.useEffect(() => {
|
|
1047
1095
|
return client.on("connected", () => setStatus("connected"));
|
|
1048
1096
|
}, [client]);
|
|
1049
|
-
|
|
1097
|
+
React4.useEffect(() => {
|
|
1050
1098
|
return client.on("disconnected", () => setStatus("disconnected"));
|
|
1051
1099
|
}, [client]);
|
|
1052
|
-
|
|
1100
|
+
React4.useEffect(() => {
|
|
1053
1101
|
return client.on("reconnecting", () => setStatus("reconnecting"));
|
|
1054
1102
|
}, [client]);
|
|
1055
|
-
const connect =
|
|
1056
|
-
const disconnect =
|
|
1103
|
+
const connect = React4.useCallback(() => client.connect(), [client]);
|
|
1104
|
+
const disconnect = React4.useCallback(() => client.disconnect(), [client]);
|
|
1057
1105
|
return { status, connect, disconnect };
|
|
1058
1106
|
}
|
|
1059
1107
|
function useChat(conversationId) {
|
|
1060
1108
|
const { client } = useChatContext();
|
|
1061
|
-
const [messages, setMessages] =
|
|
1062
|
-
const [readStatuses, setReadStatuses] =
|
|
1063
|
-
const [isLoading, setIsLoading] =
|
|
1064
|
-
const [error, setError] =
|
|
1065
|
-
const [hasMore, setHasMore] =
|
|
1066
|
-
|
|
1109
|
+
const [messages, setMessages] = React4.useState([]);
|
|
1110
|
+
const [readStatuses, setReadStatuses] = React4.useState([]);
|
|
1111
|
+
const [isLoading, setIsLoading] = React4.useState(false);
|
|
1112
|
+
const [error, setError] = React4.useState(null);
|
|
1113
|
+
const [hasMore, setHasMore] = React4.useState(false);
|
|
1114
|
+
React4.useEffect(() => {
|
|
1067
1115
|
if (!conversationId) return;
|
|
1068
1116
|
setIsLoading(true);
|
|
1069
1117
|
setError(null);
|
|
@@ -1094,7 +1142,7 @@ function useChat(conversationId) {
|
|
|
1094
1142
|
unsub?.();
|
|
1095
1143
|
};
|
|
1096
1144
|
}, [client, conversationId]);
|
|
1097
|
-
|
|
1145
|
+
React4.useEffect(() => {
|
|
1098
1146
|
if (!conversationId) return;
|
|
1099
1147
|
return client.on("message", ({ message, conversationId: convId }) => {
|
|
1100
1148
|
if (convId === conversationId) {
|
|
@@ -1102,7 +1150,7 @@ function useChat(conversationId) {
|
|
|
1102
1150
|
}
|
|
1103
1151
|
});
|
|
1104
1152
|
}, [client, conversationId]);
|
|
1105
|
-
|
|
1153
|
+
React4.useEffect(() => {
|
|
1106
1154
|
if (!conversationId) return;
|
|
1107
1155
|
return client.on("message:updated", ({ message, conversationId: convId }) => {
|
|
1108
1156
|
if (convId === conversationId) {
|
|
@@ -1110,7 +1158,7 @@ function useChat(conversationId) {
|
|
|
1110
1158
|
}
|
|
1111
1159
|
});
|
|
1112
1160
|
}, [client, conversationId]);
|
|
1113
|
-
|
|
1161
|
+
React4.useEffect(() => {
|
|
1114
1162
|
if (!conversationId) return;
|
|
1115
1163
|
return client.on("message:deleted", ({ messageId, conversationId: convId }) => {
|
|
1116
1164
|
if (convId === conversationId) {
|
|
@@ -1118,7 +1166,7 @@ function useChat(conversationId) {
|
|
|
1118
1166
|
}
|
|
1119
1167
|
});
|
|
1120
1168
|
}, [client, conversationId]);
|
|
1121
|
-
|
|
1169
|
+
React4.useEffect(() => {
|
|
1122
1170
|
if (!conversationId) return;
|
|
1123
1171
|
return client.on("reaction", ({ conversationId: convId }) => {
|
|
1124
1172
|
if (convId === conversationId) {
|
|
@@ -1126,7 +1174,7 @@ function useChat(conversationId) {
|
|
|
1126
1174
|
}
|
|
1127
1175
|
});
|
|
1128
1176
|
}, [client, conversationId]);
|
|
1129
|
-
|
|
1177
|
+
React4.useEffect(() => {
|
|
1130
1178
|
if (!conversationId) return;
|
|
1131
1179
|
return client.on("read", ({ conversationId: convId, userId, lastReadAt }) => {
|
|
1132
1180
|
if (convId !== conversationId) return;
|
|
@@ -1141,14 +1189,14 @@ function useChat(conversationId) {
|
|
|
1141
1189
|
});
|
|
1142
1190
|
});
|
|
1143
1191
|
}, [client, conversationId]);
|
|
1144
|
-
const sendMessage =
|
|
1192
|
+
const sendMessage = React4.useCallback(
|
|
1145
1193
|
async (content, options) => {
|
|
1146
1194
|
if (!conversationId) return;
|
|
1147
1195
|
return client.sendMessage(conversationId, { content, ...options });
|
|
1148
1196
|
},
|
|
1149
1197
|
[client, conversationId]
|
|
1150
1198
|
);
|
|
1151
|
-
const loadMore =
|
|
1199
|
+
const loadMore = React4.useCallback(async () => {
|
|
1152
1200
|
if (!conversationId || !messages.length) return;
|
|
1153
1201
|
const oldestId = messages[0]?.id;
|
|
1154
1202
|
const result = await client.getMessages(conversationId, { before: oldestId });
|
|
@@ -1157,7 +1205,7 @@ function useChat(conversationId) {
|
|
|
1157
1205
|
setHasMore(result.data.has_more ?? false);
|
|
1158
1206
|
}
|
|
1159
1207
|
}, [client, conversationId, messages]);
|
|
1160
|
-
const editMessage =
|
|
1208
|
+
const editMessage = React4.useCallback(
|
|
1161
1209
|
async (messageId, content) => {
|
|
1162
1210
|
const result = await client.editMessage(messageId, content);
|
|
1163
1211
|
if (result.error) {
|
|
@@ -1167,7 +1215,7 @@ function useChat(conversationId) {
|
|
|
1167
1215
|
},
|
|
1168
1216
|
[client]
|
|
1169
1217
|
);
|
|
1170
|
-
const deleteMessage =
|
|
1218
|
+
const deleteMessage = React4.useCallback(
|
|
1171
1219
|
async (messageId) => {
|
|
1172
1220
|
const result = await client.deleteMessage(messageId);
|
|
1173
1221
|
if (result.error) {
|
|
@@ -1177,7 +1225,7 @@ function useChat(conversationId) {
|
|
|
1177
1225
|
},
|
|
1178
1226
|
[client]
|
|
1179
1227
|
);
|
|
1180
|
-
const addReaction =
|
|
1228
|
+
const addReaction = React4.useCallback(
|
|
1181
1229
|
async (messageId, emoji) => {
|
|
1182
1230
|
const result = await client.addReaction(messageId, emoji);
|
|
1183
1231
|
if (result.error) {
|
|
@@ -1187,7 +1235,7 @@ function useChat(conversationId) {
|
|
|
1187
1235
|
},
|
|
1188
1236
|
[client]
|
|
1189
1237
|
);
|
|
1190
|
-
const removeReaction =
|
|
1238
|
+
const removeReaction = React4.useCallback(
|
|
1191
1239
|
async (messageId, emoji) => {
|
|
1192
1240
|
const result = await client.removeReaction(messageId, emoji);
|
|
1193
1241
|
if (result.error) {
|
|
@@ -1197,7 +1245,7 @@ function useChat(conversationId) {
|
|
|
1197
1245
|
},
|
|
1198
1246
|
[client]
|
|
1199
1247
|
);
|
|
1200
|
-
const uploadAttachment =
|
|
1248
|
+
const uploadAttachment = React4.useCallback(
|
|
1201
1249
|
async (file, onProgress, signal) => {
|
|
1202
1250
|
const result = await client.uploadAttachment(file, onProgress, signal);
|
|
1203
1251
|
if (result.error) {
|
|
@@ -1207,7 +1255,7 @@ function useChat(conversationId) {
|
|
|
1207
1255
|
},
|
|
1208
1256
|
[client]
|
|
1209
1257
|
);
|
|
1210
|
-
const refreshAttachmentUrl =
|
|
1258
|
+
const refreshAttachmentUrl = React4.useCallback(
|
|
1211
1259
|
async (messageId, fileId) => {
|
|
1212
1260
|
const result = await client.refreshAttachmentUrl(messageId, fileId);
|
|
1213
1261
|
if (result.error) {
|
|
@@ -1217,7 +1265,7 @@ function useChat(conversationId) {
|
|
|
1217
1265
|
},
|
|
1218
1266
|
[client]
|
|
1219
1267
|
);
|
|
1220
|
-
const reportMessage =
|
|
1268
|
+
const reportMessage = React4.useCallback(
|
|
1221
1269
|
async (messageId, reason, description) => {
|
|
1222
1270
|
const result = await client.reportMessage(messageId, reason, description);
|
|
1223
1271
|
if (result.error) {
|
|
@@ -1227,7 +1275,7 @@ function useChat(conversationId) {
|
|
|
1227
1275
|
},
|
|
1228
1276
|
[client]
|
|
1229
1277
|
);
|
|
1230
|
-
const muteConversation =
|
|
1278
|
+
const muteConversation = React4.useCallback(
|
|
1231
1279
|
async (mutedUntil) => {
|
|
1232
1280
|
if (!conversationId) return;
|
|
1233
1281
|
const result = await client.muteConversation(conversationId, mutedUntil);
|
|
@@ -1238,7 +1286,7 @@ function useChat(conversationId) {
|
|
|
1238
1286
|
},
|
|
1239
1287
|
[client, conversationId]
|
|
1240
1288
|
);
|
|
1241
|
-
const unmuteConversation =
|
|
1289
|
+
const unmuteConversation = React4.useCallback(async () => {
|
|
1242
1290
|
if (!conversationId) return;
|
|
1243
1291
|
const result = await client.unmuteConversation(conversationId);
|
|
1244
1292
|
if (result.error) {
|
|
@@ -1246,7 +1294,7 @@ function useChat(conversationId) {
|
|
|
1246
1294
|
}
|
|
1247
1295
|
return result;
|
|
1248
1296
|
}, [client, conversationId]);
|
|
1249
|
-
const getReadStatus =
|
|
1297
|
+
const getReadStatus = React4.useCallback(async () => {
|
|
1250
1298
|
if (!conversationId) return;
|
|
1251
1299
|
const result = await client.getReadStatus(conversationId);
|
|
1252
1300
|
if (result.data?.statuses) {
|
|
@@ -1256,7 +1304,7 @@ function useChat(conversationId) {
|
|
|
1256
1304
|
}
|
|
1257
1305
|
return result;
|
|
1258
1306
|
}, [client, conversationId]);
|
|
1259
|
-
const markRead =
|
|
1307
|
+
const markRead = React4.useCallback(async () => {
|
|
1260
1308
|
if (!conversationId) return;
|
|
1261
1309
|
await client.markRead(conversationId);
|
|
1262
1310
|
await getReadStatus();
|
|
@@ -1284,8 +1332,8 @@ function useChat(conversationId) {
|
|
|
1284
1332
|
}
|
|
1285
1333
|
function usePresence(conversationId) {
|
|
1286
1334
|
const { client } = useChatContext();
|
|
1287
|
-
const [members, setMembers] =
|
|
1288
|
-
|
|
1335
|
+
const [members, setMembers] = React4.useState([]);
|
|
1336
|
+
React4.useEffect(() => {
|
|
1289
1337
|
if (!conversationId) return;
|
|
1290
1338
|
let cancelled = false;
|
|
1291
1339
|
(async () => {
|
|
@@ -1342,9 +1390,9 @@ function usePresence(conversationId) {
|
|
|
1342
1390
|
}
|
|
1343
1391
|
function useTyping(conversationId) {
|
|
1344
1392
|
const { client } = useChatContext();
|
|
1345
|
-
const [typingUsers, setTypingUsers] =
|
|
1346
|
-
const typingTimers =
|
|
1347
|
-
|
|
1393
|
+
const [typingUsers, setTypingUsers] = React4.useState([]);
|
|
1394
|
+
const typingTimers = React4.useRef(/* @__PURE__ */ new Map());
|
|
1395
|
+
React4.useEffect(() => {
|
|
1348
1396
|
if (!conversationId) return;
|
|
1349
1397
|
const unsubTyping = client.on("typing", ({ conversationId: convId, userId }) => {
|
|
1350
1398
|
if (convId !== conversationId) return;
|
|
@@ -1377,7 +1425,7 @@ function useTyping(conversationId) {
|
|
|
1377
1425
|
typingTimers.current.clear();
|
|
1378
1426
|
};
|
|
1379
1427
|
}, [client, conversationId]);
|
|
1380
|
-
const sendTyping =
|
|
1428
|
+
const sendTyping = React4.useCallback(
|
|
1381
1429
|
(isTyping = true) => {
|
|
1382
1430
|
if (!conversationId) return;
|
|
1383
1431
|
client.sendTyping(conversationId, isTyping);
|
|
@@ -1388,10 +1436,10 @@ function useTyping(conversationId) {
|
|
|
1388
1436
|
}
|
|
1389
1437
|
function useConversations(options) {
|
|
1390
1438
|
const { client } = useChatContext();
|
|
1391
|
-
const [conversations, setConversations] =
|
|
1392
|
-
const [isLoading, setIsLoading] =
|
|
1393
|
-
const refreshTimer =
|
|
1394
|
-
const fetchConversations =
|
|
1439
|
+
const [conversations, setConversations] = React4.useState([]);
|
|
1440
|
+
const [isLoading, setIsLoading] = React4.useState(true);
|
|
1441
|
+
const refreshTimer = React4.useRef(null);
|
|
1442
|
+
const fetchConversations = React4.useCallback(async () => {
|
|
1395
1443
|
const result = await client.listConversations({
|
|
1396
1444
|
conversation_type: options?.conversationType
|
|
1397
1445
|
});
|
|
@@ -1400,10 +1448,10 @@ function useConversations(options) {
|
|
|
1400
1448
|
}
|
|
1401
1449
|
setIsLoading(false);
|
|
1402
1450
|
}, [client, options?.conversationType]);
|
|
1403
|
-
|
|
1451
|
+
React4.useEffect(() => {
|
|
1404
1452
|
fetchConversations();
|
|
1405
1453
|
}, [fetchConversations]);
|
|
1406
|
-
|
|
1454
|
+
React4.useEffect(() => {
|
|
1407
1455
|
return client.on("inbox:update", () => {
|
|
1408
1456
|
if (refreshTimer.current) clearTimeout(refreshTimer.current);
|
|
1409
1457
|
refreshTimer.current = setTimeout(() => {
|
|
@@ -1411,14 +1459,14 @@ function useConversations(options) {
|
|
|
1411
1459
|
}, 500);
|
|
1412
1460
|
});
|
|
1413
1461
|
}, [client, fetchConversations]);
|
|
1414
|
-
|
|
1462
|
+
React4.useEffect(() => {
|
|
1415
1463
|
return client.on("read", ({ conversationId }) => {
|
|
1416
1464
|
setConversations(
|
|
1417
1465
|
(prev) => prev.map((c) => c.id === conversationId ? { ...c, unread_count: 0 } : c)
|
|
1418
1466
|
);
|
|
1419
1467
|
});
|
|
1420
1468
|
}, [client]);
|
|
1421
|
-
|
|
1469
|
+
React4.useEffect(() => {
|
|
1422
1470
|
return () => {
|
|
1423
1471
|
if (refreshTimer.current) clearTimeout(refreshTimer.current);
|
|
1424
1472
|
};
|
|
@@ -1427,8 +1475,8 @@ function useConversations(options) {
|
|
|
1427
1475
|
}
|
|
1428
1476
|
function useUnreadCount() {
|
|
1429
1477
|
const { client } = useChatContext();
|
|
1430
|
-
const [totalUnread, setTotalUnread] =
|
|
1431
|
-
|
|
1478
|
+
const [totalUnread, setTotalUnread] = React4.useState(0);
|
|
1479
|
+
React4.useEffect(() => {
|
|
1432
1480
|
(async () => {
|
|
1433
1481
|
const result = await client.getUnreadTotal();
|
|
1434
1482
|
if (result.data) {
|
|
@@ -1436,12 +1484,12 @@ function useUnreadCount() {
|
|
|
1436
1484
|
}
|
|
1437
1485
|
})();
|
|
1438
1486
|
}, [client]);
|
|
1439
|
-
|
|
1487
|
+
React4.useEffect(() => {
|
|
1440
1488
|
return client.on("inbox:update", () => {
|
|
1441
1489
|
setTotalUnread((prev) => prev + 1);
|
|
1442
1490
|
});
|
|
1443
1491
|
}, [client]);
|
|
1444
|
-
|
|
1492
|
+
React4.useEffect(() => {
|
|
1445
1493
|
return client.on("read", () => {
|
|
1446
1494
|
(async () => {
|
|
1447
1495
|
const result = await client.getUnreadTotal();
|