stream-chat 10.0.0-rc.29 → 10.0.0-rc.30

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.
@@ -560,7 +560,7 @@ var channelHasReadEvents = (channel) => {
560
560
  const ownCapabilities = channel?.data?.own_capabilities;
561
561
  return !(Array.isArray(ownCapabilities) && !ownCapabilities.includes("read-events"));
562
562
  };
563
- var channelTracksReadLocally = (channel) => !channelHasReadEvents(channel) && !!channel?.config.readEvents.localUnreadCountEnabled;
563
+ var channelTracksReadLocally = (channel) => !!channel && !channel.readEventsEnabled && channel.config.readEvents.localUnreadCountEnabled;
564
564
  function retryInterval(numberOfFailures) {
565
565
  const max = Math.min(500 + numberOfFailures * 2e3, 25e3);
566
566
  const min = Math.min(Math.max(250, (numberOfFailures - 1) * 2e3), 25e3);
@@ -5521,8 +5521,15 @@ var BasePaginator = class {
5521
5521
  setFilterResolvers(resolvers) {
5522
5522
  this._filterFieldToDataResolvers = resolvers;
5523
5523
  }
5524
+ /**
5525
+ * Adds rules ahead of the existing ones. The first rule that matches a field resolves it, so an
5526
+ * added rule takes precedence over a built-in one, including a catch-all.
5527
+ */
5524
5528
  addFilterResolvers(resolvers) {
5525
- this._filterFieldToDataResolvers.push(...resolvers);
5529
+ this._filterFieldToDataResolvers = [
5530
+ ...resolvers,
5531
+ ...this._filterFieldToDataResolvers
5532
+ ];
5526
5533
  }
5527
5534
  getItemId(item) {
5528
5535
  return item.id;
@@ -7376,6 +7383,27 @@ var memberUserNameFilterResolver = {
7376
7383
  return names;
7377
7384
  }, []) : []
7378
7385
  };
7386
+ var resolveOwnInviteStatus = (channel) => {
7387
+ const { membership } = channel.state;
7388
+ if (membership?.invite_accepted_at != null) return "accepted";
7389
+ if (membership?.invite_rejected_at != null) return "rejected";
7390
+ if (membership?.invited) return "pending";
7391
+ return void 0;
7392
+ };
7393
+ var inviteFilterResolver = {
7394
+ matchesField: (field) => field === "invite",
7395
+ resolve: resolveOwnInviteStatus
7396
+ };
7397
+ var joinedFilterResolver = {
7398
+ matchesField: (field) => field === "joined",
7399
+ // A member, unless the membership is a pending or rejected invite.
7400
+ resolve: (channel) => {
7401
+ const { membership } = channel.state;
7402
+ const isMember = !!(membership?.user?.id ?? membership?.user_id);
7403
+ const inviteStatus = resolveOwnInviteStatus(channel);
7404
+ return isMember && inviteStatus !== "pending" && inviteStatus !== "rejected";
7405
+ }
7406
+ };
7379
7407
  var pinnedFilterResolver = {
7380
7408
  matchesField: (field) => field === "pinned",
7381
7409
  resolve: (channel) => channel.state.membership.pinned_at != null
@@ -7657,6 +7685,8 @@ var ChannelPaginator = class extends BasePaginator {
7657
7685
  createAppBannedFilterResolver(client),
7658
7686
  createHasUnreadFilterResolver(client),
7659
7687
  hiddenFilterResolver,
7688
+ inviteFilterResolver,
7689
+ joinedFilterResolver,
7660
7690
  lastUpdatedFilterResolver,
7661
7691
  pinnedFilterResolver,
7662
7692
  createMutedFilterResolver(client),
@@ -12901,11 +12931,12 @@ var DEFAULT_COMPOSER_CONFIG = deepFreezeConfig({
12901
12931
 
12902
12932
  // src/messageComposer/CustomDataManager.ts
12903
12933
  var import_state_store13 = require("@stream-io/state-store");
12904
- var initState4 = (options) => {
12905
- if (!options)
12906
- return { message: {}, custom: {} };
12907
- return { message: {}, custom: {} };
12908
- };
12934
+ var restoreCustomMessageData = (message) => ({ ...message?.custom });
12935
+ var initState4 = (options) => ({
12936
+ message: restoreCustomMessageData(options?.message),
12937
+ // Composer-only data that is never sent, so there is nothing to restore.
12938
+ custom: {}
12939
+ });
12909
12940
  var CustomDataManager = class {
12910
12941
  constructor({ composer, message }) {
12911
12942
  this.isMessageDataEqual = (nextState, previousState) => JSON.stringify(nextState.message) === JSON.stringify(previousState?.message);
@@ -13875,8 +13906,8 @@ var MessageDeliveryReporter = class _MessageDeliveryReporter {
13875
13906
  }, this.requestTimeoutMs);
13876
13907
  };
13877
13908
  /**
13878
- * Marks the channel or thread read. A channel with read events disabled is marked read locally when
13879
- * `localUnreadCountEnabled` is set.
13909
+ * Marks the channel or thread read. With read events off (`channel.readEventsEnabled`) no request
13910
+ * goes out: a channel is marked read locally when `localUnreadCountEnabled` is set.
13880
13911
  *
13881
13912
  * @param collection - The channel or thread to mark as read.
13882
13913
  * @param options - Flags forwarded to the underlying `markRead` call.
@@ -13892,16 +13923,16 @@ var MessageDeliveryReporter = class _MessageDeliveryReporter {
13892
13923
  result = markReadRequestHandler ? await markReadRequestHandler({
13893
13924
  options: requestOptions,
13894
13925
  thread: collection
13895
- }) ?? null : await channel.markRead(requestOptions);
13926
+ }) ?? null : channel.readEventsEnabled ? await channel.markRead(requestOptions) : null;
13896
13927
  } else {
13897
13928
  const { readEvents, requestHandlers } = channel.configState.getLatestValue();
13898
13929
  const markReadRequestHandler = requestHandlers?.markReadRequest;
13899
13930
  if (markReadRequestHandler) {
13900
13931
  result = await markReadRequestHandler({ channel, options: requestOptions }) ?? null;
13901
- } else if (!readEvents.enabled && readEvents.localUnreadCountEnabled) {
13902
- channel.markReadLocally();
13903
- } else {
13932
+ } else if (channel.readEventsEnabled) {
13904
13933
  result = await channel.markRead(requestOptions);
13934
+ } else if (readEvents.localUnreadCountEnabled) {
13935
+ channel.markReadLocally();
13905
13936
  }
13906
13937
  }
13907
13938
  if (result) this.removeCandidateFor(collection);
@@ -14654,9 +14685,11 @@ var MessageOperationStatePolicy = class {
14654
14685
  if (kind === "update") {
14655
14686
  const isFailed = localMessage.status === "failed";
14656
14687
  const editedAt = nowNs();
14688
+ const textChanged = localMessage.text !== previous?.text;
14657
14689
  const applied = {
14658
14690
  ...localMessage,
14659
14691
  error: isFailed ? localMessage.error : void 0,
14692
+ ...textChanged ? { i18n: void 0 } : {},
14660
14693
  updated_at: editedAt,
14661
14694
  // `message_text_updated_at` drives the "edited" indicator, so it appears immediately, but only
14662
14695
  // for a message the server has seen: a failed one never had a confirmed text update.
@@ -16467,6 +16500,15 @@ var Channel = class extends ChannelApi {
16467
16500
  }
16468
16501
  return this.getClient().user?.privacy_settings?.typing_indicators?.enabled ?? true;
16469
16502
  }
16503
+ /**
16504
+ * Whether read events are on. `config.readEvents.enabled` (the channel type's `read_events` and
16505
+ * the client configuration) and the own `read-events` capability allow them. Unread messages are
16506
+ * counted and marked read only while it is true, unless `readEvents.localUnreadCountEnabled` keeps
16507
+ * a local count.
16508
+ */
16509
+ get readEventsEnabled() {
16510
+ return this.config.readEvents.enabled && channelHasReadEvents(this);
16511
+ }
16470
16512
  /**
16471
16513
  * Marks read through `MessageDeliveryReporter`: uses the `markReadRequest` handler if set, marks
16472
16514
  * read locally when read events are off and `localUnreadCountEnabled` is set, and drops the
@@ -16489,9 +16531,9 @@ var Channel = class extends ChannelApi {
16489
16531
  */
16490
16532
  async markRead(...args) {
16491
16533
  this._checkInitialized();
16492
- if (!this.configController.value.readEvents.enabled) {
16534
+ if (!this.readEventsEnabled) {
16493
16535
  throw new Error(
16494
- "Read events are disabled \u2014 either by the channel type's `read_events` setting or by `channel.readEvents.enabled` in your configuration"
16536
+ "Read events are disabled by the channel type's `read_events` setting, by `channel.readEvents.enabled` in your configuration, or because the user lacks the `read-events` capability"
16495
16537
  );
16496
16538
  }
16497
16539
  return await super.markRead(...args);
@@ -16595,16 +16637,16 @@ var Channel = class extends ChannelApi {
16595
16637
  */
16596
16638
  async markUnread(...args) {
16597
16639
  this._checkInitialized();
16598
- if (!this.configController.value.readEvents.enabled) {
16640
+ if (!this.readEventsEnabled) {
16599
16641
  throw new Error(
16600
- "Read events are disabled \u2014 either by the channel type's `read_events` setting or by `channel.readEvents.enabled` in your configuration"
16642
+ "Read events are disabled by the channel type's `read_events` setting, by `channel.readEvents.enabled` in your configuration, or because the user lacks the `read-events` capability"
16601
16643
  );
16602
16644
  }
16603
16645
  return await super.markUnread(...args);
16604
16646
  }
16605
16647
  /**
16606
- * Resets the unread count without a backend call, for channels with read events disabled (e.g.
16607
- * livestreams) that set `readEvents.localUnreadCountEnabled`. Dispatches the client-only
16648
+ * Resets the unread count without a backend call, for channels with read events off
16649
+ * ({@link Channel.readEventsEnabled}, e.g. livestreams) that set `readEvents.localUnreadCountEnabled`. Dispatches the client-only
16608
16650
  * `message.read_locally` event, handled like `message.read` minus the delivery-report sync. With
16609
16651
  * offline support the reset is persisted.
16610
16652
  *
@@ -16811,7 +16853,7 @@ var Channel = class extends ChannelApi {
16811
16853
  if (message.user?.id === this.getClient().userId) return false;
16812
16854
  if (message.user?.id && this.getClient().userMuteStatus(message.user.id))
16813
16855
  return false;
16814
- if (!this.config.readEvents.localUnreadCountEnabled && !channelHasReadEvents(this)) {
16856
+ if (!this.config.readEvents.localUnreadCountEnabled && !this.readEventsEnabled) {
16815
16857
  return false;
16816
16858
  }
16817
16859
  if (this.muteStatus().muted) return false;
@@ -17324,13 +17366,18 @@ var Channel = class extends ChannelApi {
17324
17366
  case "user.watching.start":
17325
17367
  case "user.updated":
17326
17368
  if (event.user?.id) {
17327
- channelState.watchers[event.user.id] = event.user;
17369
+ channelState.watchers = {
17370
+ ...channelState.watchers,
17371
+ [event.user.id]: event.user
17372
+ };
17328
17373
  channel.getClient().state.updateUserReference(event.user, channel.cid);
17329
17374
  }
17330
17375
  break;
17331
17376
  case "user.watching.stop":
17332
- if (event.user?.id) {
17333
- delete channelState.watchers[event.user.id];
17377
+ if (event.user?.id && channelState.watchers[event.user.id]) {
17378
+ const newWatchers = { ...channelState.watchers };
17379
+ delete newWatchers[event.user.id];
17380
+ channelState.watchers = newWatchers;
17334
17381
  }
17335
17382
  break;
17336
17383
  case "message.deleted":
@@ -17421,9 +17468,8 @@ var Channel = class extends ChannelApi {
17421
17468
  );
17422
17469
  }
17423
17470
  if (countsAsOwnUnread) {
17424
- this.messagePaginator.setUnreadSnapshot({
17425
- unreadCount: channelState.unreadCount
17426
- });
17471
+ const { unreadCount } = this.messagePaginator.unreadStateSnapshot.getLatestValue();
17472
+ this.messagePaginator.setUnreadSnapshot({ unreadCount: unreadCount + 1 });
17427
17473
  }
17428
17474
  client.syncDeliveredCandidates([this]);
17429
17475
  }
@@ -17441,6 +17487,12 @@ var Channel = class extends ChannelApi {
17441
17487
  this.messagePaginator.reflectQuotedMessageUpdate(formattedMessage);
17442
17488
  this.pinnedMessagesPaginator.ingestItem(formattedMessage);
17443
17489
  this.pinnedMessagesPaginator.reflectQuotedMessageUpdate(formattedMessage);
17490
+ } else {
17491
+ const isListedAsPinned = (this.pinnedMessagesPaginator.locateByItem(formattedMessage).interval?.currentIndex ?? -1) > -1;
17492
+ const isPinChange = formattedMessage.pinned !== isListedAsPinned;
17493
+ if (!isAppliedByThread || isPinChange) {
17494
+ this.pinnedMessagesPaginator.ingestItem(formattedMessage);
17495
+ }
17444
17496
  }
17445
17497
  }
17446
17498
  break;
@@ -17488,15 +17540,20 @@ var Channel = class extends ChannelApi {
17488
17540
  }
17489
17541
  break;
17490
17542
  }
17491
- case "member.removed":
17492
- if (event.user?.id) {
17543
+ case "member.removed": {
17544
+ const removedUserId = event.member?.user?.id ?? event.member?.user_id ?? event.user?.id;
17545
+ if (removedUserId) {
17493
17546
  const newMembers = {
17494
17547
  ...channelState.members
17495
17548
  };
17496
- delete newMembers[event.user.id];
17549
+ delete newMembers[removedUserId];
17497
17550
  channelState.members = newMembers;
17551
+ if (removedUserId === this.getClient().userId) {
17552
+ channelState.membership = {};
17553
+ }
17498
17554
  }
17499
17555
  break;
17556
+ }
17500
17557
  case "notification.mark_unread": {
17501
17558
  const ownMessage = event.user?.id === this.getClient().user?.id;
17502
17559
  if (!ownMessage || !event.user || event.last_read_at == null) break;
@@ -17575,23 +17632,21 @@ var Channel = class extends ChannelApi {
17575
17632
  break;
17576
17633
  }
17577
17634
  case "user.banned":
17635
+ case "user.unbanned": {
17578
17636
  if (!event.user?.id) break;
17579
- channelState.members[event.user.id] = {
17580
- ...channelState.members[event.user.id] || {},
17581
- shadow_banned: !!event.shadow,
17582
- banned: !event.shadow,
17583
- user: { ...channelState.members[event.user.id]?.user || {}, ...event.user }
17584
- };
17585
- break;
17586
- case "user.unbanned":
17587
- if (!event.user?.id) break;
17588
- channelState.members[event.user.id] = {
17589
- ...channelState.members[event.user.id] || {},
17590
- shadow_banned: false,
17591
- banned: false,
17592
- user: { ...channelState.members[event.user.id]?.user || {}, ...event.user }
17637
+ const isBanned = event.type === "user.banned";
17638
+ const member = channelState.members[event.user.id];
17639
+ channelState.members = {
17640
+ ...channelState.members,
17641
+ [event.user.id]: {
17642
+ ...member || {},
17643
+ shadow_banned: isBanned && !!event.shadow,
17644
+ banned: isBanned && !event.shadow,
17645
+ user: { ...member?.user || {}, ...event.user }
17646
+ }
17593
17647
  };
17594
17648
  break;
17649
+ }
17595
17650
  default:
17596
17651
  }
17597
17652
  const typedEvent = event;
@@ -17641,13 +17696,15 @@ var Channel = class extends ChannelApi {
17641
17696
  if (state.watcher_count !== void 0) {
17642
17697
  this.state.watcher_count = state.watcher_count;
17643
17698
  }
17644
- if (state.watchers) {
17699
+ if (state.watchers?.length) {
17700
+ const watchers = { ...this.state.watchers };
17645
17701
  for (const watcher of state.watchers) {
17646
17702
  if (watcher) {
17647
17703
  clientState.updateUserReference(watcher, this.cid);
17648
- this.state.watchers[watcher.id] = watcher;
17704
+ watchers[watcher.id] = watcher;
17649
17705
  }
17650
17706
  }
17707
+ this.state.watchers = watchers;
17651
17708
  }
17652
17709
  const readUpdates = {};
17653
17710
  if (userID != null) {
@@ -18910,6 +18967,15 @@ var Thread = class extends WithSubscriptions {
18910
18967
  const { message } = event;
18911
18968
  this.messagePaginator.reflectQuotedMessageUpdate(formatMessage(message));
18912
18969
  };
18970
+ this.handleUserUpdated = (event) => {
18971
+ const { user } = event;
18972
+ if (!user) return;
18973
+ this.messagePaginator.reflectUserUpdate(user);
18974
+ const parent = this.client.messageStore.get(this.id);
18975
+ if (parent?.user?.id === user.id && parent.user !== user) {
18976
+ this.client.messageStore.upsert({ ...parent, user });
18977
+ }
18978
+ };
18913
18979
  // Applies a user ban or deletion to this thread's replies.
18914
18980
  this.handleUserMessagesDeleted = (event) => {
18915
18981
  if (!event.user) return;
@@ -19791,12 +19857,16 @@ var ThreadManager = class extends WithSubscriptions {
19791
19857
  )
19792
19858
  )
19793
19859
  ),
19794
- // A banned or deleted user's replies can be in any thread, so these two are the exception.
19860
+ // A user's replies can be in any thread, so the user events are the exception.
19795
19861
  ...["user.messages.deleted", "user.deleted"].map(
19796
19862
  (eventType) => this.client.on(
19797
19863
  eventType,
19798
19864
  (event) => this.threadStore.values().forEach((thread) => thread.handleUserMessagesDeleted(event))
19799
19865
  )
19866
+ ),
19867
+ this.client.on(
19868
+ "user.updated",
19869
+ (event) => this.threadStore.values().forEach((thread) => thread.handleUserUpdated(event))
19800
19870
  )
19801
19871
  ].map(({ unsubscribe }) => unsubscribe);
19802
19872
  return () => unsubscribeFunctions.forEach((unsubscribe) => unsubscribe());
@@ -25135,7 +25205,7 @@ var StreamChat = class _StreamChat extends ChatApi {
25135
25205
  return this.userAgent;
25136
25206
  }
25137
25207
  if (!this.cachedUserAgent) {
25138
- const version = "10.0.0-rc.29";
25208
+ const version = "10.0.0-rc.30";
25139
25209
  const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
25140
25210
  const { name: appName, version: appVersion } = this.appIdentifier ?? {};
25141
25211
  const { os, model: deviceModel } = this.deviceIdentifier ?? {};
@@ -26605,12 +26675,12 @@ var CHANNEL_FIELDS = {
26605
26675
  description: "Read receipts for the channel.",
26606
26676
  fields: {
26607
26677
  enabled: {
26608
- description: 'Allows marking the channel read or unread. The server must also allow it per channel type (`read_events`), and a server "no" wins.',
26678
+ description: 'Allows counting unread messages and marking the channel read or unread. The server must also allow it per channel type (`read_events`), and a server "no" wins. Without the own `read-events` capability read events stay off.',
26609
26679
  kind: "value",
26610
26680
  type: "boolean"
26611
26681
  },
26612
26682
  localUnreadCountEnabled: {
26613
- description: "Counts unread messages client-side when `enabled` is false, reset by `channel.markReadLocally()` instead of a request. Not subject to server authority.",
26683
+ description: "Counts unread messages client-side while read events are off (`channel.readEventsEnabled` is false), reset by `channel.markReadLocally()` instead of a request. Has no effect while read events are on. Not subject to server authority.",
26614
26684
  kind: "value",
26615
26685
  type: "boolean"
26616
26686
  }
@@ -27083,7 +27153,7 @@ var AbstractOfflineDB = class {
27083
27153
  const userId = client.user.id;
27084
27154
  const channel = client.channelManager.get(cid);
27085
27155
  const tracksReadLocally = channelTracksReadLocally(channel);
27086
- if (channel && (channelHasReadEvents(channel) || tracksReadLocally)) {
27156
+ if (channel && (channel.readEventsEnabled || tracksReadLocally)) {
27087
27157
  const ownReads = channel.state.read[userId];
27088
27158
  const unreadCount = channel.countUnread();
27089
27159
  const upsertReadsQueries = await this.upsertReads({
@@ -27387,7 +27457,7 @@ var AbstractOfflineDB = class {
27387
27457
  const userId = ownUser.id;
27388
27458
  const activeChannel = this.client.channelManager.get(cid);
27389
27459
  const tracksReadLocally = channelTracksReadLocally(activeChannel);
27390
- if (activeChannel && (channelHasReadEvents(activeChannel) || tracksReadLocally)) {
27460
+ if (activeChannel && (activeChannel.readEventsEnabled || tracksReadLocally)) {
27391
27461
  const ownReads = activeChannel.state.read[userId];
27392
27462
  let unreadCount = 0;
27393
27463
  if (truncated_at != null) {