@ai4b-team/fsaos-gateway-sdk 3.2.0 → 3.2.1
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/iife/gateway.js +3 -3
- package/dist/iife/gateway.js.map +3 -3
- package/dist/iife/ui.js +1 -1
- package/dist/index.cjs +57 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +57 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2449,8 +2449,62 @@ function useInfiniteChannelMessages(options) {
|
|
|
2449
2449
|
"vfs_change",
|
|
2450
2450
|
() => {
|
|
2451
2451
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
2452
|
-
debounceRef.current = setTimeout(() => {
|
|
2453
|
-
qc.
|
|
2452
|
+
debounceRef.current = setTimeout(async () => {
|
|
2453
|
+
const currentData = qc.getQueryData(stableKey);
|
|
2454
|
+
if (!currentData?.pages?.length) {
|
|
2455
|
+
qc.invalidateQueries({ queryKey: stableKey });
|
|
2456
|
+
return;
|
|
2457
|
+
}
|
|
2458
|
+
let maxSeq = 0;
|
|
2459
|
+
for (const page of currentData.pages) {
|
|
2460
|
+
for (const msg of page.messages) {
|
|
2461
|
+
if (msg.seq > maxSeq) maxSeq = msg.seq;
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
if (maxSeq === 0) {
|
|
2465
|
+
qc.invalidateQueries({ queryKey: stableKey });
|
|
2466
|
+
return;
|
|
2467
|
+
}
|
|
2468
|
+
try {
|
|
2469
|
+
const newPage = await fetchChannelMessagesPage(channelPath, {
|
|
2470
|
+
parentMessageId,
|
|
2471
|
+
limit,
|
|
2472
|
+
after_seq: maxSeq
|
|
2473
|
+
});
|
|
2474
|
+
if (newPage.messages.length === 0 && newPage.siblingCards.length === 0) {
|
|
2475
|
+
qc.invalidateQueries({ queryKey: stableKey });
|
|
2476
|
+
return;
|
|
2477
|
+
}
|
|
2478
|
+
qc.setQueryData(stableKey, (old) => {
|
|
2479
|
+
if (!old) return old;
|
|
2480
|
+
const pages = [...old.pages];
|
|
2481
|
+
const lastIdx = pages.length - 1;
|
|
2482
|
+
const lastPage = pages[lastIdx];
|
|
2483
|
+
const existingIds = new Set(lastPage.messages.map((m) => m.id));
|
|
2484
|
+
const uniqueNew = newPage.messages.filter((m) => !existingIds.has(m.id));
|
|
2485
|
+
const mergedMessages = [...lastPage.messages, ...uniqueNew].sort((a, b) => a.seq - b.seq);
|
|
2486
|
+
const mergedMsgCards = new Map(lastPage.messageCards);
|
|
2487
|
+
for (const [path, cards] of newPage.messageCards) {
|
|
2488
|
+
const existing = mergedMsgCards.get(path) || [];
|
|
2489
|
+
const existingCardIds = new Set(existing.map((c) => c.id));
|
|
2490
|
+
const newCards = cards.filter((c) => !existingCardIds.has(c.id));
|
|
2491
|
+
mergedMsgCards.set(path, [...existing, ...newCards]);
|
|
2492
|
+
}
|
|
2493
|
+
const existingSibIds = new Set(lastPage.siblingCards.map((c) => c.id));
|
|
2494
|
+
const newSiblings = newPage.siblingCards.filter((c) => !existingSibIds.has(c.id));
|
|
2495
|
+
const mergedSiblings = [...lastPage.siblingCards, ...newSiblings];
|
|
2496
|
+
pages[lastIdx] = {
|
|
2497
|
+
...lastPage,
|
|
2498
|
+
messages: mergedMessages,
|
|
2499
|
+
messageCards: mergedMsgCards,
|
|
2500
|
+
siblingCards: mergedSiblings
|
|
2501
|
+
};
|
|
2502
|
+
return { ...old, pages };
|
|
2503
|
+
});
|
|
2504
|
+
} catch (err) {
|
|
2505
|
+
console.warn("[useInfiniteChannelMessages] live tail fetch failed, falling back to full invalidation:", err);
|
|
2506
|
+
qc.invalidateQueries({ queryKey: stableKey });
|
|
2507
|
+
}
|
|
2454
2508
|
}, 500);
|
|
2455
2509
|
},
|
|
2456
2510
|
(data) => {
|
|
@@ -2461,7 +2515,7 @@ function useInfiniteChannelMessages(options) {
|
|
|
2461
2515
|
unsub();
|
|
2462
2516
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
2463
2517
|
};
|
|
2464
|
-
}, [realtime, channelPath, queryEnabled, stableKey, qc]);
|
|
2518
|
+
}, [realtime, channelPath, queryEnabled, stableKey, qc, parentMessageId, limit]);
|
|
2465
2519
|
return {
|
|
2466
2520
|
messages,
|
|
2467
2521
|
/** Cards grouped by parent message path (child cards of messages). */
|