@liveblocks/react 2.15.0-debug1 → 2.15.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.
@@ -210,6 +210,7 @@ var use = (
210
210
 
211
211
 
212
212
 
213
+
213
214
  // src/lib/autobind.ts
214
215
  function autobind(self) {
215
216
  const seen = /* @__PURE__ */ new Set();
@@ -227,6 +228,14 @@ function autobind(self) {
227
228
  } while ((obj = Reflect.getPrototypeOf(obj)) && obj !== Object.prototype);
228
229
  }
229
230
 
231
+ // src/lib/itertools.ts
232
+ function find(it, predicate) {
233
+ for (const item of it) {
234
+ if (predicate(item)) return item;
235
+ }
236
+ return void 0;
237
+ }
238
+
230
239
  // src/ThreadDB.ts
231
240
 
232
241
 
@@ -346,6 +355,18 @@ var ThreadDB = class _ThreadDB {
346
355
  this.upsert(thread);
347
356
  }
348
357
  }
358
+ applyDelta(updates) {
359
+ _core.batch.call(void 0, () => {
360
+ for (const thread of updates.newThreads) {
361
+ this.upsertIfNewer(thread);
362
+ }
363
+ for (const { id, deletedAt } of updates.deletedThreads) {
364
+ const existing = this.getEvenIfDeleted(id);
365
+ if (!existing) continue;
366
+ this.delete(id, deletedAt);
367
+ }
368
+ });
369
+ }
349
370
  /**
350
371
  * Marks a thread as deleted. It will no longer pop up in .findMany()
351
372
  * queries, but it can still be accessed via `.getEvenIfDeleted()`.
@@ -533,14 +554,11 @@ var SinglePageResource = class {
533
554
  const usable = this.#cachedPromise;
534
555
  if (usable === null || usable.status === "pending") {
535
556
  return ASYNC_LOADING;
536
- }
537
- if (usable.status === "rejected") {
557
+ } else if (usable.status === "rejected") {
538
558
  return { isLoading: false, error: usable.reason };
559
+ } else {
560
+ return { isLoading: false, data: void 0 };
539
561
  }
540
- return {
541
- isLoading: false,
542
- data: void 0
543
- };
544
562
  }
545
563
  #cachedPromise = null;
546
564
  waitUntilLoaded() {
@@ -567,9 +585,164 @@ var SinglePageResource = class {
567
585
  return promise;
568
586
  }
569
587
  };
588
+ function createStore_forNotifications() {
589
+ const signal = new (0, _core.MutableSignal)(/* @__PURE__ */ new Map());
590
+ function markRead(notificationId, readAt) {
591
+ signal.mutate((lut) => {
592
+ const existing = lut.get(notificationId);
593
+ if (!existing) {
594
+ return false;
595
+ }
596
+ lut.set(notificationId, { ...existing, readAt });
597
+ return true;
598
+ });
599
+ }
600
+ function markAllRead(readAt) {
601
+ signal.mutate((lut) => {
602
+ for (const n of lut.values()) {
603
+ n.readAt = readAt;
604
+ }
605
+ });
606
+ }
607
+ function deleteOne(inboxNotificationId) {
608
+ signal.mutate((lut) => lut.delete(inboxNotificationId));
609
+ }
610
+ function clear() {
611
+ signal.mutate((lut) => lut.clear());
612
+ }
613
+ function applyDelta(newInboxNotifications, deletedNotifications) {
614
+ signal.mutate((lut) => {
615
+ let mutated = false;
616
+ for (const n of newInboxNotifications) {
617
+ const existing = lut.get(n.id);
618
+ if (existing) {
619
+ const result = compareInboxNotifications(existing, n);
620
+ if (result === 1) continue;
621
+ }
622
+ lut.set(n.id, n);
623
+ mutated = true;
624
+ }
625
+ for (const n of deletedNotifications) {
626
+ lut.delete(n.id);
627
+ mutated = true;
628
+ }
629
+ return mutated;
630
+ });
631
+ }
632
+ function updateAssociatedNotification(newComment) {
633
+ signal.mutate((lut) => {
634
+ const existing = find(
635
+ lut.values(),
636
+ (notification) => notification.kind === "thread" && notification.threadId === newComment.threadId
637
+ );
638
+ if (!existing) return false;
639
+ lut.set(existing.id, {
640
+ ...existing,
641
+ notifiedAt: newComment.createdAt,
642
+ readAt: newComment.createdAt
643
+ });
644
+ return true;
645
+ });
646
+ }
647
+ return {
648
+ signal: signal.asReadonly(),
649
+ // Mutations
650
+ markAllRead,
651
+ markRead,
652
+ delete: deleteOne,
653
+ applyDelta,
654
+ clear,
655
+ updateAssociatedNotification,
656
+ // XXX_vincent Remove this eventually
657
+ force_set: (mutationCallback) => signal.mutate(mutationCallback),
658
+ invalidate: () => signal.mutate()
659
+ };
660
+ }
661
+ function createStore_forRoomNotificationSettings() {
662
+ const signal = new (0, _core.MutableSignal)(/* @__PURE__ */ new Map());
663
+ function update(roomId, settings) {
664
+ signal.mutate((lut) => {
665
+ lut.set(roomId, settings);
666
+ });
667
+ }
668
+ return {
669
+ signal: signal.asReadonly(),
670
+ // Mutations
671
+ update,
672
+ // XXX_vincent Remove this eventually
673
+ invalidate: () => signal.mutate()
674
+ };
675
+ }
676
+ function createStore_forHistoryVersions() {
677
+ const signal = new (0, _core.MutableSignal)(/* @__PURE__ */ new Map());
678
+ function update(roomId, versions) {
679
+ signal.mutate((lut) => {
680
+ const versionsById = _nullishCoalesce(lut.get(roomId), () => ( (lut.set(roomId, /* @__PURE__ */ new Map()), lut.get(roomId))));
681
+ for (const version of versions) {
682
+ versionsById.set(version.id, version);
683
+ }
684
+ });
685
+ }
686
+ return {
687
+ signal: signal.asReadonly(),
688
+ // Mutations
689
+ update,
690
+ // XXX_vincent Remove these eventually
691
+ force_set: (callback) => signal.mutate(callback),
692
+ invalidate: () => signal.mutate()
693
+ };
694
+ }
695
+ function createStore_forPermissionHints() {
696
+ const signal = new (0, _core.Signal)({});
697
+ function update(newHints) {
698
+ signal.set((prev) => {
699
+ const permissionsByRoom = { ...prev };
700
+ for (const [roomId, newPermissions] of Object.entries(newHints)) {
701
+ const existing = _nullishCoalesce(permissionsByRoom[roomId], () => ( /* @__PURE__ */ new Set()));
702
+ for (const permission of newPermissions) {
703
+ existing.add(permission);
704
+ }
705
+ permissionsByRoom[roomId] = existing;
706
+ }
707
+ return permissionsByRoom;
708
+ });
709
+ }
710
+ return {
711
+ signal: signal.asReadonly(),
712
+ // Mutations
713
+ update,
714
+ // XXX_vincent Remove this eventually
715
+ invalidate: () => signal.set((store) => ({ ...store }))
716
+ };
717
+ }
718
+ function createStore_forOptimistic(client) {
719
+ const signal = new (0, _core.Signal)([]);
720
+ const syncSource = client[_core.kInternal].createSyncSource();
721
+ signal.subscribe(
722
+ () => syncSource.setSyncStatus(
723
+ signal.get().length > 0 ? "synchronizing" : "synchronized"
724
+ )
725
+ );
726
+ function add(optimisticUpdate) {
727
+ const id = _core.nanoid.call(void 0, );
728
+ const newUpdate = { ...optimisticUpdate, id };
729
+ signal.set((state) => [...state, newUpdate]);
730
+ return id;
731
+ }
732
+ function remove(optimisticId) {
733
+ signal.set((state) => state.filter((ou) => ou.id !== optimisticId));
734
+ }
735
+ return {
736
+ signal: signal.asReadonly(),
737
+ // Mutations
738
+ add,
739
+ remove,
740
+ // XXX_vincent Remove this eventually
741
+ invalidate: () => signal.set((store) => [...store])
742
+ };
743
+ }
570
744
  var UmbrellaStore = class {
571
745
  #client;
572
- #syncSource;
573
746
  //
574
747
  // Internally, the UmbrellaStore keeps track of a few source signals that can
575
748
  // be set and mutated individually. When any of those are mutated then the
@@ -596,10 +769,14 @@ var UmbrellaStore = class {
596
769
  // Input signals.
597
770
  // (Can be mutated directly.)
598
771
  //
772
+ // XXX_vincent Now that we have createStore_forX, we should probably also change
773
+ // `threads` to this pattern, ie create a createStore_forThreads helper as
774
+ // well. It almost works like that already anyway!
599
775
 
600
776
  // Exposes its signal under `.signal` prop
601
777
 
602
778
 
779
+ // prettier-ignore
603
780
 
604
781
 
605
782
 
@@ -611,7 +788,7 @@ var UmbrellaStore = class {
611
788
  // threads and notifications separately, but the threadifications signal will
612
789
  // be updated whenever either of them change.
613
790
  //
614
- // TODO(vincent+nimesh) APIs like getRoomThreadsLoadingState should really also be modeled as output signals.
791
+ // XXX_vincent APIs like getRoomThreadsLoadingState should really also be modeled as output signals.
615
792
  //
616
793
 
617
794
  // Notifications
@@ -631,13 +808,11 @@ var UmbrellaStore = class {
631
808
  #roomNotificationSettings = /* @__PURE__ */ new Map();
632
809
  constructor(client) {
633
810
  this.#client = client[_core.kInternal].as();
634
- this.#syncSource = this.#client[_core.kInternal].createSyncSource();
811
+ this.optimisticUpdates = createStore_forOptimistic(this.#client);
812
+ this.permissionHints = createStore_forPermissionHints();
635
813
  const inboxFetcher = async (cursor) => {
636
814
  const result = await this.#client.getInboxNotifications({ cursor });
637
- this.updateThreadsAndNotifications(
638
- result.threads,
639
- result.inboxNotifications
640
- );
815
+ this.updateThreadifications(result.threads, result.inboxNotifications);
641
816
  if (this.#notificationsLastRequestedAt === null) {
642
817
  this.#notificationsLastRequestedAt = result.requestedAt;
643
818
  }
@@ -652,33 +827,44 @@ var UmbrellaStore = class {
652
827
  this.invalidateEntireStore()
653
828
  )
654
829
  );
655
- this.baseThreadsDB = new ThreadDB();
656
- this.optimisticUpdates = new (0, _core.Signal)([]);
657
- this.baseVersionsByRoomId = new (0, _core.Signal)({});
658
- this.baseNotificationsById = new (0, _core.Signal)({});
659
- this.baseSettingsByRoomId = new (0, _core.Signal)({});
660
- this.permissionHintsByRoomId = new (0, _core.Signal)({});
830
+ this.threads = new ThreadDB();
831
+ this.notifications = createStore_forNotifications();
832
+ this.roomNotificationSettings = createStore_forRoomNotificationSettings();
833
+ this.historyVersions = createStore_forHistoryVersions();
661
834
  const threadifications = _core.DerivedSignal.from(
662
- this.baseThreadsDB.signal,
663
- this.baseNotificationsById,
664
- this.optimisticUpdates,
835
+ this.threads.signal,
836
+ this.notifications.signal,
837
+ this.optimisticUpdates.signal,
665
838
  (ts, ns, updates) => applyOptimisticUpdates_forThreadifications(ts, ns, updates)
666
839
  );
667
- const threads = _core.DerivedSignal.from(threadifications, (s) => ({
668
- threadsDB: s.threadsDB
669
- }));
670
- const notifications = _core.DerivedSignal.from(threadifications, (s) => ({
671
- sortedNotifications: s.sortedNotifications,
672
- notificationsById: s.notificationsById
673
- }));
840
+ const threads = _core.DerivedSignal.from(
841
+ threadifications,
842
+ (s) => ({
843
+ threadsDB: s.threadsDB
844
+ }),
845
+ _core.shallow
846
+ );
847
+ const notifications = _core.DerivedSignal.from(
848
+ threadifications,
849
+ (s) => ({
850
+ sortedNotifications: s.sortedNotifications,
851
+ notificationsById: s.notificationsById
852
+ }),
853
+ _core.shallow
854
+ );
674
855
  const settingsByRoomId = _core.DerivedSignal.from(
675
- this.baseSettingsByRoomId,
676
- this.optimisticUpdates,
856
+ this.roomNotificationSettings.signal,
857
+ this.optimisticUpdates.signal,
677
858
  (settings, updates) => applyOptimisticUpdates_forSettings(settings, updates)
678
859
  );
679
860
  const versionsByRoomId = _core.DerivedSignal.from(
680
- this.baseVersionsByRoomId,
681
- (hv) => hv
861
+ this.historyVersions.signal,
862
+ (hv) => Object.fromEntries(
863
+ [...hv].map(([roomId, versions]) => [
864
+ roomId,
865
+ Object.fromEntries(versions)
866
+ ])
867
+ )
682
868
  );
683
869
  this.outputs = {
684
870
  threadifications,
@@ -687,11 +873,6 @@ var UmbrellaStore = class {
687
873
  settingsByRoomId,
688
874
  versionsByRoomId
689
875
  };
690
- this.optimisticUpdates.subscribe(
691
- () => this.#syncSource.setSyncStatus(
692
- this.optimisticUpdates.get().length > 0 ? "synchronizing" : "synchronized"
693
- )
694
- );
695
876
  autobind(this);
696
877
  }
697
878
  get1_both() {
@@ -797,7 +978,7 @@ var UmbrellaStore = class {
797
978
  };
798
979
  }
799
980
  // NOTE: This will read the async result, but WILL NOT start loading at the moment!
800
- // TODO(vincent+nimesh) This should really be a derived Signal!
981
+ // XXX_vincent This should really be a derived Signal!
801
982
  getNotificationSettingsLoadingState(roomId) {
802
983
  const queryKey = makeNotificationSettingsQueryKey(roomId);
803
984
  const resource = this.#roomNotificationSettings.get(queryKey);
@@ -828,48 +1009,17 @@ var UmbrellaStore = class {
828
1009
  versions: Object.values(_nullishCoalesce(this.get3()[roomId], () => ( {})))
829
1010
  };
830
1011
  }
831
- // Direct low-level cache mutations ------------------------------------------------- {{{
832
- #mutateThreadsDB(mutate) {
833
- _core.batch.call(void 0, () => {
834
- mutate(this.baseThreadsDB);
835
- });
836
- }
837
- #updateInboxNotificationsCache(mapFn) {
838
- this.baseNotificationsById.set((prev) => mapFn(prev));
839
- }
840
- #setNotificationSettings(roomId, settings) {
841
- this.baseSettingsByRoomId.set((state) => ({
842
- ...state,
843
- [roomId]: settings
844
- }));
845
- }
846
- #updateRoomVersions(roomId, versions) {
847
- this.baseVersionsByRoomId.set((prev) => {
848
- const newVersions = { ...prev[roomId] };
849
- for (const version of versions) {
850
- newVersions[version.id] = version;
851
- }
852
- return {
853
- ...prev,
854
- [roomId]: newVersions
855
- };
856
- });
857
- }
858
- #updateOptimisticUpdatesCache(mapFn) {
859
- this.optimisticUpdates.set(mapFn);
860
- }
861
- // ---------------------------------------------------------------------------------- }}}
862
1012
  /** @internal - Only call this method from unit tests. */
863
1013
  force_set_versions(callback) {
864
1014
  _core.batch.call(void 0, () => {
865
- this.baseVersionsByRoomId.set(callback);
1015
+ this.historyVersions.force_set(callback);
866
1016
  this.invalidateEntireStore();
867
1017
  });
868
1018
  }
869
1019
  /** @internal - Only call this method from unit tests. */
870
1020
  force_set_notifications(callback) {
871
1021
  _core.batch.call(void 0, () => {
872
- this.baseNotificationsById.set(callback);
1022
+ this.notifications.force_set(callback);
873
1023
  this.invalidateEntireStore();
874
1024
  });
875
1025
  }
@@ -877,64 +1027,47 @@ var UmbrellaStore = class {
877
1027
  * Updates an existing inbox notification with a new value, replacing the
878
1028
  * corresponding optimistic update.
879
1029
  *
880
- * This will not update anything if the inbox notification ID isn't found in
881
- * the cache.
1030
+ * This will not update anything if the inbox notification ID isn't found.
882
1031
  */
883
- updateInboxNotification(inboxNotificationId, optimisticUpdateId, callback) {
1032
+ markInboxNotificationRead(inboxNotificationId, readAt, optimisticId) {
884
1033
  _core.batch.call(void 0, () => {
885
- this.removeOptimisticUpdate(optimisticUpdateId);
886
- this.#updateInboxNotificationsCache((cache) => {
887
- const existing = cache[inboxNotificationId];
888
- if (!existing) {
889
- return cache;
890
- }
891
- return {
892
- ...cache,
893
- [inboxNotificationId]: callback(existing)
894
- };
895
- });
1034
+ this.optimisticUpdates.remove(optimisticId);
1035
+ this.notifications.markRead(inboxNotificationId, readAt);
896
1036
  });
897
1037
  }
898
- /**
899
- * Updates *all* inbox notifications by running a mapper function over all of
900
- * them, replacing the corresponding optimistic update.
901
- */
902
- updateAllInboxNotifications(optimisticUpdateId, mapFn) {
1038
+ markAllInboxNotificationsRead(optimisticId, readAt) {
903
1039
  _core.batch.call(void 0, () => {
904
- this.removeOptimisticUpdate(optimisticUpdateId);
905
- this.#updateInboxNotificationsCache((cache) => _core.mapValues.call(void 0, cache, mapFn));
1040
+ this.optimisticUpdates.remove(optimisticId);
1041
+ this.notifications.markAllRead(readAt);
906
1042
  });
907
1043
  }
908
1044
  /**
909
1045
  * Deletes an existing inbox notification, replacing the corresponding
910
1046
  * optimistic update.
911
1047
  */
912
- deleteInboxNotification(inboxNotificationId, optimisticUpdateId) {
1048
+ deleteInboxNotification(inboxNotificationId, optimisticId) {
913
1049
  _core.batch.call(void 0, () => {
914
- this.removeOptimisticUpdate(optimisticUpdateId);
915
- this.#updateInboxNotificationsCache((cache) => {
916
- const { [inboxNotificationId]: removed, ...newCache } = cache;
917
- return removed === void 0 ? cache : newCache;
918
- });
1050
+ this.optimisticUpdates.remove(optimisticId);
1051
+ this.notifications.delete(inboxNotificationId);
919
1052
  });
920
1053
  }
921
1054
  /**
922
1055
  * Deletes *all* inbox notifications, replacing the corresponding optimistic
923
1056
  * update.
924
1057
  */
925
- deleteAllInboxNotifications(optimisticUpdateId) {
1058
+ deleteAllInboxNotifications(optimisticId) {
926
1059
  _core.batch.call(void 0, () => {
927
- this.removeOptimisticUpdate(optimisticUpdateId);
928
- this.#updateInboxNotificationsCache(() => ({}));
1060
+ this.optimisticUpdates.remove(optimisticId);
1061
+ this.notifications.clear();
929
1062
  });
930
1063
  }
931
1064
  /**
932
1065
  * Creates an new thread, replacing the corresponding optimistic update.
933
1066
  */
934
- createThread(optimisticUpdateId, thread) {
1067
+ createThread(optimisticId, thread) {
935
1068
  _core.batch.call(void 0, () => {
936
- this.removeOptimisticUpdate(optimisticUpdateId);
937
- this.#mutateThreadsDB((db) => db.upsert(thread));
1069
+ this.optimisticUpdates.remove(optimisticId);
1070
+ this.threads.upsert(thread);
938
1071
  });
939
1072
  }
940
1073
  /**
@@ -942,44 +1075,43 @@ var UmbrellaStore = class {
942
1075
  * optimistic update.
943
1076
  *
944
1077
  * This will not update anything if:
945
- * - The thread ID isn't found in the cache; or
946
- * - The thread ID was already deleted from the cache; or
947
- * - The thread ID in the cache was updated more recently than the optimistic
948
- * update's timestamp (if given)
1078
+ * - The thread ID isn't found; or
1079
+ * - The thread ID was already deleted; or
1080
+ * - The thread ID was updated more recently than the optimistic update's
1081
+ * timestamp (if given)
949
1082
  */
950
- #updateThread(threadId, optimisticUpdateId, callback, updatedAt) {
1083
+ #updateThread(threadId, optimisticId, callback, updatedAt) {
951
1084
  _core.batch.call(void 0, () => {
952
- if (optimisticUpdateId !== null) {
953
- this.removeOptimisticUpdate(optimisticUpdateId);
1085
+ if (optimisticId !== null) {
1086
+ this.optimisticUpdates.remove(optimisticId);
954
1087
  }
955
- this.#mutateThreadsDB((db) => {
956
- const existing = db.get(threadId);
957
- if (!existing) return;
958
- if (!!updatedAt && existing.updatedAt > updatedAt) return;
959
- db.upsert(callback(existing));
960
- });
1088
+ const db = this.threads;
1089
+ const existing = db.get(threadId);
1090
+ if (!existing) return;
1091
+ if (!!updatedAt && existing.updatedAt > updatedAt) return;
1092
+ db.upsert(callback(existing));
961
1093
  });
962
1094
  }
963
- patchThread(threadId, optimisticUpdateId, patch, updatedAt) {
1095
+ patchThread(threadId, optimisticId, patch, updatedAt) {
964
1096
  return this.#updateThread(
965
1097
  threadId,
966
- optimisticUpdateId,
1098
+ optimisticId,
967
1099
  (thread) => ({ ...thread, ..._core.compactObject.call(void 0, patch) }),
968
1100
  updatedAt
969
1101
  );
970
1102
  }
971
- addReaction(threadId, optimisticUpdateId, commentId, reaction, createdAt) {
1103
+ addReaction(threadId, optimisticId, commentId, reaction, createdAt) {
972
1104
  this.#updateThread(
973
1105
  threadId,
974
- optimisticUpdateId,
1106
+ optimisticId,
975
1107
  (thread) => applyAddReaction(thread, commentId, reaction),
976
1108
  createdAt
977
1109
  );
978
1110
  }
979
- removeReaction(threadId, optimisticUpdateId, commentId, emoji, userId, removedAt) {
1111
+ removeReaction(threadId, optimisticId, commentId, emoji, userId, removedAt) {
980
1112
  this.#updateThread(
981
1113
  threadId,
982
- optimisticUpdateId,
1114
+ optimisticId,
983
1115
  (thread) => applyRemoveReaction(thread, commentId, emoji, userId, removedAt),
984
1116
  removedAt
985
1117
  );
@@ -989,13 +1121,13 @@ var UmbrellaStore = class {
989
1121
  * replacing the corresponding optimistic update.
990
1122
  *
991
1123
  * This will not update anything if:
992
- * - The thread ID isn't found in the cache; or
993
- * - The thread ID was already deleted from the cache
1124
+ * - The thread ID isn't found; or
1125
+ * - The thread ID was already deleted
994
1126
  */
995
- deleteThread(threadId, optimisticUpdateId) {
1127
+ deleteThread(threadId, optimisticId) {
996
1128
  return this.#updateThread(
997
1129
  threadId,
998
- optimisticUpdateId,
1130
+ optimisticId,
999
1131
  // A deletion is actually an update of the deletedAt property internally
1000
1132
  (thread) => ({ ...thread, updatedAt: /* @__PURE__ */ new Date(), deletedAt: /* @__PURE__ */ new Date() })
1001
1133
  );
@@ -1004,94 +1136,48 @@ var UmbrellaStore = class {
1004
1136
  * Creates an existing comment and ensures the associated notification is
1005
1137
  * updated correctly, replacing the corresponding optimistic update.
1006
1138
  */
1007
- createComment(newComment, optimisticUpdateId) {
1139
+ createComment(newComment, optimisticId) {
1008
1140
  _core.batch.call(void 0, () => {
1009
- this.removeOptimisticUpdate(optimisticUpdateId);
1010
- const existingThread = this.baseThreadsDB.get(newComment.threadId);
1141
+ this.optimisticUpdates.remove(optimisticId);
1142
+ const existingThread = this.threads.get(newComment.threadId);
1011
1143
  if (!existingThread) {
1012
1144
  return;
1013
1145
  }
1014
- this.#mutateThreadsDB(
1015
- (db) => db.upsert(applyUpsertComment(existingThread, newComment))
1016
- );
1017
- this.#updateInboxNotificationsCache((cache) => {
1018
- const existingNotification = Object.values(cache).find(
1019
- (notification) => notification.kind === "thread" && notification.threadId === newComment.threadId
1020
- );
1021
- if (!existingNotification) {
1022
- return cache;
1023
- }
1024
- return {
1025
- ...cache,
1026
- [existingNotification.id]: {
1027
- ...existingNotification,
1028
- notifiedAt: newComment.createdAt,
1029
- readAt: newComment.createdAt
1030
- }
1031
- };
1032
- });
1146
+ this.threads.upsert(applyUpsertComment(existingThread, newComment));
1147
+ this.notifications.updateAssociatedNotification(newComment);
1033
1148
  });
1034
1149
  }
1035
- editComment(threadId, optimisticUpdateId, editedComment) {
1150
+ editComment(threadId, optimisticId, editedComment) {
1036
1151
  return this.#updateThread(
1037
1152
  threadId,
1038
- optimisticUpdateId,
1153
+ optimisticId,
1039
1154
  (thread) => applyUpsertComment(thread, editedComment)
1040
1155
  );
1041
1156
  }
1042
- deleteComment(threadId, optimisticUpdateId, commentId, deletedAt) {
1157
+ deleteComment(threadId, optimisticId, commentId, deletedAt) {
1043
1158
  return this.#updateThread(
1044
1159
  threadId,
1045
- optimisticUpdateId,
1160
+ optimisticId,
1046
1161
  (thread) => applyDeleteComment(thread, commentId, deletedAt),
1047
1162
  deletedAt
1048
1163
  );
1049
1164
  }
1050
- updateThreadAndNotification(thread, inboxNotification) {
1165
+ updateThreadifications(threads, notifications, deletedThreads = [], deletedNotifications = []) {
1051
1166
  _core.batch.call(void 0, () => {
1052
- this.#mutateThreadsDB((db) => db.upsertIfNewer(thread));
1053
- if (inboxNotification !== void 0) {
1054
- this.#updateInboxNotificationsCache((cache) => ({
1055
- ...cache,
1056
- [inboxNotification.id]: inboxNotification
1057
- }));
1058
- }
1059
- });
1060
- }
1061
- updateThreadsAndNotifications(threads, inboxNotifications, deletedThreads = [], deletedInboxNotifications = []) {
1062
- _core.batch.call(void 0, () => {
1063
- this.#mutateThreadsDB(
1064
- (db) => applyThreadDeltaUpdates(db, { newThreads: threads, deletedThreads })
1065
- );
1066
- this.#updateInboxNotificationsCache(
1067
- (cache) => applyNotificationsUpdates(cache, {
1068
- newInboxNotifications: inboxNotifications,
1069
- deletedNotifications: deletedInboxNotifications
1070
- })
1071
- );
1167
+ this.threads.applyDelta({ newThreads: threads, deletedThreads });
1168
+ this.notifications.applyDelta(notifications, deletedNotifications);
1072
1169
  });
1073
1170
  }
1074
1171
  /**
1075
1172
  * Updates existing notification setting for a room with a new value,
1076
1173
  * replacing the corresponding optimistic update.
1077
1174
  */
1078
- updateRoomNotificationSettings_confirmOptimisticUpdate(roomId, optimisticUpdateId, settings) {
1175
+ updateRoomNotificationSettings(roomId, optimisticId, settings) {
1079
1176
  _core.batch.call(void 0, () => {
1080
- this.removeOptimisticUpdate(optimisticUpdateId);
1081
- this.#setNotificationSettings(roomId, settings);
1177
+ this.optimisticUpdates.remove(optimisticId);
1178
+ this.roomNotificationSettings.update(roomId, settings);
1082
1179
  });
1083
1180
  }
1084
- addOptimisticUpdate(optimisticUpdate) {
1085
- const id = _core.nanoid.call(void 0, );
1086
- const newUpdate = { ...optimisticUpdate, id };
1087
- this.#updateOptimisticUpdatesCache((cache) => [...cache, newUpdate]);
1088
- return id;
1089
- }
1090
- removeOptimisticUpdate(optimisticUpdateId) {
1091
- this.#updateOptimisticUpdatesCache(
1092
- (cache) => cache.filter((ou) => ou.id !== optimisticUpdateId)
1093
- );
1094
- }
1095
1181
  async fetchNotificationsDeltaUpdate(signal) {
1096
1182
  const lastRequestedAt = this.#notificationsLastRequestedAt;
1097
1183
  if (lastRequestedAt === null) {
@@ -1104,7 +1190,7 @@ var UmbrellaStore = class {
1104
1190
  if (lastRequestedAt < result.requestedAt) {
1105
1191
  this.#notificationsLastRequestedAt = result.requestedAt;
1106
1192
  }
1107
- this.updateThreadsAndNotifications(
1193
+ this.updateThreadifications(
1108
1194
  result.threads.updated,
1109
1195
  result.inboxNotifications.updated,
1110
1196
  result.threads.deleted,
@@ -1114,19 +1200,6 @@ var UmbrellaStore = class {
1114
1200
  waitUntilNotificationsLoaded() {
1115
1201
  return this.#notifications.waitUntilLoaded();
1116
1202
  }
1117
- #updatePermissionHints(newHints) {
1118
- this.permissionHintsByRoomId.set((prev) => {
1119
- const permissionsByRoom = { ...prev };
1120
- for (const [roomId, newPermissions] of Object.entries(newHints)) {
1121
- const existing = _nullishCoalesce(permissionsByRoom[roomId], () => ( /* @__PURE__ */ new Set()));
1122
- for (const permission of newPermissions) {
1123
- existing.add(permission);
1124
- }
1125
- permissionsByRoom[roomId] = existing;
1126
- }
1127
- return permissionsByRoom;
1128
- });
1129
- }
1130
1203
  waitUntilRoomThreadsLoaded(roomId, query) {
1131
1204
  const threadsFetcher = async (cursor) => {
1132
1205
  const result = await this.#client[_core.kInternal].httpClient.getThreads({
@@ -1134,11 +1207,8 @@ var UmbrellaStore = class {
1134
1207
  cursor,
1135
1208
  query
1136
1209
  });
1137
- this.updateThreadsAndNotifications(
1138
- result.threads,
1139
- result.inboxNotifications
1140
- );
1141
- this.#updatePermissionHints(result.permissionHints);
1210
+ this.updateThreadifications(result.threads, result.inboxNotifications);
1211
+ this.permissionHints.update(result.permissionHints);
1142
1212
  const lastRequestedAt = this.#roomThreadsLastRequestedAtByRoom.get(roomId);
1143
1213
  if (lastRequestedAt === void 0 || lastRequestedAt > result.requestedAt) {
1144
1214
  this.#roomThreadsLastRequestedAtByRoom.set(roomId, result.requestedAt);
@@ -1170,13 +1240,13 @@ var UmbrellaStore = class {
1170
1240
  since: lastRequestedAt,
1171
1241
  signal
1172
1242
  });
1173
- this.updateThreadsAndNotifications(
1243
+ this.updateThreadifications(
1174
1244
  updates.threads.updated,
1175
1245
  updates.inboxNotifications.updated,
1176
1246
  updates.threads.deleted,
1177
1247
  updates.inboxNotifications.deleted
1178
1248
  );
1179
- this.#updatePermissionHints(updates.permissionHints);
1249
+ this.permissionHints.update(updates.permissionHints);
1180
1250
  if (lastRequestedAt < updates.requestedAt) {
1181
1251
  this.#roomThreadsLastRequestedAtByRoom.set(roomId, updates.requestedAt);
1182
1252
  }
@@ -1188,11 +1258,8 @@ var UmbrellaStore = class {
1188
1258
  cursor,
1189
1259
  query
1190
1260
  });
1191
- this.updateThreadsAndNotifications(
1192
- result.threads,
1193
- result.inboxNotifications
1194
- );
1195
- this.#updatePermissionHints(result.permissionHints);
1261
+ this.updateThreadifications(result.threads, result.inboxNotifications);
1262
+ this.permissionHints.update(result.permissionHints);
1196
1263
  if (this.#userThreadsLastRequestedAt === null) {
1197
1264
  this.#userThreadsLastRequestedAt = result.requestedAt;
1198
1265
  }
@@ -1212,15 +1279,15 @@ var UmbrellaStore = class {
1212
1279
  this.#userThreads.set(queryKey, paginatedResource);
1213
1280
  return paginatedResource.waitUntilLoaded();
1214
1281
  }
1215
- // TODO(vincent+nimesh) We should really be going over all call sites, and replace this call
1282
+ // XXX_vincent We should really be going over all call sites, and replace this call
1216
1283
  // with a more specific invalidation!
1217
1284
  invalidateEntireStore() {
1218
1285
  _core.batch.call(void 0, () => {
1219
- this.baseVersionsByRoomId.set((store) => ({ ...store }));
1220
- this.baseNotificationsById.set((store) => ({ ...store }));
1221
- this.optimisticUpdates.set((store) => [...store]);
1222
- this.permissionHintsByRoomId.set((store) => ({ ...store }));
1223
- this.baseSettingsByRoomId.set((store) => ({ ...store }));
1286
+ this.historyVersions.invalidate();
1287
+ this.notifications.invalidate();
1288
+ this.optimisticUpdates.invalidate();
1289
+ this.permissionHints.invalidate();
1290
+ this.roomNotificationSettings.invalidate();
1224
1291
  });
1225
1292
  }
1226
1293
  async fetchUserThreadsDeltaUpdate(signal) {
@@ -1235,13 +1302,13 @@ var UmbrellaStore = class {
1235
1302
  if (lastRequestedAt < result.requestedAt) {
1236
1303
  this.#notificationsLastRequestedAt = result.requestedAt;
1237
1304
  }
1238
- this.updateThreadsAndNotifications(
1305
+ this.updateThreadifications(
1239
1306
  result.threads.updated,
1240
1307
  result.inboxNotifications.updated,
1241
1308
  result.threads.deleted,
1242
1309
  result.inboxNotifications.deleted
1243
1310
  );
1244
- this.#updatePermissionHints(result.permissionHints);
1311
+ this.permissionHints.update(result.permissionHints);
1245
1312
  }
1246
1313
  waitUntilRoomVersionsLoaded(roomId) {
1247
1314
  const queryKey = makeVersionsQueryKey(roomId);
@@ -1256,7 +1323,7 @@ var UmbrellaStore = class {
1256
1323
  );
1257
1324
  }
1258
1325
  const result = await room[_core.kInternal].listTextVersions();
1259
- this.#updateRoomVersions(roomId, result.versions);
1326
+ this.historyVersions.update(roomId, result.versions);
1260
1327
  const lastRequestedAt = this.#roomVersionsLastRequestedAtByRoom.get(roomId);
1261
1328
  if (lastRequestedAt === void 0 || lastRequestedAt > result.requestedAt) {
1262
1329
  this.#roomVersionsLastRequestedAtByRoom.set(
@@ -1290,7 +1357,7 @@ var UmbrellaStore = class {
1290
1357
  since: lastRequestedAt,
1291
1358
  signal
1292
1359
  });
1293
- this.#updateRoomVersions(roomId, updates.versions);
1360
+ this.historyVersions.update(roomId, updates.versions);
1294
1361
  if (lastRequestedAt < updates.requestedAt) {
1295
1362
  this.#roomVersionsLastRequestedAtByRoom.set(roomId, updates.requestedAt);
1296
1363
  }
@@ -1308,7 +1375,7 @@ var UmbrellaStore = class {
1308
1375
  );
1309
1376
  }
1310
1377
  const result = await room.getNotificationSettings();
1311
- this.#setNotificationSettings(roomId, result);
1378
+ this.roomNotificationSettings.update(roomId, result);
1312
1379
  };
1313
1380
  resource = new SinglePageResource(notificationSettingsFetcher);
1314
1381
  }
@@ -1328,12 +1395,12 @@ var UmbrellaStore = class {
1328
1395
  `Room with id ${roomId} is not available on client`
1329
1396
  );
1330
1397
  const result = await room.getNotificationSettings({ signal });
1331
- this.#setNotificationSettings(roomId, result);
1398
+ this.roomNotificationSettings.update(roomId, result);
1332
1399
  }
1333
1400
  };
1334
- function applyOptimisticUpdates_forThreadifications(baseThreadsDB, rawNotificationsById, optimisticUpdates) {
1401
+ function applyOptimisticUpdates_forThreadifications(baseThreadsDB, notificationsLUT, optimisticUpdates) {
1335
1402
  const threadsDB = baseThreadsDB.clone();
1336
- let notificationsById = { ...rawNotificationsById };
1403
+ let notificationsById = Object.fromEntries(notificationsLUT);
1337
1404
  for (const optimisticUpdate of optimisticUpdates) {
1338
1405
  switch (optimisticUpdate.type) {
1339
1406
  case "create-thread": {
@@ -1486,8 +1553,8 @@ function applyOptimisticUpdates_forThreadifications(baseThreadsDB, rawNotificati
1486
1553
  threadsDB
1487
1554
  };
1488
1555
  }
1489
- function applyOptimisticUpdates_forSettings(baseSettingsByRoomId, optimisticUpdates) {
1490
- const settingsByRoomId = { ...baseSettingsByRoomId };
1556
+ function applyOptimisticUpdates_forSettings(settingsLUT, optimisticUpdates) {
1557
+ const settingsByRoomId = Object.fromEntries(settingsLUT);
1491
1558
  for (const optimisticUpdate of optimisticUpdates) {
1492
1559
  switch (optimisticUpdate.type) {
1493
1560
  case "update-notification-settings": {
@@ -1504,32 +1571,6 @@ function applyOptimisticUpdates_forSettings(baseSettingsByRoomId, optimisticUpda
1504
1571
  }
1505
1572
  return settingsByRoomId;
1506
1573
  }
1507
- function applyThreadDeltaUpdates(db, updates) {
1508
- updates.newThreads.forEach((thread) => db.upsertIfNewer(thread));
1509
- updates.deletedThreads.forEach(({ id, deletedAt }) => {
1510
- const existing = db.getEvenIfDeleted(id);
1511
- if (!existing) return;
1512
- db.delete(id, deletedAt);
1513
- });
1514
- }
1515
- function applyNotificationsUpdates(existingInboxNotifications, updates) {
1516
- const updatedInboxNotifications = { ...existingInboxNotifications };
1517
- updates.newInboxNotifications.forEach((notification) => {
1518
- const existingNotification = updatedInboxNotifications[notification.id];
1519
- if (existingNotification) {
1520
- const result = compareInboxNotifications(
1521
- existingNotification,
1522
- notification
1523
- );
1524
- if (result === 1) return;
1525
- }
1526
- updatedInboxNotifications[notification.id] = notification;
1527
- });
1528
- updates.deletedNotifications.forEach(
1529
- ({ id }) => delete updatedInboxNotifications[id]
1530
- );
1531
- return updatedInboxNotifications;
1532
- }
1533
1574
  function compareInboxNotifications(inboxNotificationA, inboxNotificationB) {
1534
1575
  if (inboxNotificationA.notifiedAt > inboxNotificationB.notifiedAt) {
1535
1576
  return 1;
@@ -1885,7 +1926,7 @@ function useInboxNotifications_withClient(client, selector, isEqual) {
1885
1926
  };
1886
1927
  }, [poller]);
1887
1928
  return useSyncExternalStoreWithSelector(
1888
- store.subscribe1_threads,
1929
+ store.subscribe1_notifications,
1889
1930
  store.getInboxNotificationsLoadingState,
1890
1931
  store.getInboxNotificationsLoadingState,
1891
1932
  selector,
@@ -1920,21 +1961,21 @@ function useMarkInboxNotificationAsRead_withClient(client) {
1920
1961
  (inboxNotificationId) => {
1921
1962
  const { store } = getLiveblocksExtrasForClient(client);
1922
1963
  const readAt = /* @__PURE__ */ new Date();
1923
- const optimisticUpdateId = store.addOptimisticUpdate({
1964
+ const optimisticId = store.optimisticUpdates.add({
1924
1965
  type: "mark-inbox-notification-as-read",
1925
1966
  inboxNotificationId,
1926
1967
  readAt
1927
1968
  });
1928
1969
  client.markInboxNotificationAsRead(inboxNotificationId).then(
1929
1970
  () => {
1930
- store.updateInboxNotification(
1971
+ store.markInboxNotificationRead(
1931
1972
  inboxNotificationId,
1932
- optimisticUpdateId,
1933
- (inboxNotification) => ({ ...inboxNotification, readAt })
1973
+ readAt,
1974
+ optimisticId
1934
1975
  );
1935
1976
  },
1936
1977
  () => {
1937
- store.removeOptimisticUpdate(optimisticUpdateId);
1978
+ store.optimisticUpdates.remove(optimisticId);
1938
1979
  }
1939
1980
  );
1940
1981
  },
@@ -1945,19 +1986,16 @@ function useMarkAllInboxNotificationsAsRead_withClient(client) {
1945
1986
  return _react.useCallback.call(void 0, () => {
1946
1987
  const { store } = getLiveblocksExtrasForClient(client);
1947
1988
  const readAt = /* @__PURE__ */ new Date();
1948
- const optimisticUpdateId = store.addOptimisticUpdate({
1989
+ const optimisticId = store.optimisticUpdates.add({
1949
1990
  type: "mark-all-inbox-notifications-as-read",
1950
1991
  readAt
1951
1992
  });
1952
1993
  client.markAllInboxNotificationsAsRead().then(
1953
1994
  () => {
1954
- store.updateAllInboxNotifications(
1955
- optimisticUpdateId,
1956
- (inboxNotification) => ({ ...inboxNotification, readAt })
1957
- );
1995
+ store.markAllInboxNotificationsRead(optimisticId, readAt);
1958
1996
  },
1959
1997
  () => {
1960
- store.removeOptimisticUpdate(optimisticUpdateId);
1998
+ store.optimisticUpdates.remove(optimisticId);
1961
1999
  }
1962
2000
  );
1963
2001
  }, [client]);
@@ -1967,20 +2005,17 @@ function useDeleteInboxNotification_withClient(client) {
1967
2005
  (inboxNotificationId) => {
1968
2006
  const { store } = getLiveblocksExtrasForClient(client);
1969
2007
  const deletedAt = /* @__PURE__ */ new Date();
1970
- const optimisticUpdateId = store.addOptimisticUpdate({
2008
+ const optimisticId = store.optimisticUpdates.add({
1971
2009
  type: "delete-inbox-notification",
1972
2010
  inboxNotificationId,
1973
2011
  deletedAt
1974
2012
  });
1975
2013
  client.deleteInboxNotification(inboxNotificationId).then(
1976
2014
  () => {
1977
- store.deleteInboxNotification(
1978
- inboxNotificationId,
1979
- optimisticUpdateId
1980
- );
2015
+ store.deleteInboxNotification(inboxNotificationId, optimisticId);
1981
2016
  },
1982
2017
  () => {
1983
- store.removeOptimisticUpdate(optimisticUpdateId);
2018
+ store.optimisticUpdates.remove(optimisticId);
1984
2019
  }
1985
2020
  );
1986
2021
  },
@@ -1991,16 +2026,16 @@ function useDeleteAllInboxNotifications_withClient(client) {
1991
2026
  return _react.useCallback.call(void 0, () => {
1992
2027
  const { store } = getLiveblocksExtrasForClient(client);
1993
2028
  const deletedAt = /* @__PURE__ */ new Date();
1994
- const optimisticUpdateId = store.addOptimisticUpdate({
2029
+ const optimisticId = store.optimisticUpdates.add({
1995
2030
  type: "delete-all-inbox-notifications",
1996
2031
  deletedAt
1997
2032
  });
1998
2033
  client.deleteAllInboxNotifications().then(
1999
2034
  () => {
2000
- store.deleteAllInboxNotifications(optimisticUpdateId);
2035
+ store.deleteAllInboxNotifications(optimisticId);
2001
2036
  },
2002
2037
  () => {
2003
- store.removeOptimisticUpdate(optimisticUpdateId);
2038
+ store.optimisticUpdates.remove(optimisticId);
2004
2039
  }
2005
2040
  );
2006
2041
  }, [client]);
@@ -2594,8 +2629,8 @@ function getRoomExtrasForClient(client) {
2594
2629
  function makeRoomExtrasForClient(client) {
2595
2630
  const store = getUmbrellaStoreForClient(client);
2596
2631
  const commentsErrorEventSource = _core.makeEventSource.call(void 0, );
2597
- function onMutationFailure(innerError, optimisticUpdateId, createPublicError) {
2598
- store.removeOptimisticUpdate(optimisticUpdateId);
2632
+ function onMutationFailure(innerError, optimisticId, createPublicError) {
2633
+ store.optimisticUpdates.remove(optimisticId);
2599
2634
  if (innerError instanceof _core.HttpError) {
2600
2635
  const error = handleApiError(innerError);
2601
2636
  commentsErrorEventSource.notify(createPublicError(error));
@@ -2851,7 +2886,7 @@ function RoomProviderInner(props) {
2851
2886
  store.deleteThread(message.threadId, null);
2852
2887
  return;
2853
2888
  }
2854
- const { thread, inboxNotification } = info;
2889
+ const { thread, inboxNotification: maybeNotification } = info;
2855
2890
  const existingThread = store.get1_threads().threadsDB.getEvenIfDeleted(message.threadId);
2856
2891
  switch (message.type) {
2857
2892
  case _core.ServerMsgCode.COMMENT_EDITED:
@@ -2861,10 +2896,16 @@ function RoomProviderInner(props) {
2861
2896
  case _core.ServerMsgCode.COMMENT_REACTION_REMOVED:
2862
2897
  case _core.ServerMsgCode.COMMENT_DELETED:
2863
2898
  if (!existingThread) break;
2864
- store.updateThreadAndNotification(thread, inboxNotification);
2899
+ store.updateThreadifications(
2900
+ [thread],
2901
+ maybeNotification ? [maybeNotification] : []
2902
+ );
2865
2903
  break;
2866
2904
  case _core.ServerMsgCode.COMMENT_CREATED:
2867
- store.updateThreadAndNotification(thread, inboxNotification);
2905
+ store.updateThreadifications(
2906
+ [thread],
2907
+ maybeNotification ? [maybeNotification] : []
2908
+ );
2868
2909
  break;
2869
2910
  default:
2870
2911
  break;
@@ -3301,7 +3342,7 @@ function useCreateRoomThread(roomId) {
3301
3342
  resolved: false
3302
3343
  };
3303
3344
  const { store, onMutationFailure } = getRoomExtrasForClient(client);
3304
- const optimisticUpdateId = store.addOptimisticUpdate({
3345
+ const optimisticId = store.optimisticUpdates.add({
3305
3346
  type: "create-thread",
3306
3347
  thread: newThread,
3307
3348
  roomId
@@ -3316,11 +3357,11 @@ function useCreateRoomThread(roomId) {
3316
3357
  attachmentIds
3317
3358
  }).then(
3318
3359
  (thread) => {
3319
- store.createThread(optimisticUpdateId, thread);
3360
+ store.createThread(optimisticId, thread);
3320
3361
  },
3321
3362
  (err) => onMutationFailure(
3322
3363
  err,
3323
- optimisticUpdateId,
3364
+ optimisticId,
3324
3365
  (err2) => new CreateThreadError(err2, {
3325
3366
  roomId,
3326
3367
  threadId,
@@ -3348,7 +3389,7 @@ function useDeleteRoomThread(roomId) {
3348
3389
  if (_optionalChain([existing, 'optionalAccess', _17 => _17.comments, 'optionalAccess', _18 => _18[0], 'optionalAccess', _19 => _19.userId]) !== userId) {
3349
3390
  throw new Error("Only the thread creator can delete the thread");
3350
3391
  }
3351
- const optimisticUpdateId = store.addOptimisticUpdate({
3392
+ const optimisticId = store.optimisticUpdates.add({
3352
3393
  type: "delete-thread",
3353
3394
  roomId,
3354
3395
  threadId,
@@ -3356,11 +3397,11 @@ function useDeleteRoomThread(roomId) {
3356
3397
  });
3357
3398
  client[_core.kInternal].httpClient.deleteThread({ roomId, threadId }).then(
3358
3399
  () => {
3359
- store.deleteThread(threadId, optimisticUpdateId);
3400
+ store.deleteThread(threadId, optimisticId);
3360
3401
  },
3361
3402
  (err) => onMutationFailure(
3362
3403
  err,
3363
- optimisticUpdateId,
3404
+ optimisticId,
3364
3405
  (err2) => new DeleteThreadError(err2, { roomId, threadId })
3365
3406
  )
3366
3407
  );
@@ -3382,7 +3423,7 @@ function useEditRoomThreadMetadata(roomId) {
3382
3423
  const metadata = options.metadata;
3383
3424
  const updatedAt = /* @__PURE__ */ new Date();
3384
3425
  const { store, onMutationFailure } = getRoomExtrasForClient(client);
3385
- const optimisticUpdateId = store.addOptimisticUpdate({
3426
+ const optimisticId = store.optimisticUpdates.add({
3386
3427
  type: "edit-thread-metadata",
3387
3428
  metadata,
3388
3429
  threadId,
@@ -3391,16 +3432,11 @@ function useEditRoomThreadMetadata(roomId) {
3391
3432
  client[_core.kInternal].httpClient.editThreadMetadata({ roomId, threadId, metadata }).then(
3392
3433
  (metadata2) => (
3393
3434
  // Replace the optimistic update by the real thing
3394
- store.patchThread(
3395
- threadId,
3396
- optimisticUpdateId,
3397
- { metadata: metadata2 },
3398
- updatedAt
3399
- )
3435
+ store.patchThread(threadId, optimisticId, { metadata: metadata2 }, updatedAt)
3400
3436
  ),
3401
3437
  (err) => onMutationFailure(
3402
3438
  err,
3403
- optimisticUpdateId,
3439
+ optimisticId,
3404
3440
  (error) => new EditThreadMetadataError(error, {
3405
3441
  roomId,
3406
3442
  threadId,
@@ -3433,18 +3469,18 @@ function useCreateRoomComment(roomId) {
3433
3469
  attachments: _nullishCoalesce(attachments, () => ( []))
3434
3470
  };
3435
3471
  const { store, onMutationFailure } = getRoomExtrasForClient(client);
3436
- const optimisticUpdateId = store.addOptimisticUpdate({
3472
+ const optimisticId = store.optimisticUpdates.add({
3437
3473
  type: "create-comment",
3438
3474
  comment
3439
3475
  });
3440
3476
  const attachmentIds = _optionalChain([attachments, 'optionalAccess', _20 => _20.map, 'call', _21 => _21((attachment) => attachment.id)]);
3441
3477
  client[_core.kInternal].httpClient.createComment({ roomId, threadId, commentId, body, attachmentIds }).then(
3442
3478
  (newComment) => {
3443
- store.createComment(newComment, optimisticUpdateId);
3479
+ store.createComment(newComment, optimisticId);
3444
3480
  },
3445
3481
  (err) => onMutationFailure(
3446
3482
  err,
3447
- optimisticUpdateId,
3483
+ optimisticId,
3448
3484
  (err2) => new CreateCommentError(err2, {
3449
3485
  roomId,
3450
3486
  threadId,
@@ -3483,7 +3519,7 @@ function useEditRoomComment(roomId) {
3483
3519
  );
3484
3520
  return;
3485
3521
  }
3486
- const optimisticUpdateId = store.addOptimisticUpdate({
3522
+ const optimisticId = store.optimisticUpdates.add({
3487
3523
  type: "edit-comment",
3488
3524
  comment: {
3489
3525
  ...comment,
@@ -3495,11 +3531,11 @@ function useEditRoomComment(roomId) {
3495
3531
  const attachmentIds = _optionalChain([attachments, 'optionalAccess', _22 => _22.map, 'call', _23 => _23((attachment) => attachment.id)]);
3496
3532
  client[_core.kInternal].httpClient.editComment({ roomId, threadId, commentId, body, attachmentIds }).then(
3497
3533
  (editedComment) => {
3498
- store.editComment(threadId, optimisticUpdateId, editedComment);
3534
+ store.editComment(threadId, optimisticId, editedComment);
3499
3535
  },
3500
3536
  (err) => onMutationFailure(
3501
3537
  err,
3502
- optimisticUpdateId,
3538
+ optimisticId,
3503
3539
  (error) => new EditCommentError(error, {
3504
3540
  roomId,
3505
3541
  threadId,
@@ -3521,7 +3557,7 @@ function useDeleteRoomComment(roomId) {
3521
3557
  ({ threadId, commentId }) => {
3522
3558
  const deletedAt = /* @__PURE__ */ new Date();
3523
3559
  const { store, onMutationFailure } = getRoomExtrasForClient(client);
3524
- const optimisticUpdateId = store.addOptimisticUpdate({
3560
+ const optimisticId = store.optimisticUpdates.add({
3525
3561
  type: "delete-comment",
3526
3562
  threadId,
3527
3563
  commentId,
@@ -3530,16 +3566,11 @@ function useDeleteRoomComment(roomId) {
3530
3566
  });
3531
3567
  client[_core.kInternal].httpClient.deleteComment({ roomId, threadId, commentId }).then(
3532
3568
  () => {
3533
- store.deleteComment(
3534
- threadId,
3535
- optimisticUpdateId,
3536
- commentId,
3537
- deletedAt
3538
- );
3569
+ store.deleteComment(threadId, optimisticId, commentId, deletedAt);
3539
3570
  },
3540
3571
  (err) => onMutationFailure(
3541
3572
  err,
3542
- optimisticUpdateId,
3573
+ optimisticId,
3543
3574
  (error) => new DeleteCommentError(error, {
3544
3575
  roomId,
3545
3576
  threadId,
@@ -3561,7 +3592,7 @@ function useAddRoomCommentReaction(roomId) {
3561
3592
  const createdAt = /* @__PURE__ */ new Date();
3562
3593
  const userId = getCurrentUserId(client);
3563
3594
  const { store, onMutationFailure } = getRoomExtrasForClient(client);
3564
- const optimisticUpdateId = store.addOptimisticUpdate({
3595
+ const optimisticId = store.optimisticUpdates.add({
3565
3596
  type: "add-reaction",
3566
3597
  threadId,
3567
3598
  commentId,
@@ -3575,7 +3606,7 @@ function useAddRoomCommentReaction(roomId) {
3575
3606
  (addedReaction) => {
3576
3607
  store.addReaction(
3577
3608
  threadId,
3578
- optimisticUpdateId,
3609
+ optimisticId,
3579
3610
  commentId,
3580
3611
  addedReaction,
3581
3612
  createdAt
@@ -3583,7 +3614,7 @@ function useAddRoomCommentReaction(roomId) {
3583
3614
  },
3584
3615
  (err) => onMutationFailure(
3585
3616
  err,
3586
- optimisticUpdateId,
3617
+ optimisticId,
3587
3618
  (error) => new AddReactionError(error, {
3588
3619
  roomId,
3589
3620
  threadId,
@@ -3606,7 +3637,7 @@ function useRemoveRoomCommentReaction(roomId) {
3606
3637
  const userId = getCurrentUserId(client);
3607
3638
  const removedAt = /* @__PURE__ */ new Date();
3608
3639
  const { store, onMutationFailure } = getRoomExtrasForClient(client);
3609
- const optimisticUpdateId = store.addOptimisticUpdate({
3640
+ const optimisticId = store.optimisticUpdates.add({
3610
3641
  type: "remove-reaction",
3611
3642
  threadId,
3612
3643
  commentId,
@@ -3618,7 +3649,7 @@ function useRemoveRoomCommentReaction(roomId) {
3618
3649
  () => {
3619
3650
  store.removeReaction(
3620
3651
  threadId,
3621
- optimisticUpdateId,
3652
+ optimisticId,
3622
3653
  commentId,
3623
3654
  emoji,
3624
3655
  userId,
@@ -3627,7 +3658,7 @@ function useRemoveRoomCommentReaction(roomId) {
3627
3658
  },
3628
3659
  (err) => onMutationFailure(
3629
3660
  err,
3630
- optimisticUpdateId,
3661
+ optimisticId,
3631
3662
  (error) => new RemoveReactionError(error, {
3632
3663
  roomId,
3633
3664
  threadId,
@@ -3655,7 +3686,7 @@ function useMarkRoomThreadAsRead(roomId) {
3655
3686
  );
3656
3687
  if (!inboxNotification) return;
3657
3688
  const now = /* @__PURE__ */ new Date();
3658
- const optimisticUpdateId = store.addOptimisticUpdate({
3689
+ const optimisticId = store.optimisticUpdates.add({
3659
3690
  type: "mark-inbox-notification-as-read",
3660
3691
  inboxNotificationId: inboxNotification.id,
3661
3692
  readAt: now
@@ -3665,16 +3696,16 @@ function useMarkRoomThreadAsRead(roomId) {
3665
3696
  inboxNotificationId: inboxNotification.id
3666
3697
  }).then(
3667
3698
  () => {
3668
- store.updateInboxNotification(
3699
+ store.markInboxNotificationRead(
3669
3700
  inboxNotification.id,
3670
- optimisticUpdateId,
3671
- (inboxNotification2) => ({ ...inboxNotification2, readAt: now })
3701
+ now,
3702
+ optimisticId
3672
3703
  );
3673
3704
  },
3674
3705
  (err) => {
3675
3706
  onMutationFailure(
3676
3707
  err,
3677
- optimisticUpdateId,
3708
+ optimisticId,
3678
3709
  (error) => new MarkInboxNotificationAsReadError(error, {
3679
3710
  inboxNotificationId: inboxNotification.id
3680
3711
  })
@@ -3695,7 +3726,7 @@ function useMarkRoomThreadAsResolved(roomId) {
3695
3726
  (threadId) => {
3696
3727
  const updatedAt = /* @__PURE__ */ new Date();
3697
3728
  const { store, onMutationFailure } = getRoomExtrasForClient(client);
3698
- const optimisticUpdateId = store.addOptimisticUpdate({
3729
+ const optimisticId = store.optimisticUpdates.add({
3699
3730
  type: "mark-thread-as-resolved",
3700
3731
  threadId,
3701
3732
  updatedAt
@@ -3704,14 +3735,14 @@ function useMarkRoomThreadAsResolved(roomId) {
3704
3735
  () => {
3705
3736
  store.patchThread(
3706
3737
  threadId,
3707
- optimisticUpdateId,
3738
+ optimisticId,
3708
3739
  { resolved: true },
3709
3740
  updatedAt
3710
3741
  );
3711
3742
  },
3712
3743
  (err) => onMutationFailure(
3713
3744
  err,
3714
- optimisticUpdateId,
3745
+ optimisticId,
3715
3746
  (error) => new MarkThreadAsResolvedError(error, {
3716
3747
  roomId,
3717
3748
  threadId
@@ -3731,7 +3762,7 @@ function useMarkRoomThreadAsUnresolved(roomId) {
3731
3762
  (threadId) => {
3732
3763
  const updatedAt = /* @__PURE__ */ new Date();
3733
3764
  const { store, onMutationFailure } = getRoomExtrasForClient(client);
3734
- const optimisticUpdateId = store.addOptimisticUpdate({
3765
+ const optimisticId = store.optimisticUpdates.add({
3735
3766
  type: "mark-thread-as-unresolved",
3736
3767
  threadId,
3737
3768
  updatedAt
@@ -3740,14 +3771,14 @@ function useMarkRoomThreadAsUnresolved(roomId) {
3740
3771
  () => {
3741
3772
  store.patchThread(
3742
3773
  threadId,
3743
- optimisticUpdateId,
3774
+ optimisticId,
3744
3775
  { resolved: false },
3745
3776
  updatedAt
3746
3777
  );
3747
3778
  },
3748
3779
  (err) => onMutationFailure(
3749
3780
  err,
3750
- optimisticUpdateId,
3781
+ optimisticId,
3751
3782
  (error) => new MarkThreadAsUnresolvedError(error, {
3752
3783
  roomId,
3753
3784
  threadId
@@ -3914,22 +3945,18 @@ function useUpdateRoomNotificationSettings() {
3914
3945
  return _react.useCallback.call(void 0,
3915
3946
  (settings) => {
3916
3947
  const { store, onMutationFailure } = getRoomExtrasForClient(client);
3917
- const optimisticUpdateId = store.addOptimisticUpdate({
3948
+ const optimisticId = store.optimisticUpdates.add({
3918
3949
  type: "update-notification-settings",
3919
3950
  roomId: room.id,
3920
3951
  settings
3921
3952
  });
3922
3953
  room.updateNotificationSettings(settings).then(
3923
3954
  (settings2) => {
3924
- store.updateRoomNotificationSettings_confirmOptimisticUpdate(
3925
- room.id,
3926
- optimisticUpdateId,
3927
- settings2
3928
- );
3955
+ store.updateRoomNotificationSettings(room.id, optimisticId, settings2);
3929
3956
  },
3930
3957
  (err) => onMutationFailure(
3931
3958
  err,
3932
- optimisticUpdateId,
3959
+ optimisticId,
3933
3960
  (error) => new UpdateNotificationSettingsError(error, {
3934
3961
  roomId: room.id
3935
3962
  })
@@ -4072,7 +4099,7 @@ function useRoomPermissions(roomId) {
4072
4099
  const client = useClient();
4073
4100
  const store = getRoomExtrasForClient(client).store;
4074
4101
  return useSignal(
4075
- store.permissionHintsByRoomId,
4102
+ store.permissionHints.signal,
4076
4103
  (hints) => _nullishCoalesce(hints[roomId], () => ( /* @__PURE__ */ new Set()))
4077
4104
  );
4078
4105
  }
@@ -4223,4 +4250,4 @@ var _useUpdateMyPresence = useUpdateMyPresence;
4223
4250
 
4224
4251
 
4225
4252
  exports.RoomContext = RoomContext; exports.useRoomOrNull = useRoomOrNull; exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; exports.ClientContext = ClientContext; exports.getUmbrellaStoreForClient = getUmbrellaStoreForClient; exports.useClientOrNull = useClientOrNull; exports.useClient = useClient; exports.LiveblocksProvider = LiveblocksProvider; exports.createLiveblocksContext = createLiveblocksContext; exports.useInboxNotifications = useInboxNotifications; exports.useInboxNotificationsSuspense = useInboxNotificationsSuspense; exports.useMarkAllInboxNotificationsAsRead = useMarkAllInboxNotificationsAsRead; exports.useMarkInboxNotificationAsRead = useMarkInboxNotificationAsRead; exports.useDeleteAllInboxNotifications = useDeleteAllInboxNotifications; exports.useDeleteInboxNotification = useDeleteInboxNotification; exports.useUnreadInboxNotificationsCount = useUnreadInboxNotificationsCount; exports.useUnreadInboxNotificationsCountSuspense = useUnreadInboxNotificationsCountSuspense; exports.useRoomInfo = useRoomInfo; exports.useRoomInfoSuspense = useRoomInfoSuspense; exports._useInboxNotificationThread = _useInboxNotificationThread; exports._useUser = _useUser; exports._useUserSuspense = _useUserSuspense; exports._useUserThreads_experimental = _useUserThreads_experimental; exports._useUserThreadsSuspense_experimental = _useUserThreadsSuspense_experimental; exports.useSyncStatus = useSyncStatus; exports.CreateThreadError = CreateThreadError; exports.useSignal = useSignal; exports.useStatus = useStatus; exports.useReportTextEditor = useReportTextEditor; exports.useYjsProvider = useYjsProvider; exports.useCreateTextMention = useCreateTextMention; exports.useDeleteTextMention = useDeleteTextMention; exports.useResolveMentionSuggestions = useResolveMentionSuggestions; exports.useMentionSuggestionsCache = useMentionSuggestionsCache; exports.useStorageStatus = useStorageStatus; exports.useBatch = useBatch; exports.useLostConnectionListener = useLostConnectionListener; exports.useErrorListener = useErrorListener; exports.useHistory = useHistory; exports.useUndo = useUndo; exports.useRedo = useRedo; exports.useCanUndo = useCanUndo; exports.useCanRedo = useCanRedo; exports.useOthersConnectionIds = useOthersConnectionIds; exports.useCommentsErrorListener = useCommentsErrorListener; exports.useCreateRoomThread = useCreateRoomThread; exports.useDeleteRoomThread = useDeleteRoomThread; exports.useEditRoomThreadMetadata = useEditRoomThreadMetadata; exports.useCreateComment = useCreateComment; exports.useCreateRoomComment = useCreateRoomComment; exports.useEditComment = useEditComment; exports.useEditRoomComment = useEditRoomComment; exports.useDeleteComment = useDeleteComment; exports.useDeleteRoomComment = useDeleteRoomComment; exports.useAddRoomCommentReaction = useAddRoomCommentReaction; exports.useRemoveReaction = useRemoveReaction; exports.useRemoveRoomCommentReaction = useRemoveRoomCommentReaction; exports.useMarkThreadAsRead = useMarkThreadAsRead; exports.useMarkRoomThreadAsRead = useMarkRoomThreadAsRead; exports.useMarkThreadAsResolved = useMarkThreadAsResolved; exports.useMarkRoomThreadAsResolved = useMarkRoomThreadAsResolved; exports.useMarkThreadAsUnresolved = useMarkThreadAsUnresolved; exports.useMarkRoomThreadAsUnresolved = useMarkRoomThreadAsUnresolved; exports.useThreadSubscription = useThreadSubscription; exports.useHistoryVersionData = useHistoryVersionData; exports.useUpdateRoomNotificationSettings = useUpdateRoomNotificationSettings; exports.useOthersConnectionIdsSuspense = useOthersConnectionIdsSuspense; exports.useStorageStatusSuspense = useStorageStatusSuspense; exports.useAttachmentUrl = useAttachmentUrl; exports.useRoomAttachmentUrl = useRoomAttachmentUrl; exports.useAttachmentUrlSuspense = useAttachmentUrlSuspense; exports.useRoomPermissions = useRoomPermissions; exports.createRoomContext = createRoomContext; exports._RoomProvider = _RoomProvider; exports._useBroadcastEvent = _useBroadcastEvent; exports._useOthersListener = _useOthersListener; exports._useRoom = _useRoom; exports._useIsInsideRoom = _useIsInsideRoom; exports._useAddReaction = _useAddReaction; exports._useMutation = _useMutation; exports._useCreateThread = _useCreateThread; exports._useDeleteThread = _useDeleteThread; exports._useEditThreadMetadata = _useEditThreadMetadata; exports._useEventListener = _useEventListener; exports._useMyPresence = _useMyPresence; exports._useOthersMapped = _useOthersMapped; exports._useOthersMappedSuspense = _useOthersMappedSuspense; exports._useThreads = _useThreads; exports._useThreadsSuspense = _useThreadsSuspense; exports._useRoomNotificationSettings = _useRoomNotificationSettings; exports._useRoomNotificationSettingsSuspense = _useRoomNotificationSettingsSuspense; exports._useHistoryVersions = _useHistoryVersions; exports._useHistoryVersionsSuspense = _useHistoryVersionsSuspense; exports._useOther = _useOther; exports._useOthers = _useOthers; exports._useOtherSuspense = _useOtherSuspense; exports._useOthersSuspense = _useOthersSuspense; exports._useStorage = _useStorage; exports._useStorageSuspense = _useStorageSuspense; exports._useSelf = _useSelf; exports._useSelfSuspense = _useSelfSuspense; exports._useStorageRoot = _useStorageRoot; exports._useUpdateMyPresence = _useUpdateMyPresence;
4226
- //# sourceMappingURL=chunk-KY7WMVMG.js.map
4253
+ //# sourceMappingURL=chunk-NUDMG62P.js.map