@liveblocks/react 2.24.0-deque1 → 2.24.0
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.cjs +7 -5
- package/dist/_private.cjs.map +1 -1
- package/dist/_private.d.cts +1 -1
- package/dist/_private.d.ts +1 -1
- package/dist/_private.js +3 -1
- package/dist/_private.js.map +1 -1
- package/dist/{chunk-L4OEDVVN.js → chunk-2GC6FA36.js} +2 -2
- package/dist/{chunk-C337YEKB.cjs → chunk-32HQP5F6.cjs} +486 -137
- package/dist/chunk-32HQP5F6.cjs.map +1 -0
- package/dist/{chunk-LFSDRNVE.cjs → chunk-F2Y7N4WI.cjs} +2 -2
- package/dist/{chunk-LFSDRNVE.cjs.map → chunk-F2Y7N4WI.cjs.map} +1 -1
- package/dist/{chunk-URVBSXYW.js → chunk-N6OQQVYV.js} +501 -152
- package/dist/chunk-N6OQQVYV.js.map +1 -0
- package/dist/index.cjs +12 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/{room-CqmA66N2.d.cts → room-CqT08uWZ.d.cts} +210 -70
- package/dist/{room-CqmA66N2.d.ts → room-CqT08uWZ.d.ts} +210 -70
- package/dist/suspense.cjs +12 -4
- package/dist/suspense.cjs.map +1 -1
- package/dist/suspense.d.cts +1 -1
- package/dist/suspense.d.ts +1 -1
- package/dist/suspense.js +11 -3
- package/dist/suspense.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-C337YEKB.cjs.map +0 -1
- package/dist/chunk-URVBSXYW.js.map +0 -1
- /package/dist/{chunk-L4OEDVVN.js.map → chunk-2GC6FA36.js.map} +0 -0
|
@@ -132,8 +132,8 @@ var config = {
|
|
|
132
132
|
USER_THREADS_MAX_STALE_TIME: 30 * SECONDS,
|
|
133
133
|
HISTORY_VERSIONS_POLL_INTERVAL: 1 * MINUTES,
|
|
134
134
|
HISTORY_VERSIONS_MAX_STALE_TIME: 5 * SECONDS,
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
ROOM_SUBSCRIPTION_SETTINGS_POLL_INTERVAL: 1 * MINUTES,
|
|
136
|
+
ROOM_SUBSCRIPTION_SETTINGS_MAX_STALE_TIME: 5 * SECONDS,
|
|
137
137
|
USER_NOTIFICATION_SETTINGS_INTERVAL: 5 * MINUTES,
|
|
138
138
|
USER_NOTIFICATION_SETTINGS_MAX_STALE_TIME: 1 * MINUTES
|
|
139
139
|
};
|
|
@@ -247,6 +247,10 @@ var use = (
|
|
|
247
247
|
|
|
248
248
|
|
|
249
249
|
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
250
254
|
|
|
251
255
|
|
|
252
256
|
// src/lib/autobind.ts
|
|
@@ -266,21 +270,6 @@ function autobind(self) {
|
|
|
266
270
|
} while ((obj = Reflect.getPrototypeOf(obj)) && obj !== Object.prototype);
|
|
267
271
|
}
|
|
268
272
|
|
|
269
|
-
// src/lib/shallow2.ts
|
|
270
|
-
|
|
271
|
-
function shallow2(a, b) {
|
|
272
|
-
if (!_core.isPlainObject.call(void 0, a) || !_core.isPlainObject.call(void 0, b)) {
|
|
273
|
-
return _core.shallow.call(void 0, a, b);
|
|
274
|
-
}
|
|
275
|
-
const keysA = Object.keys(a);
|
|
276
|
-
if (keysA.length !== Object.keys(b).length) {
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
return keysA.every(
|
|
280
|
-
(key) => Object.prototype.hasOwnProperty.call(b, key) && _core.shallow.call(void 0, a[key], b[key])
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
273
|
// src/ThreadDB.ts
|
|
285
274
|
|
|
286
275
|
|
|
@@ -431,7 +420,9 @@ var ThreadDB = class _ThreadDB {
|
|
|
431
420
|
if (roomId !== void 0) {
|
|
432
421
|
crit.push((t) => t.roomId === roomId);
|
|
433
422
|
}
|
|
434
|
-
|
|
423
|
+
if (query !== void 0) {
|
|
424
|
+
crit.push(makeThreadsFilter(query));
|
|
425
|
+
}
|
|
435
426
|
return Array.from(index.filter((t) => crit.every((pred) => pred(t))));
|
|
436
427
|
}
|
|
437
428
|
};
|
|
@@ -667,7 +658,45 @@ function createStore_forNotifications() {
|
|
|
667
658
|
upsert
|
|
668
659
|
};
|
|
669
660
|
}
|
|
670
|
-
function
|
|
661
|
+
function createStore_forSubscriptions(updates, threads) {
|
|
662
|
+
const baseSignal = new (0, _core.MutableSignal)(/* @__PURE__ */ new Map());
|
|
663
|
+
function applyDelta(newSubscriptions, deletedSubscriptions) {
|
|
664
|
+
baseSignal.mutate((lut) => {
|
|
665
|
+
let mutated = false;
|
|
666
|
+
for (const s of newSubscriptions) {
|
|
667
|
+
lut.set(_core.getSubscriptionKey.call(void 0, s), s);
|
|
668
|
+
mutated = true;
|
|
669
|
+
}
|
|
670
|
+
for (const s of deletedSubscriptions) {
|
|
671
|
+
lut.delete(_core.getSubscriptionKey.call(void 0, s));
|
|
672
|
+
mutated = true;
|
|
673
|
+
}
|
|
674
|
+
return mutated;
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
function create(subscription) {
|
|
678
|
+
baseSignal.mutate((lut) => {
|
|
679
|
+
lut.set(_core.getSubscriptionKey.call(void 0, subscription), subscription);
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
function deleteOne(subscriptionKey) {
|
|
683
|
+
baseSignal.mutate((lut) => {
|
|
684
|
+
lut.delete(subscriptionKey);
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
return {
|
|
688
|
+
signal: _core.DerivedSignal.from(
|
|
689
|
+
baseSignal,
|
|
690
|
+
updates,
|
|
691
|
+
(base, updates2) => applyOptimisticUpdates_forSubscriptions(base, threads, updates2)
|
|
692
|
+
),
|
|
693
|
+
// Mutations
|
|
694
|
+
applyDelta,
|
|
695
|
+
create,
|
|
696
|
+
delete: deleteOne
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
function createStore_forRoomSubscriptionSettings(updates) {
|
|
671
700
|
const baseSignal = new (0, _core.MutableSignal)(/* @__PURE__ */ new Map());
|
|
672
701
|
function update(roomId, settings) {
|
|
673
702
|
baseSignal.mutate((lut) => {
|
|
@@ -678,7 +707,7 @@ function createStore_forRoomNotificationSettings(updates) {
|
|
|
678
707
|
signal: _core.DerivedSignal.from(
|
|
679
708
|
baseSignal,
|
|
680
709
|
updates,
|
|
681
|
-
(base, updates2) =>
|
|
710
|
+
(base, updates2) => applyOptimisticUpdates_forRoomSubscriptionSettings(base, updates2)
|
|
682
711
|
),
|
|
683
712
|
// Mutations
|
|
684
713
|
update
|
|
@@ -730,9 +759,9 @@ function createStore_forPermissionHints() {
|
|
|
730
759
|
update
|
|
731
760
|
};
|
|
732
761
|
}
|
|
733
|
-
function
|
|
762
|
+
function createStore_forNotificationSettings(updates) {
|
|
734
763
|
const signal = new (0, _core.Signal)(
|
|
735
|
-
_core.
|
|
764
|
+
_core.createNotificationSettings.call(void 0, {})
|
|
736
765
|
);
|
|
737
766
|
function update(settings) {
|
|
738
767
|
signal.set(settings);
|
|
@@ -741,7 +770,7 @@ function createStore_forUserNotificationSettings(updates) {
|
|
|
741
770
|
signal: _core.DerivedSignal.from(
|
|
742
771
|
signal,
|
|
743
772
|
updates,
|
|
744
|
-
(base, updates2) =>
|
|
773
|
+
(base, updates2) => applyOptimisticUpdates_forNotificationSettings(base, updates2)
|
|
745
774
|
),
|
|
746
775
|
// Mutations
|
|
747
776
|
update
|
|
@@ -780,16 +809,18 @@ var UmbrellaStore = class {
|
|
|
780
809
|
//
|
|
781
810
|
// Mutate inputs... ...observe clean/consistent output!
|
|
782
811
|
//
|
|
783
|
-
// .-> Base ThreadDB ---------+
|
|
812
|
+
// .-> Base ThreadDB ---------+ +-------> Clean threads by ID (Part 1)
|
|
784
813
|
// / | |
|
|
785
|
-
// mutate ----> Base Notifications --+ | |
|
|
786
|
-
// \ | | | |
|
|
814
|
+
// mutate ----> Base Notifications --+ | | +-----> Clean notifications (Part 1)
|
|
815
|
+
// \ | | | | & notifications by ID
|
|
787
816
|
// | \ | | Apply | |
|
|
788
|
-
// | `-> OptimisticUpdates --+--+--> Optimistic
|
|
789
|
-
// \ | Updates |
|
|
790
|
-
// `------- etc etc ---------+ |
|
|
791
|
-
// ^ |
|
|
792
|
-
// |
|
|
817
|
+
// | `-> OptimisticUpdates --+--+--> Optimistic -+-+-+-+-> Subscriptions (Part 2)
|
|
818
|
+
// \ | Updates | | |
|
|
819
|
+
// `------- etc etc ---------+ | | +-> History Versions (Part 3)
|
|
820
|
+
// ^ | |
|
|
821
|
+
// | | +---> Room Subscription Settings (Part 4)
|
|
822
|
+
// | |
|
|
823
|
+
// | +-------> Notification Settings (Part 5)
|
|
793
824
|
// |
|
|
794
825
|
// |
|
|
795
826
|
// | ^ ^
|
|
@@ -808,6 +839,7 @@ var UmbrellaStore = class {
|
|
|
808
839
|
// Exposes its signal under `.signal` prop
|
|
809
840
|
|
|
810
841
|
|
|
842
|
+
|
|
811
843
|
// prettier-ignore
|
|
812
844
|
|
|
813
845
|
|
|
@@ -832,8 +864,8 @@ var UmbrellaStore = class {
|
|
|
832
864
|
#userThreadsLastRequestedAt = null;
|
|
833
865
|
// Room versions
|
|
834
866
|
#roomVersionsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
|
|
835
|
-
//
|
|
836
|
-
#
|
|
867
|
+
// Notification Settings
|
|
868
|
+
#notificationSettings;
|
|
837
869
|
constructor(client) {
|
|
838
870
|
this.#client = client[_core.kInternal].as();
|
|
839
871
|
this.optimisticUpdates = createStore_forOptimistic(this.#client);
|
|
@@ -841,7 +873,11 @@ var UmbrellaStore = class {
|
|
|
841
873
|
this.#notificationsPaginationState = new PaginatedResource(
|
|
842
874
|
async (cursor) => {
|
|
843
875
|
const result = await this.#client.getInboxNotifications({ cursor });
|
|
844
|
-
this.updateThreadifications(
|
|
876
|
+
this.updateThreadifications(
|
|
877
|
+
result.threads,
|
|
878
|
+
result.inboxNotifications,
|
|
879
|
+
result.subscriptions
|
|
880
|
+
);
|
|
845
881
|
if (this.#notificationsLastRequestedAt === null) {
|
|
846
882
|
this.#notificationsLastRequestedAt = result.requestedAt;
|
|
847
883
|
}
|
|
@@ -849,19 +885,23 @@ var UmbrellaStore = class {
|
|
|
849
885
|
return nextCursor;
|
|
850
886
|
}
|
|
851
887
|
);
|
|
852
|
-
const
|
|
888
|
+
const notificationSettingsFetcher = async () => {
|
|
853
889
|
const result = await this.#client.getNotificationSettings();
|
|
854
|
-
this.
|
|
890
|
+
this.notificationSettings.update(result);
|
|
855
891
|
};
|
|
856
|
-
this.
|
|
892
|
+
this.notificationSettings = createStore_forNotificationSettings(
|
|
857
893
|
this.optimisticUpdates.signal
|
|
858
894
|
);
|
|
859
|
-
this.#
|
|
860
|
-
|
|
895
|
+
this.#notificationSettings = new SinglePageResource(
|
|
896
|
+
notificationSettingsFetcher
|
|
861
897
|
);
|
|
862
898
|
this.threads = new ThreadDB();
|
|
899
|
+
this.subscriptions = createStore_forSubscriptions(
|
|
900
|
+
this.optimisticUpdates.signal,
|
|
901
|
+
this.threads
|
|
902
|
+
);
|
|
863
903
|
this.notifications = createStore_forNotifications();
|
|
864
|
-
this.
|
|
904
|
+
this.roomSubscriptionSettings = createStore_forRoomSubscriptionSettings(
|
|
865
905
|
this.optimisticUpdates.signal
|
|
866
906
|
);
|
|
867
907
|
this.historyVersions = createStore_forHistoryVersions();
|
|
@@ -880,6 +920,14 @@ var UmbrellaStore = class {
|
|
|
880
920
|
}),
|
|
881
921
|
_core.shallow
|
|
882
922
|
);
|
|
923
|
+
const threadSubscriptions = _core.DerivedSignal.from(
|
|
924
|
+
notifications,
|
|
925
|
+
this.subscriptions.signal,
|
|
926
|
+
(n, s) => ({
|
|
927
|
+
subscriptions: s,
|
|
928
|
+
notifications: n.sortedNotifications
|
|
929
|
+
})
|
|
930
|
+
);
|
|
883
931
|
const loadingUserThreads = new (0, _core.DefaultMap)(
|
|
884
932
|
(queryKey) => {
|
|
885
933
|
const query = JSON.parse(queryKey);
|
|
@@ -890,7 +938,8 @@ var UmbrellaStore = class {
|
|
|
890
938
|
});
|
|
891
939
|
this.updateThreadifications(
|
|
892
940
|
result.threads,
|
|
893
|
-
result.inboxNotifications
|
|
941
|
+
result.inboxNotifications,
|
|
942
|
+
result.subscriptions
|
|
894
943
|
);
|
|
895
944
|
this.permissionHints.update(result.permissionHints);
|
|
896
945
|
if (this.#userThreadsLastRequestedAt === null) {
|
|
@@ -918,7 +967,7 @@ var UmbrellaStore = class {
|
|
|
918
967
|
fetchMoreError: page.fetchMoreError,
|
|
919
968
|
fetchMore: page.fetchMore
|
|
920
969
|
};
|
|
921
|
-
}, shallow2);
|
|
970
|
+
}, _core.shallow2);
|
|
922
971
|
return { signal, waitUntilLoaded: resource.waitUntilLoaded };
|
|
923
972
|
}
|
|
924
973
|
);
|
|
@@ -933,7 +982,8 @@ var UmbrellaStore = class {
|
|
|
933
982
|
});
|
|
934
983
|
this.updateThreadifications(
|
|
935
984
|
result.threads,
|
|
936
|
-
result.inboxNotifications
|
|
985
|
+
result.inboxNotifications,
|
|
986
|
+
result.subscriptions
|
|
937
987
|
);
|
|
938
988
|
this.permissionHints.update(result.permissionHints);
|
|
939
989
|
const lastRequestedAt = this.#roomThreadsLastRequestedAtByRoom.get(roomId);
|
|
@@ -960,7 +1010,7 @@ var UmbrellaStore = class {
|
|
|
960
1010
|
fetchMoreError: page.fetchMoreError,
|
|
961
1011
|
fetchMore: page.fetchMore
|
|
962
1012
|
};
|
|
963
|
-
}, shallow2);
|
|
1013
|
+
}, _core.shallow2);
|
|
964
1014
|
return { signal, waitUntilLoaded: resource.waitUntilLoaded };
|
|
965
1015
|
}
|
|
966
1016
|
);
|
|
@@ -983,28 +1033,30 @@ var UmbrellaStore = class {
|
|
|
983
1033
|
}),
|
|
984
1034
|
waitUntilLoaded: this.#notificationsPaginationState.waitUntilLoaded
|
|
985
1035
|
};
|
|
986
|
-
const
|
|
987
|
-
|
|
988
|
-
const
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
const
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1036
|
+
const roomSubscriptionSettingsByRoomId = new (0, _core.DefaultMap)(
|
|
1037
|
+
(roomId) => {
|
|
1038
|
+
const resource = new SinglePageResource(async () => {
|
|
1039
|
+
const room = this.#client.getRoom(roomId);
|
|
1040
|
+
if (room === null) {
|
|
1041
|
+
throw new Error(`Room '${roomId}' is not available on client`);
|
|
1042
|
+
}
|
|
1043
|
+
const result = await room.getSubscriptionSettings();
|
|
1044
|
+
this.roomSubscriptionSettings.update(roomId, result);
|
|
1045
|
+
});
|
|
1046
|
+
const signal = _core.DerivedSignal.from(() => {
|
|
1047
|
+
const result = resource.get();
|
|
1048
|
+
if (result.isLoading || result.error) {
|
|
1049
|
+
return result;
|
|
1050
|
+
} else {
|
|
1051
|
+
return ASYNC_OK(
|
|
1052
|
+
"settings",
|
|
1053
|
+
_core.nn.call(void 0, this.roomSubscriptionSettings.signal.get()[roomId])
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
}, _core.shallow);
|
|
1057
|
+
return { signal, waitUntilLoaded: resource.waitUntilLoaded };
|
|
1058
|
+
}
|
|
1059
|
+
);
|
|
1008
1060
|
const versionsByRoomId = new (0, _core.DefaultMap)(
|
|
1009
1061
|
(roomId) => {
|
|
1010
1062
|
const resource = new SinglePageResource(async () => {
|
|
@@ -1036,18 +1088,18 @@ var UmbrellaStore = class {
|
|
|
1036
1088
|
return { signal, waitUntilLoaded: resource.waitUntilLoaded };
|
|
1037
1089
|
}
|
|
1038
1090
|
);
|
|
1039
|
-
const
|
|
1091
|
+
const notificationSettings = {
|
|
1040
1092
|
signal: _core.DerivedSignal.from(() => {
|
|
1041
|
-
const result = this.#
|
|
1093
|
+
const result = this.#notificationSettings.get();
|
|
1042
1094
|
if (result.isLoading || result.error) {
|
|
1043
1095
|
return result;
|
|
1044
1096
|
}
|
|
1045
1097
|
return ASYNC_OK(
|
|
1046
1098
|
"settings",
|
|
1047
|
-
_core.nn.call(void 0, this.
|
|
1099
|
+
_core.nn.call(void 0, this.notificationSettings.signal.get())
|
|
1048
1100
|
);
|
|
1049
1101
|
}, _core.shallow),
|
|
1050
|
-
waitUntilLoaded: this.#
|
|
1102
|
+
waitUntilLoaded: this.#notificationSettings.waitUntilLoaded
|
|
1051
1103
|
};
|
|
1052
1104
|
this.outputs = {
|
|
1053
1105
|
threadifications,
|
|
@@ -1056,9 +1108,10 @@ var UmbrellaStore = class {
|
|
|
1056
1108
|
loadingUserThreads,
|
|
1057
1109
|
notifications,
|
|
1058
1110
|
loadingNotifications,
|
|
1059
|
-
|
|
1111
|
+
roomSubscriptionSettingsByRoomId,
|
|
1060
1112
|
versionsByRoomId,
|
|
1061
|
-
|
|
1113
|
+
notificationSettings,
|
|
1114
|
+
threadSubscriptions
|
|
1062
1115
|
};
|
|
1063
1116
|
autobind(this);
|
|
1064
1117
|
}
|
|
@@ -1100,6 +1153,26 @@ var UmbrellaStore = class {
|
|
|
1100
1153
|
this.notifications.clear();
|
|
1101
1154
|
});
|
|
1102
1155
|
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Creates an existing subscription, replacing the corresponding
|
|
1158
|
+
* optimistic update.
|
|
1159
|
+
*/
|
|
1160
|
+
createSubscription(subscription, optimisticId) {
|
|
1161
|
+
_core.batch.call(void 0, () => {
|
|
1162
|
+
this.optimisticUpdates.remove(optimisticId);
|
|
1163
|
+
this.subscriptions.create(subscription);
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Deletes an existing subscription, replacing the corresponding
|
|
1168
|
+
* optimistic update.
|
|
1169
|
+
*/
|
|
1170
|
+
deleteSubscription(subscriptionKey, optimisticId) {
|
|
1171
|
+
_core.batch.call(void 0, () => {
|
|
1172
|
+
this.optimisticUpdates.remove(optimisticId);
|
|
1173
|
+
this.subscriptions.delete(subscriptionKey);
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1103
1176
|
/**
|
|
1104
1177
|
* Creates an new thread, replacing the corresponding optimistic update.
|
|
1105
1178
|
*/
|
|
@@ -1201,20 +1274,21 @@ var UmbrellaStore = class {
|
|
|
1201
1274
|
deletedAt
|
|
1202
1275
|
);
|
|
1203
1276
|
}
|
|
1204
|
-
updateThreadifications(threads, notifications, deletedThreads = [], deletedNotifications = []) {
|
|
1277
|
+
updateThreadifications(threads, notifications, subscriptions, deletedThreads = [], deletedNotifications = [], deletedSubscriptions = []) {
|
|
1205
1278
|
_core.batch.call(void 0, () => {
|
|
1206
1279
|
this.threads.applyDelta(threads, deletedThreads);
|
|
1207
1280
|
this.notifications.applyDelta(notifications, deletedNotifications);
|
|
1281
|
+
this.subscriptions.applyDelta(subscriptions, deletedSubscriptions);
|
|
1208
1282
|
});
|
|
1209
1283
|
}
|
|
1210
1284
|
/**
|
|
1211
|
-
* Updates existing
|
|
1285
|
+
* Updates existing subscription settings for a room with a new value,
|
|
1212
1286
|
* replacing the corresponding optimistic update.
|
|
1213
1287
|
*/
|
|
1214
|
-
|
|
1288
|
+
updateRoomSubscriptionSettings(roomId, optimisticId, settings) {
|
|
1215
1289
|
_core.batch.call(void 0, () => {
|
|
1216
1290
|
this.optimisticUpdates.remove(optimisticId);
|
|
1217
|
-
this.
|
|
1291
|
+
this.roomSubscriptionSettings.update(roomId, settings);
|
|
1218
1292
|
});
|
|
1219
1293
|
}
|
|
1220
1294
|
async fetchNotificationsDeltaUpdate(signal) {
|
|
@@ -1232,8 +1306,10 @@ var UmbrellaStore = class {
|
|
|
1232
1306
|
this.updateThreadifications(
|
|
1233
1307
|
result.threads.updated,
|
|
1234
1308
|
result.inboxNotifications.updated,
|
|
1309
|
+
result.subscriptions.updated,
|
|
1235
1310
|
result.threads.deleted,
|
|
1236
|
-
result.inboxNotifications.deleted
|
|
1311
|
+
result.inboxNotifications.deleted,
|
|
1312
|
+
result.subscriptions.deleted
|
|
1237
1313
|
);
|
|
1238
1314
|
}
|
|
1239
1315
|
async fetchRoomThreadsDeltaUpdate(roomId, signal) {
|
|
@@ -1249,8 +1325,10 @@ var UmbrellaStore = class {
|
|
|
1249
1325
|
this.updateThreadifications(
|
|
1250
1326
|
updates.threads.updated,
|
|
1251
1327
|
updates.inboxNotifications.updated,
|
|
1328
|
+
updates.subscriptions.updated,
|
|
1252
1329
|
updates.threads.deleted,
|
|
1253
|
-
updates.inboxNotifications.deleted
|
|
1330
|
+
updates.inboxNotifications.deleted,
|
|
1331
|
+
updates.subscriptions.deleted
|
|
1254
1332
|
);
|
|
1255
1333
|
this.permissionHints.update(updates.permissionHints);
|
|
1256
1334
|
if (lastRequestedAt < updates.requestedAt) {
|
|
@@ -1272,8 +1350,10 @@ var UmbrellaStore = class {
|
|
|
1272
1350
|
this.updateThreadifications(
|
|
1273
1351
|
result.threads.updated,
|
|
1274
1352
|
result.inboxNotifications.updated,
|
|
1353
|
+
result.subscriptions.updated,
|
|
1275
1354
|
result.threads.deleted,
|
|
1276
|
-
result.inboxNotifications.deleted
|
|
1355
|
+
result.inboxNotifications.deleted,
|
|
1356
|
+
result.subscriptions.deleted
|
|
1277
1357
|
);
|
|
1278
1358
|
this.permissionHints.update(result.permissionHints);
|
|
1279
1359
|
}
|
|
@@ -1295,31 +1375,31 @@ var UmbrellaStore = class {
|
|
|
1295
1375
|
this.#roomVersionsLastRequestedAtByRoom.set(roomId, updates.requestedAt);
|
|
1296
1376
|
}
|
|
1297
1377
|
}
|
|
1298
|
-
async
|
|
1378
|
+
async refreshRoomSubscriptionSettings(roomId, signal) {
|
|
1299
1379
|
const room = _core.nn.call(void 0,
|
|
1300
1380
|
this.#client.getRoom(roomId),
|
|
1301
1381
|
`Room with id ${roomId} is not available on client`
|
|
1302
1382
|
);
|
|
1303
|
-
const result = await room.
|
|
1304
|
-
this.
|
|
1383
|
+
const result = await room.getSubscriptionSettings({ signal });
|
|
1384
|
+
this.roomSubscriptionSettings.update(roomId, result);
|
|
1305
1385
|
}
|
|
1306
1386
|
/**
|
|
1307
|
-
* Refresh
|
|
1387
|
+
* Refresh notification settings from poller
|
|
1308
1388
|
*/
|
|
1309
|
-
async
|
|
1389
|
+
async refreshNotificationSettings(signal) {
|
|
1310
1390
|
const result = await this.#client.getNotificationSettings({
|
|
1311
1391
|
signal
|
|
1312
1392
|
});
|
|
1313
|
-
this.
|
|
1393
|
+
this.notificationSettings.update(result);
|
|
1314
1394
|
}
|
|
1315
1395
|
/**
|
|
1316
|
-
* Updates
|
|
1396
|
+
* Updates notification settings with a new value, replacing the
|
|
1317
1397
|
* corresponding optimistic update.
|
|
1318
1398
|
*/
|
|
1319
|
-
|
|
1399
|
+
updateNotificationSettings_confirmOptimisticUpdate(settings, optimisticUpdateId) {
|
|
1320
1400
|
_core.batch.call(void 0, () => {
|
|
1321
1401
|
this.optimisticUpdates.remove(optimisticUpdateId);
|
|
1322
|
-
this.
|
|
1402
|
+
this.notificationSettings.update(settings);
|
|
1323
1403
|
});
|
|
1324
1404
|
}
|
|
1325
1405
|
};
|
|
@@ -1478,29 +1558,78 @@ function applyOptimisticUpdates_forThreadifications(baseThreadsDB, notifications
|
|
|
1478
1558
|
threadsDB
|
|
1479
1559
|
};
|
|
1480
1560
|
}
|
|
1481
|
-
function
|
|
1482
|
-
const
|
|
1561
|
+
function applyOptimisticUpdates_forRoomSubscriptionSettings(settingsLUT, optimisticUpdates) {
|
|
1562
|
+
const roomSubscriptionSettingsByRoomId = Object.fromEntries(settingsLUT);
|
|
1483
1563
|
for (const optimisticUpdate of optimisticUpdates) {
|
|
1484
1564
|
switch (optimisticUpdate.type) {
|
|
1485
|
-
case "update-
|
|
1486
|
-
const settings =
|
|
1565
|
+
case "update-room-subscription-settings": {
|
|
1566
|
+
const settings = roomSubscriptionSettingsByRoomId[optimisticUpdate.roomId];
|
|
1487
1567
|
if (settings === void 0) {
|
|
1488
1568
|
break;
|
|
1489
1569
|
}
|
|
1490
|
-
|
|
1570
|
+
roomSubscriptionSettingsByRoomId[optimisticUpdate.roomId] = {
|
|
1491
1571
|
...settings,
|
|
1492
1572
|
...optimisticUpdate.settings
|
|
1493
1573
|
};
|
|
1494
1574
|
}
|
|
1495
1575
|
}
|
|
1496
1576
|
}
|
|
1497
|
-
return
|
|
1577
|
+
return roomSubscriptionSettingsByRoomId;
|
|
1498
1578
|
}
|
|
1499
|
-
function
|
|
1579
|
+
function applyOptimisticUpdates_forSubscriptions(subscriptionsLUT, threads, optimisticUpdates) {
|
|
1580
|
+
const subscriptions = Object.fromEntries(subscriptionsLUT);
|
|
1581
|
+
for (const update of optimisticUpdates) {
|
|
1582
|
+
switch (update.type) {
|
|
1583
|
+
case "update-room-subscription-settings": {
|
|
1584
|
+
if (!update.settings.threads) {
|
|
1585
|
+
continue;
|
|
1586
|
+
}
|
|
1587
|
+
const roomThreads = threads.findMany(update.roomId, void 0, "desc");
|
|
1588
|
+
for (const thread of roomThreads) {
|
|
1589
|
+
const subscriptionKey = _core.getSubscriptionKey.call(void 0, "thread", thread.id);
|
|
1590
|
+
switch (update.settings.threads) {
|
|
1591
|
+
// Create subscriptions for all existing threads in the room
|
|
1592
|
+
case "all": {
|
|
1593
|
+
subscriptions[subscriptionKey] = {
|
|
1594
|
+
kind: "thread",
|
|
1595
|
+
subjectId: thread.id,
|
|
1596
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
1597
|
+
};
|
|
1598
|
+
break;
|
|
1599
|
+
}
|
|
1600
|
+
// Delete subscriptions for all existing threads in the room
|
|
1601
|
+
case "none": {
|
|
1602
|
+
delete subscriptions[subscriptionKey];
|
|
1603
|
+
break;
|
|
1604
|
+
}
|
|
1605
|
+
// Create subscriptions for every threads in the room which the user participates in but doesn't have a subscription for yet
|
|
1606
|
+
case "replies_and_mentions": {
|
|
1607
|
+
if (isThreadParticipant(thread, update.userId) && !subscriptions[subscriptionKey]) {
|
|
1608
|
+
subscriptions[subscriptionKey] = {
|
|
1609
|
+
kind: "thread",
|
|
1610
|
+
subjectId: thread.id,
|
|
1611
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
break;
|
|
1615
|
+
}
|
|
1616
|
+
default:
|
|
1617
|
+
_core.assertNever.call(void 0,
|
|
1618
|
+
update.settings.threads,
|
|
1619
|
+
"Unexpected thread subscription settings."
|
|
1620
|
+
);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
return subscriptions;
|
|
1627
|
+
}
|
|
1628
|
+
function applyOptimisticUpdates_forNotificationSettings(settings, optimisticUpdates) {
|
|
1500
1629
|
let outcoming = settings;
|
|
1501
1630
|
for (const update of optimisticUpdates) {
|
|
1502
|
-
if (update.type === "update-
|
|
1503
|
-
outcoming = _core.
|
|
1631
|
+
if (update.type === "update-notification-settings") {
|
|
1632
|
+
outcoming = _core.patchNotificationSettings.call(void 0, outcoming, update.settings);
|
|
1504
1633
|
}
|
|
1505
1634
|
}
|
|
1506
1635
|
return outcoming;
|
|
@@ -1682,6 +1811,24 @@ function upsertReaction(reactions, reaction) {
|
|
|
1682
1811
|
}
|
|
1683
1812
|
return reactions;
|
|
1684
1813
|
}
|
|
1814
|
+
function isThreadParticipant(thread, userId) {
|
|
1815
|
+
let isParticipant = false;
|
|
1816
|
+
for (const comment of thread.comments) {
|
|
1817
|
+
if (comment.deletedAt) {
|
|
1818
|
+
continue;
|
|
1819
|
+
}
|
|
1820
|
+
if (comment.userId === userId) {
|
|
1821
|
+
isParticipant = true;
|
|
1822
|
+
break;
|
|
1823
|
+
}
|
|
1824
|
+
const mentionedIds = _core.getMentionedIdsFromCommentBody.call(void 0, comment.body);
|
|
1825
|
+
if (mentionedIds.includes(userId)) {
|
|
1826
|
+
isParticipant = true;
|
|
1827
|
+
break;
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
return isParticipant;
|
|
1831
|
+
}
|
|
1685
1832
|
|
|
1686
1833
|
// src/liveblocks.tsx
|
|
1687
1834
|
var _jsxruntime = require('react/jsx-runtime');
|
|
@@ -1798,13 +1945,13 @@ function makeLiveblocksExtrasForClient(client) {
|
|
|
1798
1945
|
config.USER_THREADS_POLL_INTERVAL,
|
|
1799
1946
|
{ maxStaleTimeMs: config.USER_THREADS_MAX_STALE_TIME }
|
|
1800
1947
|
);
|
|
1801
|
-
const
|
|
1948
|
+
const notificationSettingsPoller = _core.makePoller.call(void 0,
|
|
1802
1949
|
async (signal) => {
|
|
1803
1950
|
try {
|
|
1804
|
-
return await store.
|
|
1951
|
+
return await store.refreshNotificationSettings(signal);
|
|
1805
1952
|
} catch (err) {
|
|
1806
1953
|
console.warn(
|
|
1807
|
-
`Polling new
|
|
1954
|
+
`Polling new notification settings failed: ${String(err)}`
|
|
1808
1955
|
);
|
|
1809
1956
|
throw err;
|
|
1810
1957
|
}
|
|
@@ -1816,7 +1963,7 @@ function makeLiveblocksExtrasForClient(client) {
|
|
|
1816
1963
|
store,
|
|
1817
1964
|
notificationsPoller,
|
|
1818
1965
|
userThreadsPoller,
|
|
1819
|
-
|
|
1966
|
+
notificationSettingsPoller
|
|
1820
1967
|
};
|
|
1821
1968
|
}
|
|
1822
1969
|
function makeLiveblocksContextBundle(client) {
|
|
@@ -2044,12 +2191,12 @@ function useUpdateNotificationSettings_withClient(client) {
|
|
|
2044
2191
|
(settings) => {
|
|
2045
2192
|
const { store } = getLiveblocksExtrasForClient(client);
|
|
2046
2193
|
const optimisticUpdateId = store.optimisticUpdates.add({
|
|
2047
|
-
type: "update-
|
|
2194
|
+
type: "update-notification-settings",
|
|
2048
2195
|
settings
|
|
2049
2196
|
});
|
|
2050
2197
|
client.updateNotificationSettings(settings).then(
|
|
2051
2198
|
(settings2) => {
|
|
2052
|
-
store.
|
|
2199
|
+
store.updateNotificationSettings_confirmOptimisticUpdate(
|
|
2053
2200
|
settings2,
|
|
2054
2201
|
optimisticUpdateId
|
|
2055
2202
|
);
|
|
@@ -2078,9 +2225,9 @@ function useUpdateNotificationSettings_withClient(client) {
|
|
|
2078
2225
|
}
|
|
2079
2226
|
function useNotificationSettings_withClient(client) {
|
|
2080
2227
|
const updateNotificationSettings = useUpdateNotificationSettings_withClient(client);
|
|
2081
|
-
const { store,
|
|
2228
|
+
const { store, notificationSettingsPoller: poller } = getLiveblocksExtrasForClient(client);
|
|
2082
2229
|
_react.useEffect.call(void 0, () => {
|
|
2083
|
-
void store.outputs.
|
|
2230
|
+
void store.outputs.notificationSettings.waitUntilLoaded();
|
|
2084
2231
|
});
|
|
2085
2232
|
_react.useEffect.call(void 0, () => {
|
|
2086
2233
|
poller.inc();
|
|
@@ -2089,7 +2236,7 @@ function useNotificationSettings_withClient(client) {
|
|
|
2089
2236
|
poller.dec();
|
|
2090
2237
|
};
|
|
2091
2238
|
}, [poller]);
|
|
2092
|
-
const result = useSignal(store.outputs.
|
|
2239
|
+
const result = useSignal(store.outputs.notificationSettings.signal);
|
|
2093
2240
|
return _react.useMemo.call(void 0, () => {
|
|
2094
2241
|
return [result, updateNotificationSettings];
|
|
2095
2242
|
}, [result, updateNotificationSettings]);
|
|
@@ -2097,7 +2244,7 @@ function useNotificationSettings_withClient(client) {
|
|
|
2097
2244
|
function useNotificationSettingsSuspense_withClient(client) {
|
|
2098
2245
|
ensureNotServerSide();
|
|
2099
2246
|
const store = getLiveblocksExtrasForClient(client).store;
|
|
2100
|
-
use(store.outputs.
|
|
2247
|
+
use(store.outputs.notificationSettings.waitUntilLoaded());
|
|
2101
2248
|
const [result, updateNotificationSettings] = useNotificationSettings_withClient(client);
|
|
2102
2249
|
_core.assert.call(void 0, !result.error, "Did not expect error");
|
|
2103
2250
|
_core.assert.call(void 0, !result.isLoading, "Did not expect loading");
|
|
@@ -2469,6 +2616,7 @@ var _client = require('@liveblocks/client');
|
|
|
2469
2616
|
|
|
2470
2617
|
|
|
2471
2618
|
|
|
2619
|
+
|
|
2472
2620
|
|
|
2473
2621
|
|
|
2474
2622
|
// src/use-scroll-to-comment-on-load-effect.ts
|
|
@@ -2615,29 +2763,36 @@ function makeRoomExtrasForClient(client) {
|
|
|
2615
2763
|
{ maxStaleTimeMs: config.HISTORY_VERSIONS_MAX_STALE_TIME }
|
|
2616
2764
|
)
|
|
2617
2765
|
);
|
|
2618
|
-
const
|
|
2766
|
+
const roomSubscriptionSettingsPollersByRoomId = new (0, _core.DefaultMap)(
|
|
2619
2767
|
(roomId) => _core.makePoller.call(void 0,
|
|
2620
2768
|
async (signal) => {
|
|
2621
2769
|
try {
|
|
2622
|
-
return await store.
|
|
2770
|
+
return await store.refreshRoomSubscriptionSettings(roomId, signal);
|
|
2623
2771
|
} catch (err) {
|
|
2624
|
-
_core.console.warn(`Polling
|
|
2772
|
+
_core.console.warn(`Polling subscription settings for '${roomId}' failed: ${String(err)}`);
|
|
2625
2773
|
throw err;
|
|
2626
2774
|
}
|
|
2627
2775
|
},
|
|
2628
|
-
config.
|
|
2629
|
-
{ maxStaleTimeMs: config.
|
|
2776
|
+
config.ROOM_SUBSCRIPTION_SETTINGS_POLL_INTERVAL,
|
|
2777
|
+
{ maxStaleTimeMs: config.ROOM_SUBSCRIPTION_SETTINGS_MAX_STALE_TIME }
|
|
2630
2778
|
)
|
|
2631
2779
|
);
|
|
2632
2780
|
return {
|
|
2633
2781
|
store,
|
|
2634
2782
|
onMutationFailure,
|
|
2783
|
+
pollThreadsForRoomId: (roomId) => {
|
|
2784
|
+
const threadsPoller = threadsPollersByRoomId.getOrCreate(roomId);
|
|
2785
|
+
if (threadsPoller) {
|
|
2786
|
+
threadsPoller.markAsStale();
|
|
2787
|
+
threadsPoller.pollNowIfStale();
|
|
2788
|
+
}
|
|
2789
|
+
},
|
|
2635
2790
|
getOrCreateThreadsPollerForRoomId: threadsPollersByRoomId.getOrCreate.bind(
|
|
2636
2791
|
threadsPollersByRoomId
|
|
2637
2792
|
),
|
|
2638
2793
|
getOrCreateVersionsPollerForRoomId: versionsPollersByRoomId.getOrCreate.bind(versionsPollersByRoomId),
|
|
2639
|
-
|
|
2640
|
-
|
|
2794
|
+
getOrCreateSubscriptionSettingsPollerForRoomId: roomSubscriptionSettingsPollersByRoomId.getOrCreate.bind(
|
|
2795
|
+
roomSubscriptionSettingsPollersByRoomId
|
|
2641
2796
|
)
|
|
2642
2797
|
};
|
|
2643
2798
|
}
|
|
@@ -2678,6 +2833,8 @@ function makeRoomContextBundle(client) {
|
|
|
2678
2833
|
useEditThreadMetadata,
|
|
2679
2834
|
useMarkThreadAsResolved,
|
|
2680
2835
|
useMarkThreadAsUnresolved,
|
|
2836
|
+
useSubscribeToThread,
|
|
2837
|
+
useUnsubscribeFromThread,
|
|
2681
2838
|
useCreateComment,
|
|
2682
2839
|
useEditComment,
|
|
2683
2840
|
useDeleteComment,
|
|
@@ -2689,7 +2846,9 @@ function makeRoomContextBundle(client) {
|
|
|
2689
2846
|
useHistoryVersions,
|
|
2690
2847
|
useHistoryVersionData,
|
|
2691
2848
|
useRoomNotificationSettings,
|
|
2849
|
+
useRoomSubscriptionSettings,
|
|
2692
2850
|
useUpdateRoomNotificationSettings,
|
|
2851
|
+
useUpdateRoomSubscriptionSettings,
|
|
2693
2852
|
...shared.classic,
|
|
2694
2853
|
suspense: {
|
|
2695
2854
|
RoomContext,
|
|
@@ -2723,6 +2882,8 @@ function makeRoomContextBundle(client) {
|
|
|
2723
2882
|
useEditThreadMetadata,
|
|
2724
2883
|
useMarkThreadAsResolved,
|
|
2725
2884
|
useMarkThreadAsUnresolved,
|
|
2885
|
+
useSubscribeToThread,
|
|
2886
|
+
useUnsubscribeFromThread,
|
|
2726
2887
|
useCreateComment,
|
|
2727
2888
|
useEditComment,
|
|
2728
2889
|
useDeleteComment,
|
|
@@ -2734,7 +2895,9 @@ function makeRoomContextBundle(client) {
|
|
|
2734
2895
|
// TODO: useHistoryVersionData: useHistoryVersionDataSuspense,
|
|
2735
2896
|
useHistoryVersions: useHistoryVersionsSuspense,
|
|
2736
2897
|
useRoomNotificationSettings: useRoomNotificationSettingsSuspense,
|
|
2898
|
+
useRoomSubscriptionSettings: useRoomSubscriptionSettingsSuspense,
|
|
2737
2899
|
useUpdateRoomNotificationSettings,
|
|
2900
|
+
useUpdateRoomSubscriptionSettings,
|
|
2738
2901
|
...shared.suspense
|
|
2739
2902
|
}
|
|
2740
2903
|
};
|
|
@@ -2813,7 +2976,11 @@ function RoomProviderInner(props) {
|
|
|
2813
2976
|
store.deleteThread(message.threadId, null);
|
|
2814
2977
|
return;
|
|
2815
2978
|
}
|
|
2816
|
-
const {
|
|
2979
|
+
const {
|
|
2980
|
+
thread,
|
|
2981
|
+
inboxNotification: maybeNotification,
|
|
2982
|
+
subscription: maybeSubscription
|
|
2983
|
+
} = info;
|
|
2817
2984
|
const existingThread = store.outputs.threads.get().getEvenIfDeleted(message.threadId);
|
|
2818
2985
|
switch (message.type) {
|
|
2819
2986
|
case _core.ServerMsgCode.COMMENT_EDITED:
|
|
@@ -2825,13 +2992,15 @@ function RoomProviderInner(props) {
|
|
|
2825
2992
|
if (!existingThread) break;
|
|
2826
2993
|
store.updateThreadifications(
|
|
2827
2994
|
[thread],
|
|
2828
|
-
maybeNotification ? [maybeNotification] : []
|
|
2995
|
+
maybeNotification ? [maybeNotification] : [],
|
|
2996
|
+
maybeSubscription ? [maybeSubscription] : []
|
|
2829
2997
|
);
|
|
2830
2998
|
break;
|
|
2831
2999
|
case _core.ServerMsgCode.COMMENT_CREATED:
|
|
2832
3000
|
store.updateThreadifications(
|
|
2833
3001
|
[thread],
|
|
2834
|
-
maybeNotification ? [maybeNotification] : []
|
|
3002
|
+
maybeNotification ? [maybeNotification] : [],
|
|
3003
|
+
maybeSubscription ? [maybeSubscription] : []
|
|
2835
3004
|
);
|
|
2836
3005
|
break;
|
|
2837
3006
|
default:
|
|
@@ -3680,25 +3849,103 @@ function useMarkRoomThreadAsUnresolved(roomId) {
|
|
|
3680
3849
|
[client, roomId]
|
|
3681
3850
|
);
|
|
3682
3851
|
}
|
|
3852
|
+
function useSubscribeToThread() {
|
|
3853
|
+
return useSubscribeToRoomThread(useRoom().id);
|
|
3854
|
+
}
|
|
3855
|
+
function useSubscribeToRoomThread(roomId) {
|
|
3856
|
+
const client = useClient();
|
|
3857
|
+
return _react.useCallback.call(void 0,
|
|
3858
|
+
(threadId) => {
|
|
3859
|
+
const subscribedAt = /* @__PURE__ */ new Date();
|
|
3860
|
+
const { store, onMutationFailure } = getRoomExtrasForClient(client);
|
|
3861
|
+
const optimisticId = store.optimisticUpdates.add({
|
|
3862
|
+
type: "subscribe-to-thread",
|
|
3863
|
+
threadId,
|
|
3864
|
+
subscribedAt
|
|
3865
|
+
});
|
|
3866
|
+
client[_core.kInternal].httpClient.subscribeToThread({ roomId, threadId }).then(
|
|
3867
|
+
(subscription) => {
|
|
3868
|
+
store.createSubscription(subscription, optimisticId);
|
|
3869
|
+
},
|
|
3870
|
+
(err) => onMutationFailure(
|
|
3871
|
+
optimisticId,
|
|
3872
|
+
{ type: "SUBSCRIBE_TO_THREAD_ERROR", roomId, threadId },
|
|
3873
|
+
err
|
|
3874
|
+
)
|
|
3875
|
+
);
|
|
3876
|
+
},
|
|
3877
|
+
[client, roomId]
|
|
3878
|
+
);
|
|
3879
|
+
}
|
|
3880
|
+
function useUnsubscribeFromThread() {
|
|
3881
|
+
return useUnsubscribeFromRoomThread(useRoom().id);
|
|
3882
|
+
}
|
|
3883
|
+
function useUnsubscribeFromRoomThread(roomId) {
|
|
3884
|
+
const client = useClient();
|
|
3885
|
+
return _react.useCallback.call(void 0,
|
|
3886
|
+
(threadId) => {
|
|
3887
|
+
const unsubscribedAt = /* @__PURE__ */ new Date();
|
|
3888
|
+
const { store, onMutationFailure } = getRoomExtrasForClient(client);
|
|
3889
|
+
const optimisticId = store.optimisticUpdates.add({
|
|
3890
|
+
type: "unsubscribe-from-thread",
|
|
3891
|
+
threadId,
|
|
3892
|
+
unsubscribedAt
|
|
3893
|
+
});
|
|
3894
|
+
client[_core.kInternal].httpClient.unsubscribeFromThread({ roomId, threadId }).then(
|
|
3895
|
+
() => {
|
|
3896
|
+
store.deleteSubscription(
|
|
3897
|
+
_core.getSubscriptionKey.call(void 0, "thread", threadId),
|
|
3898
|
+
optimisticId
|
|
3899
|
+
);
|
|
3900
|
+
},
|
|
3901
|
+
(err) => onMutationFailure(
|
|
3902
|
+
optimisticId,
|
|
3903
|
+
{ type: "UNSUBSCRIBE_FROM_THREAD_ERROR", roomId, threadId },
|
|
3904
|
+
err
|
|
3905
|
+
)
|
|
3906
|
+
);
|
|
3907
|
+
},
|
|
3908
|
+
[client, roomId]
|
|
3909
|
+
);
|
|
3910
|
+
}
|
|
3683
3911
|
function useThreadSubscription(threadId) {
|
|
3912
|
+
return useRoomThreadSubscription(useRoom().id, threadId);
|
|
3913
|
+
}
|
|
3914
|
+
function useRoomThreadSubscription(roomId, threadId) {
|
|
3684
3915
|
const client = useClient();
|
|
3685
3916
|
const { store } = getRoomExtrasForClient(client);
|
|
3686
|
-
const
|
|
3917
|
+
const subscriptionKey = _react.useMemo.call(void 0,
|
|
3918
|
+
() => _core.getSubscriptionKey.call(void 0, "thread", threadId),
|
|
3919
|
+
[threadId]
|
|
3920
|
+
);
|
|
3921
|
+
const subscribeToThread = useSubscribeToRoomThread(roomId);
|
|
3922
|
+
const unsubscribeFromThread = useUnsubscribeFromRoomThread(roomId);
|
|
3923
|
+
const subscribe = _react.useCallback.call(void 0,
|
|
3924
|
+
() => subscribeToThread(threadId),
|
|
3925
|
+
[subscribeToThread, threadId]
|
|
3926
|
+
);
|
|
3927
|
+
const unsubscribe = _react.useCallback.call(void 0,
|
|
3928
|
+
() => unsubscribeFromThread(threadId),
|
|
3929
|
+
[unsubscribeFromThread, threadId]
|
|
3930
|
+
);
|
|
3931
|
+
const signal = store.outputs.threadSubscriptions;
|
|
3687
3932
|
const selector = _react.useCallback.call(void 0,
|
|
3688
3933
|
(state) => {
|
|
3689
|
-
const
|
|
3934
|
+
const subscription = state.subscriptions[subscriptionKey];
|
|
3935
|
+
const notification = state.notifications.find(
|
|
3690
3936
|
(inboxNotification) => inboxNotification.kind === "thread" && inboxNotification.threadId === threadId
|
|
3691
3937
|
);
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
return { status: "not-subscribed" };
|
|
3938
|
+
if (subscription === void 0) {
|
|
3939
|
+
return { status: "not-subscribed", subscribe, unsubscribe };
|
|
3695
3940
|
}
|
|
3696
3941
|
return {
|
|
3697
3942
|
status: "subscribed",
|
|
3698
|
-
unreadSince: notification.readAt
|
|
3943
|
+
unreadSince: _nullishCoalesce(_optionalChain([notification, 'optionalAccess', _33 => _33.readAt]), () => ( null)),
|
|
3944
|
+
subscribe,
|
|
3945
|
+
unsubscribe
|
|
3699
3946
|
};
|
|
3700
3947
|
},
|
|
3701
|
-
[threadId]
|
|
3948
|
+
[subscriptionKey, threadId, subscribe, unsubscribe]
|
|
3702
3949
|
);
|
|
3703
3950
|
return useSignal(signal, selector, _client.shallow);
|
|
3704
3951
|
}
|
|
@@ -3706,10 +3953,10 @@ function useRoomNotificationSettings() {
|
|
|
3706
3953
|
const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
|
|
3707
3954
|
const client = useClient();
|
|
3708
3955
|
const room = useRoom();
|
|
3709
|
-
const { store,
|
|
3710
|
-
const poller =
|
|
3956
|
+
const { store, getOrCreateSubscriptionSettingsPollerForRoomId } = getRoomExtrasForClient(client);
|
|
3957
|
+
const poller = getOrCreateSubscriptionSettingsPollerForRoomId(room.id);
|
|
3711
3958
|
_react.useEffect.call(void 0,
|
|
3712
|
-
() => void store.outputs.
|
|
3959
|
+
() => void store.outputs.roomSubscriptionSettingsByRoomId.getOrCreate(room.id).waitUntilLoaded()
|
|
3713
3960
|
// NOTE: Deliberately *not* using a dependency array here!
|
|
3714
3961
|
//
|
|
3715
3962
|
// It is important to call waitUntil on *every* render.
|
|
@@ -3727,18 +3974,51 @@ function useRoomNotificationSettings() {
|
|
|
3727
3974
|
};
|
|
3728
3975
|
}, [poller]);
|
|
3729
3976
|
const settings = useSignal(
|
|
3730
|
-
store.outputs.
|
|
3977
|
+
store.outputs.roomSubscriptionSettingsByRoomId.getOrCreate(room.id).signal
|
|
3731
3978
|
);
|
|
3732
3979
|
return _react.useMemo.call(void 0, () => {
|
|
3733
3980
|
return [settings, updateRoomNotificationSettings];
|
|
3734
3981
|
}, [settings, updateRoomNotificationSettings]);
|
|
3735
3982
|
}
|
|
3983
|
+
function useRoomSubscriptionSettings() {
|
|
3984
|
+
const updateRoomSubscriptionSettings = useUpdateRoomSubscriptionSettings();
|
|
3985
|
+
const client = useClient();
|
|
3986
|
+
const room = useRoom();
|
|
3987
|
+
const { store, getOrCreateSubscriptionSettingsPollerForRoomId } = getRoomExtrasForClient(client);
|
|
3988
|
+
const poller = getOrCreateSubscriptionSettingsPollerForRoomId(room.id);
|
|
3989
|
+
_react.useEffect.call(void 0,
|
|
3990
|
+
() => void store.outputs.roomSubscriptionSettingsByRoomId.getOrCreate(room.id).waitUntilLoaded()
|
|
3991
|
+
// NOTE: Deliberately *not* using a dependency array here!
|
|
3992
|
+
//
|
|
3993
|
+
// It is important to call waitUntil on *every* render.
|
|
3994
|
+
// This is harmless though, on most renders, except:
|
|
3995
|
+
// 1. The very first render, in which case we'll want to trigger the initial page fetch.
|
|
3996
|
+
// 2. All other subsequent renders now "just" return the same promise (a quick operation).
|
|
3997
|
+
// 3. If ever the promise would fail, then after 5 seconds it would reset, and on the very
|
|
3998
|
+
// *next* render after that, a *new* fetch/promise will get created.
|
|
3999
|
+
);
|
|
4000
|
+
_react.useEffect.call(void 0, () => {
|
|
4001
|
+
poller.inc();
|
|
4002
|
+
poller.pollNowIfStale();
|
|
4003
|
+
return () => {
|
|
4004
|
+
poller.dec();
|
|
4005
|
+
};
|
|
4006
|
+
}, [poller]);
|
|
4007
|
+
const settings = useSignal(
|
|
4008
|
+
store.outputs.roomSubscriptionSettingsByRoomId.getOrCreate(room.id).signal
|
|
4009
|
+
);
|
|
4010
|
+
return _react.useMemo.call(void 0, () => {
|
|
4011
|
+
return [settings, updateRoomSubscriptionSettings];
|
|
4012
|
+
}, [settings, updateRoomSubscriptionSettings]);
|
|
4013
|
+
}
|
|
3736
4014
|
function useRoomNotificationSettingsSuspense() {
|
|
3737
4015
|
ensureNotServerSide();
|
|
3738
4016
|
const client = useClient();
|
|
3739
4017
|
const store = getRoomExtrasForClient(client).store;
|
|
3740
4018
|
const room = useRoom();
|
|
3741
|
-
use(
|
|
4019
|
+
use(
|
|
4020
|
+
store.outputs.roomSubscriptionSettingsByRoomId.getOrCreate(room.id).waitUntilLoaded()
|
|
4021
|
+
);
|
|
3742
4022
|
const [settings, updateRoomNotificationSettings] = useRoomNotificationSettings();
|
|
3743
4023
|
_core.assert.call(void 0, !settings.error, "Did not expect error");
|
|
3744
4024
|
_core.assert.call(void 0, !settings.isLoading, "Did not expect loading");
|
|
@@ -3746,6 +4026,21 @@ function useRoomNotificationSettingsSuspense() {
|
|
|
3746
4026
|
return [settings, updateRoomNotificationSettings];
|
|
3747
4027
|
}, [settings, updateRoomNotificationSettings]);
|
|
3748
4028
|
}
|
|
4029
|
+
function useRoomSubscriptionSettingsSuspense() {
|
|
4030
|
+
ensureNotServerSide();
|
|
4031
|
+
const client = useClient();
|
|
4032
|
+
const store = getRoomExtrasForClient(client).store;
|
|
4033
|
+
const room = useRoom();
|
|
4034
|
+
use(
|
|
4035
|
+
store.outputs.roomSubscriptionSettingsByRoomId.getOrCreate(room.id).waitUntilLoaded()
|
|
4036
|
+
);
|
|
4037
|
+
const [settings, updateRoomSubscriptionSettings] = useRoomSubscriptionSettings();
|
|
4038
|
+
_core.assert.call(void 0, !settings.error, "Did not expect error");
|
|
4039
|
+
_core.assert.call(void 0, !settings.isLoading, "Did not expect loading");
|
|
4040
|
+
return _react.useMemo.call(void 0, () => {
|
|
4041
|
+
return [settings, updateRoomSubscriptionSettings];
|
|
4042
|
+
}, [settings, updateRoomSubscriptionSettings]);
|
|
4043
|
+
}
|
|
3749
4044
|
function useHistoryVersionData(versionId) {
|
|
3750
4045
|
const [state, setState] = _react.useState.call(void 0, {
|
|
3751
4046
|
isLoading: true
|
|
@@ -3814,15 +4109,24 @@ function useUpdateRoomNotificationSettings() {
|
|
|
3814
4109
|
const room = useRoom();
|
|
3815
4110
|
return _react.useCallback.call(void 0,
|
|
3816
4111
|
(settings) => {
|
|
3817
|
-
const { store, onMutationFailure } = getRoomExtrasForClient(client);
|
|
4112
|
+
const { store, onMutationFailure, pollThreadsForRoomId } = getRoomExtrasForClient(client);
|
|
4113
|
+
const userId = getCurrentUserId(client);
|
|
3818
4114
|
const optimisticId = store.optimisticUpdates.add({
|
|
3819
|
-
type: "update-
|
|
4115
|
+
type: "update-room-subscription-settings",
|
|
3820
4116
|
roomId: room.id,
|
|
4117
|
+
userId,
|
|
3821
4118
|
settings
|
|
3822
4119
|
});
|
|
3823
|
-
room.
|
|
3824
|
-
(
|
|
3825
|
-
store.
|
|
4120
|
+
room.updateSubscriptionSettings(settings).then(
|
|
4121
|
+
(updatedSettings) => {
|
|
4122
|
+
store.updateRoomSubscriptionSettings(
|
|
4123
|
+
room.id,
|
|
4124
|
+
optimisticId,
|
|
4125
|
+
updatedSettings
|
|
4126
|
+
);
|
|
4127
|
+
if (settings.threads) {
|
|
4128
|
+
pollThreadsForRoomId(room.id);
|
|
4129
|
+
}
|
|
3826
4130
|
},
|
|
3827
4131
|
(err) => onMutationFailure(
|
|
3828
4132
|
optimisticId,
|
|
@@ -3834,6 +4138,43 @@ function useUpdateRoomNotificationSettings() {
|
|
|
3834
4138
|
[client, room]
|
|
3835
4139
|
);
|
|
3836
4140
|
}
|
|
4141
|
+
function useUpdateRoomSubscriptionSettings() {
|
|
4142
|
+
const client = useClient();
|
|
4143
|
+
const room = useRoom();
|
|
4144
|
+
return _react.useCallback.call(void 0,
|
|
4145
|
+
(settings) => {
|
|
4146
|
+
const { store, onMutationFailure, pollThreadsForRoomId } = getRoomExtrasForClient(client);
|
|
4147
|
+
const userId = getCurrentUserId(client);
|
|
4148
|
+
const optimisticId = store.optimisticUpdates.add({
|
|
4149
|
+
type: "update-room-subscription-settings",
|
|
4150
|
+
roomId: room.id,
|
|
4151
|
+
userId,
|
|
4152
|
+
settings
|
|
4153
|
+
});
|
|
4154
|
+
room.updateSubscriptionSettings(settings).then(
|
|
4155
|
+
(udpatedSettings) => {
|
|
4156
|
+
store.updateRoomSubscriptionSettings(
|
|
4157
|
+
room.id,
|
|
4158
|
+
optimisticId,
|
|
4159
|
+
udpatedSettings
|
|
4160
|
+
);
|
|
4161
|
+
if (settings.threads) {
|
|
4162
|
+
pollThreadsForRoomId(room.id);
|
|
4163
|
+
}
|
|
4164
|
+
},
|
|
4165
|
+
(err) => onMutationFailure(
|
|
4166
|
+
optimisticId,
|
|
4167
|
+
{
|
|
4168
|
+
type: "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR",
|
|
4169
|
+
roomId: room.id
|
|
4170
|
+
},
|
|
4171
|
+
err
|
|
4172
|
+
)
|
|
4173
|
+
);
|
|
4174
|
+
},
|
|
4175
|
+
[client, room]
|
|
4176
|
+
);
|
|
4177
|
+
}
|
|
3837
4178
|
function useSuspendUntilPresenceReady() {
|
|
3838
4179
|
ensureNotServerSide();
|
|
3839
4180
|
const room = useRoom();
|
|
@@ -3894,7 +4235,7 @@ function useThreadsSuspense(options = {}) {
|
|
|
3894
4235
|
return result;
|
|
3895
4236
|
}
|
|
3896
4237
|
function selectorFor_useAttachmentUrl(state) {
|
|
3897
|
-
if (state === void 0 || _optionalChain([state, 'optionalAccess',
|
|
4238
|
+
if (state === void 0 || _optionalChain([state, 'optionalAccess', _34 => _34.isLoading])) {
|
|
3898
4239
|
return _nullishCoalesce(state, () => ( { isLoading: true }));
|
|
3899
4240
|
}
|
|
3900
4241
|
if (state.error) {
|
|
@@ -3985,7 +4326,9 @@ var _useOthersMappedSuspense = useOthersMappedSuspense;
|
|
|
3985
4326
|
var _useThreads = useThreads;
|
|
3986
4327
|
var _useThreadsSuspense = useThreadsSuspense;
|
|
3987
4328
|
var _useRoomNotificationSettings = useRoomNotificationSettings;
|
|
4329
|
+
var _useRoomSubscriptionSettings = useRoomSubscriptionSettings;
|
|
3988
4330
|
var _useRoomNotificationSettingsSuspense = useRoomNotificationSettingsSuspense;
|
|
4331
|
+
var _useRoomSubscriptionSettingsSuspense = useRoomSubscriptionSettingsSuspense;
|
|
3989
4332
|
var _useHistoryVersions = useHistoryVersions;
|
|
3990
4333
|
var _useHistoryVersionsSuspense = useHistoryVersionsSuspense;
|
|
3991
4334
|
var _useOther = useOther;
|
|
@@ -4111,5 +4454,11 @@ var _useUpdateMyPresence = useUpdateMyPresence;
|
|
|
4111
4454
|
|
|
4112
4455
|
|
|
4113
4456
|
|
|
4114
|
-
|
|
4115
|
-
|
|
4457
|
+
|
|
4458
|
+
|
|
4459
|
+
|
|
4460
|
+
|
|
4461
|
+
|
|
4462
|
+
|
|
4463
|
+
exports.RoomContext = RoomContext; exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; exports.useSignal = useSignal; 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.useNotificationSettings = useNotificationSettings; exports.useNotificationSettingsSuspense = useNotificationSettingsSuspense; exports.useUpdateNotificationSettings = useUpdateNotificationSettings; 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.useErrorListener = useErrorListener; 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.useHistory = useHistory; exports.useUndo = useUndo; exports.useRedo = useRedo; exports.useCanUndo = useCanUndo; exports.useCanRedo = useCanRedo; exports.useOthersConnectionIds = useOthersConnectionIds; 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.useSubscribeToThread = useSubscribeToThread; exports.useUnsubscribeFromThread = useUnsubscribeFromThread; exports.useThreadSubscription = useThreadSubscription; exports.useRoomThreadSubscription = useRoomThreadSubscription; exports.useHistoryVersionData = useHistoryVersionData; exports.useUpdateRoomNotificationSettings = useUpdateRoomNotificationSettings; exports.useUpdateRoomSubscriptionSettings = useUpdateRoomSubscriptionSettings; 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._useRoomSubscriptionSettings = _useRoomSubscriptionSettings; exports._useRoomNotificationSettingsSuspense = _useRoomNotificationSettingsSuspense; exports._useRoomSubscriptionSettingsSuspense = _useRoomSubscriptionSettingsSuspense; 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;
|
|
4464
|
+
//# sourceMappingURL=chunk-32HQP5F6.cjs.map
|