@liveblocks/react 2.15.0 → 2.15.2
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 +5 -3
- package/dist/_private.d.ts +5 -3
- package/dist/_private.js +11 -6
- package/dist/_private.js.map +1 -1
- package/dist/_private.mjs +10 -5
- package/dist/_private.mjs.map +1 -1
- package/dist/{chunk-36VCTTYL.js → chunk-3KHBALYA.js} +2 -2
- package/dist/{chunk-UKPVXB7D.js → chunk-DEAPV4GE.js} +498 -682
- package/dist/chunk-DEAPV4GE.js.map +1 -0
- package/dist/{chunk-NZZCQLBR.mjs → chunk-EEYUKRIA.mjs} +500 -684
- package/dist/chunk-EEYUKRIA.mjs.map +1 -0
- package/dist/{chunk-4HZJQXE5.mjs → chunk-Z5VZOX7K.mjs} +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-XbmI0Hoh.d.mts → room-0rxzsE_0.d.mts} +29 -64
- package/dist/{room-XbmI0Hoh.d.ts → room-0rxzsE_0.d.ts} +29 -64
- 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-NZZCQLBR.mjs.map +0 -1
- package/dist/chunk-UKPVXB7D.js.map +0 -1
- /package/dist/{chunk-36VCTTYL.js.map → chunk-3KHBALYA.js.map} +0 -0
- /package/dist/{chunk-4HZJQXE5.mjs.map → chunk-Z5VZOX7K.mjs.map} +0 -0
|
@@ -85,6 +85,18 @@ function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnaps
|
|
|
85
85
|
return value;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
// src/use-signal.ts
|
|
89
|
+
var identity = (value) => value;
|
|
90
|
+
function useSignal(signal, selector, isEqual) {
|
|
91
|
+
return useSyncExternalStoreWithSelector(
|
|
92
|
+
signal.subscribe,
|
|
93
|
+
signal.get,
|
|
94
|
+
signal.get,
|
|
95
|
+
_nullishCoalesce(selector, () => ( identity)),
|
|
96
|
+
isEqual
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
88
100
|
// src/liveblocks.tsx
|
|
89
101
|
|
|
90
102
|
|
|
@@ -121,19 +133,30 @@ var config = {
|
|
|
121
133
|
NOTIFICATION_SETTINGS_MAX_STALE_TIME: 5 * SECONDS
|
|
122
134
|
};
|
|
123
135
|
|
|
124
|
-
// src/lib/
|
|
136
|
+
// src/lib/AsyncResult.ts
|
|
137
|
+
var ASYNC_LOADING = Object.freeze({ isLoading: true });
|
|
138
|
+
var ASYNC_ERR = (error) => Object.freeze({ isLoading: false, error });
|
|
139
|
+
function ASYNC_OK(fieldOrData, data) {
|
|
140
|
+
if (arguments.length === 1) {
|
|
141
|
+
return Object.freeze({ isLoading: false, data: fieldOrData });
|
|
142
|
+
} else {
|
|
143
|
+
return Object.freeze({ isLoading: false, [fieldOrData]: data });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
125
146
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
147
|
+
// src/lib/itertools.ts
|
|
148
|
+
function find(it, predicate) {
|
|
149
|
+
for (const item of it) {
|
|
150
|
+
if (predicate(item)) return item;
|
|
129
151
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
152
|
+
return void 0;
|
|
153
|
+
}
|
|
154
|
+
function count(it, predicate) {
|
|
155
|
+
let total = 0;
|
|
156
|
+
for (const item of it) {
|
|
157
|
+
if (predicate(item)) total++;
|
|
133
158
|
}
|
|
134
|
-
return
|
|
135
|
-
(key) => Object.prototype.hasOwnProperty.call(b, key) && _core.shallow.call(void 0, a[key], b[key])
|
|
136
|
-
);
|
|
159
|
+
return total;
|
|
137
160
|
}
|
|
138
161
|
|
|
139
162
|
// src/lib/use-initial.ts
|
|
@@ -210,6 +233,8 @@ var use = (
|
|
|
210
233
|
|
|
211
234
|
|
|
212
235
|
|
|
236
|
+
|
|
237
|
+
|
|
213
238
|
// src/lib/autobind.ts
|
|
214
239
|
function autobind(self) {
|
|
215
240
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -227,12 +252,19 @@ function autobind(self) {
|
|
|
227
252
|
} while ((obj = Reflect.getPrototypeOf(obj)) && obj !== Object.prototype);
|
|
228
253
|
}
|
|
229
254
|
|
|
230
|
-
// src/lib/
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
255
|
+
// src/lib/shallow2.ts
|
|
256
|
+
|
|
257
|
+
function shallow2(a, b) {
|
|
258
|
+
if (!_core.isPlainObject.call(void 0, a) || !_core.isPlainObject.call(void 0, b)) {
|
|
259
|
+
return _core.shallow.call(void 0, a, b);
|
|
234
260
|
}
|
|
235
|
-
|
|
261
|
+
const keysA = Object.keys(a);
|
|
262
|
+
if (keysA.length !== Object.keys(b).length) {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
return keysA.every(
|
|
266
|
+
(key) => Object.prototype.hasOwnProperty.call(b, key) && _core.shallow.call(void 0, a[key], b[key])
|
|
267
|
+
);
|
|
236
268
|
}
|
|
237
269
|
|
|
238
270
|
// src/ThreadDB.ts
|
|
@@ -354,12 +386,12 @@ var ThreadDB = class _ThreadDB {
|
|
|
354
386
|
this.upsert(thread);
|
|
355
387
|
}
|
|
356
388
|
}
|
|
357
|
-
applyDelta(
|
|
389
|
+
applyDelta(newThreads, deletedThreads) {
|
|
358
390
|
_core.batch.call(void 0, () => {
|
|
359
|
-
for (const thread of
|
|
391
|
+
for (const thread of newThreads) {
|
|
360
392
|
this.upsertIfNewer(thread);
|
|
361
393
|
}
|
|
362
|
-
for (const { id, deletedAt } of
|
|
394
|
+
for (const { id, deletedAt } of deletedThreads) {
|
|
363
395
|
const existing = this.getEvenIfDeleted(id);
|
|
364
396
|
if (!existing) continue;
|
|
365
397
|
this.delete(id, deletedAt);
|
|
@@ -400,16 +432,10 @@ var ThreadDB = class _ThreadDB {
|
|
|
400
432
|
|
|
401
433
|
// src/umbrella-store.ts
|
|
402
434
|
function makeRoomThreadsQueryKey(roomId, query) {
|
|
403
|
-
return
|
|
435
|
+
return _core.stringify.call(void 0, [roomId, _nullishCoalesce(query, () => ( {}))]);
|
|
404
436
|
}
|
|
405
437
|
function makeUserThreadsQueryKey(query) {
|
|
406
|
-
return
|
|
407
|
-
}
|
|
408
|
-
function makeNotificationSettingsQueryKey(roomId) {
|
|
409
|
-
return `${roomId}:NOTIFICATION_SETTINGS`;
|
|
410
|
-
}
|
|
411
|
-
function makeVersionsQueryKey(roomId) {
|
|
412
|
-
return `${roomId}-VERSIONS`;
|
|
438
|
+
return _core.stringify.call(void 0, _nullishCoalesce(query, () => ( {})));
|
|
413
439
|
}
|
|
414
440
|
function usify(promise) {
|
|
415
441
|
if ("status" in promise) {
|
|
@@ -430,53 +456,50 @@ function usify(promise) {
|
|
|
430
456
|
return usable;
|
|
431
457
|
}
|
|
432
458
|
var noop2 = Promise.resolve();
|
|
433
|
-
var ASYNC_LOADING = Object.freeze({ isLoading: true });
|
|
434
459
|
var PaginatedResource = class {
|
|
460
|
+
#signal;
|
|
435
461
|
|
|
436
|
-
#eventSource;
|
|
437
462
|
#fetchPage;
|
|
438
|
-
#paginationState;
|
|
439
|
-
// Should be null while in loading or error state!
|
|
440
463
|
#pendingFetchMore;
|
|
441
464
|
constructor(fetchPage) {
|
|
442
|
-
this.#
|
|
465
|
+
this.#signal = new (0, _core.Signal)(ASYNC_LOADING);
|
|
443
466
|
this.#fetchPage = fetchPage;
|
|
444
|
-
this.#eventSource = _core.makeEventSource.call(void 0, );
|
|
445
467
|
this.#pendingFetchMore = null;
|
|
446
|
-
this.
|
|
468
|
+
this.signal = this.#signal.asReadonly();
|
|
447
469
|
autobind(this);
|
|
448
470
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
this.#
|
|
471
|
+
get() {
|
|
472
|
+
return this.#signal.get();
|
|
473
|
+
}
|
|
474
|
+
#patch(patch) {
|
|
475
|
+
const state = this.#signal.get();
|
|
476
|
+
if (state.data === void 0) return;
|
|
477
|
+
this.#signal.set(ASYNC_OK({ ...state.data, ...patch }));
|
|
454
478
|
}
|
|
455
479
|
async #fetchMore() {
|
|
456
|
-
const state = this.#
|
|
457
|
-
if (!_optionalChain([state, '
|
|
480
|
+
const state = this.#signal.get();
|
|
481
|
+
if (!_optionalChain([state, 'access', _3 => _3.data, 'optionalAccess', _4 => _4.cursor]) || state.data.isFetchingMore) {
|
|
458
482
|
return;
|
|
459
483
|
}
|
|
460
|
-
this.#
|
|
484
|
+
this.#patch({ isFetchingMore: true });
|
|
461
485
|
try {
|
|
462
|
-
const nextCursor = await this.#fetchPage(state.cursor);
|
|
463
|
-
this.#
|
|
486
|
+
const nextCursor = await this.#fetchPage(state.data.cursor);
|
|
487
|
+
this.#patch({
|
|
464
488
|
cursor: nextCursor,
|
|
489
|
+
hasFetchedAll: nextCursor === null,
|
|
465
490
|
fetchMoreError: void 0,
|
|
466
491
|
isFetchingMore: false
|
|
467
492
|
});
|
|
468
493
|
} catch (err) {
|
|
469
|
-
this.#
|
|
494
|
+
this.#patch({
|
|
470
495
|
isFetchingMore: false,
|
|
471
496
|
fetchMoreError: err
|
|
472
497
|
});
|
|
473
498
|
}
|
|
474
499
|
}
|
|
475
500
|
fetchMore() {
|
|
476
|
-
const state = this.#
|
|
477
|
-
if (_optionalChain([state, 'optionalAccess',
|
|
478
|
-
return noop2;
|
|
479
|
-
}
|
|
501
|
+
const state = this.#signal.get();
|
|
502
|
+
if (!_optionalChain([state, 'access', _5 => _5.data, 'optionalAccess', _6 => _6.cursor])) return noop2;
|
|
480
503
|
if (!this.#pendingFetchMore) {
|
|
481
504
|
this.#pendingFetchMore = this.#fetchMore().finally(() => {
|
|
482
505
|
this.#pendingFetchMore = null;
|
|
@@ -484,31 +507,12 @@ var PaginatedResource = class {
|
|
|
484
507
|
}
|
|
485
508
|
return this.#pendingFetchMore;
|
|
486
509
|
}
|
|
487
|
-
get() {
|
|
488
|
-
const usable = this.#cachedPromise;
|
|
489
|
-
if (usable === null || usable.status === "pending") {
|
|
490
|
-
return ASYNC_LOADING;
|
|
491
|
-
}
|
|
492
|
-
if (usable.status === "rejected") {
|
|
493
|
-
return { isLoading: false, error: usable.reason };
|
|
494
|
-
}
|
|
495
|
-
const state = this.#paginationState;
|
|
496
|
-
return {
|
|
497
|
-
isLoading: false,
|
|
498
|
-
data: {
|
|
499
|
-
fetchMore: this.fetchMore,
|
|
500
|
-
isFetchingMore: state.isFetchingMore,
|
|
501
|
-
fetchMoreError: state.fetchMoreError,
|
|
502
|
-
hasFetchedAll: state.cursor === null
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
510
|
#cachedPromise = null;
|
|
507
511
|
waitUntilLoaded() {
|
|
508
512
|
if (this.#cachedPromise) {
|
|
509
513
|
return this.#cachedPromise;
|
|
510
514
|
}
|
|
511
|
-
const
|
|
515
|
+
const initialPageFetch$ = _core.autoRetry.call(void 0,
|
|
512
516
|
() => this.#fetchPage(
|
|
513
517
|
/* cursor */
|
|
514
518
|
void 0
|
|
@@ -516,67 +520,64 @@ var PaginatedResource = class {
|
|
|
516
520
|
5,
|
|
517
521
|
[5e3, 5e3, 1e4, 15e3]
|
|
518
522
|
);
|
|
519
|
-
const promise = usify(
|
|
520
|
-
initialFetcher.then((cursor) => {
|
|
521
|
-
this.#paginationState = {
|
|
522
|
-
cursor,
|
|
523
|
-
isFetchingMore: false,
|
|
524
|
-
fetchMoreError: void 0
|
|
525
|
-
};
|
|
526
|
-
})
|
|
527
|
-
);
|
|
523
|
+
const promise = usify(initialPageFetch$);
|
|
528
524
|
promise.then(
|
|
529
|
-
() =>
|
|
530
|
-
|
|
531
|
-
|
|
525
|
+
(cursor) => {
|
|
526
|
+
this.#signal.set(
|
|
527
|
+
ASYNC_OK({
|
|
528
|
+
cursor,
|
|
529
|
+
hasFetchedAll: cursor === null,
|
|
530
|
+
isFetchingMore: false,
|
|
531
|
+
fetchMoreError: void 0,
|
|
532
|
+
fetchMore: this.fetchMore
|
|
533
|
+
})
|
|
534
|
+
);
|
|
535
|
+
},
|
|
536
|
+
(err) => {
|
|
537
|
+
this.#signal.set(ASYNC_ERR(err));
|
|
532
538
|
setTimeout(() => {
|
|
533
539
|
this.#cachedPromise = null;
|
|
534
|
-
this.#
|
|
540
|
+
this.#signal.set(ASYNC_LOADING);
|
|
535
541
|
}, 5e3);
|
|
536
542
|
}
|
|
537
543
|
);
|
|
538
544
|
this.#cachedPromise = promise;
|
|
539
|
-
return
|
|
545
|
+
return this.#cachedPromise;
|
|
540
546
|
}
|
|
541
547
|
};
|
|
542
548
|
var SinglePageResource = class {
|
|
549
|
+
#signal;
|
|
543
550
|
|
|
544
|
-
#eventSource;
|
|
545
551
|
#fetchPage;
|
|
546
552
|
constructor(fetchPage) {
|
|
553
|
+
this.#signal = new (0, _core.Signal)(ASYNC_LOADING);
|
|
554
|
+
this.signal = this.#signal.asReadonly();
|
|
547
555
|
this.#fetchPage = fetchPage;
|
|
548
|
-
this.#eventSource = _core.makeEventSource.call(void 0, );
|
|
549
|
-
this.observable = this.#eventSource.observable;
|
|
550
556
|
autobind(this);
|
|
551
557
|
}
|
|
552
558
|
get() {
|
|
553
|
-
|
|
554
|
-
if (usable === null || usable.status === "pending") {
|
|
555
|
-
return ASYNC_LOADING;
|
|
556
|
-
} else if (usable.status === "rejected") {
|
|
557
|
-
return { isLoading: false, error: usable.reason };
|
|
558
|
-
} else {
|
|
559
|
-
return { isLoading: false, data: void 0 };
|
|
560
|
-
}
|
|
559
|
+
return this.#signal.get();
|
|
561
560
|
}
|
|
562
561
|
#cachedPromise = null;
|
|
563
562
|
waitUntilLoaded() {
|
|
564
563
|
if (this.#cachedPromise) {
|
|
565
564
|
return this.#cachedPromise;
|
|
566
565
|
}
|
|
567
|
-
const initialFetcher = _core.autoRetry.call(void 0,
|
|
566
|
+
const initialFetcher$ = _core.autoRetry.call(void 0,
|
|
568
567
|
() => this.#fetchPage(),
|
|
569
568
|
5,
|
|
570
569
|
[5e3, 5e3, 1e4, 15e3]
|
|
571
570
|
);
|
|
572
|
-
const promise = usify(initialFetcher);
|
|
571
|
+
const promise = usify(initialFetcher$);
|
|
573
572
|
promise.then(
|
|
574
|
-
() => this.#eventSource.notify(),
|
|
575
573
|
() => {
|
|
576
|
-
this.#
|
|
574
|
+
this.#signal.set(ASYNC_OK(void 0));
|
|
575
|
+
},
|
|
576
|
+
(err) => {
|
|
577
|
+
this.#signal.set(ASYNC_ERR(err));
|
|
577
578
|
setTimeout(() => {
|
|
578
579
|
this.#cachedPromise = null;
|
|
579
|
-
this.#
|
|
580
|
+
this.#signal.set(ASYNC_LOADING);
|
|
580
581
|
}, 5e3);
|
|
581
582
|
}
|
|
582
583
|
);
|
|
@@ -597,7 +598,7 @@ function createStore_forNotifications() {
|
|
|
597
598
|
});
|
|
598
599
|
}
|
|
599
600
|
function markAllRead(readAt) {
|
|
600
|
-
|
|
601
|
+
signal.mutate((lut) => {
|
|
601
602
|
for (const n of lut.values()) {
|
|
602
603
|
n.readAt = readAt;
|
|
603
604
|
}
|
|
@@ -609,10 +610,10 @@ function createStore_forNotifications() {
|
|
|
609
610
|
function clear() {
|
|
610
611
|
signal.mutate((lut) => lut.clear());
|
|
611
612
|
}
|
|
612
|
-
function applyDelta(
|
|
613
|
+
function applyDelta(newNotifications, deletedNotifications) {
|
|
613
614
|
signal.mutate((lut) => {
|
|
614
615
|
let mutated = false;
|
|
615
|
-
for (const n of
|
|
616
|
+
for (const n of newNotifications) {
|
|
616
617
|
const existing = lut.get(n.id);
|
|
617
618
|
if (existing) {
|
|
618
619
|
const result = compareInboxNotifications(existing, n);
|
|
@@ -643,6 +644,11 @@ function createStore_forNotifications() {
|
|
|
643
644
|
return true;
|
|
644
645
|
});
|
|
645
646
|
}
|
|
647
|
+
function upsert(notification) {
|
|
648
|
+
signal.mutate((lut) => {
|
|
649
|
+
lut.set(notification.id, notification);
|
|
650
|
+
});
|
|
651
|
+
}
|
|
646
652
|
return {
|
|
647
653
|
signal: signal.asReadonly(),
|
|
648
654
|
// Mutations
|
|
@@ -652,66 +658,70 @@ function createStore_forNotifications() {
|
|
|
652
658
|
applyDelta,
|
|
653
659
|
clear,
|
|
654
660
|
updateAssociatedNotification,
|
|
655
|
-
|
|
656
|
-
force_set: (mutationCallback) => signal.mutate(mutationCallback),
|
|
657
|
-
invalidate: () => signal.mutate()
|
|
661
|
+
upsert
|
|
658
662
|
};
|
|
659
663
|
}
|
|
660
|
-
function createStore_forRoomNotificationSettings() {
|
|
661
|
-
const
|
|
664
|
+
function createStore_forRoomNotificationSettings(updates) {
|
|
665
|
+
const baseSignal = new (0, _core.MutableSignal)(/* @__PURE__ */ new Map());
|
|
662
666
|
function update(roomId, settings) {
|
|
663
|
-
|
|
667
|
+
baseSignal.mutate((lut) => {
|
|
664
668
|
lut.set(roomId, settings);
|
|
665
669
|
});
|
|
666
670
|
}
|
|
667
671
|
return {
|
|
668
|
-
signal:
|
|
672
|
+
signal: _core.DerivedSignal.from(
|
|
673
|
+
baseSignal,
|
|
674
|
+
updates,
|
|
675
|
+
(base, updates2) => applyOptimisticUpdates_forSettings(base, updates2)
|
|
676
|
+
),
|
|
669
677
|
// Mutations
|
|
670
|
-
update
|
|
671
|
-
// XXX_vincent Remove this eventually
|
|
672
|
-
invalidate: () => signal.mutate()
|
|
678
|
+
update
|
|
673
679
|
};
|
|
674
680
|
}
|
|
675
681
|
function createStore_forHistoryVersions() {
|
|
676
|
-
const
|
|
682
|
+
const baseSignal = new (0, _core.MutableSignal)(
|
|
683
|
+
new (0, _core.DefaultMap)(() => /* @__PURE__ */ new Map())
|
|
684
|
+
);
|
|
677
685
|
function update(roomId, versions) {
|
|
678
|
-
|
|
679
|
-
const versionsById =
|
|
686
|
+
baseSignal.mutate((lut) => {
|
|
687
|
+
const versionsById = lut.getOrCreate(roomId);
|
|
680
688
|
for (const version of versions) {
|
|
681
689
|
versionsById.set(version.id, version);
|
|
682
690
|
}
|
|
683
691
|
});
|
|
684
692
|
}
|
|
685
693
|
return {
|
|
686
|
-
signal:
|
|
694
|
+
signal: _core.DerivedSignal.from(
|
|
695
|
+
baseSignal,
|
|
696
|
+
(hv) => Object.fromEntries(
|
|
697
|
+
[...hv].map(([roomId, versions]) => [
|
|
698
|
+
roomId,
|
|
699
|
+
Object.fromEntries(versions)
|
|
700
|
+
])
|
|
701
|
+
)
|
|
702
|
+
),
|
|
687
703
|
// Mutations
|
|
688
|
-
update
|
|
689
|
-
// XXX_vincent Remove these eventually
|
|
690
|
-
force_set: (callback) => signal.mutate(callback),
|
|
691
|
-
invalidate: () => signal.mutate()
|
|
704
|
+
update
|
|
692
705
|
};
|
|
693
706
|
}
|
|
694
707
|
function createStore_forPermissionHints() {
|
|
695
|
-
const signal = new (0, _core.
|
|
708
|
+
const signal = new (0, _core.MutableSignal)(
|
|
709
|
+
new (0, _core.DefaultMap)(() => /* @__PURE__ */ new Set())
|
|
710
|
+
);
|
|
696
711
|
function update(newHints) {
|
|
697
|
-
signal.
|
|
698
|
-
const permissionsByRoom = { ...prev };
|
|
712
|
+
signal.mutate((lut) => {
|
|
699
713
|
for (const [roomId, newPermissions] of Object.entries(newHints)) {
|
|
700
|
-
const existing =
|
|
714
|
+
const existing = lut.getOrCreate(roomId);
|
|
701
715
|
for (const permission of newPermissions) {
|
|
702
716
|
existing.add(permission);
|
|
703
717
|
}
|
|
704
|
-
permissionsByRoom[roomId] = existing;
|
|
705
718
|
}
|
|
706
|
-
return permissionsByRoom;
|
|
707
719
|
});
|
|
708
720
|
}
|
|
709
721
|
return {
|
|
710
722
|
signal: signal.asReadonly(),
|
|
711
723
|
// Mutations
|
|
712
|
-
update
|
|
713
|
-
// XXX_vincent Remove this eventually
|
|
714
|
-
invalidate: () => signal.set((store) => ({ ...store }))
|
|
724
|
+
update
|
|
715
725
|
};
|
|
716
726
|
}
|
|
717
727
|
function createStore_forOptimistic(client) {
|
|
@@ -735,9 +745,7 @@ function createStore_forOptimistic(client) {
|
|
|
735
745
|
signal: signal.asReadonly(),
|
|
736
746
|
// Mutations
|
|
737
747
|
add,
|
|
738
|
-
remove
|
|
739
|
-
// XXX_vincent Remove this eventually
|
|
740
|
-
invalidate: () => signal.set((store) => [...store])
|
|
748
|
+
remove
|
|
741
749
|
};
|
|
742
750
|
}
|
|
743
751
|
var UmbrellaStore = class {
|
|
@@ -787,48 +795,37 @@ var UmbrellaStore = class {
|
|
|
787
795
|
// threads and notifications separately, but the threadifications signal will
|
|
788
796
|
// be updated whenever either of them change.
|
|
789
797
|
//
|
|
790
|
-
// XXX_vincent APIs like getRoomThreadsLoadingState should really also be modeled as output signals.
|
|
791
|
-
//
|
|
792
798
|
|
|
793
799
|
// Notifications
|
|
794
800
|
#notificationsLastRequestedAt = null;
|
|
795
801
|
// Keeps track of when we successfully requested an inbox notifications update for the last time. Will be `null` as long as the first successful fetch hasn't happened yet.
|
|
796
|
-
#
|
|
802
|
+
#notificationsPaginationState;
|
|
797
803
|
// Room Threads
|
|
798
804
|
#roomThreadsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
|
|
799
|
-
#roomThreads = /* @__PURE__ */ new Map();
|
|
800
805
|
// User Threads
|
|
801
806
|
#userThreadsLastRequestedAt = null;
|
|
802
|
-
#userThreads = /* @__PURE__ */ new Map();
|
|
803
807
|
// Room versions
|
|
804
|
-
#roomVersions = /* @__PURE__ */ new Map();
|
|
805
808
|
#roomVersionsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
|
|
806
|
-
// Room notification settings
|
|
807
|
-
#roomNotificationSettings = /* @__PURE__ */ new Map();
|
|
808
809
|
constructor(client) {
|
|
809
810
|
this.#client = client[_core.kInternal].as();
|
|
810
811
|
this.optimisticUpdates = createStore_forOptimistic(this.#client);
|
|
811
812
|
this.permissionHints = createStore_forPermissionHints();
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
this.#notificationsLastRequestedAt
|
|
813
|
+
this.#notificationsPaginationState = new PaginatedResource(
|
|
814
|
+
async (cursor) => {
|
|
815
|
+
const result = await this.#client.getInboxNotifications({ cursor });
|
|
816
|
+
this.updateThreadifications(result.threads, result.inboxNotifications);
|
|
817
|
+
if (this.#notificationsLastRequestedAt === null) {
|
|
818
|
+
this.#notificationsLastRequestedAt = result.requestedAt;
|
|
819
|
+
}
|
|
820
|
+
const nextCursor = result.nextCursor;
|
|
821
|
+
return nextCursor;
|
|
817
822
|
}
|
|
818
|
-
const nextCursor = result.nextCursor;
|
|
819
|
-
return nextCursor;
|
|
820
|
-
};
|
|
821
|
-
this.#notifications = new PaginatedResource(inboxFetcher);
|
|
822
|
-
this.#notifications.observable.subscribe(
|
|
823
|
-
() => (
|
|
824
|
-
// Note that the store itself does not change, but it's only vehicle at
|
|
825
|
-
// the moment to trigger a re-render, so we'll do a no-op update here.
|
|
826
|
-
this.invalidateEntireStore()
|
|
827
|
-
)
|
|
828
823
|
);
|
|
829
824
|
this.threads = new ThreadDB();
|
|
830
825
|
this.notifications = createStore_forNotifications();
|
|
831
|
-
this.roomNotificationSettings = createStore_forRoomNotificationSettings(
|
|
826
|
+
this.roomNotificationSettings = createStore_forRoomNotificationSettings(
|
|
827
|
+
this.optimisticUpdates.signal
|
|
828
|
+
);
|
|
832
829
|
this.historyVersions = createStore_forHistoryVersions();
|
|
833
830
|
const threadifications = _core.DerivedSignal.from(
|
|
834
831
|
this.threads.signal,
|
|
@@ -836,184 +833,190 @@ var UmbrellaStore = class {
|
|
|
836
833
|
this.optimisticUpdates.signal,
|
|
837
834
|
(ts, ns, updates) => applyOptimisticUpdates_forThreadifications(ts, ns, updates)
|
|
838
835
|
);
|
|
839
|
-
const threads = _core.DerivedSignal.from(threadifications, (s) =>
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
this.roomNotificationSettings.signal,
|
|
848
|
-
this.optimisticUpdates.signal,
|
|
849
|
-
(settings, updates) => applyOptimisticUpdates_forSettings(settings, updates)
|
|
836
|
+
const threads = _core.DerivedSignal.from(threadifications, (s) => s.threadsDB);
|
|
837
|
+
const notifications = _core.DerivedSignal.from(
|
|
838
|
+
threadifications,
|
|
839
|
+
(s) => ({
|
|
840
|
+
sortedNotifications: s.sortedNotifications,
|
|
841
|
+
notificationsById: s.notificationsById
|
|
842
|
+
}),
|
|
843
|
+
_core.shallow
|
|
850
844
|
);
|
|
851
|
-
const
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
845
|
+
const loadingUserThreads = new (0, _core.DefaultMap)(
|
|
846
|
+
(queryKey) => {
|
|
847
|
+
const query = _core.unstringify.call(void 0, queryKey);
|
|
848
|
+
const resource = new PaginatedResource(async (cursor) => {
|
|
849
|
+
const result = await this.#client[_core.kInternal].httpClient.getUserThreads_experimental({
|
|
850
|
+
cursor,
|
|
851
|
+
query
|
|
852
|
+
});
|
|
853
|
+
this.updateThreadifications(
|
|
854
|
+
result.threads,
|
|
855
|
+
result.inboxNotifications
|
|
856
|
+
);
|
|
857
|
+
this.permissionHints.update(result.permissionHints);
|
|
858
|
+
if (this.#userThreadsLastRequestedAt === null) {
|
|
859
|
+
this.#userThreadsLastRequestedAt = result.requestedAt;
|
|
860
|
+
}
|
|
861
|
+
return result.nextCursor;
|
|
862
|
+
});
|
|
863
|
+
const signal = _core.DerivedSignal.from(() => {
|
|
864
|
+
const result = resource.get();
|
|
865
|
+
if (result.isLoading || result.error) {
|
|
866
|
+
return result;
|
|
867
|
+
}
|
|
868
|
+
const threads2 = this.outputs.threads.get().findMany(
|
|
869
|
+
void 0,
|
|
870
|
+
// Do _not_ filter by roomId
|
|
871
|
+
_nullishCoalesce(query, () => ( {})),
|
|
872
|
+
"desc"
|
|
873
|
+
);
|
|
874
|
+
const page = result.data;
|
|
875
|
+
return {
|
|
876
|
+
isLoading: false,
|
|
877
|
+
threads: threads2,
|
|
878
|
+
hasFetchedAll: page.hasFetchedAll,
|
|
879
|
+
isFetchingMore: page.isFetchingMore,
|
|
880
|
+
fetchMoreError: page.fetchMoreError,
|
|
881
|
+
fetchMore: page.fetchMore
|
|
882
|
+
};
|
|
883
|
+
}, shallow2);
|
|
884
|
+
return { signal, waitUntilLoaded: resource.waitUntilLoaded };
|
|
885
|
+
}
|
|
886
|
+
);
|
|
887
|
+
const loadingRoomThreads = new (0, _core.DefaultMap)(
|
|
888
|
+
(queryKey) => {
|
|
889
|
+
const [roomId, query] = _core.unstringify.call(void 0, queryKey);
|
|
890
|
+
const resource = new PaginatedResource(async (cursor) => {
|
|
891
|
+
const result = await this.#client[_core.kInternal].httpClient.getThreads({
|
|
892
|
+
roomId,
|
|
893
|
+
cursor,
|
|
894
|
+
query
|
|
895
|
+
});
|
|
896
|
+
this.updateThreadifications(
|
|
897
|
+
result.threads,
|
|
898
|
+
result.inboxNotifications
|
|
899
|
+
);
|
|
900
|
+
this.permissionHints.update(result.permissionHints);
|
|
901
|
+
const lastRequestedAt = this.#roomThreadsLastRequestedAtByRoom.get(roomId);
|
|
902
|
+
if (lastRequestedAt === void 0 || lastRequestedAt > result.requestedAt) {
|
|
903
|
+
this.#roomThreadsLastRequestedAtByRoom.set(
|
|
904
|
+
roomId,
|
|
905
|
+
result.requestedAt
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
return result.nextCursor;
|
|
909
|
+
});
|
|
910
|
+
const signal = _core.DerivedSignal.from(() => {
|
|
911
|
+
const result = resource.get();
|
|
912
|
+
if (result.isLoading || result.error) {
|
|
913
|
+
return result;
|
|
914
|
+
}
|
|
915
|
+
const threads2 = this.outputs.threads.get().findMany(roomId, _nullishCoalesce(query, () => ( {})), "asc");
|
|
916
|
+
const page = result.data;
|
|
917
|
+
return {
|
|
918
|
+
isLoading: false,
|
|
919
|
+
threads: threads2,
|
|
920
|
+
hasFetchedAll: page.hasFetchedAll,
|
|
921
|
+
isFetchingMore: page.isFetchingMore,
|
|
922
|
+
fetchMoreError: page.fetchMoreError,
|
|
923
|
+
fetchMore: page.fetchMore
|
|
924
|
+
};
|
|
925
|
+
}, shallow2);
|
|
926
|
+
return { signal, waitUntilLoaded: resource.waitUntilLoaded };
|
|
927
|
+
}
|
|
928
|
+
);
|
|
929
|
+
const loadingNotifications = {
|
|
930
|
+
signal: _core.DerivedSignal.from(() => {
|
|
931
|
+
const result = this.#notificationsPaginationState.get();
|
|
932
|
+
if (result.isLoading || result.error) {
|
|
933
|
+
return result;
|
|
934
|
+
}
|
|
935
|
+
const page = result.data;
|
|
936
|
+
return {
|
|
937
|
+
isLoading: false,
|
|
938
|
+
inboxNotifications: this.outputs.notifications.get().sortedNotifications,
|
|
939
|
+
hasFetchedAll: page.hasFetchedAll,
|
|
940
|
+
isFetchingMore: page.isFetchingMore,
|
|
941
|
+
fetchMoreError: page.fetchMoreError,
|
|
942
|
+
fetchMore: page.fetchMore
|
|
943
|
+
};
|
|
944
|
+
}),
|
|
945
|
+
waitUntilLoaded: this.#notificationsPaginationState.waitUntilLoaded
|
|
946
|
+
};
|
|
947
|
+
const settingsByRoomId = new (0, _core.DefaultMap)((roomId) => {
|
|
948
|
+
const resource = new SinglePageResource(async () => {
|
|
949
|
+
const room = this.#client.getRoom(roomId);
|
|
950
|
+
if (room === null) {
|
|
951
|
+
throw new (0, _core.HttpError)(
|
|
952
|
+
`Room '${roomId}' is not available on client`,
|
|
953
|
+
479
|
|
954
|
+
);
|
|
955
|
+
}
|
|
956
|
+
const result = await room.getNotificationSettings();
|
|
957
|
+
this.roomNotificationSettings.update(roomId, result);
|
|
958
|
+
});
|
|
959
|
+
const signal = _core.DerivedSignal.from(() => {
|
|
960
|
+
const result = resource.get();
|
|
961
|
+
if (result.isLoading || result.error) {
|
|
962
|
+
return result;
|
|
963
|
+
} else {
|
|
964
|
+
return ASYNC_OK(
|
|
965
|
+
"settings",
|
|
966
|
+
_core.nn.call(void 0, this.roomNotificationSettings.signal.get()[roomId])
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
}, _core.shallow);
|
|
970
|
+
return { signal, waitUntilLoaded: resource.waitUntilLoaded };
|
|
971
|
+
});
|
|
972
|
+
const versionsByRoomId = new (0, _core.DefaultMap)(
|
|
973
|
+
(roomId) => {
|
|
974
|
+
const resource = new SinglePageResource(async () => {
|
|
975
|
+
const room = this.#client.getRoom(roomId);
|
|
976
|
+
if (room === null) {
|
|
977
|
+
throw new (0, _core.HttpError)(
|
|
978
|
+
`Room '${roomId}' is not available on client`,
|
|
979
|
+
479
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
const result = await room[_core.kInternal].listTextVersions();
|
|
983
|
+
this.historyVersions.update(roomId, result.versions);
|
|
984
|
+
const lastRequestedAt = this.#roomVersionsLastRequestedAtByRoom.get(roomId);
|
|
985
|
+
if (lastRequestedAt === void 0 || lastRequestedAt > result.requestedAt) {
|
|
986
|
+
this.#roomVersionsLastRequestedAtByRoom.set(
|
|
987
|
+
roomId,
|
|
988
|
+
result.requestedAt
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
const signal = _core.DerivedSignal.from(() => {
|
|
993
|
+
const result = resource.get();
|
|
994
|
+
if (result.isLoading || result.error) {
|
|
995
|
+
return result;
|
|
996
|
+
} else {
|
|
997
|
+
return {
|
|
998
|
+
isLoading: false,
|
|
999
|
+
versions: Object.values(
|
|
1000
|
+
_nullishCoalesce(this.historyVersions.signal.get()[roomId], () => ( {}))
|
|
1001
|
+
)
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
}, _core.shallow);
|
|
1005
|
+
return { signal, waitUntilLoaded: resource.waitUntilLoaded };
|
|
1006
|
+
}
|
|
859
1007
|
);
|
|
860
1008
|
this.outputs = {
|
|
861
1009
|
threadifications,
|
|
862
1010
|
threads,
|
|
1011
|
+
loadingRoomThreads,
|
|
1012
|
+
loadingUserThreads,
|
|
863
1013
|
notifications,
|
|
1014
|
+
loadingNotifications,
|
|
864
1015
|
settingsByRoomId,
|
|
865
1016
|
versionsByRoomId
|
|
866
1017
|
};
|
|
867
1018
|
autobind(this);
|
|
868
1019
|
}
|
|
869
|
-
get1_both() {
|
|
870
|
-
return this.outputs.threadifications.get();
|
|
871
|
-
}
|
|
872
|
-
subscribe1_both(callback) {
|
|
873
|
-
return this.outputs.threadifications.subscribe(callback);
|
|
874
|
-
}
|
|
875
|
-
get1_threads() {
|
|
876
|
-
return this.outputs.threads.get();
|
|
877
|
-
}
|
|
878
|
-
subscribe1_threads(callback) {
|
|
879
|
-
return this.outputs.threads.subscribe(callback);
|
|
880
|
-
}
|
|
881
|
-
get1_notifications() {
|
|
882
|
-
return this.outputs.notifications.get();
|
|
883
|
-
}
|
|
884
|
-
subscribe1_notifications(callback) {
|
|
885
|
-
return this.outputs.notifications.subscribe(callback);
|
|
886
|
-
}
|
|
887
|
-
get2() {
|
|
888
|
-
return this.outputs.settingsByRoomId.get();
|
|
889
|
-
}
|
|
890
|
-
subscribe2(callback) {
|
|
891
|
-
return this.outputs.settingsByRoomId.subscribe(callback);
|
|
892
|
-
}
|
|
893
|
-
get3() {
|
|
894
|
-
return this.outputs.versionsByRoomId.get();
|
|
895
|
-
}
|
|
896
|
-
subscribe3(callback) {
|
|
897
|
-
return this.outputs.versionsByRoomId.subscribe(callback);
|
|
898
|
-
}
|
|
899
|
-
/**
|
|
900
|
-
* Returns the async result of the given query and room id. If the query is success,
|
|
901
|
-
* then it will return the threads that match that provided query and room id.
|
|
902
|
-
*
|
|
903
|
-
*/
|
|
904
|
-
getRoomThreadsLoadingState(roomId, query) {
|
|
905
|
-
const queryKey = makeRoomThreadsQueryKey(roomId, query);
|
|
906
|
-
const paginatedResource = this.#roomThreads.get(queryKey);
|
|
907
|
-
if (paginatedResource === void 0) {
|
|
908
|
-
return ASYNC_LOADING;
|
|
909
|
-
}
|
|
910
|
-
const asyncResult = paginatedResource.get();
|
|
911
|
-
if (asyncResult.isLoading || asyncResult.error) {
|
|
912
|
-
return asyncResult;
|
|
913
|
-
}
|
|
914
|
-
const threads = this.get1_threads().threadsDB.findMany(
|
|
915
|
-
roomId,
|
|
916
|
-
_nullishCoalesce(query, () => ( {})),
|
|
917
|
-
"asc"
|
|
918
|
-
);
|
|
919
|
-
const page = asyncResult.data;
|
|
920
|
-
return {
|
|
921
|
-
isLoading: false,
|
|
922
|
-
threads,
|
|
923
|
-
hasFetchedAll: page.hasFetchedAll,
|
|
924
|
-
isFetchingMore: page.isFetchingMore,
|
|
925
|
-
fetchMoreError: page.fetchMoreError,
|
|
926
|
-
fetchMore: page.fetchMore
|
|
927
|
-
};
|
|
928
|
-
}
|
|
929
|
-
getUserThreadsLoadingState(query) {
|
|
930
|
-
const queryKey = makeUserThreadsQueryKey(query);
|
|
931
|
-
const paginatedResource = this.#userThreads.get(queryKey);
|
|
932
|
-
if (paginatedResource === void 0) {
|
|
933
|
-
return ASYNC_LOADING;
|
|
934
|
-
}
|
|
935
|
-
const asyncResult = paginatedResource.get();
|
|
936
|
-
if (asyncResult.isLoading || asyncResult.error) {
|
|
937
|
-
return asyncResult;
|
|
938
|
-
}
|
|
939
|
-
const threads = this.get1_threads().threadsDB.findMany(
|
|
940
|
-
void 0,
|
|
941
|
-
// Do _not_ filter by roomId
|
|
942
|
-
_nullishCoalesce(query, () => ( {})),
|
|
943
|
-
"desc"
|
|
944
|
-
);
|
|
945
|
-
const page = asyncResult.data;
|
|
946
|
-
return {
|
|
947
|
-
isLoading: false,
|
|
948
|
-
threads,
|
|
949
|
-
hasFetchedAll: page.hasFetchedAll,
|
|
950
|
-
isFetchingMore: page.isFetchingMore,
|
|
951
|
-
fetchMoreError: page.fetchMoreError,
|
|
952
|
-
fetchMore: page.fetchMore
|
|
953
|
-
};
|
|
954
|
-
}
|
|
955
|
-
// NOTE: This will read the async result, but WILL NOT start loading at the moment!
|
|
956
|
-
getInboxNotificationsLoadingState() {
|
|
957
|
-
const asyncResult = this.#notifications.get();
|
|
958
|
-
if (asyncResult.isLoading || asyncResult.error) {
|
|
959
|
-
return asyncResult;
|
|
960
|
-
}
|
|
961
|
-
const page = asyncResult.data;
|
|
962
|
-
return {
|
|
963
|
-
isLoading: false,
|
|
964
|
-
inboxNotifications: this.get1_notifications().sortedNotifications,
|
|
965
|
-
hasFetchedAll: page.hasFetchedAll,
|
|
966
|
-
isFetchingMore: page.isFetchingMore,
|
|
967
|
-
fetchMoreError: page.fetchMoreError,
|
|
968
|
-
fetchMore: page.fetchMore
|
|
969
|
-
};
|
|
970
|
-
}
|
|
971
|
-
// NOTE: This will read the async result, but WILL NOT start loading at the moment!
|
|
972
|
-
// XXX_vincent This should really be a derived Signal!
|
|
973
|
-
getNotificationSettingsLoadingState(roomId) {
|
|
974
|
-
const queryKey = makeNotificationSettingsQueryKey(roomId);
|
|
975
|
-
const resource = this.#roomNotificationSettings.get(queryKey);
|
|
976
|
-
if (resource === void 0) {
|
|
977
|
-
return ASYNC_LOADING;
|
|
978
|
-
}
|
|
979
|
-
const asyncResult = resource.get();
|
|
980
|
-
if (asyncResult.isLoading || asyncResult.error) {
|
|
981
|
-
return asyncResult;
|
|
982
|
-
}
|
|
983
|
-
return {
|
|
984
|
-
isLoading: false,
|
|
985
|
-
settings: _core.nn.call(void 0, this.get2()[roomId])
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
getRoomVersionsLoadingState(roomId) {
|
|
989
|
-
const queryKey = makeVersionsQueryKey(roomId);
|
|
990
|
-
const resource = this.#roomVersions.get(queryKey);
|
|
991
|
-
if (resource === void 0) {
|
|
992
|
-
return ASYNC_LOADING;
|
|
993
|
-
}
|
|
994
|
-
const asyncResult = resource.get();
|
|
995
|
-
if (asyncResult.isLoading || asyncResult.error) {
|
|
996
|
-
return asyncResult;
|
|
997
|
-
}
|
|
998
|
-
return {
|
|
999
|
-
isLoading: false,
|
|
1000
|
-
versions: Object.values(_nullishCoalesce(this.get3()[roomId], () => ( {})))
|
|
1001
|
-
};
|
|
1002
|
-
}
|
|
1003
|
-
/** @internal - Only call this method from unit tests. */
|
|
1004
|
-
force_set_versions(callback) {
|
|
1005
|
-
_core.batch.call(void 0, () => {
|
|
1006
|
-
this.historyVersions.force_set(callback);
|
|
1007
|
-
this.invalidateEntireStore();
|
|
1008
|
-
});
|
|
1009
|
-
}
|
|
1010
|
-
/** @internal - Only call this method from unit tests. */
|
|
1011
|
-
force_set_notifications(callback) {
|
|
1012
|
-
_core.batch.call(void 0, () => {
|
|
1013
|
-
this.notifications.force_set(callback);
|
|
1014
|
-
this.invalidateEntireStore();
|
|
1015
|
-
});
|
|
1016
|
-
}
|
|
1017
1020
|
/**
|
|
1018
1021
|
* Updates an existing inbox notification with a new value, replacing the
|
|
1019
1022
|
* corresponding optimistic update.
|
|
@@ -1155,7 +1158,7 @@ var UmbrellaStore = class {
|
|
|
1155
1158
|
}
|
|
1156
1159
|
updateThreadifications(threads, notifications, deletedThreads = [], deletedNotifications = []) {
|
|
1157
1160
|
_core.batch.call(void 0, () => {
|
|
1158
|
-
this.threads.applyDelta(
|
|
1161
|
+
this.threads.applyDelta(threads, deletedThreads);
|
|
1159
1162
|
this.notifications.applyDelta(notifications, deletedNotifications);
|
|
1160
1163
|
});
|
|
1161
1164
|
}
|
|
@@ -1188,39 +1191,6 @@ var UmbrellaStore = class {
|
|
|
1188
1191
|
result.inboxNotifications.deleted
|
|
1189
1192
|
);
|
|
1190
1193
|
}
|
|
1191
|
-
waitUntilNotificationsLoaded() {
|
|
1192
|
-
return this.#notifications.waitUntilLoaded();
|
|
1193
|
-
}
|
|
1194
|
-
waitUntilRoomThreadsLoaded(roomId, query) {
|
|
1195
|
-
const threadsFetcher = async (cursor) => {
|
|
1196
|
-
const result = await this.#client[_core.kInternal].httpClient.getThreads({
|
|
1197
|
-
roomId,
|
|
1198
|
-
cursor,
|
|
1199
|
-
query
|
|
1200
|
-
});
|
|
1201
|
-
this.updateThreadifications(result.threads, result.inboxNotifications);
|
|
1202
|
-
this.permissionHints.update(result.permissionHints);
|
|
1203
|
-
const lastRequestedAt = this.#roomThreadsLastRequestedAtByRoom.get(roomId);
|
|
1204
|
-
if (lastRequestedAt === void 0 || lastRequestedAt > result.requestedAt) {
|
|
1205
|
-
this.#roomThreadsLastRequestedAtByRoom.set(roomId, result.requestedAt);
|
|
1206
|
-
}
|
|
1207
|
-
return result.nextCursor;
|
|
1208
|
-
};
|
|
1209
|
-
const queryKey = makeRoomThreadsQueryKey(roomId, query);
|
|
1210
|
-
let paginatedResource = this.#roomThreads.get(queryKey);
|
|
1211
|
-
if (paginatedResource === void 0) {
|
|
1212
|
-
paginatedResource = new PaginatedResource(threadsFetcher);
|
|
1213
|
-
}
|
|
1214
|
-
paginatedResource.observable.subscribe(
|
|
1215
|
-
() => (
|
|
1216
|
-
// Note that the store itself does not change, but it's only vehicle at
|
|
1217
|
-
// the moment to trigger a re-render, so we'll do a no-op update here.
|
|
1218
|
-
this.invalidateEntireStore()
|
|
1219
|
-
)
|
|
1220
|
-
);
|
|
1221
|
-
this.#roomThreads.set(queryKey, paginatedResource);
|
|
1222
|
-
return paginatedResource.waitUntilLoaded();
|
|
1223
|
-
}
|
|
1224
1194
|
async fetchRoomThreadsDeltaUpdate(roomId, signal) {
|
|
1225
1195
|
const lastRequestedAt = this.#roomThreadsLastRequestedAtByRoom.get(roomId);
|
|
1226
1196
|
if (lastRequestedAt === void 0) {
|
|
@@ -1242,45 +1212,6 @@ var UmbrellaStore = class {
|
|
|
1242
1212
|
this.#roomThreadsLastRequestedAtByRoom.set(roomId, updates.requestedAt);
|
|
1243
1213
|
}
|
|
1244
1214
|
}
|
|
1245
|
-
waitUntilUserThreadsLoaded(query) {
|
|
1246
|
-
const queryKey = makeUserThreadsQueryKey(query);
|
|
1247
|
-
const threadsFetcher = async (cursor) => {
|
|
1248
|
-
const result = await this.#client[_core.kInternal].httpClient.getUserThreads_experimental({
|
|
1249
|
-
cursor,
|
|
1250
|
-
query
|
|
1251
|
-
});
|
|
1252
|
-
this.updateThreadifications(result.threads, result.inboxNotifications);
|
|
1253
|
-
this.permissionHints.update(result.permissionHints);
|
|
1254
|
-
if (this.#userThreadsLastRequestedAt === null) {
|
|
1255
|
-
this.#userThreadsLastRequestedAt = result.requestedAt;
|
|
1256
|
-
}
|
|
1257
|
-
return result.nextCursor;
|
|
1258
|
-
};
|
|
1259
|
-
let paginatedResource = this.#userThreads.get(queryKey);
|
|
1260
|
-
if (paginatedResource === void 0) {
|
|
1261
|
-
paginatedResource = new PaginatedResource(threadsFetcher);
|
|
1262
|
-
}
|
|
1263
|
-
paginatedResource.observable.subscribe(
|
|
1264
|
-
() => (
|
|
1265
|
-
// Note that the store itself does not change, but it's only vehicle at
|
|
1266
|
-
// the moment to trigger a re-render, so we'll do a no-op update here.
|
|
1267
|
-
this.invalidateEntireStore()
|
|
1268
|
-
)
|
|
1269
|
-
);
|
|
1270
|
-
this.#userThreads.set(queryKey, paginatedResource);
|
|
1271
|
-
return paginatedResource.waitUntilLoaded();
|
|
1272
|
-
}
|
|
1273
|
-
// XXX_vincent We should really be going over all call sites, and replace this call
|
|
1274
|
-
// with a more specific invalidation!
|
|
1275
|
-
invalidateEntireStore() {
|
|
1276
|
-
_core.batch.call(void 0, () => {
|
|
1277
|
-
this.historyVersions.invalidate();
|
|
1278
|
-
this.notifications.invalidate();
|
|
1279
|
-
this.optimisticUpdates.invalidate();
|
|
1280
|
-
this.permissionHints.invalidate();
|
|
1281
|
-
this.roomNotificationSettings.invalidate();
|
|
1282
|
-
});
|
|
1283
|
-
}
|
|
1284
1215
|
async fetchUserThreadsDeltaUpdate(signal) {
|
|
1285
1216
|
const lastRequestedAt = this.#userThreadsLastRequestedAt;
|
|
1286
1217
|
if (lastRequestedAt === null) {
|
|
@@ -1301,40 +1232,6 @@ var UmbrellaStore = class {
|
|
|
1301
1232
|
);
|
|
1302
1233
|
this.permissionHints.update(result.permissionHints);
|
|
1303
1234
|
}
|
|
1304
|
-
waitUntilRoomVersionsLoaded(roomId) {
|
|
1305
|
-
const queryKey = makeVersionsQueryKey(roomId);
|
|
1306
|
-
let resource = this.#roomVersions.get(queryKey);
|
|
1307
|
-
if (resource === void 0) {
|
|
1308
|
-
const versionsFetcher = async () => {
|
|
1309
|
-
const room = this.#client.getRoom(roomId);
|
|
1310
|
-
if (room === null) {
|
|
1311
|
-
throw new (0, _core.HttpError)(
|
|
1312
|
-
`Room '${roomId}' is not available on client`,
|
|
1313
|
-
479
|
|
1314
|
-
);
|
|
1315
|
-
}
|
|
1316
|
-
const result = await room[_core.kInternal].listTextVersions();
|
|
1317
|
-
this.historyVersions.update(roomId, result.versions);
|
|
1318
|
-
const lastRequestedAt = this.#roomVersionsLastRequestedAtByRoom.get(roomId);
|
|
1319
|
-
if (lastRequestedAt === void 0 || lastRequestedAt > result.requestedAt) {
|
|
1320
|
-
this.#roomVersionsLastRequestedAtByRoom.set(
|
|
1321
|
-
roomId,
|
|
1322
|
-
result.requestedAt
|
|
1323
|
-
);
|
|
1324
|
-
}
|
|
1325
|
-
};
|
|
1326
|
-
resource = new SinglePageResource(versionsFetcher);
|
|
1327
|
-
}
|
|
1328
|
-
resource.observable.subscribe(
|
|
1329
|
-
() => (
|
|
1330
|
-
// Note that the store itself does not change, but it's only vehicle at
|
|
1331
|
-
// the moment to trigger a re-render, so we'll do a no-op update here.
|
|
1332
|
-
this.invalidateEntireStore()
|
|
1333
|
-
)
|
|
1334
|
-
);
|
|
1335
|
-
this.#roomVersions.set(queryKey, resource);
|
|
1336
|
-
return resource.waitUntilLoaded();
|
|
1337
|
-
}
|
|
1338
1235
|
async fetchRoomVersionsDeltaUpdate(roomId, signal) {
|
|
1339
1236
|
const lastRequestedAt = this.#roomVersionsLastRequestedAtByRoom.get(roomId);
|
|
1340
1237
|
if (lastRequestedAt === void 0) {
|
|
@@ -1353,33 +1250,6 @@ var UmbrellaStore = class {
|
|
|
1353
1250
|
this.#roomVersionsLastRequestedAtByRoom.set(roomId, updates.requestedAt);
|
|
1354
1251
|
}
|
|
1355
1252
|
}
|
|
1356
|
-
waitUntilRoomNotificationSettingsLoaded(roomId) {
|
|
1357
|
-
const queryKey = makeNotificationSettingsQueryKey(roomId);
|
|
1358
|
-
let resource = this.#roomNotificationSettings.get(queryKey);
|
|
1359
|
-
if (resource === void 0) {
|
|
1360
|
-
const notificationSettingsFetcher = async () => {
|
|
1361
|
-
const room = this.#client.getRoom(roomId);
|
|
1362
|
-
if (room === null) {
|
|
1363
|
-
throw new (0, _core.HttpError)(
|
|
1364
|
-
`Room '${roomId}' is not available on client`,
|
|
1365
|
-
479
|
|
1366
|
-
);
|
|
1367
|
-
}
|
|
1368
|
-
const result = await room.getNotificationSettings();
|
|
1369
|
-
this.roomNotificationSettings.update(roomId, result);
|
|
1370
|
-
};
|
|
1371
|
-
resource = new SinglePageResource(notificationSettingsFetcher);
|
|
1372
|
-
}
|
|
1373
|
-
resource.observable.subscribe(
|
|
1374
|
-
() => (
|
|
1375
|
-
// Note that the store itself does not change, but it's only vehicle at
|
|
1376
|
-
// the moment to trigger a re-render, so we'll do a no-op update here.
|
|
1377
|
-
this.invalidateEntireStore()
|
|
1378
|
-
)
|
|
1379
|
-
);
|
|
1380
|
-
this.#roomNotificationSettings.set(queryKey, resource);
|
|
1381
|
-
return resource.waitUntilLoaded();
|
|
1382
|
-
}
|
|
1383
1253
|
async refreshRoomNotificationSettings(roomId, signal) {
|
|
1384
1254
|
const room = _core.nn.call(void 0,
|
|
1385
1255
|
this.#client.getRoom(roomId),
|
|
@@ -1611,7 +1481,7 @@ function applyUpsertComment(thread, comment) {
|
|
|
1611
1481
|
updatedAt: new Date(
|
|
1612
1482
|
Math.max(
|
|
1613
1483
|
thread.updatedAt.getTime(),
|
|
1614
|
-
_optionalChain([comment, 'access',
|
|
1484
|
+
_optionalChain([comment, 'access', _7 => _7.editedAt, 'optionalAccess', _8 => _8.getTime, 'call', _9 => _9()]) || comment.createdAt.getTime()
|
|
1615
1485
|
)
|
|
1616
1486
|
),
|
|
1617
1487
|
comments: updatedComments
|
|
@@ -1751,32 +1621,26 @@ function missingRoomInfoError(roomId) {
|
|
|
1751
1621
|
`resolveRoomsInfo didn't return anything for room '${roomId}'`
|
|
1752
1622
|
);
|
|
1753
1623
|
}
|
|
1754
|
-
function
|
|
1624
|
+
function identity2(x) {
|
|
1755
1625
|
return x;
|
|
1756
1626
|
}
|
|
1757
1627
|
var _umbrellaStores = /* @__PURE__ */ new WeakMap();
|
|
1758
1628
|
var _extras = /* @__PURE__ */ new WeakMap();
|
|
1759
1629
|
var _bundles = /* @__PURE__ */ new WeakMap();
|
|
1760
|
-
function selectUnreadInboxNotificationsCount(inboxNotifications) {
|
|
1761
|
-
let count = 0;
|
|
1762
|
-
for (const notification of inboxNotifications) {
|
|
1763
|
-
if (notification.readAt === null || notification.readAt < notification.notifiedAt) {
|
|
1764
|
-
count++;
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
return count;
|
|
1768
|
-
}
|
|
1769
1630
|
function selectorFor_useUnreadInboxNotificationsCount(result) {
|
|
1770
1631
|
if (!result.inboxNotifications) {
|
|
1771
1632
|
return result;
|
|
1772
1633
|
}
|
|
1773
|
-
return
|
|
1774
|
-
|
|
1775
|
-
count
|
|
1776
|
-
|
|
1634
|
+
return ASYNC_OK(
|
|
1635
|
+
"count",
|
|
1636
|
+
count(
|
|
1637
|
+
result.inboxNotifications,
|
|
1638
|
+
(n) => n.readAt === null || n.readAt < n.notifiedAt
|
|
1639
|
+
)
|
|
1640
|
+
);
|
|
1777
1641
|
}
|
|
1778
1642
|
function selectorFor_useUser(state, userId) {
|
|
1779
|
-
if (state === void 0 || _optionalChain([state, 'optionalAccess',
|
|
1643
|
+
if (state === void 0 || _optionalChain([state, 'optionalAccess', _10 => _10.isLoading])) {
|
|
1780
1644
|
return _nullishCoalesce(state, () => ( { isLoading: true }));
|
|
1781
1645
|
}
|
|
1782
1646
|
if (state.error) {
|
|
@@ -1794,7 +1658,7 @@ function selectorFor_useUser(state, userId) {
|
|
|
1794
1658
|
};
|
|
1795
1659
|
}
|
|
1796
1660
|
function selectorFor_useRoomInfo(state, roomId) {
|
|
1797
|
-
if (state === void 0 || _optionalChain([state, 'optionalAccess',
|
|
1661
|
+
if (state === void 0 || _optionalChain([state, 'optionalAccess', _11 => _11.isLoading])) {
|
|
1798
1662
|
return _nullishCoalesce(state, () => ( { isLoading: true }));
|
|
1799
1663
|
}
|
|
1800
1664
|
if (state.error) {
|
|
@@ -1880,7 +1744,7 @@ function makeLiveblocksContextBundle(client) {
|
|
|
1880
1744
|
const shared = createSharedContext(client);
|
|
1881
1745
|
const bundle = {
|
|
1882
1746
|
LiveblocksProvider: LiveblocksProvider2,
|
|
1883
|
-
useInboxNotifications: () => useInboxNotifications_withClient(client,
|
|
1747
|
+
useInboxNotifications: () => useInboxNotifications_withClient(client, identity2, _core.shallow),
|
|
1884
1748
|
useUnreadInboxNotificationsCount: () => useUnreadInboxNotificationsCount_withClient(client),
|
|
1885
1749
|
useMarkInboxNotificationAsRead: useMarkInboxNotificationAsRead2,
|
|
1886
1750
|
useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
|
|
@@ -1906,9 +1770,17 @@ function makeLiveblocksContextBundle(client) {
|
|
|
1906
1770
|
}
|
|
1907
1771
|
function useInboxNotifications_withClient(client, selector, isEqual) {
|
|
1908
1772
|
const { store, notificationsPoller: poller } = getLiveblocksExtrasForClient(client);
|
|
1909
|
-
_react.useEffect.call(void 0,
|
|
1910
|
-
void store.
|
|
1911
|
-
|
|
1773
|
+
_react.useEffect.call(void 0,
|
|
1774
|
+
() => void store.outputs.loadingNotifications.waitUntilLoaded()
|
|
1775
|
+
// NOTE: Deliberately *not* using a dependency array here!
|
|
1776
|
+
//
|
|
1777
|
+
// It is important to call waitUntil on *every* render.
|
|
1778
|
+
// This is harmless though, on most renders, except:
|
|
1779
|
+
// 1. The very first render, in which case we'll want to trigger the initial page fetch.
|
|
1780
|
+
// 2. All other subsequent renders now "just" return the same promise (a quick operation).
|
|
1781
|
+
// 3. If ever the promise would fail, then after 5 seconds it would reset, and on the very
|
|
1782
|
+
// *next* render after that, a *new* fetch/promise will get created.
|
|
1783
|
+
);
|
|
1912
1784
|
_react.useEffect.call(void 0, () => {
|
|
1913
1785
|
poller.inc();
|
|
1914
1786
|
poller.pollNowIfStale();
|
|
@@ -1916,18 +1788,16 @@ function useInboxNotifications_withClient(client, selector, isEqual) {
|
|
|
1916
1788
|
poller.dec();
|
|
1917
1789
|
};
|
|
1918
1790
|
}, [poller]);
|
|
1919
|
-
return
|
|
1920
|
-
store.
|
|
1921
|
-
store.getInboxNotificationsLoadingState,
|
|
1922
|
-
store.getInboxNotificationsLoadingState,
|
|
1791
|
+
return useSignal(
|
|
1792
|
+
store.outputs.loadingNotifications.signal,
|
|
1923
1793
|
selector,
|
|
1924
1794
|
isEqual
|
|
1925
1795
|
);
|
|
1926
1796
|
}
|
|
1927
1797
|
function useInboxNotificationsSuspense_withClient(client) {
|
|
1928
1798
|
const store = getLiveblocksExtrasForClient(client).store;
|
|
1929
|
-
use(store.
|
|
1930
|
-
const result = useInboxNotifications_withClient(client,
|
|
1799
|
+
use(store.outputs.loadingNotifications.waitUntilLoaded());
|
|
1800
|
+
const result = useInboxNotifications_withClient(client, identity2, _core.shallow);
|
|
1931
1801
|
_core.assert.call(void 0, !result.error, "Did not expect error");
|
|
1932
1802
|
_core.assert.call(void 0, !result.isLoading, "Did not expect loading");
|
|
1933
1803
|
return result;
|
|
@@ -1941,7 +1811,7 @@ function useUnreadInboxNotificationsCount_withClient(client) {
|
|
|
1941
1811
|
}
|
|
1942
1812
|
function useUnreadInboxNotificationsCountSuspense_withClient(client) {
|
|
1943
1813
|
const store = getLiveblocksExtrasForClient(client).store;
|
|
1944
|
-
use(store.
|
|
1814
|
+
use(store.outputs.loadingNotifications.waitUntilLoaded());
|
|
1945
1815
|
const result = useUnreadInboxNotificationsCount_withClient(client);
|
|
1946
1816
|
_core.assert.call(void 0, !result.isLoading, "Did not expect loading");
|
|
1947
1817
|
_core.assert.call(void 0, !result.error, "Did not expect error");
|
|
@@ -2033,34 +1903,31 @@ function useDeleteAllInboxNotifications_withClient(client) {
|
|
|
2033
1903
|
}
|
|
2034
1904
|
function useInboxNotificationThread_withClient(client, inboxNotificationId) {
|
|
2035
1905
|
const { store } = getLiveblocksExtrasForClient(client);
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
(
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
)
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
getter,
|
|
2056
|
-
getter,
|
|
2057
|
-
selector
|
|
1906
|
+
return useSignal(
|
|
1907
|
+
store.outputs.threadifications,
|
|
1908
|
+
_react.useCallback.call(void 0,
|
|
1909
|
+
(state) => {
|
|
1910
|
+
const inboxNotification = _nullishCoalesce(state.notificationsById[inboxNotificationId], () => ( _core.raise.call(void 0,
|
|
1911
|
+
`Inbox notification with ID "${inboxNotificationId}" not found`
|
|
1912
|
+
)));
|
|
1913
|
+
if (inboxNotification.kind !== "thread") {
|
|
1914
|
+
_core.raise.call(void 0,
|
|
1915
|
+
`Inbox notification with ID "${inboxNotificationId}" is not of kind "thread"`
|
|
1916
|
+
);
|
|
1917
|
+
}
|
|
1918
|
+
const thread = _nullishCoalesce(state.threadsDB.get(inboxNotification.threadId), () => ( _core.raise.call(void 0,
|
|
1919
|
+
`Thread with ID "${inboxNotification.threadId}" not found, this inbox notification might not be of kind "thread"`
|
|
1920
|
+
)));
|
|
1921
|
+
return thread;
|
|
1922
|
+
},
|
|
1923
|
+
[inboxNotificationId]
|
|
1924
|
+
)
|
|
2058
1925
|
);
|
|
2059
1926
|
}
|
|
2060
1927
|
function useUser_withClient(client, userId) {
|
|
2061
1928
|
const usersStore = client[_core.kInternal].usersStore;
|
|
2062
1929
|
const getUserState = _react.useCallback.call(void 0,
|
|
2063
|
-
() => usersStore.
|
|
1930
|
+
() => usersStore.getItemState(userId),
|
|
2064
1931
|
[usersStore, userId]
|
|
2065
1932
|
);
|
|
2066
1933
|
const selector = _react.useCallback.call(void 0,
|
|
@@ -2074,20 +1941,29 @@ function useUser_withClient(client, userId) {
|
|
|
2074
1941
|
selector,
|
|
2075
1942
|
_core.shallow
|
|
2076
1943
|
);
|
|
2077
|
-
_react.useEffect.call(void 0,
|
|
2078
|
-
void usersStore.
|
|
2079
|
-
|
|
1944
|
+
_react.useEffect.call(void 0,
|
|
1945
|
+
() => void usersStore.enqueue(userId)
|
|
1946
|
+
// NOTE: Deliberately *not* using a dependency array here!
|
|
1947
|
+
//
|
|
1948
|
+
// It is important to call usersStore.enqueue on *every* render.
|
|
1949
|
+
// This is harmless though, on most renders, except:
|
|
1950
|
+
// 1. The very first render, in which case we'll want to trigger evaluation
|
|
1951
|
+
// of the userId.
|
|
1952
|
+
// 2. All other subsequent renders now are a no-op (from the implementation
|
|
1953
|
+
// of .enqueue)
|
|
1954
|
+
// 3. If ever the userId gets invalidated, the user would be fetched again.
|
|
1955
|
+
);
|
|
2080
1956
|
return result;
|
|
2081
1957
|
}
|
|
2082
1958
|
function useUserSuspense_withClient(client, userId) {
|
|
2083
1959
|
const usersStore = client[_core.kInternal].usersStore;
|
|
2084
1960
|
const getUserState = _react.useCallback.call(void 0,
|
|
2085
|
-
() => usersStore.
|
|
1961
|
+
() => usersStore.getItemState(userId),
|
|
2086
1962
|
[usersStore, userId]
|
|
2087
1963
|
);
|
|
2088
1964
|
const userState = getUserState();
|
|
2089
1965
|
if (!userState || userState.isLoading) {
|
|
2090
|
-
throw usersStore.
|
|
1966
|
+
throw usersStore.enqueue(userId);
|
|
2091
1967
|
}
|
|
2092
1968
|
if (userState.error) {
|
|
2093
1969
|
throw userState.error;
|
|
@@ -2112,7 +1988,7 @@ function useUserSuspense_withClient(client, userId) {
|
|
|
2112
1988
|
function useRoomInfo_withClient(client, roomId) {
|
|
2113
1989
|
const roomsInfoStore = client[_core.kInternal].roomsInfoStore;
|
|
2114
1990
|
const getRoomInfoState = _react.useCallback.call(void 0,
|
|
2115
|
-
() => roomsInfoStore.
|
|
1991
|
+
() => roomsInfoStore.getItemState(roomId),
|
|
2116
1992
|
[roomsInfoStore, roomId]
|
|
2117
1993
|
);
|
|
2118
1994
|
const selector = _react.useCallback.call(void 0,
|
|
@@ -2126,20 +2002,29 @@ function useRoomInfo_withClient(client, roomId) {
|
|
|
2126
2002
|
selector,
|
|
2127
2003
|
_core.shallow
|
|
2128
2004
|
);
|
|
2129
|
-
_react.useEffect.call(void 0,
|
|
2130
|
-
void roomsInfoStore.
|
|
2131
|
-
|
|
2005
|
+
_react.useEffect.call(void 0,
|
|
2006
|
+
() => void roomsInfoStore.enqueue(roomId)
|
|
2007
|
+
// NOTE: Deliberately *not* using a dependency array here!
|
|
2008
|
+
//
|
|
2009
|
+
// It is important to call roomsInfoStore.enqueue on *every* render.
|
|
2010
|
+
// This is harmless though, on most renders, except:
|
|
2011
|
+
// 1. The very first render, in which case we'll want to trigger evaluation
|
|
2012
|
+
// of the roomId.
|
|
2013
|
+
// 2. All other subsequent renders now are a no-op (from the implementation
|
|
2014
|
+
// of .enqueue)
|
|
2015
|
+
// 3. If ever the roomId gets invalidated, the room info would be fetched again.
|
|
2016
|
+
);
|
|
2132
2017
|
return result;
|
|
2133
2018
|
}
|
|
2134
2019
|
function useRoomInfoSuspense_withClient(client, roomId) {
|
|
2135
2020
|
const roomsInfoStore = client[_core.kInternal].roomsInfoStore;
|
|
2136
2021
|
const getRoomInfoState = _react.useCallback.call(void 0,
|
|
2137
|
-
() => roomsInfoStore.
|
|
2022
|
+
() => roomsInfoStore.getItemState(roomId),
|
|
2138
2023
|
[roomsInfoStore, roomId]
|
|
2139
2024
|
);
|
|
2140
2025
|
const roomInfoState = getRoomInfoState();
|
|
2141
2026
|
if (!roomInfoState || roomInfoState.isLoading) {
|
|
2142
|
-
throw roomsInfoStore.
|
|
2027
|
+
throw roomsInfoStore.enqueue(roomId);
|
|
2143
2028
|
}
|
|
2144
2029
|
if (roomInfoState.error) {
|
|
2145
2030
|
throw roomInfoState.error;
|
|
@@ -2186,7 +2071,7 @@ function createSharedContext(client) {
|
|
|
2186
2071
|
}
|
|
2187
2072
|
function useEnsureNoLiveblocksProvider(options) {
|
|
2188
2073
|
const existing = useClientOrNull();
|
|
2189
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
2074
|
+
if (!_optionalChain([options, 'optionalAccess', _12 => _12.allowNesting]) && existing !== null) {
|
|
2190
2075
|
throw new Error(
|
|
2191
2076
|
"You cannot nest multiple LiveblocksProvider instances in the same React tree."
|
|
2192
2077
|
);
|
|
@@ -2241,10 +2126,9 @@ function useUserThreads_experimental(options = {
|
|
|
2241
2126
|
}) {
|
|
2242
2127
|
const client = useClient();
|
|
2243
2128
|
const { store, userThreadsPoller: poller } = getLiveblocksExtrasForClient(client);
|
|
2129
|
+
const queryKey = makeUserThreadsQueryKey(options.query);
|
|
2244
2130
|
_react.useEffect.call(void 0,
|
|
2245
|
-
() =>
|
|
2246
|
-
void store.waitUntilUserThreadsLoaded(options.query);
|
|
2247
|
-
}
|
|
2131
|
+
() => void store.outputs.loadingUserThreads.getOrCreate(queryKey).waitUntilLoaded()
|
|
2248
2132
|
// NOTE: Deliberately *not* using a dependency array here!
|
|
2249
2133
|
//
|
|
2250
2134
|
// It is important to call waitUntil on *every* render.
|
|
@@ -2261,17 +2145,8 @@ function useUserThreads_experimental(options = {
|
|
|
2261
2145
|
poller.dec();
|
|
2262
2146
|
};
|
|
2263
2147
|
}, [poller]);
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
[store, options.query]
|
|
2267
|
-
);
|
|
2268
|
-
return useSyncExternalStoreWithSelector(
|
|
2269
|
-
store.subscribe1_threads,
|
|
2270
|
-
getter,
|
|
2271
|
-
getter,
|
|
2272
|
-
identity,
|
|
2273
|
-
shallow2
|
|
2274
|
-
// NOTE: Using 2-level-deep shallow check here, because the result of selectThreads() is not stable!
|
|
2148
|
+
return useSignal(
|
|
2149
|
+
store.outputs.loadingUserThreads.getOrCreate(queryKey).signal
|
|
2275
2150
|
);
|
|
2276
2151
|
}
|
|
2277
2152
|
function useUserThreadsSuspense_experimental(options = {
|
|
@@ -2281,14 +2156,15 @@ function useUserThreadsSuspense_experimental(options = {
|
|
|
2281
2156
|
}) {
|
|
2282
2157
|
const client = useClient();
|
|
2283
2158
|
const { store } = getLiveblocksExtrasForClient(client);
|
|
2284
|
-
|
|
2159
|
+
const queryKey = makeUserThreadsQueryKey(options.query);
|
|
2160
|
+
use(store.outputs.loadingUserThreads.getOrCreate(queryKey).waitUntilLoaded());
|
|
2285
2161
|
const result = useUserThreads_experimental(options);
|
|
2286
2162
|
_core.assert.call(void 0, !result.error, "Did not expect error");
|
|
2287
2163
|
_core.assert.call(void 0, !result.isLoading, "Did not expect loading");
|
|
2288
2164
|
return result;
|
|
2289
2165
|
}
|
|
2290
2166
|
function useInboxNotifications() {
|
|
2291
|
-
return useInboxNotifications_withClient(useClient(),
|
|
2167
|
+
return useInboxNotifications_withClient(useClient(), identity2, _core.shallow);
|
|
2292
2168
|
}
|
|
2293
2169
|
function useInboxNotificationsSuspense() {
|
|
2294
2170
|
return useInboxNotificationsSuspense_withClient(useClient());
|
|
@@ -2337,7 +2213,7 @@ var _useUserSuspense = useUserSuspense;
|
|
|
2337
2213
|
var _useUserThreads_experimental = useUserThreads_experimental;
|
|
2338
2214
|
var _useUserThreadsSuspense_experimental = useUserThreadsSuspense_experimental;
|
|
2339
2215
|
function useSyncStatus_withClient(client, options) {
|
|
2340
|
-
const smooth = useInitial(_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2216
|
+
const smooth = useInitial(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _13 => _13.smooth]), () => ( false)));
|
|
2341
2217
|
if (smooth) {
|
|
2342
2218
|
return useSyncStatusSmooth_withClient(client);
|
|
2343
2219
|
} else {
|
|
@@ -2475,18 +2351,6 @@ var UpdateNotificationSettingsError = class extends Error {
|
|
|
2475
2351
|
}
|
|
2476
2352
|
};
|
|
2477
2353
|
|
|
2478
|
-
// src/use-signal.ts
|
|
2479
|
-
var identity2 = (value) => value;
|
|
2480
|
-
function useSignal(signal, selector, isEqual) {
|
|
2481
|
-
return useSyncExternalStoreWithSelector(
|
|
2482
|
-
signal.subscribe,
|
|
2483
|
-
signal.get,
|
|
2484
|
-
signal.get,
|
|
2485
|
-
_nullishCoalesce(selector, () => ( identity2)),
|
|
2486
|
-
isEqual
|
|
2487
|
-
);
|
|
2488
|
-
}
|
|
2489
|
-
|
|
2490
2354
|
// src/room.tsx
|
|
2491
2355
|
var _client = require('@liveblocks/client');
|
|
2492
2356
|
|
|
@@ -2509,6 +2373,7 @@ var _client = require('@liveblocks/client');
|
|
|
2509
2373
|
|
|
2510
2374
|
|
|
2511
2375
|
|
|
2376
|
+
|
|
2512
2377
|
|
|
2513
2378
|
|
|
2514
2379
|
// src/use-scroll-to-comment-on-load-effect.ts
|
|
@@ -2593,7 +2458,7 @@ function getCurrentUserId(client) {
|
|
|
2593
2458
|
}
|
|
2594
2459
|
function handleApiError(err) {
|
|
2595
2460
|
const message = `Request failed with status ${err.status}: ${err.message}`;
|
|
2596
|
-
if (_optionalChain([err, 'access',
|
|
2461
|
+
if (_optionalChain([err, 'access', _14 => _14.details, 'optionalAccess', _15 => _15.error]) === "FORBIDDEN") {
|
|
2597
2462
|
const detailedMessage = [message, err.details.suggestion, err.details.docs].filter(Boolean).join("\n");
|
|
2598
2463
|
_core.console.error(detailedMessage);
|
|
2599
2464
|
}
|
|
@@ -2633,73 +2498,59 @@ function makeRoomExtrasForClient(client) {
|
|
|
2633
2498
|
}
|
|
2634
2499
|
throw innerError;
|
|
2635
2500
|
}
|
|
2636
|
-
const threadsPollersByRoomId =
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
}
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
let poller = roomNotificationSettingsPollersByRoomId.get(roomId);
|
|
2679
|
-
if (!poller) {
|
|
2680
|
-
poller = _core.makePoller.call(void 0,
|
|
2681
|
-
async (signal) => {
|
|
2682
|
-
try {
|
|
2683
|
-
return await store.refreshRoomNotificationSettings(roomId, signal);
|
|
2684
|
-
} catch (err) {
|
|
2685
|
-
_core.console.warn(`Polling notification settings for '${roomId}' failed: ${String(err)}`);
|
|
2686
|
-
throw err;
|
|
2687
|
-
}
|
|
2688
|
-
},
|
|
2689
|
-
config.NOTIFICATION_SETTINGS_POLL_INTERVAL,
|
|
2690
|
-
{ maxStaleTimeMs: config.NOTIFICATION_SETTINGS_MAX_STALE_TIME }
|
|
2691
|
-
);
|
|
2692
|
-
roomNotificationSettingsPollersByRoomId.set(roomId, poller);
|
|
2693
|
-
}
|
|
2694
|
-
return poller;
|
|
2695
|
-
}
|
|
2501
|
+
const threadsPollersByRoomId = new (0, _core.DefaultMap)(
|
|
2502
|
+
(roomId) => _core.makePoller.call(void 0,
|
|
2503
|
+
async (signal) => {
|
|
2504
|
+
try {
|
|
2505
|
+
return await store.fetchRoomThreadsDeltaUpdate(roomId, signal);
|
|
2506
|
+
} catch (err) {
|
|
2507
|
+
_core.console.warn(`Polling new threads for '${roomId}' failed: ${String(err)}`);
|
|
2508
|
+
throw err;
|
|
2509
|
+
}
|
|
2510
|
+
},
|
|
2511
|
+
config.ROOM_THREADS_POLL_INTERVAL,
|
|
2512
|
+
{ maxStaleTimeMs: config.ROOM_THREADS_MAX_STALE_TIME }
|
|
2513
|
+
)
|
|
2514
|
+
);
|
|
2515
|
+
const versionsPollersByRoomId = new (0, _core.DefaultMap)(
|
|
2516
|
+
(roomId) => _core.makePoller.call(void 0,
|
|
2517
|
+
async (signal) => {
|
|
2518
|
+
try {
|
|
2519
|
+
return await store.fetchRoomVersionsDeltaUpdate(roomId, signal);
|
|
2520
|
+
} catch (err) {
|
|
2521
|
+
_core.console.warn(`Polling new history versions for '${roomId}' failed: ${String(err)}`);
|
|
2522
|
+
throw err;
|
|
2523
|
+
}
|
|
2524
|
+
},
|
|
2525
|
+
config.HISTORY_VERSIONS_POLL_INTERVAL,
|
|
2526
|
+
{ maxStaleTimeMs: config.HISTORY_VERSIONS_MAX_STALE_TIME }
|
|
2527
|
+
)
|
|
2528
|
+
);
|
|
2529
|
+
const roomNotificationSettingsPollersByRoomId = new (0, _core.DefaultMap)(
|
|
2530
|
+
(roomId) => _core.makePoller.call(void 0,
|
|
2531
|
+
async (signal) => {
|
|
2532
|
+
try {
|
|
2533
|
+
return await store.refreshRoomNotificationSettings(roomId, signal);
|
|
2534
|
+
} catch (err) {
|
|
2535
|
+
_core.console.warn(`Polling notification settings for '${roomId}' failed: ${String(err)}`);
|
|
2536
|
+
throw err;
|
|
2537
|
+
}
|
|
2538
|
+
},
|
|
2539
|
+
config.NOTIFICATION_SETTINGS_POLL_INTERVAL,
|
|
2540
|
+
{ maxStaleTimeMs: config.NOTIFICATION_SETTINGS_MAX_STALE_TIME }
|
|
2541
|
+
)
|
|
2542
|
+
);
|
|
2696
2543
|
return {
|
|
2697
2544
|
store,
|
|
2698
2545
|
commentsErrorEventSource: commentsErrorEventSource.observable,
|
|
2699
2546
|
onMutationFailure,
|
|
2700
|
-
getOrCreateThreadsPollerForRoomId
|
|
2701
|
-
|
|
2702
|
-
|
|
2547
|
+
getOrCreateThreadsPollerForRoomId: threadsPollersByRoomId.getOrCreate.bind(
|
|
2548
|
+
threadsPollersByRoomId
|
|
2549
|
+
),
|
|
2550
|
+
getOrCreateVersionsPollerForRoomId: versionsPollersByRoomId.getOrCreate.bind(versionsPollersByRoomId),
|
|
2551
|
+
getOrCreateNotificationsSettingsPollerForRoomId: roomNotificationSettingsPollersByRoomId.getOrCreate.bind(
|
|
2552
|
+
roomNotificationSettingsPollersByRoomId
|
|
2553
|
+
)
|
|
2703
2554
|
};
|
|
2704
2555
|
}
|
|
2705
2556
|
function makeRoomContextBundle(client) {
|
|
@@ -2878,7 +2729,7 @@ function RoomProviderInner(props) {
|
|
|
2878
2729
|
return;
|
|
2879
2730
|
}
|
|
2880
2731
|
const { thread, inboxNotification: maybeNotification } = info;
|
|
2881
|
-
const existingThread = store.
|
|
2732
|
+
const existingThread = store.outputs.threads.get().getEvenIfDeleted(message.threadId);
|
|
2882
2733
|
switch (message.type) {
|
|
2883
2734
|
case _core.ServerMsgCode.COMMENT_EDITED:
|
|
2884
2735
|
case _core.ServerMsgCode.THREAD_METADATA_UPDATED:
|
|
@@ -2996,7 +2847,7 @@ function useMentionSuggestionsCache() {
|
|
|
2996
2847
|
return client[_core.kInternal].mentionSuggestionsCache;
|
|
2997
2848
|
}
|
|
2998
2849
|
function useStorageStatus(options) {
|
|
2999
|
-
const smooth = useInitial(_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2850
|
+
const smooth = useInitial(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _16 => _16.smooth]), () => ( false)));
|
|
3000
2851
|
if (smooth) {
|
|
3001
2852
|
return useStorageStatusSmooth();
|
|
3002
2853
|
} else {
|
|
@@ -3249,18 +3100,15 @@ function useMutation(callback, deps) {
|
|
|
3249
3100
|
[room, ...deps]
|
|
3250
3101
|
);
|
|
3251
3102
|
}
|
|
3252
|
-
function useThreads(options = {
|
|
3253
|
-
query: { metadata: {} }
|
|
3254
|
-
}) {
|
|
3103
|
+
function useThreads(options = {}) {
|
|
3255
3104
|
const { scrollOnLoad = true } = options;
|
|
3256
3105
|
const client = useClient();
|
|
3257
3106
|
const room = useRoom();
|
|
3258
3107
|
const { store, getOrCreateThreadsPollerForRoomId } = getRoomExtrasForClient(client);
|
|
3108
|
+
const queryKey = makeRoomThreadsQueryKey(room.id, options.query);
|
|
3259
3109
|
const poller = getOrCreateThreadsPollerForRoomId(room.id);
|
|
3260
3110
|
_react.useEffect.call(void 0,
|
|
3261
|
-
() =>
|
|
3262
|
-
void store.waitUntilRoomThreadsLoaded(room.id, options.query);
|
|
3263
|
-
}
|
|
3111
|
+
() => void store.outputs.loadingRoomThreads.getOrCreate(queryKey).waitUntilLoaded()
|
|
3264
3112
|
// NOTE: Deliberately *not* using a dependency array here!
|
|
3265
3113
|
//
|
|
3266
3114
|
// It is important to call waitUntil on *every* render.
|
|
@@ -3275,20 +3123,11 @@ function useThreads(options = {
|
|
|
3275
3123
|
poller.pollNowIfStale();
|
|
3276
3124
|
return () => poller.dec();
|
|
3277
3125
|
}, [poller]);
|
|
3278
|
-
const
|
|
3279
|
-
|
|
3280
|
-
[store, room.id, options.query]
|
|
3281
|
-
);
|
|
3282
|
-
const state = useSyncExternalStoreWithSelector(
|
|
3283
|
-
store.subscribe1_threads,
|
|
3284
|
-
getter,
|
|
3285
|
-
getter,
|
|
3286
|
-
identity3,
|
|
3287
|
-
shallow2
|
|
3288
|
-
// NOTE: Using 2-level-deep shallow check here, because the result of selectThreads() is not stable!
|
|
3126
|
+
const result = useSignal(
|
|
3127
|
+
store.outputs.loadingRoomThreads.getOrCreate(queryKey).signal
|
|
3289
3128
|
);
|
|
3290
|
-
useScrollToCommentOnLoadEffect(scrollOnLoad,
|
|
3291
|
-
return
|
|
3129
|
+
useScrollToCommentOnLoadEffect(scrollOnLoad, result);
|
|
3130
|
+
return result;
|
|
3292
3131
|
}
|
|
3293
3132
|
function useCommentsErrorListener(callback) {
|
|
3294
3133
|
const client = useClient();
|
|
@@ -3338,7 +3177,7 @@ function useCreateRoomThread(roomId) {
|
|
|
3338
3177
|
thread: newThread,
|
|
3339
3178
|
roomId
|
|
3340
3179
|
});
|
|
3341
|
-
const attachmentIds = _optionalChain([attachments, 'optionalAccess',
|
|
3180
|
+
const attachmentIds = _optionalChain([attachments, 'optionalAccess', _17 => _17.map, 'call', _18 => _18((attachment) => attachment.id)]);
|
|
3342
3181
|
client[_core.kInternal].httpClient.createThread({
|
|
3343
3182
|
roomId,
|
|
3344
3183
|
threadId,
|
|
@@ -3376,8 +3215,8 @@ function useDeleteRoomThread(roomId) {
|
|
|
3376
3215
|
(threadId) => {
|
|
3377
3216
|
const { store, onMutationFailure } = getRoomExtrasForClient(client);
|
|
3378
3217
|
const userId = getCurrentUserId(client);
|
|
3379
|
-
const existing = store.
|
|
3380
|
-
if (_optionalChain([existing, 'optionalAccess',
|
|
3218
|
+
const existing = store.outputs.threads.get().get(threadId);
|
|
3219
|
+
if (_optionalChain([existing, 'optionalAccess', _19 => _19.comments, 'optionalAccess', _20 => _20[0], 'optionalAccess', _21 => _21.userId]) !== userId) {
|
|
3381
3220
|
throw new Error("Only the thread creator can delete the thread");
|
|
3382
3221
|
}
|
|
3383
3222
|
const optimisticId = store.optimisticUpdates.add({
|
|
@@ -3464,7 +3303,7 @@ function useCreateRoomComment(roomId) {
|
|
|
3464
3303
|
type: "create-comment",
|
|
3465
3304
|
comment
|
|
3466
3305
|
});
|
|
3467
|
-
const attachmentIds = _optionalChain([attachments, 'optionalAccess',
|
|
3306
|
+
const attachmentIds = _optionalChain([attachments, 'optionalAccess', _22 => _22.map, 'call', _23 => _23((attachment) => attachment.id)]);
|
|
3468
3307
|
client[_core.kInternal].httpClient.createComment({ roomId, threadId, commentId, body, attachmentIds }).then(
|
|
3469
3308
|
(newComment) => {
|
|
3470
3309
|
store.createComment(newComment, optimisticId);
|
|
@@ -3494,7 +3333,7 @@ function useEditRoomComment(roomId) {
|
|
|
3494
3333
|
({ threadId, commentId, body, attachments }) => {
|
|
3495
3334
|
const editedAt = /* @__PURE__ */ new Date();
|
|
3496
3335
|
const { store, onMutationFailure } = getRoomExtrasForClient(client);
|
|
3497
|
-
const existing = store.
|
|
3336
|
+
const existing = store.outputs.threads.get().getEvenIfDeleted(threadId);
|
|
3498
3337
|
if (existing === void 0) {
|
|
3499
3338
|
_core.console.warn(
|
|
3500
3339
|
`Internal unexpected behavior. Cannot edit comment in thread "${threadId}" because the thread does not exist in the cache.`
|
|
@@ -3519,7 +3358,7 @@ function useEditRoomComment(roomId) {
|
|
|
3519
3358
|
attachments: _nullishCoalesce(attachments, () => ( []))
|
|
3520
3359
|
}
|
|
3521
3360
|
});
|
|
3522
|
-
const attachmentIds = _optionalChain([attachments, 'optionalAccess',
|
|
3361
|
+
const attachmentIds = _optionalChain([attachments, 'optionalAccess', _24 => _24.map, 'call', _25 => _25((attachment) => attachment.id)]);
|
|
3523
3362
|
client[_core.kInternal].httpClient.editComment({ roomId, threadId, commentId, body, attachmentIds }).then(
|
|
3524
3363
|
(editedComment) => {
|
|
3525
3364
|
store.editComment(threadId, optimisticId, editedComment);
|
|
@@ -3671,7 +3510,7 @@ function useMarkRoomThreadAsRead(roomId) {
|
|
|
3671
3510
|
(threadId) => {
|
|
3672
3511
|
const { store, onMutationFailure } = getRoomExtrasForClient(client);
|
|
3673
3512
|
const inboxNotification = Object.values(
|
|
3674
|
-
store.
|
|
3513
|
+
store.outputs.notifications.get().notificationsById
|
|
3675
3514
|
).find(
|
|
3676
3515
|
(inboxNotification2) => inboxNotification2.kind === "thread" && inboxNotification2.threadId === threadId
|
|
3677
3516
|
);
|
|
@@ -3809,9 +3648,7 @@ function useRoomNotificationSettings() {
|
|
|
3809
3648
|
const { store, getOrCreateNotificationsSettingsPollerForRoomId } = getRoomExtrasForClient(client);
|
|
3810
3649
|
const poller = getOrCreateNotificationsSettingsPollerForRoomId(room.id);
|
|
3811
3650
|
_react.useEffect.call(void 0,
|
|
3812
|
-
() =>
|
|
3813
|
-
void store.waitUntilRoomNotificationSettingsLoaded(room.id);
|
|
3814
|
-
}
|
|
3651
|
+
() => void store.outputs.settingsByRoomId.getOrCreate(room.id).waitUntilLoaded()
|
|
3815
3652
|
// NOTE: Deliberately *not* using a dependency array here!
|
|
3816
3653
|
//
|
|
3817
3654
|
// It is important to call waitUntil on *every* render.
|
|
@@ -3828,16 +3665,8 @@ function useRoomNotificationSettings() {
|
|
|
3828
3665
|
poller.dec();
|
|
3829
3666
|
};
|
|
3830
3667
|
}, [poller]);
|
|
3831
|
-
const
|
|
3832
|
-
|
|
3833
|
-
[store, room.id]
|
|
3834
|
-
);
|
|
3835
|
-
const settings = useSyncExternalStoreWithSelector(
|
|
3836
|
-
store.subscribe2,
|
|
3837
|
-
getter,
|
|
3838
|
-
getter,
|
|
3839
|
-
identity3,
|
|
3840
|
-
shallow2
|
|
3668
|
+
const settings = useSignal(
|
|
3669
|
+
store.outputs.settingsByRoomId.getOrCreate(room.id).signal
|
|
3841
3670
|
);
|
|
3842
3671
|
return _react.useMemo.call(void 0, () => {
|
|
3843
3672
|
return [settings, updateRoomNotificationSettings];
|
|
@@ -3847,7 +3676,7 @@ function useRoomNotificationSettingsSuspense() {
|
|
|
3847
3676
|
const client = useClient();
|
|
3848
3677
|
const store = getRoomExtrasForClient(client).store;
|
|
3849
3678
|
const room = useRoom();
|
|
3850
|
-
use(store.
|
|
3679
|
+
use(store.outputs.settingsByRoomId.getOrCreate(room.id).waitUntilLoaded());
|
|
3851
3680
|
const [settings, updateRoomNotificationSettings] = useRoomNotificationSettings();
|
|
3852
3681
|
_core.assert.call(void 0, !settings.error, "Did not expect error");
|
|
3853
3682
|
_core.assert.call(void 0, !settings.isLoading, "Did not expect loading");
|
|
@@ -3894,14 +3723,8 @@ function useHistoryVersions() {
|
|
|
3894
3723
|
poller.pollNowIfStale();
|
|
3895
3724
|
return () => poller.dec();
|
|
3896
3725
|
}, [poller]);
|
|
3897
|
-
const getter = _react.useCallback.call(void 0,
|
|
3898
|
-
() => store.getRoomVersionsLoadingState(room.id),
|
|
3899
|
-
[store, room.id]
|
|
3900
|
-
);
|
|
3901
3726
|
_react.useEffect.call(void 0,
|
|
3902
|
-
() =>
|
|
3903
|
-
void store.waitUntilRoomVersionsLoaded(room.id);
|
|
3904
|
-
}
|
|
3727
|
+
() => void store.outputs.versionsByRoomId.getOrCreate(room.id).waitUntilLoaded()
|
|
3905
3728
|
// NOTE: Deliberately *not* using a dependency array here!
|
|
3906
3729
|
//
|
|
3907
3730
|
// It is important to call waitUntil on *every* render.
|
|
@@ -3911,20 +3734,13 @@ function useHistoryVersions() {
|
|
|
3911
3734
|
// 3. If ever the promise would fail, then after 5 seconds it would reset, and on the very
|
|
3912
3735
|
// *next* render after that, a *new* fetch/promise will get created.
|
|
3913
3736
|
);
|
|
3914
|
-
|
|
3915
|
-
store.subscribe3,
|
|
3916
|
-
getter,
|
|
3917
|
-
getter,
|
|
3918
|
-
identity3,
|
|
3919
|
-
shallow2
|
|
3920
|
-
);
|
|
3921
|
-
return state;
|
|
3737
|
+
return useSignal(store.outputs.versionsByRoomId.getOrCreate(room.id).signal);
|
|
3922
3738
|
}
|
|
3923
3739
|
function useHistoryVersionsSuspense() {
|
|
3924
3740
|
const client = useClient();
|
|
3925
3741
|
const room = useRoom();
|
|
3926
3742
|
const store = getRoomExtrasForClient(client).store;
|
|
3927
|
-
use(store.
|
|
3743
|
+
use(store.outputs.versionsByRoomId.getOrCreate(room.id).waitUntilLoaded());
|
|
3928
3744
|
const result = useHistoryVersions();
|
|
3929
3745
|
_core.assert.call(void 0, !result.error, "Did not expect error");
|
|
3930
3746
|
_core.assert.call(void 0, !result.isLoading, "Did not expect loading");
|
|
@@ -4011,20 +3827,19 @@ function useStorageStatusSuspense(options) {
|
|
|
4011
3827
|
useSuspendUntilStorageReady();
|
|
4012
3828
|
return useStorageStatus(options);
|
|
4013
3829
|
}
|
|
4014
|
-
function useThreadsSuspense(options = {
|
|
4015
|
-
query: { metadata: {} }
|
|
4016
|
-
}) {
|
|
3830
|
+
function useThreadsSuspense(options = {}) {
|
|
4017
3831
|
const client = useClient();
|
|
4018
3832
|
const room = useRoom();
|
|
4019
3833
|
const { store } = getRoomExtrasForClient(client);
|
|
4020
|
-
|
|
3834
|
+
const queryKey = makeRoomThreadsQueryKey(room.id, options.query);
|
|
3835
|
+
use(store.outputs.loadingRoomThreads.getOrCreate(queryKey).waitUntilLoaded());
|
|
4021
3836
|
const result = useThreads(options);
|
|
4022
3837
|
_core.assert.call(void 0, !result.error, "Did not expect error");
|
|
4023
3838
|
_core.assert.call(void 0, !result.isLoading, "Did not expect loading");
|
|
4024
3839
|
return result;
|
|
4025
3840
|
}
|
|
4026
3841
|
function selectorFor_useAttachmentUrl(state) {
|
|
4027
|
-
if (state === void 0 || _optionalChain([state, 'optionalAccess',
|
|
3842
|
+
if (state === void 0 || _optionalChain([state, 'optionalAccess', _26 => _26.isLoading])) {
|
|
4028
3843
|
return _nullishCoalesce(state, () => ( { isLoading: true }));
|
|
4029
3844
|
}
|
|
4030
3845
|
if (state.error) {
|
|
@@ -4044,11 +3859,11 @@ function useRoomAttachmentUrl(attachmentId, roomId) {
|
|
|
4044
3859
|
const client = useClient();
|
|
4045
3860
|
const store = client[_core.kInternal].httpClient.getOrCreateAttachmentUrlsStore(roomId);
|
|
4046
3861
|
const getAttachmentUrlState = _react.useCallback.call(void 0,
|
|
4047
|
-
() => store.
|
|
3862
|
+
() => store.getItemState(attachmentId),
|
|
4048
3863
|
[store, attachmentId]
|
|
4049
3864
|
);
|
|
4050
3865
|
_react.useEffect.call(void 0, () => {
|
|
4051
|
-
void store.
|
|
3866
|
+
void store.enqueue(attachmentId);
|
|
4052
3867
|
}, [store, attachmentId]);
|
|
4053
3868
|
return useSyncExternalStoreWithSelector(
|
|
4054
3869
|
store.subscribe,
|
|
@@ -4062,12 +3877,12 @@ function useAttachmentUrlSuspense(attachmentId) {
|
|
|
4062
3877
|
const room = useRoom();
|
|
4063
3878
|
const { attachmentUrlsStore } = room[_core.kInternal];
|
|
4064
3879
|
const getAttachmentUrlState = _react.useCallback.call(void 0,
|
|
4065
|
-
() => attachmentUrlsStore.
|
|
3880
|
+
() => attachmentUrlsStore.getItemState(attachmentId),
|
|
4066
3881
|
[attachmentUrlsStore, attachmentId]
|
|
4067
3882
|
);
|
|
4068
3883
|
const attachmentUrlState = getAttachmentUrlState();
|
|
4069
3884
|
if (!attachmentUrlState || attachmentUrlState.isLoading) {
|
|
4070
|
-
throw attachmentUrlsStore.
|
|
3885
|
+
throw attachmentUrlsStore.enqueue(attachmentId);
|
|
4071
3886
|
}
|
|
4072
3887
|
if (attachmentUrlState.error) {
|
|
4073
3888
|
throw attachmentUrlState.error;
|
|
@@ -4086,12 +3901,13 @@ function useAttachmentUrlSuspense(attachmentId) {
|
|
|
4086
3901
|
error: void 0
|
|
4087
3902
|
};
|
|
4088
3903
|
}
|
|
3904
|
+
var NO_PERMISSIONS = /* @__PURE__ */ new Set();
|
|
4089
3905
|
function useRoomPermissions(roomId) {
|
|
4090
3906
|
const client = useClient();
|
|
4091
3907
|
const store = getRoomExtrasForClient(client).store;
|
|
4092
3908
|
return useSignal(
|
|
4093
3909
|
store.permissionHints.signal,
|
|
4094
|
-
(hints) => _nullishCoalesce(hints
|
|
3910
|
+
(hints) => _nullishCoalesce(hints.get(roomId), () => ( NO_PERMISSIONS))
|
|
4095
3911
|
);
|
|
4096
3912
|
}
|
|
4097
3913
|
function createRoomContext(client) {
|
|
@@ -4240,5 +4056,5 @@ var _useUpdateMyPresence = useUpdateMyPresence;
|
|
|
4240
4056
|
|
|
4241
4057
|
|
|
4242
4058
|
|
|
4243
|
-
exports.RoomContext = RoomContext; exports.useRoomOrNull = useRoomOrNull; exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; exports.ClientContext = ClientContext; exports.getUmbrellaStoreForClient = getUmbrellaStoreForClient; exports.useClientOrNull = useClientOrNull; exports.useClient = useClient; exports.LiveblocksProvider = LiveblocksProvider; exports.createLiveblocksContext = createLiveblocksContext; exports.useInboxNotifications = useInboxNotifications; exports.useInboxNotificationsSuspense = useInboxNotificationsSuspense; exports.useMarkAllInboxNotificationsAsRead = useMarkAllInboxNotificationsAsRead; exports.useMarkInboxNotificationAsRead = useMarkInboxNotificationAsRead; exports.useDeleteAllInboxNotifications = useDeleteAllInboxNotifications; exports.useDeleteInboxNotification = useDeleteInboxNotification; exports.useUnreadInboxNotificationsCount = useUnreadInboxNotificationsCount; exports.useUnreadInboxNotificationsCountSuspense = useUnreadInboxNotificationsCountSuspense; exports.useRoomInfo = useRoomInfo; exports.useRoomInfoSuspense = useRoomInfoSuspense; exports._useInboxNotificationThread = _useInboxNotificationThread; exports._useUser = _useUser; exports._useUserSuspense = _useUserSuspense; exports._useUserThreads_experimental = _useUserThreads_experimental; exports._useUserThreadsSuspense_experimental = _useUserThreadsSuspense_experimental; exports.useSyncStatus = useSyncStatus; exports.CreateThreadError = CreateThreadError; exports.
|
|
4244
|
-
//# sourceMappingURL=chunk-
|
|
4059
|
+
exports.RoomContext = RoomContext; exports.useRoomOrNull = useRoomOrNull; 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.useRoomInfo = useRoomInfo; exports.useRoomInfoSuspense = useRoomInfoSuspense; exports._useInboxNotificationThread = _useInboxNotificationThread; exports._useUser = _useUser; exports._useUserSuspense = _useUserSuspense; exports._useUserThreads_experimental = _useUserThreads_experimental; exports._useUserThreadsSuspense_experimental = _useUserThreadsSuspense_experimental; exports.useSyncStatus = useSyncStatus; exports.CreateThreadError = CreateThreadError; exports.useStatus = useStatus; exports.useReportTextEditor = useReportTextEditor; exports.useYjsProvider = useYjsProvider; exports.useCreateTextMention = useCreateTextMention; exports.useDeleteTextMention = useDeleteTextMention; exports.useResolveMentionSuggestions = useResolveMentionSuggestions; exports.useMentionSuggestionsCache = useMentionSuggestionsCache; exports.useStorageStatus = useStorageStatus; exports.useBatch = useBatch; exports.useLostConnectionListener = useLostConnectionListener; exports.useErrorListener = useErrorListener; exports.useHistory = useHistory; exports.useUndo = useUndo; exports.useRedo = useRedo; exports.useCanUndo = useCanUndo; exports.useCanRedo = useCanRedo; exports.useOthersConnectionIds = useOthersConnectionIds; exports.useCommentsErrorListener = useCommentsErrorListener; exports.useCreateRoomThread = useCreateRoomThread; exports.useDeleteRoomThread = useDeleteRoomThread; exports.useEditRoomThreadMetadata = useEditRoomThreadMetadata; exports.useCreateComment = useCreateComment; exports.useCreateRoomComment = useCreateRoomComment; exports.useEditComment = useEditComment; exports.useEditRoomComment = useEditRoomComment; exports.useDeleteComment = useDeleteComment; exports.useDeleteRoomComment = useDeleteRoomComment; exports.useAddRoomCommentReaction = useAddRoomCommentReaction; exports.useRemoveReaction = useRemoveReaction; exports.useRemoveRoomCommentReaction = useRemoveRoomCommentReaction; exports.useMarkThreadAsRead = useMarkThreadAsRead; exports.useMarkRoomThreadAsRead = useMarkRoomThreadAsRead; exports.useMarkThreadAsResolved = useMarkThreadAsResolved; exports.useMarkRoomThreadAsResolved = useMarkRoomThreadAsResolved; exports.useMarkThreadAsUnresolved = useMarkThreadAsUnresolved; exports.useMarkRoomThreadAsUnresolved = useMarkRoomThreadAsUnresolved; exports.useThreadSubscription = useThreadSubscription; exports.useHistoryVersionData = useHistoryVersionData; exports.useUpdateRoomNotificationSettings = useUpdateRoomNotificationSettings; exports.useOthersConnectionIdsSuspense = useOthersConnectionIdsSuspense; exports.useStorageStatusSuspense = useStorageStatusSuspense; exports.useAttachmentUrl = useAttachmentUrl; exports.useRoomAttachmentUrl = useRoomAttachmentUrl; exports.useAttachmentUrlSuspense = useAttachmentUrlSuspense; exports.useRoomPermissions = useRoomPermissions; exports.createRoomContext = createRoomContext; exports._RoomProvider = _RoomProvider; exports._useBroadcastEvent = _useBroadcastEvent; exports._useOthersListener = _useOthersListener; exports._useRoom = _useRoom; exports._useIsInsideRoom = _useIsInsideRoom; exports._useAddReaction = _useAddReaction; exports._useMutation = _useMutation; exports._useCreateThread = _useCreateThread; exports._useDeleteThread = _useDeleteThread; exports._useEditThreadMetadata = _useEditThreadMetadata; exports._useEventListener = _useEventListener; exports._useMyPresence = _useMyPresence; exports._useOthersMapped = _useOthersMapped; exports._useOthersMappedSuspense = _useOthersMappedSuspense; exports._useThreads = _useThreads; exports._useThreadsSuspense = _useThreadsSuspense; exports._useRoomNotificationSettings = _useRoomNotificationSettings; exports._useRoomNotificationSettingsSuspense = _useRoomNotificationSettingsSuspense; exports._useHistoryVersions = _useHistoryVersions; exports._useHistoryVersionsSuspense = _useHistoryVersionsSuspense; exports._useOther = _useOther; exports._useOthers = _useOthers; exports._useOtherSuspense = _useOtherSuspense; exports._useOthersSuspense = _useOthersSuspense; exports._useStorage = _useStorage; exports._useStorageSuspense = _useStorageSuspense; exports._useSelf = _useSelf; exports._useSelfSuspense = _useSelfSuspense; exports._useStorageRoot = _useStorageRoot; exports._useUpdateMyPresence = _useUpdateMyPresence;
|
|
4060
|
+
//# sourceMappingURL=chunk-DEAPV4GE.js.map
|