@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.
- package/dist/_private.d.mts +1 -1
- package/dist/_private.d.ts +1 -1
- package/dist/_private.js +5 -5
- package/dist/_private.mjs +1 -1
- package/dist/{chunk-UJLD6FYC.mjs → chunk-GMKB6I6V.mjs} +395 -368
- package/dist/chunk-GMKB6I6V.mjs.map +1 -0
- package/dist/{chunk-KY7WMVMG.js → chunk-NUDMG62P.js} +364 -337
- package/dist/chunk-NUDMG62P.js.map +1 -0
- package/dist/{chunk-A4ABDZ5E.mjs → chunk-UX3CG7ZS.mjs} +2 -2
- package/dist/{chunk-MI7M3UBZ.js → chunk-WV5AI4AE.js} +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +2 -2
- package/dist/{room-C_NzlTZP.d.mts → room-XbmI0Hoh.d.mts} +74 -35
- package/dist/{room-C_NzlTZP.d.ts → room-XbmI0Hoh.d.ts} +74 -35
- package/dist/suspense.d.mts +1 -1
- package/dist/suspense.d.ts +1 -1
- package/dist/suspense.js +4 -4
- package/dist/suspense.mjs +2 -2
- package/package.json +3 -3
- package/dist/chunk-KY7WMVMG.js.map +0 -1
- package/dist/chunk-UJLD6FYC.mjs.map +0 -1
- /package/dist/{chunk-A4ABDZ5E.mjs.map → chunk-UX3CG7ZS.mjs.map} +0 -0
- /package/dist/{chunk-MI7M3UBZ.js.map → chunk-WV5AI4AE.js.map} +0 -0
|
@@ -92,7 +92,7 @@ import {
|
|
|
92
92
|
kInternal as kInternal2,
|
|
93
93
|
makePoller,
|
|
94
94
|
raise,
|
|
95
|
-
shallow as
|
|
95
|
+
shallow as shallow4
|
|
96
96
|
} from "@liveblocks/core";
|
|
97
97
|
import {
|
|
98
98
|
createContext as createContext2,
|
|
@@ -196,16 +196,17 @@ var use = (
|
|
|
196
196
|
// src/umbrella-store.ts
|
|
197
197
|
import {
|
|
198
198
|
autoRetry,
|
|
199
|
-
batch,
|
|
199
|
+
batch as batch2,
|
|
200
200
|
compactObject,
|
|
201
201
|
console as console2,
|
|
202
202
|
DerivedSignal,
|
|
203
203
|
HttpError,
|
|
204
204
|
kInternal,
|
|
205
205
|
makeEventSource,
|
|
206
|
-
|
|
206
|
+
MutableSignal as MutableSignal2,
|
|
207
207
|
nanoid,
|
|
208
208
|
nn,
|
|
209
|
+
shallow as shallow3,
|
|
209
210
|
Signal,
|
|
210
211
|
stringify
|
|
211
212
|
} from "@liveblocks/core";
|
|
@@ -227,8 +228,16 @@ 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
|
-
import { MutableSignal, SortedList } from "@liveblocks/core";
|
|
240
|
+
import { batch, MutableSignal, SortedList } from "@liveblocks/core";
|
|
232
241
|
|
|
233
242
|
// src/lib/guards.ts
|
|
234
243
|
import { isPlainObject as isPlainObject2 } from "@liveblocks/core";
|
|
@@ -346,6 +355,18 @@ var ThreadDB = class _ThreadDB {
|
|
|
346
355
|
this.upsert(thread);
|
|
347
356
|
}
|
|
348
357
|
}
|
|
358
|
+
applyDelta(updates) {
|
|
359
|
+
batch(() => {
|
|
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 MutableSignal2(/* @__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 MutableSignal2(/* @__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 MutableSignal2(/* @__PURE__ */ new Map());
|
|
678
|
+
function update(roomId, versions) {
|
|
679
|
+
signal.mutate((lut) => {
|
|
680
|
+
const versionsById = 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 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 = 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 Signal([]);
|
|
720
|
+
const syncSource = client[kInternal].createSyncSource();
|
|
721
|
+
signal.subscribe(
|
|
722
|
+
() => syncSource.setSyncStatus(
|
|
723
|
+
signal.get().length > 0 ? "synchronizing" : "synchronized"
|
|
724
|
+
)
|
|
725
|
+
);
|
|
726
|
+
function add(optimisticUpdate) {
|
|
727
|
+
const id = nanoid();
|
|
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,13 +769,17 @@ var UmbrellaStore = class {
|
|
|
596
769
|
// Input signals.
|
|
597
770
|
// (Can be mutated directly.)
|
|
598
771
|
//
|
|
599
|
-
|
|
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!
|
|
775
|
+
threads;
|
|
600
776
|
// Exposes its signal under `.signal` prop
|
|
601
|
-
|
|
602
|
-
|
|
777
|
+
notifications;
|
|
778
|
+
roomNotificationSettings;
|
|
779
|
+
// prettier-ignore
|
|
780
|
+
historyVersions;
|
|
781
|
+
permissionHints;
|
|
603
782
|
optimisticUpdates;
|
|
604
|
-
baseVersionsByRoomId;
|
|
605
|
-
permissionHintsByRoomId;
|
|
606
783
|
//
|
|
607
784
|
// Output signals.
|
|
608
785
|
// (Readonly, clean, consistent. With optimistic updates applied.)
|
|
@@ -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
|
-
//
|
|
791
|
+
// XXX_vincent APIs like getRoomThreadsLoadingState should really also be modeled as output signals.
|
|
615
792
|
//
|
|
616
793
|
outputs;
|
|
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[kInternal].as();
|
|
634
|
-
this
|
|
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.
|
|
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.
|
|
656
|
-
this.
|
|
657
|
-
this.
|
|
658
|
-
this.
|
|
659
|
-
this.baseSettingsByRoomId = new Signal({});
|
|
660
|
-
this.permissionHintsByRoomId = new 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 = DerivedSignal.from(
|
|
662
|
-
this.
|
|
663
|
-
this.
|
|
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 = DerivedSignal.from(
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
840
|
+
const threads = DerivedSignal.from(
|
|
841
|
+
threadifications,
|
|
842
|
+
(s) => ({
|
|
843
|
+
threadsDB: s.threadsDB
|
|
844
|
+
}),
|
|
845
|
+
shallow3
|
|
846
|
+
);
|
|
847
|
+
const notifications = DerivedSignal.from(
|
|
848
|
+
threadifications,
|
|
849
|
+
(s) => ({
|
|
850
|
+
sortedNotifications: s.sortedNotifications,
|
|
851
|
+
notificationsById: s.notificationsById
|
|
852
|
+
}),
|
|
853
|
+
shallow3
|
|
854
|
+
);
|
|
674
855
|
const settingsByRoomId = DerivedSignal.from(
|
|
675
|
-
this.
|
|
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 = DerivedSignal.from(
|
|
680
|
-
this.
|
|
681
|
-
(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
|
-
//
|
|
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(this.get3()[roomId] ?? {})
|
|
829
1010
|
};
|
|
830
1011
|
}
|
|
831
|
-
// Direct low-level cache mutations ------------------------------------------------- {{{
|
|
832
|
-
#mutateThreadsDB(mutate) {
|
|
833
|
-
batch(() => {
|
|
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
|
-
|
|
865
|
-
this.
|
|
1014
|
+
batch2(() => {
|
|
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
|
-
|
|
872
|
-
this.
|
|
1021
|
+
batch2(() => {
|
|
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
|
|
881
|
-
* the cache.
|
|
1030
|
+
* This will not update anything if the inbox notification ID isn't found.
|
|
882
1031
|
*/
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
this.
|
|
886
|
-
this
|
|
887
|
-
const existing = cache[inboxNotificationId];
|
|
888
|
-
if (!existing) {
|
|
889
|
-
return cache;
|
|
890
|
-
}
|
|
891
|
-
return {
|
|
892
|
-
...cache,
|
|
893
|
-
[inboxNotificationId]: callback(existing)
|
|
894
|
-
};
|
|
895
|
-
});
|
|
1032
|
+
markInboxNotificationRead(inboxNotificationId, readAt, optimisticId) {
|
|
1033
|
+
batch2(() => {
|
|
1034
|
+
this.optimisticUpdates.remove(optimisticId);
|
|
1035
|
+
this.notifications.markRead(inboxNotificationId, readAt);
|
|
896
1036
|
});
|
|
897
1037
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
updateAllInboxNotifications(optimisticUpdateId, mapFn) {
|
|
903
|
-
batch(() => {
|
|
904
|
-
this.removeOptimisticUpdate(optimisticUpdateId);
|
|
905
|
-
this.#updateInboxNotificationsCache((cache) => mapValues(cache, mapFn));
|
|
1038
|
+
markAllInboxNotificationsRead(optimisticId, readAt) {
|
|
1039
|
+
batch2(() => {
|
|
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,
|
|
913
|
-
|
|
914
|
-
this.
|
|
915
|
-
this
|
|
916
|
-
const { [inboxNotificationId]: removed, ...newCache } = cache;
|
|
917
|
-
return removed === void 0 ? cache : newCache;
|
|
918
|
-
});
|
|
1048
|
+
deleteInboxNotification(inboxNotificationId, optimisticId) {
|
|
1049
|
+
batch2(() => {
|
|
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(
|
|
926
|
-
|
|
927
|
-
this.
|
|
928
|
-
this
|
|
1058
|
+
deleteAllInboxNotifications(optimisticId) {
|
|
1059
|
+
batch2(() => {
|
|
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(
|
|
935
|
-
|
|
936
|
-
this.
|
|
937
|
-
this
|
|
1067
|
+
createThread(optimisticId, thread) {
|
|
1068
|
+
batch2(() => {
|
|
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
|
|
946
|
-
* - The thread ID was already deleted
|
|
947
|
-
* - The thread ID
|
|
948
|
-
*
|
|
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,
|
|
951
|
-
|
|
952
|
-
if (
|
|
953
|
-
this.
|
|
1083
|
+
#updateThread(threadId, optimisticId, callback, updatedAt) {
|
|
1084
|
+
batch2(() => {
|
|
1085
|
+
if (optimisticId !== null) {
|
|
1086
|
+
this.optimisticUpdates.remove(optimisticId);
|
|
954
1087
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
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,
|
|
1095
|
+
patchThread(threadId, optimisticId, patch, updatedAt) {
|
|
964
1096
|
return this.#updateThread(
|
|
965
1097
|
threadId,
|
|
966
|
-
|
|
1098
|
+
optimisticId,
|
|
967
1099
|
(thread) => ({ ...thread, ...compactObject(patch) }),
|
|
968
1100
|
updatedAt
|
|
969
1101
|
);
|
|
970
1102
|
}
|
|
971
|
-
addReaction(threadId,
|
|
1103
|
+
addReaction(threadId, optimisticId, commentId, reaction, createdAt) {
|
|
972
1104
|
this.#updateThread(
|
|
973
1105
|
threadId,
|
|
974
|
-
|
|
1106
|
+
optimisticId,
|
|
975
1107
|
(thread) => applyAddReaction(thread, commentId, reaction),
|
|
976
1108
|
createdAt
|
|
977
1109
|
);
|
|
978
1110
|
}
|
|
979
|
-
removeReaction(threadId,
|
|
1111
|
+
removeReaction(threadId, optimisticId, commentId, emoji, userId, removedAt) {
|
|
980
1112
|
this.#updateThread(
|
|
981
1113
|
threadId,
|
|
982
|
-
|
|
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
|
|
993
|
-
* - The thread ID was already deleted
|
|
1124
|
+
* - The thread ID isn't found; or
|
|
1125
|
+
* - The thread ID was already deleted
|
|
994
1126
|
*/
|
|
995
|
-
deleteThread(threadId,
|
|
1127
|
+
deleteThread(threadId, optimisticId) {
|
|
996
1128
|
return this.#updateThread(
|
|
997
1129
|
threadId,
|
|
998
|
-
|
|
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,
|
|
1008
|
-
|
|
1009
|
-
this.
|
|
1010
|
-
const existingThread = this.
|
|
1139
|
+
createComment(newComment, optimisticId) {
|
|
1140
|
+
batch2(() => {
|
|
1141
|
+
this.optimisticUpdates.remove(optimisticId);
|
|
1142
|
+
const existingThread = this.threads.get(newComment.threadId);
|
|
1011
1143
|
if (!existingThread) {
|
|
1012
1144
|
return;
|
|
1013
1145
|
}
|
|
1014
|
-
this
|
|
1015
|
-
|
|
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,
|
|
1150
|
+
editComment(threadId, optimisticId, editedComment) {
|
|
1036
1151
|
return this.#updateThread(
|
|
1037
1152
|
threadId,
|
|
1038
|
-
|
|
1153
|
+
optimisticId,
|
|
1039
1154
|
(thread) => applyUpsertComment(thread, editedComment)
|
|
1040
1155
|
);
|
|
1041
1156
|
}
|
|
1042
|
-
deleteComment(threadId,
|
|
1157
|
+
deleteComment(threadId, optimisticId, commentId, deletedAt) {
|
|
1043
1158
|
return this.#updateThread(
|
|
1044
1159
|
threadId,
|
|
1045
|
-
|
|
1160
|
+
optimisticId,
|
|
1046
1161
|
(thread) => applyDeleteComment(thread, commentId, deletedAt),
|
|
1047
1162
|
deletedAt
|
|
1048
1163
|
);
|
|
1049
1164
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
this
|
|
1053
|
-
|
|
1054
|
-
this.#updateInboxNotificationsCache((cache) => ({
|
|
1055
|
-
...cache,
|
|
1056
|
-
[inboxNotification.id]: inboxNotification
|
|
1057
|
-
}));
|
|
1058
|
-
}
|
|
1059
|
-
});
|
|
1060
|
-
}
|
|
1061
|
-
updateThreadsAndNotifications(threads, inboxNotifications, deletedThreads = [], deletedInboxNotifications = []) {
|
|
1062
|
-
batch(() => {
|
|
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
|
-
);
|
|
1165
|
+
updateThreadifications(threads, notifications, deletedThreads = [], deletedNotifications = []) {
|
|
1166
|
+
batch2(() => {
|
|
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
|
-
|
|
1079
|
-
|
|
1080
|
-
this.
|
|
1081
|
-
this
|
|
1175
|
+
updateRoomNotificationSettings(roomId, optimisticId, settings) {
|
|
1176
|
+
batch2(() => {
|
|
1177
|
+
this.optimisticUpdates.remove(optimisticId);
|
|
1178
|
+
this.roomNotificationSettings.update(roomId, settings);
|
|
1082
1179
|
});
|
|
1083
1180
|
}
|
|
1084
|
-
addOptimisticUpdate(optimisticUpdate) {
|
|
1085
|
-
const id = nanoid();
|
|
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.
|
|
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 = 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[kInternal].httpClient.getThreads({
|
|
@@ -1134,11 +1207,8 @@ var UmbrellaStore = class {
|
|
|
1134
1207
|
cursor,
|
|
1135
1208
|
query
|
|
1136
1209
|
});
|
|
1137
|
-
this.
|
|
1138
|
-
|
|
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.
|
|
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
|
|
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.
|
|
1192
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
1219
|
-
this.
|
|
1220
|
-
this.
|
|
1221
|
-
this.optimisticUpdates.
|
|
1222
|
-
this.
|
|
1223
|
-
this.
|
|
1285
|
+
batch2(() => {
|
|
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.
|
|
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
|
|
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[kInternal].listTextVersions();
|
|
1259
|
-
this
|
|
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
|
|
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
|
|
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
|
|
1398
|
+
this.roomNotificationSettings.update(roomId, result);
|
|
1332
1399
|
}
|
|
1333
1400
|
};
|
|
1334
|
-
function applyOptimisticUpdates_forThreadifications(baseThreadsDB,
|
|
1401
|
+
function applyOptimisticUpdates_forThreadifications(baseThreadsDB, notificationsLUT, optimisticUpdates) {
|
|
1335
1402
|
const threadsDB = baseThreadsDB.clone();
|
|
1336
|
-
let notificationsById =
|
|
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(
|
|
1490
|
-
const settingsByRoomId =
|
|
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;
|
|
@@ -1848,7 +1889,7 @@ function makeLiveblocksContextBundle(client) {
|
|
|
1848
1889
|
const shared = createSharedContext(client);
|
|
1849
1890
|
const bundle = {
|
|
1850
1891
|
LiveblocksProvider: LiveblocksProvider2,
|
|
1851
|
-
useInboxNotifications: () => useInboxNotifications_withClient(client, identity,
|
|
1892
|
+
useInboxNotifications: () => useInboxNotifications_withClient(client, identity, shallow4),
|
|
1852
1893
|
useUnreadInboxNotificationsCount: () => useUnreadInboxNotificationsCount_withClient(client),
|
|
1853
1894
|
useMarkInboxNotificationAsRead: useMarkInboxNotificationAsRead2,
|
|
1854
1895
|
useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
|
|
@@ -1885,7 +1926,7 @@ function useInboxNotifications_withClient(client, selector, isEqual) {
|
|
|
1885
1926
|
};
|
|
1886
1927
|
}, [poller]);
|
|
1887
1928
|
return useSyncExternalStoreWithSelector(
|
|
1888
|
-
store.
|
|
1929
|
+
store.subscribe1_notifications,
|
|
1889
1930
|
store.getInboxNotificationsLoadingState,
|
|
1890
1931
|
store.getInboxNotificationsLoadingState,
|
|
1891
1932
|
selector,
|
|
@@ -1895,7 +1936,7 @@ function useInboxNotifications_withClient(client, selector, isEqual) {
|
|
|
1895
1936
|
function useInboxNotificationsSuspense_withClient(client) {
|
|
1896
1937
|
const store = getLiveblocksExtrasForClient(client).store;
|
|
1897
1938
|
use(store.waitUntilNotificationsLoaded());
|
|
1898
|
-
const result = useInboxNotifications_withClient(client, identity,
|
|
1939
|
+
const result = useInboxNotifications_withClient(client, identity, shallow4);
|
|
1899
1940
|
assert(!result.error, "Did not expect error");
|
|
1900
1941
|
assert(!result.isLoading, "Did not expect loading");
|
|
1901
1942
|
return result;
|
|
@@ -1904,7 +1945,7 @@ function useUnreadInboxNotificationsCount_withClient(client) {
|
|
|
1904
1945
|
return useInboxNotifications_withClient(
|
|
1905
1946
|
client,
|
|
1906
1947
|
selectorFor_useUnreadInboxNotificationsCount,
|
|
1907
|
-
|
|
1948
|
+
shallow4
|
|
1908
1949
|
);
|
|
1909
1950
|
}
|
|
1910
1951
|
function useUnreadInboxNotificationsCountSuspense_withClient(client) {
|
|
@@ -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
|
|
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.
|
|
1971
|
+
store.markInboxNotificationRead(
|
|
1931
1972
|
inboxNotificationId,
|
|
1932
|
-
|
|
1933
|
-
|
|
1973
|
+
readAt,
|
|
1974
|
+
optimisticId
|
|
1934
1975
|
);
|
|
1935
1976
|
},
|
|
1936
1977
|
() => {
|
|
1937
|
-
store.
|
|
1978
|
+
store.optimisticUpdates.remove(optimisticId);
|
|
1938
1979
|
}
|
|
1939
1980
|
);
|
|
1940
1981
|
},
|
|
@@ -1945,19 +1986,16 @@ function useMarkAllInboxNotificationsAsRead_withClient(client) {
|
|
|
1945
1986
|
return useCallback2(() => {
|
|
1946
1987
|
const { store } = getLiveblocksExtrasForClient(client);
|
|
1947
1988
|
const readAt = /* @__PURE__ */ new Date();
|
|
1948
|
-
const
|
|
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.
|
|
1955
|
-
optimisticUpdateId,
|
|
1956
|
-
(inboxNotification) => ({ ...inboxNotification, readAt })
|
|
1957
|
-
);
|
|
1995
|
+
store.markAllInboxNotificationsRead(optimisticId, readAt);
|
|
1958
1996
|
},
|
|
1959
1997
|
() => {
|
|
1960
|
-
store.
|
|
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
|
|
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.
|
|
2018
|
+
store.optimisticUpdates.remove(optimisticId);
|
|
1984
2019
|
}
|
|
1985
2020
|
);
|
|
1986
2021
|
},
|
|
@@ -1991,16 +2026,16 @@ function useDeleteAllInboxNotifications_withClient(client) {
|
|
|
1991
2026
|
return useCallback2(() => {
|
|
1992
2027
|
const { store } = getLiveblocksExtrasForClient(client);
|
|
1993
2028
|
const deletedAt = /* @__PURE__ */ new Date();
|
|
1994
|
-
const
|
|
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(
|
|
2035
|
+
store.deleteAllInboxNotifications(optimisticId);
|
|
2001
2036
|
},
|
|
2002
2037
|
() => {
|
|
2003
|
-
store.
|
|
2038
|
+
store.optimisticUpdates.remove(optimisticId);
|
|
2004
2039
|
}
|
|
2005
2040
|
);
|
|
2006
2041
|
}, [client]);
|
|
@@ -2046,7 +2081,7 @@ function useUser_withClient(client, userId) {
|
|
|
2046
2081
|
getUserState,
|
|
2047
2082
|
getUserState,
|
|
2048
2083
|
selector,
|
|
2049
|
-
|
|
2084
|
+
shallow4
|
|
2050
2085
|
);
|
|
2051
2086
|
useEffect3(() => {
|
|
2052
2087
|
void usersStore.get(userId);
|
|
@@ -2098,7 +2133,7 @@ function useRoomInfo_withClient(client, roomId) {
|
|
|
2098
2133
|
getRoomInfoState,
|
|
2099
2134
|
getRoomInfoState,
|
|
2100
2135
|
selector,
|
|
2101
|
-
|
|
2136
|
+
shallow4
|
|
2102
2137
|
);
|
|
2103
2138
|
useEffect3(() => {
|
|
2104
2139
|
void roomsInfoStore.get(roomId);
|
|
@@ -2262,7 +2297,7 @@ function useUserThreadsSuspense_experimental(options = {
|
|
|
2262
2297
|
return result;
|
|
2263
2298
|
}
|
|
2264
2299
|
function useInboxNotifications() {
|
|
2265
|
-
return useInboxNotifications_withClient(useClient(), identity,
|
|
2300
|
+
return useInboxNotifications_withClient(useClient(), identity, shallow4);
|
|
2266
2301
|
}
|
|
2267
2302
|
function useInboxNotificationsSuspense() {
|
|
2268
2303
|
return useInboxNotificationsSuspense_withClient(useClient());
|
|
@@ -2462,7 +2497,7 @@ function useSignal(signal, selector, isEqual) {
|
|
|
2462
2497
|
}
|
|
2463
2498
|
|
|
2464
2499
|
// src/room.tsx
|
|
2465
|
-
import { shallow as
|
|
2500
|
+
import { shallow as shallow5 } from "@liveblocks/client";
|
|
2466
2501
|
import {
|
|
2467
2502
|
assert as assert2,
|
|
2468
2503
|
console as console3,
|
|
@@ -2594,8 +2629,8 @@ function getRoomExtrasForClient(client) {
|
|
|
2594
2629
|
function makeRoomExtrasForClient(client) {
|
|
2595
2630
|
const store = getUmbrellaStoreForClient(client);
|
|
2596
2631
|
const commentsErrorEventSource = makeEventSource2();
|
|
2597
|
-
function onMutationFailure(innerError,
|
|
2598
|
-
store.
|
|
2632
|
+
function onMutationFailure(innerError, optimisticId, createPublicError) {
|
|
2633
|
+
store.optimisticUpdates.remove(optimisticId);
|
|
2599
2634
|
if (innerError instanceof HttpError2) {
|
|
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 ServerMsgCode.COMMENT_EDITED:
|
|
@@ -2861,10 +2896,16 @@ function RoomProviderInner(props) {
|
|
|
2861
2896
|
case ServerMsgCode.COMMENT_REACTION_REMOVED:
|
|
2862
2897
|
case ServerMsgCode.COMMENT_DELETED:
|
|
2863
2898
|
if (!existingThread) break;
|
|
2864
|
-
store.
|
|
2899
|
+
store.updateThreadifications(
|
|
2900
|
+
[thread],
|
|
2901
|
+
maybeNotification ? [maybeNotification] : []
|
|
2902
|
+
);
|
|
2865
2903
|
break;
|
|
2866
2904
|
case ServerMsgCode.COMMENT_CREATED:
|
|
2867
|
-
store.
|
|
2905
|
+
store.updateThreadifications(
|
|
2906
|
+
[thread],
|
|
2907
|
+
maybeNotification ? [maybeNotification] : []
|
|
2908
|
+
);
|
|
2868
2909
|
break;
|
|
2869
2910
|
default:
|
|
2870
2911
|
break;
|
|
@@ -3128,7 +3169,7 @@ function useOthersMapped(itemSelector, itemIsEqual) {
|
|
|
3128
3169
|
return useOthers(wrappedSelector, wrappedIsEqual);
|
|
3129
3170
|
}
|
|
3130
3171
|
function useOthersConnectionIds() {
|
|
3131
|
-
return useOthers(selectorFor_useOthersConnectionIds,
|
|
3172
|
+
return useOthers(selectorFor_useOthersConnectionIds, shallow5);
|
|
3132
3173
|
}
|
|
3133
3174
|
var NOT_FOUND = Symbol();
|
|
3134
3175
|
function useOther(connectionId, selector, isEqual) {
|
|
@@ -3301,7 +3342,7 @@ function useCreateRoomThread(roomId) {
|
|
|
3301
3342
|
resolved: false
|
|
3302
3343
|
};
|
|
3303
3344
|
const { store, onMutationFailure } = getRoomExtrasForClient(client);
|
|
3304
|
-
const
|
|
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(
|
|
3360
|
+
store.createThread(optimisticId, thread);
|
|
3320
3361
|
},
|
|
3321
3362
|
(err) => onMutationFailure(
|
|
3322
3363
|
err,
|
|
3323
|
-
|
|
3364
|
+
optimisticId,
|
|
3324
3365
|
(err2) => new CreateThreadError(err2, {
|
|
3325
3366
|
roomId,
|
|
3326
3367
|
threadId,
|
|
@@ -3348,7 +3389,7 @@ function useDeleteRoomThread(roomId) {
|
|
|
3348
3389
|
if (existing?.comments?.[0]?.userId !== userId) {
|
|
3349
3390
|
throw new Error("Only the thread creator can delete the thread");
|
|
3350
3391
|
}
|
|
3351
|
-
const
|
|
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[kInternal3].httpClient.deleteThread({ roomId, threadId }).then(
|
|
3358
3399
|
() => {
|
|
3359
|
-
store.deleteThread(threadId,
|
|
3400
|
+
store.deleteThread(threadId, optimisticId);
|
|
3360
3401
|
},
|
|
3361
3402
|
(err) => onMutationFailure(
|
|
3362
3403
|
err,
|
|
3363
|
-
|
|
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
|
|
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[kInternal3].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
|
-
|
|
3439
|
+
optimisticId,
|
|
3404
3440
|
(error) => new EditThreadMetadataError(error, {
|
|
3405
3441
|
roomId,
|
|
3406
3442
|
threadId,
|
|
@@ -3433,18 +3469,18 @@ function useCreateRoomComment(roomId) {
|
|
|
3433
3469
|
attachments: attachments ?? []
|
|
3434
3470
|
};
|
|
3435
3471
|
const { store, onMutationFailure } = getRoomExtrasForClient(client);
|
|
3436
|
-
const
|
|
3472
|
+
const optimisticId = store.optimisticUpdates.add({
|
|
3437
3473
|
type: "create-comment",
|
|
3438
3474
|
comment
|
|
3439
3475
|
});
|
|
3440
3476
|
const attachmentIds = attachments?.map((attachment) => attachment.id);
|
|
3441
3477
|
client[kInternal3].httpClient.createComment({ roomId, threadId, commentId, body, attachmentIds }).then(
|
|
3442
3478
|
(newComment) => {
|
|
3443
|
-
store.createComment(newComment,
|
|
3479
|
+
store.createComment(newComment, optimisticId);
|
|
3444
3480
|
},
|
|
3445
3481
|
(err) => onMutationFailure(
|
|
3446
3482
|
err,
|
|
3447
|
-
|
|
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
|
|
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 = attachments?.map((attachment) => attachment.id);
|
|
3496
3532
|
client[kInternal3].httpClient.editComment({ roomId, threadId, commentId, body, attachmentIds }).then(
|
|
3497
3533
|
(editedComment) => {
|
|
3498
|
-
store.editComment(threadId,
|
|
3534
|
+
store.editComment(threadId, optimisticId, editedComment);
|
|
3499
3535
|
},
|
|
3500
3536
|
(err) => onMutationFailure(
|
|
3501
3537
|
err,
|
|
3502
|
-
|
|
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
|
|
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[kInternal3].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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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.
|
|
3699
|
+
store.markInboxNotificationRead(
|
|
3669
3700
|
inboxNotification.id,
|
|
3670
|
-
|
|
3671
|
-
|
|
3701
|
+
now,
|
|
3702
|
+
optimisticId
|
|
3672
3703
|
);
|
|
3673
3704
|
},
|
|
3674
3705
|
(err) => {
|
|
3675
3706
|
onMutationFailure(
|
|
3676
3707
|
err,
|
|
3677
|
-
|
|
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
|
|
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
|
-
|
|
3738
|
+
optimisticId,
|
|
3708
3739
|
{ resolved: true },
|
|
3709
3740
|
updatedAt
|
|
3710
3741
|
);
|
|
3711
3742
|
},
|
|
3712
3743
|
(err) => onMutationFailure(
|
|
3713
3744
|
err,
|
|
3714
|
-
|
|
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
|
|
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
|
-
|
|
3774
|
+
optimisticId,
|
|
3744
3775
|
{ resolved: false },
|
|
3745
3776
|
updatedAt
|
|
3746
3777
|
);
|
|
3747
3778
|
},
|
|
3748
3779
|
(err) => onMutationFailure(
|
|
3749
3780
|
err,
|
|
3750
|
-
|
|
3781
|
+
optimisticId,
|
|
3751
3782
|
(error) => new MarkThreadAsUnresolvedError(error, {
|
|
3752
3783
|
roomId,
|
|
3753
3784
|
threadId
|
|
@@ -3778,7 +3809,7 @@ function useThreadSubscription(threadId) {
|
|
|
3778
3809
|
},
|
|
3779
3810
|
[threadId]
|
|
3780
3811
|
);
|
|
3781
|
-
return useSignal(signal, selector,
|
|
3812
|
+
return useSignal(signal, selector, shallow5);
|
|
3782
3813
|
}
|
|
3783
3814
|
function useRoomNotificationSettings() {
|
|
3784
3815
|
const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
|
|
@@ -3914,22 +3945,18 @@ function useUpdateRoomNotificationSettings() {
|
|
|
3914
3945
|
return useCallback3(
|
|
3915
3946
|
(settings) => {
|
|
3916
3947
|
const { store, onMutationFailure } = getRoomExtrasForClient(client);
|
|
3917
|
-
const
|
|
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.
|
|
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
|
-
|
|
3959
|
+
optimisticId,
|
|
3933
3960
|
(error) => new UpdateNotificationSettingsError(error, {
|
|
3934
3961
|
roomId: room.id
|
|
3935
3962
|
})
|
|
@@ -4037,7 +4064,7 @@ function useRoomAttachmentUrl(attachmentId, roomId) {
|
|
|
4037
4064
|
getAttachmentUrlState,
|
|
4038
4065
|
getAttachmentUrlState,
|
|
4039
4066
|
selectorFor_useAttachmentUrl,
|
|
4040
|
-
|
|
4067
|
+
shallow5
|
|
4041
4068
|
);
|
|
4042
4069
|
}
|
|
4043
4070
|
function useAttachmentUrlSuspense(attachmentId) {
|
|
@@ -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.
|
|
4102
|
+
store.permissionHints.signal,
|
|
4076
4103
|
(hints) => hints[roomId] ?? /* @__PURE__ */ new Set()
|
|
4077
4104
|
);
|
|
4078
4105
|
}
|
|
@@ -4223,4 +4250,4 @@ export {
|
|
|
4223
4250
|
_useStorageRoot,
|
|
4224
4251
|
_useUpdateMyPresence
|
|
4225
4252
|
};
|
|
4226
|
-
//# sourceMappingURL=chunk-
|
|
4253
|
+
//# sourceMappingURL=chunk-GMKB6I6V.mjs.map
|