@natoe/colab 0.1.26 → 0.1.27
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/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5071,6 +5071,8 @@ function useInlineCollab({
|
|
|
5071
5071
|
const elementRef = useRef(null);
|
|
5072
5072
|
const observerRef = useRef(null);
|
|
5073
5073
|
const subscribedConversationIdRef = useRef(null);
|
|
5074
|
+
const latestMessageIdRef = useRef(null);
|
|
5075
|
+
const lastMarkedReadIdRef = useRef(null);
|
|
5074
5076
|
const channelSubscriptionRef = useRef(null);
|
|
5075
5077
|
const trimToLimit = useCallback(
|
|
5076
5078
|
(msgs) => msgs.length > messageLimit ? msgs.slice(msgs.length - messageLimit) : msgs,
|
|
@@ -5080,6 +5082,18 @@ function useInlineCollab({
|
|
|
5080
5082
|
() => buildChannelName(patientData),
|
|
5081
5083
|
[patientData]
|
|
5082
5084
|
);
|
|
5085
|
+
useEffect(() => {
|
|
5086
|
+
latestMessageIdRef.current = messages[messages.length - 1]?.id ?? null;
|
|
5087
|
+
}, [messages]);
|
|
5088
|
+
const markLatestRead = useCallback(
|
|
5089
|
+
(conversationId) => {
|
|
5090
|
+
const messageId = latestMessageIdRef.current;
|
|
5091
|
+
if (!messageId || lastMarkedReadIdRef.current === messageId) return;
|
|
5092
|
+
lastMarkedReadIdRef.current = messageId;
|
|
5093
|
+
socket.markAsRead(conversationId, messageId);
|
|
5094
|
+
},
|
|
5095
|
+
[socket]
|
|
5096
|
+
);
|
|
5083
5097
|
useEffect(() => {
|
|
5084
5098
|
let cancelled = false;
|
|
5085
5099
|
const load = async () => {
|
|
@@ -5213,6 +5227,7 @@ function useInlineCollab({
|
|
|
5213
5227
|
try {
|
|
5214
5228
|
await socket.sendMessage(preview.conversationId, payload);
|
|
5215
5229
|
setUnreadCount(0);
|
|
5230
|
+
markLatestRead(preview.conversationId);
|
|
5216
5231
|
} catch (err) {
|
|
5217
5232
|
setError(err instanceof Error ? err.message : "Failed to send message");
|
|
5218
5233
|
config.onError?.({
|
|
@@ -5231,7 +5246,8 @@ function useInlineCollab({
|
|
|
5231
5246
|
invalidatePreview,
|
|
5232
5247
|
subscribe,
|
|
5233
5248
|
socket,
|
|
5234
|
-
config
|
|
5249
|
+
config,
|
|
5250
|
+
markLatestRead
|
|
5235
5251
|
]
|
|
5236
5252
|
);
|
|
5237
5253
|
const sendMessage = useCallback(
|