@liveblocks/react 2.13.3-emails2 → 2.14.0-v2encoding
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_private.d.mts +1 -1
- package/dist/_private.d.ts +1 -1
- package/dist/_private.js +16 -7
- package/dist/_private.js.map +1 -1
- package/dist/_private.mjs +19 -10
- package/dist/_private.mjs.map +1 -1
- package/dist/{chunk-X4DDEZYL.js → chunk-7ZCTUIE6.js} +274 -202
- package/dist/chunk-7ZCTUIE6.js.map +1 -0
- package/dist/{chunk-BRCWZCNY.mjs → chunk-BYPL4Y26.mjs} +270 -198
- package/dist/chunk-BYPL4Y26.mjs.map +1 -0
- package/dist/{chunk-ZKHAR6BQ.mjs → chunk-CAMSPWNT.mjs} +2 -2
- package/dist/{chunk-RWQ74ZK6.js → chunk-FPO6VPFA.js} +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +2 -2
- package/dist/{room-Rl_QnQMY.d.mts → room-gbqt3lTY.d.mts} +14 -40
- package/dist/{room-Rl_QnQMY.d.ts → room-gbqt3lTY.d.ts} +14 -40
- 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-BRCWZCNY.mjs.map +0 -1
- package/dist/chunk-X4DDEZYL.js.map +0 -1
- /package/dist/{chunk-ZKHAR6BQ.mjs.map → chunk-CAMSPWNT.mjs.map} +0 -0
- /package/dist/{chunk-RWQ74ZK6.js.map → chunk-FPO6VPFA.js.map} +0 -0
|
@@ -202,35 +202,39 @@ function sanitizeThread(thread) {
|
|
|
202
202
|
return thread;
|
|
203
203
|
}
|
|
204
204
|
var ThreadDB = class _ThreadDB {
|
|
205
|
+
#byId;
|
|
206
|
+
#asc;
|
|
207
|
+
#desc;
|
|
208
|
+
#version;
|
|
205
209
|
// The version is auto-incremented on every mutation and can be used as a reliable indicator to tell if the contents of the thread pool has changed
|
|
206
210
|
constructor() {
|
|
207
|
-
this
|
|
211
|
+
this.#asc = _core.SortedList.from([], (t1, t2) => {
|
|
208
212
|
const d1 = t1.createdAt;
|
|
209
213
|
const d2 = t2.createdAt;
|
|
210
214
|
return d1 < d2 ? true : d1 === d2 ? t1.id < t2.id : false;
|
|
211
215
|
});
|
|
212
|
-
this
|
|
216
|
+
this.#desc = _core.SortedList.from([], (t1, t2) => {
|
|
213
217
|
const d2 = t2.updatedAt;
|
|
214
218
|
const d1 = t1.updatedAt;
|
|
215
219
|
return d2 < d1 ? true : d2 === d1 ? t2.id < t1.id : false;
|
|
216
220
|
});
|
|
217
|
-
this
|
|
218
|
-
this
|
|
221
|
+
this.#byId = /* @__PURE__ */ new Map();
|
|
222
|
+
this.#version = 0;
|
|
219
223
|
}
|
|
220
224
|
//
|
|
221
225
|
// Public APIs
|
|
222
226
|
//
|
|
223
227
|
clone() {
|
|
224
228
|
const newPool = new _ThreadDB();
|
|
225
|
-
newPool
|
|
226
|
-
newPool
|
|
227
|
-
newPool
|
|
228
|
-
newPool
|
|
229
|
+
newPool.#byId = new Map(this.#byId);
|
|
230
|
+
newPool.#asc = this.#asc.clone();
|
|
231
|
+
newPool.#desc = this.#desc.clone();
|
|
232
|
+
newPool.#version = this.#version;
|
|
229
233
|
return newPool;
|
|
230
234
|
}
|
|
231
235
|
/** Gets the transaction count for this DB. Increments any time the DB is modified. */
|
|
232
236
|
get version() {
|
|
233
|
-
return this
|
|
237
|
+
return this.#version;
|
|
234
238
|
}
|
|
235
239
|
/** Returns an existing thread by ID. Will never return a deleted thread. */
|
|
236
240
|
get(threadId) {
|
|
@@ -239,24 +243,24 @@ var ThreadDB = class _ThreadDB {
|
|
|
239
243
|
}
|
|
240
244
|
/** Returns the (possibly deleted) thread by ID. */
|
|
241
245
|
getEvenIfDeleted(threadId) {
|
|
242
|
-
return this.
|
|
246
|
+
return this.#byId.get(threadId);
|
|
243
247
|
}
|
|
244
248
|
/** Adds or updates a thread in the DB. If the newly given thread is a deleted one, it will get deleted. */
|
|
245
249
|
upsert(thread) {
|
|
246
250
|
thread = sanitizeThread(thread);
|
|
247
251
|
const id = thread.id;
|
|
248
|
-
const toRemove = this.
|
|
252
|
+
const toRemove = this.#byId.get(id);
|
|
249
253
|
if (toRemove) {
|
|
250
254
|
if (toRemove.deletedAt) return;
|
|
251
|
-
this.
|
|
252
|
-
this.
|
|
255
|
+
this.#asc.remove(toRemove);
|
|
256
|
+
this.#desc.remove(toRemove);
|
|
253
257
|
}
|
|
254
258
|
if (!thread.deletedAt) {
|
|
255
|
-
this.
|
|
256
|
-
this.
|
|
259
|
+
this.#asc.add(thread);
|
|
260
|
+
this.#desc.add(thread);
|
|
257
261
|
}
|
|
258
|
-
this.
|
|
259
|
-
this
|
|
262
|
+
this.#byId.set(id, thread);
|
|
263
|
+
this.#touch();
|
|
260
264
|
}
|
|
261
265
|
/** Like .upsert(), except it won't update if a thread by this ID already exists. */
|
|
262
266
|
// TODO Consider renaming this to just .upsert(). I'm not sure if we really
|
|
@@ -272,7 +276,7 @@ var ThreadDB = class _ThreadDB {
|
|
|
272
276
|
* queries, but it can still be accessed via `.getEvenIfDeleted()`.
|
|
273
277
|
*/
|
|
274
278
|
delete(threadId, deletedAt) {
|
|
275
|
-
const existing = this.
|
|
279
|
+
const existing = this.#byId.get(threadId);
|
|
276
280
|
if (existing && !existing.deletedAt) {
|
|
277
281
|
this.upsert({ ...existing, deletedAt, updatedAt: deletedAt });
|
|
278
282
|
}
|
|
@@ -289,7 +293,7 @@ var ThreadDB = class _ThreadDB {
|
|
|
289
293
|
* Will never return deleted threads in the result.
|
|
290
294
|
*/
|
|
291
295
|
findMany(roomId, query, direction) {
|
|
292
|
-
const index = direction === "desc" ? this
|
|
296
|
+
const index = direction === "desc" ? this.#desc : this.#asc;
|
|
293
297
|
const crit = [];
|
|
294
298
|
if (roomId !== void 0) {
|
|
295
299
|
crit.push((t) => t.roomId === roomId);
|
|
@@ -300,8 +304,8 @@ var ThreadDB = class _ThreadDB {
|
|
|
300
304
|
//
|
|
301
305
|
// Private APIs
|
|
302
306
|
//
|
|
303
|
-
touch() {
|
|
304
|
-
++this
|
|
307
|
+
#touch() {
|
|
308
|
+
++this.#version;
|
|
305
309
|
}
|
|
306
310
|
};
|
|
307
311
|
|
|
@@ -339,62 +343,67 @@ function usify(promise) {
|
|
|
339
343
|
var noop2 = Promise.resolve();
|
|
340
344
|
var ASYNC_LOADING = Object.freeze({ isLoading: true });
|
|
341
345
|
var PaginatedResource = class {
|
|
346
|
+
|
|
347
|
+
#eventSource;
|
|
348
|
+
#fetchPage;
|
|
349
|
+
#paginationState;
|
|
350
|
+
// Should be null while in loading or error state!
|
|
351
|
+
#pendingFetchMore;
|
|
342
352
|
constructor(fetchPage) {
|
|
343
|
-
this
|
|
344
|
-
this
|
|
345
|
-
this
|
|
346
|
-
this
|
|
347
|
-
this.
|
|
348
|
-
this.observable = this._eventSource.observable;
|
|
353
|
+
this.#paginationState = null;
|
|
354
|
+
this.#fetchPage = fetchPage;
|
|
355
|
+
this.#eventSource = _core.makeEventSource.call(void 0, );
|
|
356
|
+
this.#pendingFetchMore = null;
|
|
357
|
+
this.observable = this.#eventSource.observable;
|
|
349
358
|
autobind(this);
|
|
350
359
|
}
|
|
351
|
-
patchPaginationState(patch) {
|
|
352
|
-
const state = this
|
|
360
|
+
#patchPaginationState(patch) {
|
|
361
|
+
const state = this.#paginationState;
|
|
353
362
|
if (state === null) return;
|
|
354
|
-
this
|
|
355
|
-
this.
|
|
363
|
+
this.#paginationState = { ...state, ...patch };
|
|
364
|
+
this.#eventSource.notify();
|
|
356
365
|
}
|
|
357
|
-
async
|
|
358
|
-
const state = this
|
|
366
|
+
async #fetchMore() {
|
|
367
|
+
const state = this.#paginationState;
|
|
359
368
|
if (!_optionalChain([state, 'optionalAccess', _3 => _3.cursor])) {
|
|
360
369
|
return;
|
|
361
370
|
}
|
|
362
|
-
this
|
|
371
|
+
this.#patchPaginationState({ isFetchingMore: true });
|
|
363
372
|
try {
|
|
364
|
-
const nextCursor = await this
|
|
365
|
-
this
|
|
373
|
+
const nextCursor = await this.#fetchPage(state.cursor);
|
|
374
|
+
this.#patchPaginationState({
|
|
366
375
|
cursor: nextCursor,
|
|
367
376
|
fetchMoreError: void 0,
|
|
368
377
|
isFetchingMore: false
|
|
369
378
|
});
|
|
370
379
|
} catch (err) {
|
|
371
|
-
this
|
|
380
|
+
this.#patchPaginationState({
|
|
372
381
|
isFetchingMore: false,
|
|
373
382
|
fetchMoreError: err
|
|
374
383
|
});
|
|
375
384
|
}
|
|
376
385
|
}
|
|
377
386
|
fetchMore() {
|
|
378
|
-
const state = this
|
|
387
|
+
const state = this.#paginationState;
|
|
379
388
|
if (_optionalChain([state, 'optionalAccess', _4 => _4.cursor]) === null) {
|
|
380
389
|
return noop2;
|
|
381
390
|
}
|
|
382
|
-
if (!this
|
|
383
|
-
this
|
|
384
|
-
this
|
|
391
|
+
if (!this.#pendingFetchMore) {
|
|
392
|
+
this.#pendingFetchMore = this.#fetchMore().finally(() => {
|
|
393
|
+
this.#pendingFetchMore = null;
|
|
385
394
|
});
|
|
386
395
|
}
|
|
387
|
-
return this
|
|
396
|
+
return this.#pendingFetchMore;
|
|
388
397
|
}
|
|
389
398
|
get() {
|
|
390
|
-
const usable = this
|
|
399
|
+
const usable = this.#cachedPromise;
|
|
391
400
|
if (usable === null || usable.status === "pending") {
|
|
392
401
|
return ASYNC_LOADING;
|
|
393
402
|
}
|
|
394
403
|
if (usable.status === "rejected") {
|
|
395
404
|
return { isLoading: false, error: usable.reason };
|
|
396
405
|
}
|
|
397
|
-
const state = this
|
|
406
|
+
const state = this.#paginationState;
|
|
398
407
|
return {
|
|
399
408
|
isLoading: false,
|
|
400
409
|
data: {
|
|
@@ -405,12 +414,13 @@ var PaginatedResource = class {
|
|
|
405
414
|
}
|
|
406
415
|
};
|
|
407
416
|
}
|
|
417
|
+
#cachedPromise = null;
|
|
408
418
|
waitUntilLoaded() {
|
|
409
|
-
if (this
|
|
410
|
-
return this
|
|
419
|
+
if (this.#cachedPromise) {
|
|
420
|
+
return this.#cachedPromise;
|
|
411
421
|
}
|
|
412
422
|
const initialFetcher = _core.autoRetry.call(void 0,
|
|
413
|
-
() => this
|
|
423
|
+
() => this.#fetchPage(
|
|
414
424
|
/* cursor */
|
|
415
425
|
void 0
|
|
416
426
|
),
|
|
@@ -419,7 +429,7 @@ var PaginatedResource = class {
|
|
|
419
429
|
);
|
|
420
430
|
const promise = usify(
|
|
421
431
|
initialFetcher.then((cursor) => {
|
|
422
|
-
this
|
|
432
|
+
this.#paginationState = {
|
|
423
433
|
cursor,
|
|
424
434
|
isFetchingMore: false,
|
|
425
435
|
fetchMoreError: void 0
|
|
@@ -427,29 +437,31 @@ var PaginatedResource = class {
|
|
|
427
437
|
})
|
|
428
438
|
);
|
|
429
439
|
promise.then(
|
|
430
|
-
() => this.
|
|
440
|
+
() => this.#eventSource.notify(),
|
|
431
441
|
() => {
|
|
432
|
-
this.
|
|
442
|
+
this.#eventSource.notify();
|
|
433
443
|
setTimeout(() => {
|
|
434
|
-
this
|
|
435
|
-
this.
|
|
444
|
+
this.#cachedPromise = null;
|
|
445
|
+
this.#eventSource.notify();
|
|
436
446
|
}, 5e3);
|
|
437
447
|
}
|
|
438
448
|
);
|
|
439
|
-
this
|
|
449
|
+
this.#cachedPromise = promise;
|
|
440
450
|
return promise;
|
|
441
451
|
}
|
|
442
452
|
};
|
|
443
453
|
var SinglePageResource = class {
|
|
454
|
+
|
|
455
|
+
#eventSource;
|
|
456
|
+
#fetchPage;
|
|
444
457
|
constructor(fetchPage) {
|
|
445
|
-
this
|
|
446
|
-
this
|
|
447
|
-
this.
|
|
448
|
-
this.observable = this._eventSource.observable;
|
|
458
|
+
this.#fetchPage = fetchPage;
|
|
459
|
+
this.#eventSource = _core.makeEventSource.call(void 0, );
|
|
460
|
+
this.observable = this.#eventSource.observable;
|
|
449
461
|
autobind(this);
|
|
450
462
|
}
|
|
451
463
|
get() {
|
|
452
|
-
const usable = this
|
|
464
|
+
const usable = this.#cachedPromise;
|
|
453
465
|
if (usable === null || usable.status === "pending") {
|
|
454
466
|
return ASYNC_LOADING;
|
|
455
467
|
}
|
|
@@ -461,72 +473,81 @@ var SinglePageResource = class {
|
|
|
461
473
|
data: void 0
|
|
462
474
|
};
|
|
463
475
|
}
|
|
476
|
+
#cachedPromise = null;
|
|
464
477
|
waitUntilLoaded() {
|
|
465
|
-
if (this
|
|
466
|
-
return this
|
|
478
|
+
if (this.#cachedPromise) {
|
|
479
|
+
return this.#cachedPromise;
|
|
467
480
|
}
|
|
468
481
|
const initialFetcher = _core.autoRetry.call(void 0,
|
|
469
|
-
() => this
|
|
482
|
+
() => this.#fetchPage(),
|
|
470
483
|
5,
|
|
471
484
|
[5e3, 5e3, 1e4, 15e3]
|
|
472
485
|
);
|
|
473
486
|
const promise = usify(initialFetcher);
|
|
474
487
|
promise.then(
|
|
475
|
-
() => this.
|
|
488
|
+
() => this.#eventSource.notify(),
|
|
476
489
|
() => {
|
|
477
|
-
this.
|
|
490
|
+
this.#eventSource.notify();
|
|
478
491
|
setTimeout(() => {
|
|
479
|
-
this
|
|
480
|
-
this.
|
|
492
|
+
this.#cachedPromise = null;
|
|
493
|
+
this.#eventSource.notify();
|
|
481
494
|
}, 5e3);
|
|
482
495
|
}
|
|
483
496
|
);
|
|
484
|
-
this
|
|
497
|
+
this.#cachedPromise = promise;
|
|
485
498
|
return promise;
|
|
486
499
|
}
|
|
487
500
|
};
|
|
488
501
|
var UmbrellaStore = class {
|
|
502
|
+
#client;
|
|
503
|
+
#syncSource;
|
|
504
|
+
// Raw threads DB (without any optimistic updates applied)
|
|
505
|
+
/** @internal - accessed in unit tests */
|
|
506
|
+
|
|
507
|
+
#prevVersion = -1;
|
|
508
|
+
#store;
|
|
509
|
+
#prevState = null;
|
|
510
|
+
#stateCached = null;
|
|
511
|
+
// Notifications
|
|
512
|
+
#notificationsLastRequestedAt = null;
|
|
513
|
+
// 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.
|
|
514
|
+
#notifications;
|
|
515
|
+
// Room Threads
|
|
516
|
+
#roomThreadsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
|
|
517
|
+
#roomThreads = /* @__PURE__ */ new Map();
|
|
518
|
+
// User Threads
|
|
519
|
+
#userThreadsLastRequestedAt = null;
|
|
520
|
+
#userThreads = /* @__PURE__ */ new Map();
|
|
521
|
+
// Room versions
|
|
522
|
+
#roomVersions = /* @__PURE__ */ new Map();
|
|
523
|
+
#roomVersionsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
|
|
524
|
+
// Room notification settings
|
|
525
|
+
#roomNotificationSettings = /* @__PURE__ */ new Map();
|
|
489
526
|
constructor(client) {
|
|
490
|
-
this
|
|
491
|
-
this
|
|
492
|
-
this._stateCached = null;
|
|
493
|
-
// Notifications
|
|
494
|
-
this._notificationsLastRequestedAt = null;
|
|
495
|
-
// Room Threads
|
|
496
|
-
this._roomThreadsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
|
|
497
|
-
this._roomThreads = /* @__PURE__ */ new Map();
|
|
498
|
-
// User Threads
|
|
499
|
-
this._userThreadsLastRequestedAt = null;
|
|
500
|
-
this._userThreads = /* @__PURE__ */ new Map();
|
|
501
|
-
// Room versions
|
|
502
|
-
this._roomVersions = /* @__PURE__ */ new Map();
|
|
503
|
-
this._roomVersionsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
|
|
504
|
-
// Room notification settings
|
|
505
|
-
this._roomNotificationSettings = /* @__PURE__ */ new Map();
|
|
506
|
-
this._client = client[_core.kInternal].as();
|
|
507
|
-
this._syncSource = this._client[_core.kInternal].createSyncSource();
|
|
527
|
+
this.#client = client[_core.kInternal].as();
|
|
528
|
+
this.#syncSource = this.#client[_core.kInternal].createSyncSource();
|
|
508
529
|
const inboxFetcher = async (cursor) => {
|
|
509
|
-
const result = await this.
|
|
530
|
+
const result = await this.#client.getInboxNotifications({ cursor });
|
|
510
531
|
this.updateThreadsAndNotifications(
|
|
511
532
|
result.threads,
|
|
512
533
|
result.inboxNotifications
|
|
513
534
|
);
|
|
514
|
-
if (this
|
|
515
|
-
this
|
|
535
|
+
if (this.#notificationsLastRequestedAt === null) {
|
|
536
|
+
this.#notificationsLastRequestedAt = result.requestedAt;
|
|
516
537
|
}
|
|
517
538
|
const nextCursor = result.nextCursor;
|
|
518
539
|
return nextCursor;
|
|
519
540
|
};
|
|
520
|
-
this
|
|
521
|
-
this.
|
|
541
|
+
this.#notifications = new PaginatedResource(inboxFetcher);
|
|
542
|
+
this.#notifications.observable.subscribe(
|
|
522
543
|
() => (
|
|
523
544
|
// Note that the store itself does not change, but it's only vehicle at
|
|
524
545
|
// the moment to trigger a re-render, so we'll do a no-op update here.
|
|
525
|
-
this.
|
|
546
|
+
this.#store.set((store) => ({ ...store }))
|
|
526
547
|
)
|
|
527
548
|
);
|
|
528
549
|
this._rawThreadsDB = new ThreadDB();
|
|
529
|
-
this
|
|
550
|
+
this.#store = _core.createStore.call(void 0, {
|
|
530
551
|
optimisticUpdates: [],
|
|
531
552
|
permissionsByRoom: {},
|
|
532
553
|
notificationsById: {},
|
|
@@ -536,17 +557,17 @@ var UmbrellaStore = class {
|
|
|
536
557
|
autobind(this);
|
|
537
558
|
}
|
|
538
559
|
get() {
|
|
539
|
-
const rawState = this.
|
|
540
|
-
if (this
|
|
541
|
-
this
|
|
542
|
-
this
|
|
543
|
-
this
|
|
544
|
-
this
|
|
560
|
+
const rawState = this.#store.get();
|
|
561
|
+
if (this.#prevVersion !== this._rawThreadsDB.version || // Note: Version check is only needed temporarily, until we can get rid of the Zustand-like update model
|
|
562
|
+
this.#prevState !== rawState || this.#stateCached === null) {
|
|
563
|
+
this.#stateCached = internalToExternalState(rawState, this._rawThreadsDB);
|
|
564
|
+
this.#prevState = rawState;
|
|
565
|
+
this.#prevVersion = this._rawThreadsDB.version;
|
|
545
566
|
}
|
|
546
|
-
return this
|
|
567
|
+
return this.#stateCached;
|
|
547
568
|
}
|
|
548
569
|
batch(callback) {
|
|
549
|
-
return this.
|
|
570
|
+
return this.#store.batch(callback);
|
|
550
571
|
}
|
|
551
572
|
getFullState() {
|
|
552
573
|
return this.get();
|
|
@@ -558,7 +579,7 @@ var UmbrellaStore = class {
|
|
|
558
579
|
*/
|
|
559
580
|
getRoomThreadsLoadingState(roomId, query) {
|
|
560
581
|
const queryKey = makeRoomThreadsQueryKey(roomId, query);
|
|
561
|
-
const paginatedResource = this.
|
|
582
|
+
const paginatedResource = this.#roomThreads.get(queryKey);
|
|
562
583
|
if (paginatedResource === void 0) {
|
|
563
584
|
return ASYNC_LOADING;
|
|
564
585
|
}
|
|
@@ -583,7 +604,7 @@ var UmbrellaStore = class {
|
|
|
583
604
|
}
|
|
584
605
|
getUserThreadsLoadingState(query) {
|
|
585
606
|
const queryKey = makeUserThreadsQueryKey(query);
|
|
586
|
-
const paginatedResource = this.
|
|
607
|
+
const paginatedResource = this.#userThreads.get(queryKey);
|
|
587
608
|
if (paginatedResource === void 0) {
|
|
588
609
|
return ASYNC_LOADING;
|
|
589
610
|
}
|
|
@@ -609,7 +630,7 @@ var UmbrellaStore = class {
|
|
|
609
630
|
}
|
|
610
631
|
// NOTE: This will read the async result, but WILL NOT start loading at the moment!
|
|
611
632
|
getInboxNotificationsLoadingState() {
|
|
612
|
-
const asyncResult = this.
|
|
633
|
+
const asyncResult = this.#notifications.get();
|
|
613
634
|
if (asyncResult.isLoading || asyncResult.error) {
|
|
614
635
|
return asyncResult;
|
|
615
636
|
}
|
|
@@ -626,7 +647,7 @@ var UmbrellaStore = class {
|
|
|
626
647
|
// NOTE: This will read the async result, but WILL NOT start loading at the moment!
|
|
627
648
|
getNotificationSettingsLoadingState(roomId) {
|
|
628
649
|
const queryKey = makeNotificationSettingsQueryKey(roomId);
|
|
629
|
-
const resource = this.
|
|
650
|
+
const resource = this.#roomNotificationSettings.get(queryKey);
|
|
630
651
|
if (resource === void 0) {
|
|
631
652
|
return ASYNC_LOADING;
|
|
632
653
|
}
|
|
@@ -641,7 +662,7 @@ var UmbrellaStore = class {
|
|
|
641
662
|
}
|
|
642
663
|
getRoomVersionsLoadingState(roomId) {
|
|
643
664
|
const queryKey = makeVersionsQueryKey(roomId);
|
|
644
|
-
const resource = this.
|
|
665
|
+
const resource = this.#roomVersions.get(queryKey);
|
|
645
666
|
if (resource === void 0) {
|
|
646
667
|
return ASYNC_LOADING;
|
|
647
668
|
}
|
|
@@ -655,28 +676,28 @@ var UmbrellaStore = class {
|
|
|
655
676
|
};
|
|
656
677
|
}
|
|
657
678
|
subscribe(callback) {
|
|
658
|
-
return this.
|
|
679
|
+
return this.#store.subscribe(callback);
|
|
659
680
|
}
|
|
660
681
|
_getPermissions(roomId) {
|
|
661
|
-
return this.
|
|
682
|
+
return this.#store.get().permissionsByRoom[roomId];
|
|
662
683
|
}
|
|
663
684
|
// Direct low-level cache mutations ------------------------------------------------- {{{
|
|
664
|
-
mutateThreadsDB(mutate) {
|
|
685
|
+
#mutateThreadsDB(mutate) {
|
|
665
686
|
const db = this._rawThreadsDB;
|
|
666
687
|
const old = db.version;
|
|
667
688
|
mutate(db);
|
|
668
689
|
if (old !== db.version) {
|
|
669
|
-
this.
|
|
690
|
+
this.#store.set((state) => ({ ...state }));
|
|
670
691
|
}
|
|
671
692
|
}
|
|
672
|
-
updateInboxNotificationsCache(mapFn) {
|
|
673
|
-
this.
|
|
693
|
+
#updateInboxNotificationsCache(mapFn) {
|
|
694
|
+
this.#store.set((state) => {
|
|
674
695
|
const inboxNotifications = mapFn(state.notificationsById);
|
|
675
696
|
return inboxNotifications !== state.notificationsById ? { ...state, notificationsById: inboxNotifications } : state;
|
|
676
697
|
});
|
|
677
698
|
}
|
|
678
|
-
setNotificationSettings(roomId, settings) {
|
|
679
|
-
this.
|
|
699
|
+
#setNotificationSettings(roomId, settings) {
|
|
700
|
+
this.#store.set((state) => ({
|
|
680
701
|
...state,
|
|
681
702
|
settingsByRoomId: {
|
|
682
703
|
...state.settingsByRoomId,
|
|
@@ -684,8 +705,8 @@ var UmbrellaStore = class {
|
|
|
684
705
|
}
|
|
685
706
|
}));
|
|
686
707
|
}
|
|
687
|
-
updateRoomVersions(roomId, versions) {
|
|
688
|
-
this.
|
|
708
|
+
#updateRoomVersions(roomId, versions) {
|
|
709
|
+
this.#store.set((state) => {
|
|
689
710
|
const versionsById = Object.fromEntries(
|
|
690
711
|
versions.map((version2) => [version2.id, version2])
|
|
691
712
|
);
|
|
@@ -702,10 +723,10 @@ var UmbrellaStore = class {
|
|
|
702
723
|
};
|
|
703
724
|
});
|
|
704
725
|
}
|
|
705
|
-
updateOptimisticUpdatesCache(mapFn) {
|
|
706
|
-
this.
|
|
726
|
+
#updateOptimisticUpdatesCache(mapFn) {
|
|
727
|
+
this.#store.set((state) => {
|
|
707
728
|
const optimisticUpdates = mapFn(state.optimisticUpdates);
|
|
708
|
-
this.
|
|
729
|
+
this.#syncSource.setSyncStatus(
|
|
709
730
|
optimisticUpdates.length > 0 ? "synchronizing" : "synchronized"
|
|
710
731
|
);
|
|
711
732
|
return { ...state, optimisticUpdates };
|
|
@@ -714,7 +735,7 @@ var UmbrellaStore = class {
|
|
|
714
735
|
// ---------------------------------------------------------------------------------- }}}
|
|
715
736
|
/** @internal - Only call this method from unit tests. */
|
|
716
737
|
force_set(callback) {
|
|
717
|
-
return this.
|
|
738
|
+
return this.#store.set(callback);
|
|
718
739
|
}
|
|
719
740
|
/**
|
|
720
741
|
* Updates an existing inbox notification with a new value, replacing the
|
|
@@ -724,9 +745,9 @@ var UmbrellaStore = class {
|
|
|
724
745
|
* the cache.
|
|
725
746
|
*/
|
|
726
747
|
updateInboxNotification(inboxNotificationId, optimisticUpdateId, callback) {
|
|
727
|
-
this.
|
|
748
|
+
this.#store.batch(() => {
|
|
728
749
|
this.removeOptimisticUpdate(optimisticUpdateId);
|
|
729
|
-
this
|
|
750
|
+
this.#updateInboxNotificationsCache((cache) => {
|
|
730
751
|
const existing = cache[inboxNotificationId];
|
|
731
752
|
if (!existing) {
|
|
732
753
|
return cache;
|
|
@@ -744,9 +765,9 @@ var UmbrellaStore = class {
|
|
|
744
765
|
* them, replacing the corresponding optimistic update.
|
|
745
766
|
*/
|
|
746
767
|
updateAllInboxNotifications(optimisticUpdateId, mapFn) {
|
|
747
|
-
this.
|
|
768
|
+
this.#store.batch(() => {
|
|
748
769
|
this.removeOptimisticUpdate(optimisticUpdateId);
|
|
749
|
-
this
|
|
770
|
+
this.#updateInboxNotificationsCache((cache) => _core.mapValues.call(void 0, cache, mapFn));
|
|
750
771
|
});
|
|
751
772
|
}
|
|
752
773
|
/**
|
|
@@ -754,9 +775,9 @@ var UmbrellaStore = class {
|
|
|
754
775
|
* optimistic update.
|
|
755
776
|
*/
|
|
756
777
|
deleteInboxNotification(inboxNotificationId, optimisticUpdateId) {
|
|
757
|
-
this.
|
|
778
|
+
this.#store.batch(() => {
|
|
758
779
|
this.removeOptimisticUpdate(optimisticUpdateId);
|
|
759
|
-
this
|
|
780
|
+
this.#updateInboxNotificationsCache((cache) => {
|
|
760
781
|
const { [inboxNotificationId]: removed, ...newCache } = cache;
|
|
761
782
|
return removed === void 0 ? cache : newCache;
|
|
762
783
|
});
|
|
@@ -767,18 +788,18 @@ var UmbrellaStore = class {
|
|
|
767
788
|
* update.
|
|
768
789
|
*/
|
|
769
790
|
deleteAllInboxNotifications(optimisticUpdateId) {
|
|
770
|
-
this.
|
|
791
|
+
this.#store.batch(() => {
|
|
771
792
|
this.removeOptimisticUpdate(optimisticUpdateId);
|
|
772
|
-
this
|
|
793
|
+
this.#updateInboxNotificationsCache(() => ({}));
|
|
773
794
|
});
|
|
774
795
|
}
|
|
775
796
|
/**
|
|
776
797
|
* Creates an new thread, replacing the corresponding optimistic update.
|
|
777
798
|
*/
|
|
778
799
|
createThread(optimisticUpdateId, thread) {
|
|
779
|
-
this.
|
|
800
|
+
this.#store.batch(() => {
|
|
780
801
|
this.removeOptimisticUpdate(optimisticUpdateId);
|
|
781
|
-
this
|
|
802
|
+
this.#mutateThreadsDB((db) => db.upsert(thread));
|
|
782
803
|
});
|
|
783
804
|
}
|
|
784
805
|
/**
|
|
@@ -791,12 +812,12 @@ var UmbrellaStore = class {
|
|
|
791
812
|
* - The thread ID in the cache was updated more recently than the optimistic
|
|
792
813
|
* update's timestamp (if given)
|
|
793
814
|
*/
|
|
794
|
-
updateThread(threadId, optimisticUpdateId, callback, updatedAt) {
|
|
795
|
-
this.
|
|
815
|
+
#updateThread(threadId, optimisticUpdateId, callback, updatedAt) {
|
|
816
|
+
this.#store.batch(() => {
|
|
796
817
|
if (optimisticUpdateId !== null) {
|
|
797
818
|
this.removeOptimisticUpdate(optimisticUpdateId);
|
|
798
819
|
}
|
|
799
|
-
this
|
|
820
|
+
this.#mutateThreadsDB((db) => {
|
|
800
821
|
const existing = db.get(threadId);
|
|
801
822
|
if (!existing) return;
|
|
802
823
|
if (!!updatedAt && existing.updatedAt > updatedAt) return;
|
|
@@ -805,7 +826,7 @@ var UmbrellaStore = class {
|
|
|
805
826
|
});
|
|
806
827
|
}
|
|
807
828
|
patchThread(threadId, optimisticUpdateId, patch, updatedAt) {
|
|
808
|
-
return this
|
|
829
|
+
return this.#updateThread(
|
|
809
830
|
threadId,
|
|
810
831
|
optimisticUpdateId,
|
|
811
832
|
(thread) => ({ ...thread, ..._core.compactObject.call(void 0, patch) }),
|
|
@@ -813,7 +834,7 @@ var UmbrellaStore = class {
|
|
|
813
834
|
);
|
|
814
835
|
}
|
|
815
836
|
addReaction(threadId, optimisticUpdateId, commentId, reaction, createdAt) {
|
|
816
|
-
this
|
|
837
|
+
this.#updateThread(
|
|
817
838
|
threadId,
|
|
818
839
|
optimisticUpdateId,
|
|
819
840
|
(thread) => applyAddReaction(thread, commentId, reaction),
|
|
@@ -821,7 +842,7 @@ var UmbrellaStore = class {
|
|
|
821
842
|
);
|
|
822
843
|
}
|
|
823
844
|
removeReaction(threadId, optimisticUpdateId, commentId, emoji, userId, removedAt) {
|
|
824
|
-
this
|
|
845
|
+
this.#updateThread(
|
|
825
846
|
threadId,
|
|
826
847
|
optimisticUpdateId,
|
|
827
848
|
(thread) => applyRemoveReaction(thread, commentId, emoji, userId, removedAt),
|
|
@@ -837,7 +858,7 @@ var UmbrellaStore = class {
|
|
|
837
858
|
* - The thread ID was already deleted from the cache
|
|
838
859
|
*/
|
|
839
860
|
deleteThread(threadId, optimisticUpdateId) {
|
|
840
|
-
return this
|
|
861
|
+
return this.#updateThread(
|
|
841
862
|
threadId,
|
|
842
863
|
optimisticUpdateId,
|
|
843
864
|
// A deletion is actually an update of the deletedAt property internally
|
|
@@ -849,16 +870,16 @@ var UmbrellaStore = class {
|
|
|
849
870
|
* updated correctly, replacing the corresponding optimistic update.
|
|
850
871
|
*/
|
|
851
872
|
createComment(newComment, optimisticUpdateId) {
|
|
852
|
-
this.
|
|
873
|
+
this.#store.batch(() => {
|
|
853
874
|
this.removeOptimisticUpdate(optimisticUpdateId);
|
|
854
875
|
const existingThread = this._rawThreadsDB.get(newComment.threadId);
|
|
855
876
|
if (!existingThread) {
|
|
856
877
|
return;
|
|
857
878
|
}
|
|
858
|
-
this
|
|
879
|
+
this.#mutateThreadsDB(
|
|
859
880
|
(db) => db.upsert(applyUpsertComment(existingThread, newComment))
|
|
860
881
|
);
|
|
861
|
-
this
|
|
882
|
+
this.#updateInboxNotificationsCache((cache) => {
|
|
862
883
|
const existingNotification = Object.values(cache).find(
|
|
863
884
|
(notification) => notification.kind === "thread" && notification.threadId === newComment.threadId
|
|
864
885
|
);
|
|
@@ -877,14 +898,14 @@ var UmbrellaStore = class {
|
|
|
877
898
|
});
|
|
878
899
|
}
|
|
879
900
|
editComment(threadId, optimisticUpdateId, editedComment) {
|
|
880
|
-
return this
|
|
901
|
+
return this.#updateThread(
|
|
881
902
|
threadId,
|
|
882
903
|
optimisticUpdateId,
|
|
883
904
|
(thread) => applyUpsertComment(thread, editedComment)
|
|
884
905
|
);
|
|
885
906
|
}
|
|
886
907
|
deleteComment(threadId, optimisticUpdateId, commentId, deletedAt) {
|
|
887
|
-
return this
|
|
908
|
+
return this.#updateThread(
|
|
888
909
|
threadId,
|
|
889
910
|
optimisticUpdateId,
|
|
890
911
|
(thread) => applyDeleteComment(thread, commentId, deletedAt),
|
|
@@ -892,10 +913,10 @@ var UmbrellaStore = class {
|
|
|
892
913
|
);
|
|
893
914
|
}
|
|
894
915
|
updateThreadAndNotification(thread, inboxNotification) {
|
|
895
|
-
this.
|
|
896
|
-
this
|
|
916
|
+
this.#store.batch(() => {
|
|
917
|
+
this.#mutateThreadsDB((db) => db.upsertIfNewer(thread));
|
|
897
918
|
if (inboxNotification !== void 0) {
|
|
898
|
-
this
|
|
919
|
+
this.#updateInboxNotificationsCache((cache) => ({
|
|
899
920
|
...cache,
|
|
900
921
|
[inboxNotification.id]: inboxNotification
|
|
901
922
|
}));
|
|
@@ -903,11 +924,11 @@ var UmbrellaStore = class {
|
|
|
903
924
|
});
|
|
904
925
|
}
|
|
905
926
|
updateThreadsAndNotifications(threads, inboxNotifications, deletedThreads = [], deletedInboxNotifications = []) {
|
|
906
|
-
this.
|
|
907
|
-
this
|
|
927
|
+
this.#store.batch(() => {
|
|
928
|
+
this.#mutateThreadsDB(
|
|
908
929
|
(db) => applyThreadDeltaUpdates(db, { newThreads: threads, deletedThreads })
|
|
909
930
|
);
|
|
910
|
-
this
|
|
931
|
+
this.#updateInboxNotificationsCache(
|
|
911
932
|
(cache) => applyNotificationsUpdates(cache, {
|
|
912
933
|
newInboxNotifications: inboxNotifications,
|
|
913
934
|
deletedNotifications: deletedInboxNotifications
|
|
@@ -920,33 +941,33 @@ var UmbrellaStore = class {
|
|
|
920
941
|
* replacing the corresponding optimistic update.
|
|
921
942
|
*/
|
|
922
943
|
updateRoomNotificationSettings_confirmOptimisticUpdate(roomId, optimisticUpdateId, settings) {
|
|
923
|
-
this.
|
|
944
|
+
this.#store.batch(() => {
|
|
924
945
|
this.removeOptimisticUpdate(optimisticUpdateId);
|
|
925
|
-
this
|
|
946
|
+
this.#setNotificationSettings(roomId, settings);
|
|
926
947
|
});
|
|
927
948
|
}
|
|
928
949
|
addOptimisticUpdate(optimisticUpdate) {
|
|
929
950
|
const id = _core.nanoid.call(void 0, );
|
|
930
951
|
const newUpdate = { ...optimisticUpdate, id };
|
|
931
|
-
this
|
|
952
|
+
this.#updateOptimisticUpdatesCache((cache) => [...cache, newUpdate]);
|
|
932
953
|
return id;
|
|
933
954
|
}
|
|
934
955
|
removeOptimisticUpdate(optimisticUpdateId) {
|
|
935
|
-
this
|
|
956
|
+
this.#updateOptimisticUpdatesCache(
|
|
936
957
|
(cache) => cache.filter((ou) => ou.id !== optimisticUpdateId)
|
|
937
958
|
);
|
|
938
959
|
}
|
|
939
960
|
async fetchNotificationsDeltaUpdate(signal) {
|
|
940
|
-
const lastRequestedAt = this
|
|
961
|
+
const lastRequestedAt = this.#notificationsLastRequestedAt;
|
|
941
962
|
if (lastRequestedAt === null) {
|
|
942
963
|
return;
|
|
943
964
|
}
|
|
944
|
-
const result = await this.
|
|
965
|
+
const result = await this.#client.getInboxNotificationsSince({
|
|
945
966
|
since: lastRequestedAt,
|
|
946
967
|
signal
|
|
947
968
|
});
|
|
948
969
|
if (lastRequestedAt < result.requestedAt) {
|
|
949
|
-
this
|
|
970
|
+
this.#notificationsLastRequestedAt = result.requestedAt;
|
|
950
971
|
}
|
|
951
972
|
this.updateThreadsAndNotifications(
|
|
952
973
|
result.threads.updated,
|
|
@@ -956,10 +977,10 @@ var UmbrellaStore = class {
|
|
|
956
977
|
);
|
|
957
978
|
}
|
|
958
979
|
waitUntilNotificationsLoaded() {
|
|
959
|
-
return this.
|
|
980
|
+
return this.#notifications.waitUntilLoaded();
|
|
960
981
|
}
|
|
961
|
-
updateRoomPermissions(permissions) {
|
|
962
|
-
const permissionsByRoom = { ...this.
|
|
982
|
+
#updateRoomPermissions(permissions) {
|
|
983
|
+
const permissionsByRoom = { ...this.#store.get().permissionsByRoom };
|
|
963
984
|
Object.entries(permissions).forEach(([roomId, newPermissions]) => {
|
|
964
985
|
const existingPermissions = _nullishCoalesce(permissionsByRoom[roomId], () => ( /* @__PURE__ */ new Set()));
|
|
965
986
|
newPermissions.forEach(
|
|
@@ -967,14 +988,14 @@ var UmbrellaStore = class {
|
|
|
967
988
|
);
|
|
968
989
|
permissionsByRoom[roomId] = existingPermissions;
|
|
969
990
|
});
|
|
970
|
-
this.
|
|
991
|
+
this.#store.set((state) => ({
|
|
971
992
|
...state,
|
|
972
993
|
permissionsByRoom
|
|
973
994
|
}));
|
|
974
995
|
}
|
|
975
996
|
waitUntilRoomThreadsLoaded(roomId, query) {
|
|
976
997
|
const threadsFetcher = async (cursor) => {
|
|
977
|
-
const result = await this
|
|
998
|
+
const result = await this.#client[_core.kInternal].httpClient.getThreads({
|
|
978
999
|
roomId,
|
|
979
1000
|
cursor,
|
|
980
1001
|
query
|
|
@@ -983,15 +1004,15 @@ var UmbrellaStore = class {
|
|
|
983
1004
|
result.threads,
|
|
984
1005
|
result.inboxNotifications
|
|
985
1006
|
);
|
|
986
|
-
this
|
|
987
|
-
const lastRequestedAt = this.
|
|
1007
|
+
this.#updateRoomPermissions(result.permissionHints);
|
|
1008
|
+
const lastRequestedAt = this.#roomThreadsLastRequestedAtByRoom.get(roomId);
|
|
988
1009
|
if (lastRequestedAt === void 0 || lastRequestedAt > result.requestedAt) {
|
|
989
|
-
this.
|
|
1010
|
+
this.#roomThreadsLastRequestedAtByRoom.set(roomId, result.requestedAt);
|
|
990
1011
|
}
|
|
991
1012
|
return result.nextCursor;
|
|
992
1013
|
};
|
|
993
1014
|
const queryKey = makeRoomThreadsQueryKey(roomId, query);
|
|
994
|
-
let paginatedResource = this.
|
|
1015
|
+
let paginatedResource = this.#roomThreads.get(queryKey);
|
|
995
1016
|
if (paginatedResource === void 0) {
|
|
996
1017
|
paginatedResource = new PaginatedResource(threadsFetcher);
|
|
997
1018
|
}
|
|
@@ -999,18 +1020,18 @@ var UmbrellaStore = class {
|
|
|
999
1020
|
() => (
|
|
1000
1021
|
// Note that the store itself does not change, but it's only vehicle at
|
|
1001
1022
|
// the moment to trigger a re-render, so we'll do a no-op update here.
|
|
1002
|
-
this.
|
|
1023
|
+
this.#store.set((store) => ({ ...store }))
|
|
1003
1024
|
)
|
|
1004
1025
|
);
|
|
1005
|
-
this.
|
|
1026
|
+
this.#roomThreads.set(queryKey, paginatedResource);
|
|
1006
1027
|
return paginatedResource.waitUntilLoaded();
|
|
1007
1028
|
}
|
|
1008
1029
|
async fetchRoomThreadsDeltaUpdate(roomId, signal) {
|
|
1009
|
-
const lastRequestedAt = this.
|
|
1030
|
+
const lastRequestedAt = this.#roomThreadsLastRequestedAtByRoom.get(roomId);
|
|
1010
1031
|
if (lastRequestedAt === void 0) {
|
|
1011
1032
|
return;
|
|
1012
1033
|
}
|
|
1013
|
-
const updates = await this
|
|
1034
|
+
const updates = await this.#client[_core.kInternal].httpClient.getThreadsSince({
|
|
1014
1035
|
roomId,
|
|
1015
1036
|
since: lastRequestedAt,
|
|
1016
1037
|
signal
|
|
@@ -1021,15 +1042,15 @@ var UmbrellaStore = class {
|
|
|
1021
1042
|
updates.threads.deleted,
|
|
1022
1043
|
updates.inboxNotifications.deleted
|
|
1023
1044
|
);
|
|
1024
|
-
this
|
|
1045
|
+
this.#updateRoomPermissions(updates.permissionHints);
|
|
1025
1046
|
if (lastRequestedAt < updates.requestedAt) {
|
|
1026
|
-
this.
|
|
1047
|
+
this.#roomThreadsLastRequestedAtByRoom.set(roomId, updates.requestedAt);
|
|
1027
1048
|
}
|
|
1028
1049
|
}
|
|
1029
1050
|
waitUntilUserThreadsLoaded(query) {
|
|
1030
1051
|
const queryKey = makeUserThreadsQueryKey(query);
|
|
1031
1052
|
const threadsFetcher = async (cursor) => {
|
|
1032
|
-
const result = await this
|
|
1053
|
+
const result = await this.#client[_core.kInternal].httpClient.getUserThreads_experimental({
|
|
1033
1054
|
cursor,
|
|
1034
1055
|
query
|
|
1035
1056
|
});
|
|
@@ -1037,13 +1058,13 @@ var UmbrellaStore = class {
|
|
|
1037
1058
|
result.threads,
|
|
1038
1059
|
result.inboxNotifications
|
|
1039
1060
|
);
|
|
1040
|
-
this
|
|
1041
|
-
if (this
|
|
1042
|
-
this
|
|
1061
|
+
this.#updateRoomPermissions(result.permissionHints);
|
|
1062
|
+
if (this.#userThreadsLastRequestedAt === null) {
|
|
1063
|
+
this.#userThreadsLastRequestedAt = result.requestedAt;
|
|
1043
1064
|
}
|
|
1044
1065
|
return result.nextCursor;
|
|
1045
1066
|
};
|
|
1046
|
-
let paginatedResource = this.
|
|
1067
|
+
let paginatedResource = this.#userThreads.get(queryKey);
|
|
1047
1068
|
if (paginatedResource === void 0) {
|
|
1048
1069
|
paginatedResource = new PaginatedResource(threadsFetcher);
|
|
1049
1070
|
}
|
|
@@ -1051,23 +1072,23 @@ var UmbrellaStore = class {
|
|
|
1051
1072
|
() => (
|
|
1052
1073
|
// Note that the store itself does not change, but it's only vehicle at
|
|
1053
1074
|
// the moment to trigger a re-render, so we'll do a no-op update here.
|
|
1054
|
-
this.
|
|
1075
|
+
this.#store.set((store) => ({ ...store }))
|
|
1055
1076
|
)
|
|
1056
1077
|
);
|
|
1057
|
-
this.
|
|
1078
|
+
this.#userThreads.set(queryKey, paginatedResource);
|
|
1058
1079
|
return paginatedResource.waitUntilLoaded();
|
|
1059
1080
|
}
|
|
1060
1081
|
async fetchUserThreadsDeltaUpdate(signal) {
|
|
1061
|
-
const lastRequestedAt = this
|
|
1082
|
+
const lastRequestedAt = this.#userThreadsLastRequestedAt;
|
|
1062
1083
|
if (lastRequestedAt === null) {
|
|
1063
1084
|
return;
|
|
1064
1085
|
}
|
|
1065
|
-
const result = await this
|
|
1086
|
+
const result = await this.#client[_core.kInternal].httpClient.getUserThreadsSince_experimental({
|
|
1066
1087
|
since: lastRequestedAt,
|
|
1067
1088
|
signal
|
|
1068
1089
|
});
|
|
1069
1090
|
if (lastRequestedAt < result.requestedAt) {
|
|
1070
|
-
this
|
|
1091
|
+
this.#notificationsLastRequestedAt = result.requestedAt;
|
|
1071
1092
|
}
|
|
1072
1093
|
this.updateThreadsAndNotifications(
|
|
1073
1094
|
result.threads.updated,
|
|
@@ -1075,14 +1096,14 @@ var UmbrellaStore = class {
|
|
|
1075
1096
|
result.threads.deleted,
|
|
1076
1097
|
result.inboxNotifications.deleted
|
|
1077
1098
|
);
|
|
1078
|
-
this
|
|
1099
|
+
this.#updateRoomPermissions(result.permissionHints);
|
|
1079
1100
|
}
|
|
1080
1101
|
waitUntilRoomVersionsLoaded(roomId) {
|
|
1081
1102
|
const queryKey = makeVersionsQueryKey(roomId);
|
|
1082
|
-
let resource = this.
|
|
1103
|
+
let resource = this.#roomVersions.get(queryKey);
|
|
1083
1104
|
if (resource === void 0) {
|
|
1084
1105
|
const versionsFetcher = async () => {
|
|
1085
|
-
const room = this.
|
|
1106
|
+
const room = this.#client.getRoom(roomId);
|
|
1086
1107
|
if (room === null) {
|
|
1087
1108
|
throw new (0, _core.HttpError)(
|
|
1088
1109
|
`Room '${roomId}' is not available on client`,
|
|
@@ -1090,10 +1111,10 @@ var UmbrellaStore = class {
|
|
|
1090
1111
|
);
|
|
1091
1112
|
}
|
|
1092
1113
|
const result = await room[_core.kInternal].listTextVersions();
|
|
1093
|
-
this
|
|
1094
|
-
const lastRequestedAt = this.
|
|
1114
|
+
this.#updateRoomVersions(roomId, result.versions);
|
|
1115
|
+
const lastRequestedAt = this.#roomVersionsLastRequestedAtByRoom.get(roomId);
|
|
1095
1116
|
if (lastRequestedAt === void 0 || lastRequestedAt > result.requestedAt) {
|
|
1096
|
-
this.
|
|
1117
|
+
this.#roomVersionsLastRequestedAtByRoom.set(
|
|
1097
1118
|
roomId,
|
|
1098
1119
|
result.requestedAt
|
|
1099
1120
|
);
|
|
@@ -1105,36 +1126,36 @@ var UmbrellaStore = class {
|
|
|
1105
1126
|
() => (
|
|
1106
1127
|
// Note that the store itself does not change, but it's only vehicle at
|
|
1107
1128
|
// the moment to trigger a re-render, so we'll do a no-op update here.
|
|
1108
|
-
this.
|
|
1129
|
+
this.#store.set((store) => ({ ...store }))
|
|
1109
1130
|
)
|
|
1110
1131
|
);
|
|
1111
|
-
this.
|
|
1132
|
+
this.#roomVersions.set(queryKey, resource);
|
|
1112
1133
|
return resource.waitUntilLoaded();
|
|
1113
1134
|
}
|
|
1114
1135
|
async fetchRoomVersionsDeltaUpdate(roomId, signal) {
|
|
1115
|
-
const lastRequestedAt = this.
|
|
1136
|
+
const lastRequestedAt = this.#roomVersionsLastRequestedAtByRoom.get(roomId);
|
|
1116
1137
|
if (lastRequestedAt === void 0) {
|
|
1117
1138
|
return;
|
|
1118
1139
|
}
|
|
1119
1140
|
const room = _core.nn.call(void 0,
|
|
1120
|
-
this.
|
|
1141
|
+
this.#client.getRoom(roomId),
|
|
1121
1142
|
`Room with id ${roomId} is not available on client`
|
|
1122
1143
|
);
|
|
1123
1144
|
const updates = await room[_core.kInternal].listTextVersionsSince({
|
|
1124
1145
|
since: lastRequestedAt,
|
|
1125
1146
|
signal
|
|
1126
1147
|
});
|
|
1127
|
-
this
|
|
1148
|
+
this.#updateRoomVersions(roomId, updates.versions);
|
|
1128
1149
|
if (lastRequestedAt < updates.requestedAt) {
|
|
1129
|
-
this.
|
|
1150
|
+
this.#roomVersionsLastRequestedAtByRoom.set(roomId, updates.requestedAt);
|
|
1130
1151
|
}
|
|
1131
1152
|
}
|
|
1132
1153
|
waitUntilRoomNotificationSettingsLoaded(roomId) {
|
|
1133
1154
|
const queryKey = makeNotificationSettingsQueryKey(roomId);
|
|
1134
|
-
let resource = this.
|
|
1155
|
+
let resource = this.#roomNotificationSettings.get(queryKey);
|
|
1135
1156
|
if (resource === void 0) {
|
|
1136
1157
|
const notificationSettingsFetcher = async () => {
|
|
1137
|
-
const room = this.
|
|
1158
|
+
const room = this.#client.getRoom(roomId);
|
|
1138
1159
|
if (room === null) {
|
|
1139
1160
|
throw new (0, _core.HttpError)(
|
|
1140
1161
|
`Room '${roomId}' is not available on client`,
|
|
@@ -1142,7 +1163,7 @@ var UmbrellaStore = class {
|
|
|
1142
1163
|
);
|
|
1143
1164
|
}
|
|
1144
1165
|
const result = await room.getNotificationSettings();
|
|
1145
|
-
this
|
|
1166
|
+
this.#setNotificationSettings(roomId, result);
|
|
1146
1167
|
};
|
|
1147
1168
|
resource = new SinglePageResource(notificationSettingsFetcher);
|
|
1148
1169
|
}
|
|
@@ -1150,19 +1171,19 @@ var UmbrellaStore = class {
|
|
|
1150
1171
|
() => (
|
|
1151
1172
|
// Note that the store itself does not change, but it's only vehicle at
|
|
1152
1173
|
// the moment to trigger a re-render, so we'll do a no-op update here.
|
|
1153
|
-
this.
|
|
1174
|
+
this.#store.set((store) => ({ ...store }))
|
|
1154
1175
|
)
|
|
1155
1176
|
);
|
|
1156
|
-
this.
|
|
1177
|
+
this.#roomNotificationSettings.set(queryKey, resource);
|
|
1157
1178
|
return resource.waitUntilLoaded();
|
|
1158
1179
|
}
|
|
1159
1180
|
async refreshRoomNotificationSettings(roomId, signal) {
|
|
1160
1181
|
const room = _core.nn.call(void 0,
|
|
1161
|
-
this.
|
|
1182
|
+
this.#client.getRoom(roomId),
|
|
1162
1183
|
`Room with id ${roomId} is not available on client`
|
|
1163
1184
|
);
|
|
1164
1185
|
const result = await room.getNotificationSettings({ signal });
|
|
1165
|
-
this
|
|
1186
|
+
this.#setNotificationSettings(roomId, result);
|
|
1166
1187
|
}
|
|
1167
1188
|
};
|
|
1168
1189
|
function internalToExternalState(state, rawThreadsDB) {
|
|
@@ -2282,7 +2303,7 @@ var UpdateNotificationSettingsError = class extends Error {
|
|
|
2282
2303
|
};
|
|
2283
2304
|
|
|
2284
2305
|
// src/room.tsx
|
|
2285
|
-
var
|
|
2306
|
+
var _client = require('@liveblocks/client');
|
|
2286
2307
|
|
|
2287
2308
|
|
|
2288
2309
|
|
|
@@ -2750,6 +2771,52 @@ function useReportTextEditor(editor, rootKey) {
|
|
|
2750
2771
|
return unsubscribe;
|
|
2751
2772
|
}, [room, editor, rootKey]);
|
|
2752
2773
|
}
|
|
2774
|
+
function useYjsProvider() {
|
|
2775
|
+
const room = useRoom();
|
|
2776
|
+
const subscribe = React4.useCallback(
|
|
2777
|
+
(onStoreChange) => {
|
|
2778
|
+
return room[_core.kInternal].yjsProviderDidChange.subscribe(onStoreChange);
|
|
2779
|
+
},
|
|
2780
|
+
[room]
|
|
2781
|
+
);
|
|
2782
|
+
const getSnapshot = React4.useCallback(() => {
|
|
2783
|
+
return room[_core.kInternal].getYjsProvider();
|
|
2784
|
+
}, [room]);
|
|
2785
|
+
return useSyncExternalStore2(subscribe, getSnapshot, getSnapshot);
|
|
2786
|
+
}
|
|
2787
|
+
function useCreateTextMention() {
|
|
2788
|
+
const room = useRoom();
|
|
2789
|
+
return React4.useCallback(
|
|
2790
|
+
(userId, mentionId) => {
|
|
2791
|
+
room[_core.kInternal].createTextMention(userId, mentionId).catch((err) => {
|
|
2792
|
+
_core.console.error(
|
|
2793
|
+
`Cannot create text mention for user '${userId}' and mention '${mentionId}'`,
|
|
2794
|
+
err
|
|
2795
|
+
);
|
|
2796
|
+
});
|
|
2797
|
+
},
|
|
2798
|
+
[room]
|
|
2799
|
+
);
|
|
2800
|
+
}
|
|
2801
|
+
function useDeleteTextMention() {
|
|
2802
|
+
const room = useRoom();
|
|
2803
|
+
return React4.useCallback(
|
|
2804
|
+
(mentionId) => {
|
|
2805
|
+
room[_core.kInternal].deleteTextMention(mentionId).catch((err) => {
|
|
2806
|
+
_core.console.error(`Cannot delete text mention '${mentionId}'`, err);
|
|
2807
|
+
});
|
|
2808
|
+
},
|
|
2809
|
+
[room]
|
|
2810
|
+
);
|
|
2811
|
+
}
|
|
2812
|
+
function useResolveMentionSuggestions() {
|
|
2813
|
+
const client = useClient();
|
|
2814
|
+
return client[_core.kInternal].resolveMentionSuggestions;
|
|
2815
|
+
}
|
|
2816
|
+
function useMentionSuggestionsCache() {
|
|
2817
|
+
const client = useClient();
|
|
2818
|
+
return client[_core.kInternal].mentionSuggestionsCache;
|
|
2819
|
+
}
|
|
2753
2820
|
function useStorageStatus(options) {
|
|
2754
2821
|
const smooth = useInitial(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _14 => _14.smooth]), () => ( false)));
|
|
2755
2822
|
if (smooth) {
|
|
@@ -2915,7 +2982,7 @@ function useOthersMapped(itemSelector, itemIsEqual) {
|
|
|
2915
2982
|
return useOthers(wrappedSelector, wrappedIsEqual);
|
|
2916
2983
|
}
|
|
2917
2984
|
function useOthersConnectionIds() {
|
|
2918
|
-
return useOthers(selectorFor_useOthersConnectionIds,
|
|
2985
|
+
return useOthers(selectorFor_useOthersConnectionIds, _client.shallow);
|
|
2919
2986
|
}
|
|
2920
2987
|
var NOT_FOUND = Symbol();
|
|
2921
2988
|
function useOther(connectionId, selector, isEqual) {
|
|
@@ -3828,7 +3895,7 @@ function useRoomAttachmentUrl(attachmentId, roomId) {
|
|
|
3828
3895
|
getAttachmentUrlState,
|
|
3829
3896
|
getAttachmentUrlState,
|
|
3830
3897
|
selectorFor_useAttachmentUrl,
|
|
3831
|
-
|
|
3898
|
+
_client.shallow
|
|
3832
3899
|
);
|
|
3833
3900
|
}
|
|
3834
3901
|
function useAttachmentUrlSuspense(attachmentId) {
|
|
@@ -4007,5 +4074,10 @@ var _useUpdateMyPresence = useUpdateMyPresence;
|
|
|
4007
4074
|
|
|
4008
4075
|
|
|
4009
4076
|
|
|
4010
|
-
|
|
4011
|
-
|
|
4077
|
+
|
|
4078
|
+
|
|
4079
|
+
|
|
4080
|
+
|
|
4081
|
+
|
|
4082
|
+
exports.RoomContext = RoomContext; exports.useRoomOrNull = useRoomOrNull; 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;
|
|
4083
|
+
//# sourceMappingURL=chunk-7ZCTUIE6.js.map
|