@natoe/colab 0.1.34 → 0.1.36

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.mjs CHANGED
@@ -601,6 +601,7 @@ function CollabProvider({ config, apiBaseUrl, children }) {
601
601
  });
602
602
  const [unreadCounts, setUnreadCounts] = useState({});
603
603
  const [unreadCountsByOrder, setUnreadCountsByOrder] = useState({});
604
+ const [unreadUpdateSeq, setUnreadUpdateSeq] = useState(0);
604
605
  const pendingKeys = useRef(/* @__PURE__ */ new Set());
605
606
  const pendingResolvers = useRef(/* @__PURE__ */ new Map());
606
607
  const previewCache = useRef(/* @__PURE__ */ new Map());
@@ -619,6 +620,7 @@ function CollabProvider({ config, apiBaseUrl, children }) {
619
620
  setUnreadCounts(counts.conversation);
620
621
  setUnreadCountsByOrder(counts.order);
621
622
  previewCache.current.clear();
623
+ setUnreadUpdateSeq((n) => n + 1);
622
624
  });
623
625
  if (!s.isConnected()) {
624
626
  s.connect(config);
@@ -852,6 +854,7 @@ function CollabProvider({ config, apiBaseUrl, children }) {
852
854
  config,
853
855
  apiBaseUrl,
854
856
  totalUnread,
857
+ unreadUpdateSeq,
855
858
  unreadCounts,
856
859
  unreadCountsByOrder,
857
860
  requestPreview,
@@ -5870,7 +5873,7 @@ var styles14 = {
5870
5873
  }};
5871
5874
  function useConversationList(options) {
5872
5875
  const enabled = options?.enabled ?? true;
5873
- const { fetchConversationList, config, totalUnread: serverTotalUnread } = useCollab();
5876
+ const { fetchConversationList, config, unreadUpdateSeq } = useCollab();
5874
5877
  const [conversations, setConversations] = useState([]);
5875
5878
  const [isLoading, setIsLoading] = useState(enabled);
5876
5879
  const [error, setError] = useState(null);
@@ -5908,15 +5911,16 @@ function useConversationList(options) {
5908
5911
  if (!enabled) return;
5909
5912
  refresh();
5910
5913
  }, [enabled, refresh]);
5911
- const hasHandledInitialUnreadRef = useRef(false);
5914
+ const hasHandledInitialSeqRef = useRef(false);
5912
5915
  useEffect(() => {
5913
5916
  if (!enabled) return;
5914
- if (!hasHandledInitialUnreadRef.current) {
5915
- hasHandledInitialUnreadRef.current = true;
5917
+ if (!hasHandledInitialSeqRef.current) {
5918
+ hasHandledInitialSeqRef.current = true;
5916
5919
  return;
5917
5920
  }
5918
- silentRefresh();
5919
- }, [serverTotalUnread, enabled]);
5921
+ const t = setTimeout(silentRefresh, 250);
5922
+ return () => clearTimeout(t);
5923
+ }, [unreadUpdateSeq, enabled]);
5920
5924
  const filter = useCallback(
5921
5925
  (query) => {
5922
5926
  const q = query.trim().toLowerCase();