@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.js
CHANGED
|
@@ -5077,6 +5077,8 @@ function useInlineCollab({
|
|
|
5077
5077
|
const elementRef = React4.useRef(null);
|
|
5078
5078
|
const observerRef = React4.useRef(null);
|
|
5079
5079
|
const subscribedConversationIdRef = React4.useRef(null);
|
|
5080
|
+
const latestMessageIdRef = React4.useRef(null);
|
|
5081
|
+
const lastMarkedReadIdRef = React4.useRef(null);
|
|
5080
5082
|
const channelSubscriptionRef = React4.useRef(null);
|
|
5081
5083
|
const trimToLimit = React4.useCallback(
|
|
5082
5084
|
(msgs) => msgs.length > messageLimit ? msgs.slice(msgs.length - messageLimit) : msgs,
|
|
@@ -5086,6 +5088,18 @@ function useInlineCollab({
|
|
|
5086
5088
|
() => buildChannelName(patientData),
|
|
5087
5089
|
[patientData]
|
|
5088
5090
|
);
|
|
5091
|
+
React4.useEffect(() => {
|
|
5092
|
+
latestMessageIdRef.current = messages[messages.length - 1]?.id ?? null;
|
|
5093
|
+
}, [messages]);
|
|
5094
|
+
const markLatestRead = React4.useCallback(
|
|
5095
|
+
(conversationId) => {
|
|
5096
|
+
const messageId = latestMessageIdRef.current;
|
|
5097
|
+
if (!messageId || lastMarkedReadIdRef.current === messageId) return;
|
|
5098
|
+
lastMarkedReadIdRef.current = messageId;
|
|
5099
|
+
socket.markAsRead(conversationId, messageId);
|
|
5100
|
+
},
|
|
5101
|
+
[socket]
|
|
5102
|
+
);
|
|
5089
5103
|
React4.useEffect(() => {
|
|
5090
5104
|
let cancelled = false;
|
|
5091
5105
|
const load = async () => {
|
|
@@ -5219,6 +5233,7 @@ function useInlineCollab({
|
|
|
5219
5233
|
try {
|
|
5220
5234
|
await socket.sendMessage(preview.conversationId, payload);
|
|
5221
5235
|
setUnreadCount(0);
|
|
5236
|
+
markLatestRead(preview.conversationId);
|
|
5222
5237
|
} catch (err) {
|
|
5223
5238
|
setError(err instanceof Error ? err.message : "Failed to send message");
|
|
5224
5239
|
config.onError?.({
|
|
@@ -5237,7 +5252,8 @@ function useInlineCollab({
|
|
|
5237
5252
|
invalidatePreview,
|
|
5238
5253
|
subscribe,
|
|
5239
5254
|
socket,
|
|
5240
|
-
config
|
|
5255
|
+
config,
|
|
5256
|
+
markLatestRead
|
|
5241
5257
|
]
|
|
5242
5258
|
);
|
|
5243
5259
|
const sendMessage = React4.useCallback(
|