@liveblocks/react 2.17.0-channels1 → 2.17.0-usrnotsettings1

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.
@@ -131,8 +131,8 @@ var config = {
131
131
  HISTORY_VERSIONS_MAX_STALE_TIME: 5 * SECONDS,
132
132
  NOTIFICATION_SETTINGS_POLL_INTERVAL: 1 * MINUTES,
133
133
  NOTIFICATION_SETTINGS_MAX_STALE_TIME: 5 * SECONDS,
134
- CHANNEL_NOTIFICATION_SETTINGS_INTERVAL: 5 * MINUTES,
135
- CHANNEL_NOTIFICATION_SETTINGS_MAX_STALE_TIME: 1 * MINUTES
134
+ USER_NOTIFICATION_SETTINGS_INTERVAL: 5 * MINUTES,
135
+ USER_NOTIFICATION_SETTINGS_MAX_STALE_TIME: 1 * MINUTES
136
136
  };
137
137
 
138
138
  // src/lib/AsyncResult.ts
@@ -227,7 +227,6 @@ import {
227
227
  DefaultMap,
228
228
  DerivedSignal,
229
229
  entries,
230
- HttpError,
231
230
  keys,
232
231
  kInternal,
233
232
  MutableSignal as MutableSignal2,
@@ -235,8 +234,7 @@ import {
235
234
  nn,
236
235
  shallow as shallow3,
237
236
  Signal,
238
- stringify,
239
- unstringify
237
+ stringify
240
238
  } from "@liveblocks/core";
241
239
 
242
240
  // src/lib/autobind.ts
@@ -286,16 +284,16 @@ function matchesMetadata(thread, q) {
286
284
  const metadata = thread.metadata;
287
285
  return q.metadata === void 0 || Object.entries(q.metadata).every(
288
286
  ([key, op]) => (
289
- // NOTE: `op` can be explicitly-`undefined` here, which ideally would not
290
- // mean "filter for absence" like it does now, as this does not match the
291
- // backend behavior at the moment. For an in-depth discussion, see
292
- // https://liveblocks.slack.com/archives/C02PZL7QAAW/p1728546988505989
293
- matchesOperator(metadata[key], op)
287
+ // Ignore explicit-undefined filters
288
+ // Boolean logic: op? => value matches the operator
289
+ op === void 0 || matchesOperator(metadata[key], op)
294
290
  )
295
291
  );
296
292
  }
297
293
  function matchesOperator(value, op) {
298
- if (isStartsWithOperator(op)) {
294
+ if (op === null) {
295
+ return value === void 0;
296
+ } else if (isStartsWithOperator(op)) {
299
297
  return typeof value === "string" && value.startsWith(op.startsWith);
300
298
  } else {
301
299
  return value === op;
@@ -720,7 +718,7 @@ function createStore_forPermissionHints() {
720
718
  update
721
719
  };
722
720
  }
723
- function createStore_forChannelsNotificationSettings(updates) {
721
+ function createStore_forUserNotificationSettings(updates) {
724
722
  const signal = new Signal({});
725
723
  function update(settings) {
726
724
  signal.set((prevSettings) => {
@@ -734,7 +732,7 @@ function createStore_forChannelsNotificationSettings(updates) {
734
732
  signal: DerivedSignal.from(
735
733
  signal,
736
734
  updates,
737
- (base, updates2) => applyOptimisticUpdates_forChannelNotificationSettings(base, updates2)
735
+ (base, updates2) => applyOptimisticUpdates_forUserNotificationSettings(base, updates2)
738
736
  ),
739
737
  // Mutations
740
738
  update
@@ -804,7 +802,7 @@ var UmbrellaStore = class {
804
802
  // prettier-ignore
805
803
  historyVersions;
806
804
  permissionHints;
807
- channelNotificationSettings;
805
+ userNotificationSettings;
808
806
  optimisticUpdates;
809
807
  //
810
808
  // Output signals.
@@ -825,8 +823,8 @@ var UmbrellaStore = class {
825
823
  #userThreadsLastRequestedAt = null;
826
824
  // Room versions
827
825
  #roomVersionsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
828
- // Channels Notification Settings
829
- #channelsNotificationSettings;
826
+ // User Notification Settings
827
+ #userNotificationSettings;
830
828
  constructor(client) {
831
829
  this.#client = client[kInternal].as();
832
830
  this.optimisticUpdates = createStore_forOptimistic(this.#client);
@@ -843,13 +841,13 @@ var UmbrellaStore = class {
843
841
  }
844
842
  );
845
843
  const channelsNotificationSettingsFetcher = async () => {
846
- const result = await this.#client.getChannelsNotificationSettings();
847
- this.channelNotificationSettings.update(result);
844
+ const result = await this.#client.getNotificationSettings();
845
+ this.userNotificationSettings.update(result);
848
846
  };
849
- this.channelNotificationSettings = createStore_forChannelsNotificationSettings(
847
+ this.userNotificationSettings = createStore_forUserNotificationSettings(
850
848
  this.optimisticUpdates.signal
851
849
  );
852
- this.#channelsNotificationSettings = new SinglePageResource(
850
+ this.#userNotificationSettings = new SinglePageResource(
853
851
  channelsNotificationSettingsFetcher
854
852
  );
855
853
  this.threads = new ThreadDB();
@@ -875,7 +873,7 @@ var UmbrellaStore = class {
875
873
  );
876
874
  const loadingUserThreads = new DefaultMap(
877
875
  (queryKey) => {
878
- const query = unstringify(queryKey);
876
+ const query = JSON.parse(queryKey);
879
877
  const resource = new PaginatedResource(async (cursor) => {
880
878
  const result = await this.#client[kInternal].httpClient.getUserThreads_experimental({
881
879
  cursor,
@@ -917,7 +915,7 @@ var UmbrellaStore = class {
917
915
  );
918
916
  const loadingRoomThreads = new DefaultMap(
919
917
  (queryKey) => {
920
- const [roomId, query] = unstringify(queryKey);
918
+ const [roomId, query] = JSON.parse(queryKey);
921
919
  const resource = new PaginatedResource(async (cursor) => {
922
920
  const result = await this.#client[kInternal].httpClient.getThreads({
923
921
  roomId,
@@ -980,10 +978,7 @@ var UmbrellaStore = class {
980
978
  const resource = new SinglePageResource(async () => {
981
979
  const room = this.#client.getRoom(roomId);
982
980
  if (room === null) {
983
- throw new HttpError(
984
- `Room '${roomId}' is not available on client`,
985
- 479
986
- );
981
+ throw new Error(`Room '${roomId}' is not available on client`);
987
982
  }
988
983
  const result = await room.getNotificationSettings();
989
984
  this.roomNotificationSettings.update(roomId, result);
@@ -1006,10 +1001,7 @@ var UmbrellaStore = class {
1006
1001
  const resource = new SinglePageResource(async () => {
1007
1002
  const room = this.#client.getRoom(roomId);
1008
1003
  if (room === null) {
1009
- throw new HttpError(
1010
- `Room '${roomId}' is not available on client`,
1011
- 479
1012
- );
1004
+ throw new Error(`Room '${roomId}' is not available on client`);
1013
1005
  }
1014
1006
  const result = await room[kInternal].listTextVersions();
1015
1007
  this.historyVersions.update(roomId, result.versions);
@@ -1035,21 +1027,18 @@ var UmbrellaStore = class {
1035
1027
  return { signal, waitUntilLoaded: resource.waitUntilLoaded };
1036
1028
  }
1037
1029
  );
1038
- const channelNotificationSettings = {
1039
- signal: DerivedSignal.from(
1040
- () => {
1041
- const result = this.#channelsNotificationSettings.get();
1042
- if (result.isLoading || result.error) {
1043
- return result;
1044
- }
1045
- return ASYNC_OK(
1046
- "settings",
1047
- nn(this.channelNotificationSettings.signal.get())
1048
- );
1049
- },
1050
- shallow3
1051
- ),
1052
- waitUntilLoaded: this.#channelsNotificationSettings.waitUntilLoaded
1030
+ const userNotificationSettings = {
1031
+ signal: DerivedSignal.from(() => {
1032
+ const result = this.#userNotificationSettings.get();
1033
+ if (result.isLoading || result.error) {
1034
+ return result;
1035
+ }
1036
+ return ASYNC_OK(
1037
+ "settings",
1038
+ nn(this.userNotificationSettings.signal.get())
1039
+ );
1040
+ }, shallow3),
1041
+ waitUntilLoaded: this.#userNotificationSettings.waitUntilLoaded
1053
1042
  };
1054
1043
  this.outputs = {
1055
1044
  threadifications,
@@ -1060,7 +1049,7 @@ var UmbrellaStore = class {
1060
1049
  loadingNotifications,
1061
1050
  settingsByRoomId,
1062
1051
  versionsByRoomId,
1063
- channelNotificationSettings
1052
+ userNotificationSettings
1064
1053
  };
1065
1054
  autobind(this);
1066
1055
  }
@@ -1306,22 +1295,22 @@ var UmbrellaStore = class {
1306
1295
  this.roomNotificationSettings.update(roomId, result);
1307
1296
  }
1308
1297
  /**
1309
- * Refresh Channels Notification Settings from poller
1298
+ * Refresh User Notification Settings from poller
1310
1299
  */
1311
- async refreshChannelsNotificationSettings(signal) {
1312
- const result = await this.#client.getChannelsNotificationSettings({
1300
+ async refreshUserNotificationSettings(signal) {
1301
+ const result = await this.#client.getNotificationSettings({
1313
1302
  signal
1314
1303
  });
1315
- this.channelNotificationSettings.update(result);
1304
+ this.userNotificationSettings.update(result);
1316
1305
  }
1317
1306
  /**
1318
- * Updates channels notification settings with a new value, replacing the
1307
+ * Updates user notification settings with a new value, replacing the
1319
1308
  * corresponding optimistic update.
1320
1309
  */
1321
- updateChannelsNotificationSettings_confirmOptimisticUpdate(settings, optimisticUpdateId) {
1310
+ updateUserNotificationSettings_confirmOptimisticUpdate(settings, optimisticUpdateId) {
1322
1311
  batch2(() => {
1323
1312
  this.optimisticUpdates.remove(optimisticUpdateId);
1324
- this.channelNotificationSettings.update(settings);
1313
+ this.userNotificationSettings.update(settings);
1325
1314
  });
1326
1315
  }
1327
1316
  };
@@ -1498,11 +1487,11 @@ function applyOptimisticUpdates_forSettings(settingsLUT, optimisticUpdates) {
1498
1487
  }
1499
1488
  return settingsByRoomId;
1500
1489
  }
1501
- function applyOptimisticUpdates_forChannelNotificationSettings(baseChannelsNotificationSettings, optimisticUpdates) {
1502
- const outcomingSettings = { ...baseChannelsNotificationSettings };
1490
+ function applyOptimisticUpdates_forUserNotificationSettings(baseSettings, optimisticUpdates) {
1491
+ const outcomingSettings = { ...baseSettings };
1503
1492
  for (const optimisticUpdate of optimisticUpdates) {
1504
1493
  switch (optimisticUpdate.type) {
1505
- case "update-channels-notification-settings": {
1494
+ case "update-user-notification-settings": {
1506
1495
  const incomingSettings = optimisticUpdate.settings;
1507
1496
  for (const channelKey of keys(incomingSettings)) {
1508
1497
  const key = channelKey;
@@ -1818,25 +1807,25 @@ function makeLiveblocksExtrasForClient(client) {
1818
1807
  config.USER_THREADS_POLL_INTERVAL,
1819
1808
  { maxStaleTimeMs: config.USER_THREADS_MAX_STALE_TIME }
1820
1809
  );
1821
- const channelNotificationSettingsPoller = makePoller(
1810
+ const userNotificationSettingsPoller = makePoller(
1822
1811
  async (signal) => {
1823
1812
  try {
1824
- return await store.refreshChannelsNotificationSettings(signal);
1813
+ return await store.refreshUserNotificationSettings(signal);
1825
1814
  } catch (err) {
1826
1815
  console.warn(
1827
- `Polling new channel notification settings failed: ${String(err)}`
1816
+ `Polling new user notification settings failed: ${String(err)}`
1828
1817
  );
1829
1818
  throw err;
1830
1819
  }
1831
1820
  },
1832
- config.CHANNEL_NOTIFICATION_SETTINGS_INTERVAL,
1833
- { maxStaleTimeMs: config.CHANNEL_NOTIFICATION_SETTINGS_MAX_STALE_TIME }
1821
+ config.USER_NOTIFICATION_SETTINGS_INTERVAL,
1822
+ { maxStaleTimeMs: config.USER_NOTIFICATION_SETTINGS_MAX_STALE_TIME }
1834
1823
  );
1835
1824
  return {
1836
1825
  store,
1837
1826
  notificationsPoller,
1838
1827
  userThreadsPoller,
1839
- channelNotificationSettingsPoller
1828
+ userNotificationSettingsPoller
1840
1829
  };
1841
1830
  }
1842
1831
  function makeLiveblocksContextBundle(client) {
@@ -1845,7 +1834,7 @@ function makeLiveblocksContextBundle(client) {
1845
1834
  const useMarkAllInboxNotificationsAsRead2 = () => useMarkAllInboxNotificationsAsRead_withClient(client);
1846
1835
  const useDeleteInboxNotification2 = () => useDeleteInboxNotification_withClient(client);
1847
1836
  const useDeleteAllInboxNotifications2 = () => useDeleteAllInboxNotifications_withClient(client);
1848
- const useUpdateChannelsNotificationSettings2 = () => useUpdateChannelsNotificationSettings_withClient(client);
1837
+ const useUpdateNotificationSettings2 = () => useUpdateNotificationSettings_withClient(client);
1849
1838
  function LiveblocksProvider2(props) {
1850
1839
  useEnsureNoLiveblocksProvider();
1851
1840
  return /* @__PURE__ */ jsx(ClientContext.Provider, { value: client, children: props.children });
@@ -1859,8 +1848,8 @@ function makeLiveblocksContextBundle(client) {
1859
1848
  useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
1860
1849
  useDeleteInboxNotification: useDeleteInboxNotification2,
1861
1850
  useDeleteAllInboxNotifications: useDeleteAllInboxNotifications2,
1862
- useChannelsNotificationSettings: () => useChannelsNotificationSettings_withClient(client),
1863
- useUpdateChannelsNotificationSettings: useUpdateChannelsNotificationSettings2,
1851
+ useNotificationSettings: () => useNotificationSettings_withClient(client),
1852
+ useUpdateNotificationSettings: useUpdateNotificationSettings2,
1864
1853
  useInboxNotificationThread: useInboxNotificationThread2,
1865
1854
  useUserThreads_experimental,
1866
1855
  ...shared.classic,
@@ -1873,8 +1862,8 @@ function makeLiveblocksContextBundle(client) {
1873
1862
  useDeleteInboxNotification: useDeleteInboxNotification2,
1874
1863
  useDeleteAllInboxNotifications: useDeleteAllInboxNotifications2,
1875
1864
  useInboxNotificationThread: useInboxNotificationThread2,
1876
- useChannelsNotificationSettings: () => useChannelsNotificationSettingsSuspense_withClient(client),
1877
- useUpdateChannelsNotificationSettings: useUpdateChannelsNotificationSettings2,
1865
+ useNotificationSettings: () => useNotificationSettingsSuspense_withClient(client),
1866
+ useUpdateNotificationSettings: useUpdateNotificationSettings2,
1878
1867
  useUserThreads_experimental: useUserThreadsSuspense_experimental,
1879
1868
  ...shared.suspense
1880
1869
  }
@@ -1948,8 +1937,15 @@ function useMarkInboxNotificationAsRead_withClient(client) {
1948
1937
  optimisticId
1949
1938
  );
1950
1939
  },
1951
- () => {
1940
+ (err) => {
1952
1941
  store.optimisticUpdates.remove(optimisticId);
1942
+ client[kInternal2].emitError(
1943
+ {
1944
+ type: "MARK_INBOX_NOTIFICATION_AS_READ_ERROR",
1945
+ inboxNotificationId
1946
+ },
1947
+ err
1948
+ );
1953
1949
  }
1954
1950
  );
1955
1951
  },
@@ -1968,8 +1964,13 @@ function useMarkAllInboxNotificationsAsRead_withClient(client) {
1968
1964
  () => {
1969
1965
  store.markAllInboxNotificationsRead(optimisticId, readAt);
1970
1966
  },
1971
- () => {
1967
+ (err) => {
1972
1968
  store.optimisticUpdates.remove(optimisticId);
1969
+ client[kInternal2].emitError(
1970
+ // No roomId, threadId, commentId to include for this error
1971
+ { type: "MARK_ALL_INBOX_NOTIFICATIONS_AS_READ_ERROR" },
1972
+ err
1973
+ );
1973
1974
  }
1974
1975
  );
1975
1976
  }, [client]);
@@ -1988,8 +1989,12 @@ function useDeleteInboxNotification_withClient(client) {
1988
1989
  () => {
1989
1990
  store.deleteInboxNotification(inboxNotificationId, optimisticId);
1990
1991
  },
1991
- () => {
1992
+ (err) => {
1992
1993
  store.optimisticUpdates.remove(optimisticId);
1994
+ client[kInternal2].emitError(
1995
+ { type: "DELETE_INBOX_NOTIFICATION_ERROR", inboxNotificationId },
1996
+ err
1997
+ );
1993
1998
  }
1994
1999
  );
1995
2000
  },
@@ -2008,8 +2013,12 @@ function useDeleteAllInboxNotifications_withClient(client) {
2008
2013
  () => {
2009
2014
  store.deleteAllInboxNotifications(optimisticId);
2010
2015
  },
2011
- () => {
2016
+ (err) => {
2012
2017
  store.optimisticUpdates.remove(optimisticId);
2018
+ client[kInternal2].emitError(
2019
+ { type: "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR" },
2020
+ err
2021
+ );
2013
2022
  }
2014
2023
  );
2015
2024
  }, [client]);
@@ -2037,17 +2046,17 @@ function useInboxNotificationThread_withClient(client, inboxNotificationId) {
2037
2046
  )
2038
2047
  );
2039
2048
  }
2040
- function useUpdateChannelsNotificationSettings_withClient(client) {
2049
+ function useUpdateNotificationSettings_withClient(client) {
2041
2050
  return useCallback2(
2042
2051
  (settings) => {
2043
2052
  const { store } = getLiveblocksExtrasForClient(client);
2044
2053
  const optimisticUpdateId = store.optimisticUpdates.add({
2045
- type: "update-channels-notification-settings",
2054
+ type: "update-user-notification-settings",
2046
2055
  settings
2047
2056
  });
2048
- client.updateChannelsNotificationSettings(settings).then(
2057
+ client.updateNotificationSettings(settings).then(
2049
2058
  (settings2) => {
2050
- store.updateChannelsNotificationSettings_confirmOptimisticUpdate(
2059
+ store.updateUserNotificationSettings_confirmOptimisticUpdate(
2051
2060
  settings2,
2052
2061
  optimisticUpdateId
2053
2062
  );
@@ -2060,11 +2069,11 @@ function useUpdateChannelsNotificationSettings_withClient(client) {
2060
2069
  [client]
2061
2070
  );
2062
2071
  }
2063
- function useChannelsNotificationSettings_withClient(client) {
2064
- const updateChannelsNotificationSettings = useUpdateChannelsNotificationSettings_withClient(client);
2065
- const { store, channelNotificationSettingsPoller: poller } = getLiveblocksExtrasForClient(client);
2072
+ function useNotificationSettings_withClient(client) {
2073
+ const updateNotificationSettings = useUpdateNotificationSettings_withClient(client);
2074
+ const { store, userNotificationSettingsPoller: poller } = getLiveblocksExtrasForClient(client);
2066
2075
  useEffect3(() => {
2067
- void store.outputs.channelNotificationSettings.waitUntilLoaded();
2076
+ void store.outputs.userNotificationSettings.waitUntilLoaded();
2068
2077
  });
2069
2078
  useEffect3(() => {
2070
2079
  poller.inc();
@@ -2073,20 +2082,20 @@ function useChannelsNotificationSettings_withClient(client) {
2073
2082
  poller.dec();
2074
2083
  };
2075
2084
  }, [poller]);
2076
- const settings = useSignal(store.outputs.channelNotificationSettings.signal);
2085
+ const settings = useSignal(store.outputs.userNotificationSettings.signal);
2077
2086
  return useMemo2(() => {
2078
- return [settings, updateChannelsNotificationSettings];
2079
- }, [settings, updateChannelsNotificationSettings]);
2087
+ return [settings, updateNotificationSettings];
2088
+ }, [settings, updateNotificationSettings]);
2080
2089
  }
2081
- function useChannelsNotificationSettingsSuspense_withClient(client) {
2090
+ function useNotificationSettingsSuspense_withClient(client) {
2082
2091
  const store = getLiveblocksExtrasForClient(client).store;
2083
- use(store.outputs.channelNotificationSettings.waitUntilLoaded());
2084
- const [settings, updateChannelsNotificationSettings] = useChannelsNotificationSettings_withClient(client);
2092
+ use(store.outputs.userNotificationSettings.waitUntilLoaded());
2093
+ const [settings, updateNotificationSettings] = useNotificationSettings_withClient(client);
2085
2094
  assert(!settings.error, "Did not expect error");
2086
2095
  assert(!settings.isLoading, "Did not expect loading");
2087
2096
  return useMemo2(() => {
2088
- return [settings, updateChannelsNotificationSettings];
2089
- }, [settings, updateChannelsNotificationSettings]);
2097
+ return [settings, updateNotificationSettings];
2098
+ }, [settings, updateNotificationSettings]);
2090
2099
  }
2091
2100
  function useUser_withClient(client, userId) {
2092
2101
  const usersStore = client[kInternal2].usersStore;
@@ -2222,6 +2231,7 @@ function createSharedContext(client) {
2222
2231
  useUser: (userId) => useUser_withClient(client, userId),
2223
2232
  useRoomInfo: (roomId) => useRoomInfo_withClient(client, roomId),
2224
2233
  useIsInsideRoom,
2234
+ useErrorListener,
2225
2235
  useSyncStatus: useSyncStatus2
2226
2236
  },
2227
2237
  suspense: {
@@ -2229,6 +2239,7 @@ function createSharedContext(client) {
2229
2239
  useUser: (userId) => useUserSuspense_withClient(client, userId),
2230
2240
  useRoomInfo: (roomId) => useRoomInfoSuspense_withClient(client, roomId),
2231
2241
  useIsInsideRoom,
2242
+ useErrorListener,
2232
2243
  useSyncStatus: useSyncStatus2
2233
2244
  }
2234
2245
  };
@@ -2349,14 +2360,14 @@ function useUnreadInboxNotificationsCount() {
2349
2360
  function useUnreadInboxNotificationsCountSuspense() {
2350
2361
  return useUnreadInboxNotificationsCountSuspense_withClient(useClient());
2351
2362
  }
2352
- function useChannelsNotificationSettings() {
2353
- return useChannelsNotificationSettings_withClient(useClient());
2363
+ function useNotificationSettings() {
2364
+ return useNotificationSettings_withClient(useClient());
2354
2365
  }
2355
- function useChannelsNotificationSettingsSuspense() {
2356
- return useChannelsNotificationSettingsSuspense_withClient(useClient());
2366
+ function useNotificationSettingsSuspense() {
2367
+ return useNotificationSettingsSuspense_withClient(useClient());
2357
2368
  }
2358
- function useUpdateChannelsNotificationSettings() {
2359
- return useUpdateChannelsNotificationSettings_withClient(useClient());
2369
+ function useUpdateNotificationSettings() {
2370
+ return useUpdateNotificationSettings_withClient(useClient());
2360
2371
  }
2361
2372
  function useUser(userId) {
2362
2373
  const client = useClient();
@@ -2417,104 +2428,14 @@ function useSyncStatusSmooth_withClient(client) {
2417
2428
  function useSyncStatus(options) {
2418
2429
  return useSyncStatus_withClient(useClient(), options);
2419
2430
  }
2420
-
2421
- // src/types/errors.ts
2422
- var CreateThreadError = class extends Error {
2423
- constructor(cause, context) {
2424
- super("Create thread failed.");
2425
- this.cause = cause;
2426
- this.context = context;
2427
- this.name = "CreateThreadError";
2428
- }
2429
- };
2430
- var DeleteThreadError = class extends Error {
2431
- constructor(cause, context) {
2432
- super("Delete thread failed.");
2433
- this.cause = cause;
2434
- this.context = context;
2435
- this.name = "DeleteThreadError";
2436
- }
2437
- };
2438
- var EditThreadMetadataError = class extends Error {
2439
- constructor(cause, context) {
2440
- super("Edit thread metadata failed.");
2441
- this.cause = cause;
2442
- this.context = context;
2443
- this.name = "EditThreadMetadataError";
2444
- }
2445
- };
2446
- var MarkThreadAsResolvedError = class extends Error {
2447
- constructor(cause, context) {
2448
- super("Mark thread as resolved failed.");
2449
- this.cause = cause;
2450
- this.context = context;
2451
- this.name = "MarkThreadAsResolvedError";
2452
- }
2453
- };
2454
- var MarkThreadAsUnresolvedError = class extends Error {
2455
- constructor(cause, context) {
2456
- super("Mark thread as unresolved failed.");
2457
- this.cause = cause;
2458
- this.context = context;
2459
- this.name = "MarkThreadAsUnresolvedError";
2460
- }
2461
- };
2462
- var CreateCommentError = class extends Error {
2463
- constructor(cause, context) {
2464
- super("Create comment failed.");
2465
- this.cause = cause;
2466
- this.context = context;
2467
- this.name = "CreateCommentError";
2468
- }
2469
- };
2470
- var EditCommentError = class extends Error {
2471
- constructor(cause, context) {
2472
- super("Edit comment failed.");
2473
- this.cause = cause;
2474
- this.context = context;
2475
- this.name = "EditCommentError";
2476
- }
2477
- };
2478
- var DeleteCommentError = class extends Error {
2479
- constructor(cause, context) {
2480
- super("Delete comment failed.");
2481
- this.cause = cause;
2482
- this.context = context;
2483
- this.name = "DeleteCommentError";
2484
- }
2485
- };
2486
- var AddReactionError = class extends Error {
2487
- constructor(cause, context) {
2488
- super("Add reaction failed.");
2489
- this.cause = cause;
2490
- this.context = context;
2491
- this.name = "AddReactionError";
2492
- }
2493
- };
2494
- var RemoveReactionError = class extends Error {
2495
- constructor(cause, context) {
2496
- super("Remove reaction failed.");
2497
- this.cause = cause;
2498
- this.context = context;
2499
- this.name = "RemoveReactionError";
2500
- }
2501
- };
2502
- var MarkInboxNotificationAsReadError = class extends Error {
2503
- constructor(cause, context) {
2504
- super("Mark inbox notification as read failed.");
2505
- this.cause = cause;
2506
- this.context = context;
2507
- this.name = "MarkInboxNotificationAsReadError";
2508
- }
2509
- };
2510
- var UpdateNotificationSettingsError = class extends Error {
2511
- constructor(cause, context) {
2512
- super("Update notification settings failed.");
2513
- this.cause = cause;
2514
- this.context = context;
2515
- this.name = "UpdateNotificationSettingsError";
2516
- }
2517
- };
2431
+ function useErrorListener(callback) {
2432
+ const client = useClient();
2433
+ const savedCallback = useLatest(callback);
2434
+ useEffect3(
2435
+ () => client.events.error.subscribe((e) => savedCallback.current(e)),
2436
+ [client, savedCallback]
2437
+ );
2438
+ }
2518
2439
 
2519
2440
  // src/room.tsx
2520
2441
  import { shallow as shallow5 } from "@liveblocks/client";
@@ -2525,9 +2446,8 @@ import {
2525
2446
  createThreadId,
2526
2447
  DefaultMap as DefaultMap2,
2527
2448
  errorIf,
2528
- HttpError as HttpError2,
2449
+ HttpError,
2529
2450
  kInternal as kInternal3,
2530
- makeEventSource,
2531
2451
  makePoller as makePoller2,
2532
2452
  ServerMsgCode
2533
2453
  } from "@liveblocks/core";
@@ -2621,14 +2541,6 @@ function getCurrentUserId(client) {
2621
2541
  }
2622
2542
  return userId;
2623
2543
  }
2624
- function handleApiError(err) {
2625
- const message = `Request failed with status ${err.status}: ${err.message}`;
2626
- if (err.details?.error === "FORBIDDEN") {
2627
- const detailedMessage = [message, err.details.suggestion, err.details.docs].filter(Boolean).join("\n");
2628
- console3.error(detailedMessage);
2629
- }
2630
- return new Error(message);
2631
- }
2632
2544
  var _extras2 = /* @__PURE__ */ new WeakMap();
2633
2545
  var _bundles2 = /* @__PURE__ */ new WeakMap();
2634
2546
  function getOrCreateRoomContextBundle(client) {
@@ -2649,19 +2561,21 @@ function getRoomExtrasForClient(client) {
2649
2561
  }
2650
2562
  function makeRoomExtrasForClient(client) {
2651
2563
  const store = getUmbrellaStoreForClient(client);
2652
- const commentsErrorEventSource = makeEventSource();
2653
- function onMutationFailure(innerError, optimisticId, createPublicError) {
2564
+ function onMutationFailure(optimisticId, context, innerError) {
2654
2565
  store.optimisticUpdates.remove(optimisticId);
2655
- if (innerError instanceof HttpError2) {
2656
- const error = handleApiError(innerError);
2657
- commentsErrorEventSource.notify(createPublicError(error));
2658
- return;
2659
- }
2660
- if (innerError instanceof HttpError2) {
2661
- handleApiError(innerError);
2662
- return;
2566
+ if (innerError instanceof HttpError) {
2567
+ if (innerError.status === 403) {
2568
+ const detailedMessage = [
2569
+ innerError.message,
2570
+ innerError.details?.suggestion,
2571
+ innerError.details?.docs
2572
+ ].filter(Boolean).join("\n");
2573
+ console3.error(detailedMessage);
2574
+ }
2575
+ client[kInternal3].emitError(context, innerError);
2576
+ } else {
2577
+ throw innerError;
2663
2578
  }
2664
- throw innerError;
2665
2579
  }
2666
2580
  const threadsPollersByRoomId = new DefaultMap2(
2667
2581
  (roomId) => makePoller2(
@@ -2707,7 +2621,6 @@ function makeRoomExtrasForClient(client) {
2707
2621
  );
2708
2622
  return {
2709
2623
  store,
2710
- commentsErrorEventSource: commentsErrorEventSource.observable,
2711
2624
  onMutationFailure,
2712
2625
  getOrCreateThreadsPollerForRoomId: threadsPollersByRoomId.getOrCreate.bind(
2713
2626
  threadsPollersByRoomId
@@ -2733,7 +2646,6 @@ function makeRoomContextBundle(client) {
2733
2646
  useBroadcastEvent,
2734
2647
  useOthersListener,
2735
2648
  useLostConnectionListener,
2736
- useErrorListener,
2737
2649
  useEventListener,
2738
2650
  useHistory,
2739
2651
  useUndo,
@@ -2779,7 +2691,6 @@ function makeRoomContextBundle(client) {
2779
2691
  useBroadcastEvent,
2780
2692
  useOthersListener,
2781
2693
  useLostConnectionListener,
2782
- useErrorListener,
2783
2694
  useEventListener,
2784
2695
  useHistory,
2785
2696
  useUndo,
@@ -2815,8 +2726,7 @@ function makeRoomContextBundle(client) {
2815
2726
  useRoomNotificationSettings: useRoomNotificationSettingsSuspense,
2816
2727
  useUpdateRoomNotificationSettings,
2817
2728
  ...shared.suspense
2818
- },
2819
- useCommentsErrorListener
2729
+ }
2820
2730
  };
2821
2731
  return Object.defineProperty(bundle, kInternal3, {
2822
2732
  enumerable: false
@@ -3077,14 +2987,6 @@ function useLostConnectionListener(callback) {
3077
2987
  [room, savedCallback]
3078
2988
  );
3079
2989
  }
3080
- function useErrorListener(callback) {
3081
- const room = useRoom();
3082
- const savedCallback = useLatest(callback);
3083
- useEffect5(
3084
- () => room.events.error.subscribe((e) => savedCallback.current(e)),
3085
- [room, savedCallback]
3086
- );
3087
- }
3088
2990
  function useEventListener(callback) {
3089
2991
  const room = useRoom();
3090
2992
  const savedCallback = useLatest(callback);
@@ -3294,14 +3196,6 @@ function useThreads(options = {}) {
3294
3196
  useScrollToCommentOnLoadEffect(scrollOnLoad, result);
3295
3197
  return result;
3296
3198
  }
3297
- function useCommentsErrorListener(callback) {
3298
- const client = useClient();
3299
- const savedCallback = useLatest(callback);
3300
- const { commentsErrorEventSource } = getRoomExtrasForClient(client);
3301
- useEffect5(() => {
3302
- return commentsErrorEventSource.subscribe(savedCallback.current);
3303
- }, [savedCallback, commentsErrorEventSource]);
3304
- }
3305
3199
  function useCreateThread() {
3306
3200
  return useCreateRoomThread(useRoom().id);
3307
3201
  }
@@ -3355,15 +3249,16 @@ function useCreateRoomThread(roomId) {
3355
3249
  store.createThread(optimisticId, thread);
3356
3250
  },
3357
3251
  (err) => onMutationFailure(
3358
- err,
3359
3252
  optimisticId,
3360
- (err2) => new CreateThreadError(err2, {
3253
+ {
3254
+ type: "CREATE_THREAD_ERROR",
3361
3255
  roomId,
3362
3256
  threadId,
3363
3257
  commentId,
3364
3258
  body,
3365
3259
  metadata
3366
- })
3260
+ },
3261
+ err
3367
3262
  )
3368
3263
  );
3369
3264
  return newThread;
@@ -3395,9 +3290,9 @@ function useDeleteRoomThread(roomId) {
3395
3290
  store.deleteThread(threadId, optimisticId);
3396
3291
  },
3397
3292
  (err) => onMutationFailure(
3398
- err,
3399
3293
  optimisticId,
3400
- (err2) => new DeleteThreadError(err2, { roomId, threadId })
3294
+ { type: "DELETE_THREAD_ERROR", roomId, threadId },
3295
+ err
3401
3296
  )
3402
3297
  );
3403
3298
  },
@@ -3430,13 +3325,14 @@ function useEditRoomThreadMetadata(roomId) {
3430
3325
  store.patchThread(threadId, optimisticId, { metadata: metadata2 }, updatedAt)
3431
3326
  ),
3432
3327
  (err) => onMutationFailure(
3433
- err,
3434
3328
  optimisticId,
3435
- (error) => new EditThreadMetadataError(error, {
3329
+ {
3330
+ type: "EDIT_THREAD_METADATA_ERROR",
3436
3331
  roomId,
3437
3332
  threadId,
3438
3333
  metadata
3439
- })
3334
+ },
3335
+ err
3440
3336
  )
3441
3337
  );
3442
3338
  },
@@ -3474,14 +3370,15 @@ function useCreateRoomComment(roomId) {
3474
3370
  store.createComment(newComment, optimisticId);
3475
3371
  },
3476
3372
  (err) => onMutationFailure(
3477
- err,
3478
3373
  optimisticId,
3479
- (err2) => new CreateCommentError(err2, {
3374
+ {
3375
+ type: "CREATE_COMMENT_ERROR",
3480
3376
  roomId,
3481
3377
  threadId,
3482
3378
  commentId,
3483
3379
  body
3484
- })
3380
+ },
3381
+ err
3485
3382
  )
3486
3383
  );
3487
3384
  return comment;
@@ -3529,14 +3426,9 @@ function useEditRoomComment(roomId) {
3529
3426
  store.editComment(threadId, optimisticId, editedComment);
3530
3427
  },
3531
3428
  (err) => onMutationFailure(
3532
- err,
3533
3429
  optimisticId,
3534
- (error) => new EditCommentError(error, {
3535
- roomId,
3536
- threadId,
3537
- commentId,
3538
- body
3539
- })
3430
+ { type: "EDIT_COMMENT_ERROR", roomId, threadId, commentId, body },
3431
+ err
3540
3432
  )
3541
3433
  );
3542
3434
  },
@@ -3564,13 +3456,9 @@ function useDeleteRoomComment(roomId) {
3564
3456
  store.deleteComment(threadId, optimisticId, commentId, deletedAt);
3565
3457
  },
3566
3458
  (err) => onMutationFailure(
3567
- err,
3568
3459
  optimisticId,
3569
- (error) => new DeleteCommentError(error, {
3570
- roomId,
3571
- threadId,
3572
- commentId
3573
- })
3460
+ { type: "DELETE_COMMENT_ERROR", roomId, threadId, commentId },
3461
+ err
3574
3462
  )
3575
3463
  );
3576
3464
  },
@@ -3608,14 +3496,15 @@ function useAddRoomCommentReaction(roomId) {
3608
3496
  );
3609
3497
  },
3610
3498
  (err) => onMutationFailure(
3611
- err,
3612
3499
  optimisticId,
3613
- (error) => new AddReactionError(error, {
3500
+ {
3501
+ type: "ADD_REACTION_ERROR",
3614
3502
  roomId,
3615
3503
  threadId,
3616
3504
  commentId,
3617
3505
  emoji
3618
- })
3506
+ },
3507
+ err
3619
3508
  )
3620
3509
  );
3621
3510
  },
@@ -3652,14 +3541,15 @@ function useRemoveRoomCommentReaction(roomId) {
3652
3541
  );
3653
3542
  },
3654
3543
  (err) => onMutationFailure(
3655
- err,
3656
3544
  optimisticId,
3657
- (error) => new RemoveReactionError(error, {
3545
+ {
3546
+ type: "REMOVE_REACTION_ERROR",
3658
3547
  roomId,
3659
3548
  threadId,
3660
3549
  commentId,
3661
3550
  emoji
3662
- })
3551
+ },
3552
+ err
3663
3553
  )
3664
3554
  );
3665
3555
  },
@@ -3699,11 +3589,13 @@ function useMarkRoomThreadAsRead(roomId) {
3699
3589
  },
3700
3590
  (err) => {
3701
3591
  onMutationFailure(
3702
- err,
3703
3592
  optimisticId,
3704
- (error) => new MarkInboxNotificationAsReadError(error, {
3593
+ {
3594
+ type: "MARK_INBOX_NOTIFICATION_AS_READ_ERROR",
3595
+ roomId,
3705
3596
  inboxNotificationId: inboxNotification.id
3706
- })
3597
+ },
3598
+ err
3707
3599
  );
3708
3600
  return;
3709
3601
  }
@@ -3736,12 +3628,9 @@ function useMarkRoomThreadAsResolved(roomId) {
3736
3628
  );
3737
3629
  },
3738
3630
  (err) => onMutationFailure(
3739
- err,
3740
3631
  optimisticId,
3741
- (error) => new MarkThreadAsResolvedError(error, {
3742
- roomId,
3743
- threadId
3744
- })
3632
+ { type: "MARK_THREAD_AS_RESOLVED_ERROR", roomId, threadId },
3633
+ err
3745
3634
  )
3746
3635
  );
3747
3636
  },
@@ -3772,12 +3661,9 @@ function useMarkRoomThreadAsUnresolved(roomId) {
3772
3661
  );
3773
3662
  },
3774
3663
  (err) => onMutationFailure(
3775
- err,
3776
3664
  optimisticId,
3777
- (error) => new MarkThreadAsUnresolvedError(error, {
3778
- roomId,
3779
- threadId
3780
- })
3665
+ { type: "MARK_THREAD_AS_UNRESOLVED_ERROR", roomId, threadId },
3666
+ err
3781
3667
  )
3782
3668
  );
3783
3669
  },
@@ -3927,11 +3813,9 @@ function useUpdateRoomNotificationSettings() {
3927
3813
  store.updateRoomNotificationSettings(room.id, optimisticId, settings2);
3928
3814
  },
3929
3815
  (err) => onMutationFailure(
3930
- err,
3931
3816
  optimisticId,
3932
- (error) => new UpdateNotificationSettingsError(error, {
3933
- roomId: room.id
3934
- })
3817
+ { type: "UPDATE_NOTIFICATION_SETTINGS_ERROR", roomId: room.id },
3818
+ err
3935
3819
  )
3936
3820
  );
3937
3821
  },
@@ -4136,9 +4020,9 @@ export {
4136
4020
  useDeleteInboxNotification,
4137
4021
  useUnreadInboxNotificationsCount,
4138
4022
  useUnreadInboxNotificationsCountSuspense,
4139
- useChannelsNotificationSettings,
4140
- useChannelsNotificationSettingsSuspense,
4141
- useUpdateChannelsNotificationSettings,
4023
+ useNotificationSettings,
4024
+ useNotificationSettingsSuspense,
4025
+ useUpdateNotificationSettings,
4142
4026
  useRoomInfo,
4143
4027
  useRoomInfoSuspense,
4144
4028
  _useInboxNotificationThread,
@@ -4147,7 +4031,7 @@ export {
4147
4031
  _useUserThreads_experimental,
4148
4032
  _useUserThreadsSuspense_experimental,
4149
4033
  useSyncStatus,
4150
- CreateThreadError,
4034
+ useErrorListener,
4151
4035
  useStatus,
4152
4036
  useReportTextEditor,
4153
4037
  useYjsProvider,
@@ -4158,14 +4042,12 @@ export {
4158
4042
  useStorageStatus,
4159
4043
  useBatch,
4160
4044
  useLostConnectionListener,
4161
- useErrorListener,
4162
4045
  useHistory,
4163
4046
  useUndo,
4164
4047
  useRedo,
4165
4048
  useCanUndo,
4166
4049
  useCanRedo,
4167
4050
  useOthersConnectionIds,
4168
- useCommentsErrorListener,
4169
4051
  useCreateRoomThread,
4170
4052
  useDeleteRoomThread,
4171
4053
  useEditRoomThreadMetadata,
@@ -4225,4 +4107,4 @@ export {
4225
4107
  _useStorageRoot,
4226
4108
  _useUpdateMyPresence
4227
4109
  };
4228
- //# sourceMappingURL=chunk-VX6Y3GQO.mjs.map
4110
+ //# sourceMappingURL=chunk-LOPNJCSB.mjs.map