stream-chat-react 13.4.0 → 13.5.1

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.
@@ -134,6 +134,10 @@ const ChannelInner = (props) => {
134
134
  type: 'updateThreadOnEvent',
135
135
  });
136
136
  }
137
+ // ignore the event if it is not targeted at the current channel.
138
+ // Event targeted at this channel or globally targeted event should lead to state refresh
139
+ if (event.type === 'user.messages.deleted' && event.cid && event.cid !== channel.cid)
140
+ return;
137
141
  if (event.type === 'user.watching.start' || event.type === 'user.watching.stop')
138
142
  return;
139
143
  if (event.type === 'typing.start' || event.type === 'typing.stop') {
@@ -257,6 +261,7 @@ const ChannelInner = (props) => {
257
261
  client.on('connection.recovered', handleEvent);
258
262
  client.on('user.updated', handleEvent);
259
263
  client.on('user.deleted', handleEvent);
264
+ client.on('user.messages.deleted', handleEvent);
260
265
  channel.on(handleEvent);
261
266
  }
262
267
  })();
@@ -148,10 +148,6 @@ export const useChannelListShapeDefaults = () => {
148
148
  lastPinnedChannelIndex = findLastPinnedChannelIndex({ channels: newChannels });
149
149
  }
150
150
  const newTargetChannelIndex = typeof lastPinnedChannelIndex === 'number' ? lastPinnedChannelIndex + 1 : 0;
151
- // skip re-render if the position of the channel does not change
152
- if (currentChannels[newTargetChannelIndex] === targetChannel) {
153
- return currentChannels;
154
- }
155
151
  newChannels.splice(newTargetChannelIndex, 0, targetChannel);
156
152
  return newChannels;
157
153
  });
@@ -55,23 +55,28 @@ export const ChannelPreview = (props) => {
55
55
  }, 400), [channel, muted]);
56
56
  useEffect(() => {
57
57
  refreshUnreadCount();
58
- const handleEvent = () => {
58
+ const handleEvent = (event) => {
59
+ const deletedMessagesInAnotherChannel = event.type === 'user.messages.deleted' && event.cid && event.cid !== channel.cid;
60
+ if (deletedMessagesInAnotherChannel)
61
+ return;
59
62
  setLastMessage(channel.state.latestMessages[channel.state.latestMessages.length - 1]);
60
63
  refreshUnreadCount();
61
64
  };
62
65
  channel.on('message.new', handleEvent);
63
66
  channel.on('message.updated', handleEvent);
64
67
  channel.on('message.deleted', handleEvent);
68
+ client.on('user.messages.deleted', handleEvent);
65
69
  channel.on('message.undeleted', handleEvent);
66
70
  channel.on('channel.truncated', handleEvent);
67
71
  return () => {
68
72
  channel.off('message.new', handleEvent);
69
73
  channel.off('message.updated', handleEvent);
70
74
  channel.off('message.deleted', handleEvent);
75
+ client.off('user.messages.deleted', handleEvent);
71
76
  channel.off('message.undeleted', handleEvent);
72
77
  channel.off('channel.truncated', handleEvent);
73
78
  };
74
- }, [channel, refreshUnreadCount, channelUpdateCount]);
79
+ }, [channel, client, refreshUnreadCount, channelUpdateCount]);
75
80
  if (!Preview)
76
81
  return null;
77
82
  const latestMessagePreview = getLatestMessagePreview(channel, t, userLanguage, isMessageAIGenerated);
@@ -24,7 +24,7 @@ export const useChat = ({ client, defaultLanguage = 'en', i18nInstance, initialN
24
24
  useEffect(() => {
25
25
  if (!client)
26
26
  return;
27
- const version = "13.4.0";
27
+ const version = "13.5.1";
28
28
  const userAgent = client.getUserAgent();
29
29
  if (!userAgent.includes('stream-chat-react')) {
30
30
  // result looks like: 'stream-chat-react-2.3.2-stream-chat-javascript-client-browser-2.2.2'
@@ -10720,7 +10720,9 @@ var ChannelPreview = (props) => {
10720
10720
  );
10721
10721
  (0, import_react23.useEffect)(() => {
10722
10722
  refreshUnreadCount();
10723
- const handleEvent = () => {
10723
+ const handleEvent = (event) => {
10724
+ const deletedMessagesInAnotherChannel = event.type === "user.messages.deleted" && event.cid && event.cid !== channel.cid;
10725
+ if (deletedMessagesInAnotherChannel) return;
10724
10726
  setLastMessage(
10725
10727
  channel.state.latestMessages[channel.state.latestMessages.length - 1]
10726
10728
  );
@@ -10729,16 +10731,18 @@ var ChannelPreview = (props) => {
10729
10731
  channel.on("message.new", handleEvent);
10730
10732
  channel.on("message.updated", handleEvent);
10731
10733
  channel.on("message.deleted", handleEvent);
10734
+ client.on("user.messages.deleted", handleEvent);
10732
10735
  channel.on("message.undeleted", handleEvent);
10733
10736
  channel.on("channel.truncated", handleEvent);
10734
10737
  return () => {
10735
10738
  channel.off("message.new", handleEvent);
10736
10739
  channel.off("message.updated", handleEvent);
10737
10740
  channel.off("message.deleted", handleEvent);
10741
+ client.off("user.messages.deleted", handleEvent);
10738
10742
  channel.off("message.undeleted", handleEvent);
10739
10743
  channel.off("channel.truncated", handleEvent);
10740
10744
  };
10741
- }, [channel, refreshUnreadCount, channelUpdateCount]);
10745
+ }, [channel, client, refreshUnreadCount, channelUpdateCount]);
10742
10746
  if (!Preview) return null;
10743
10747
  const latestMessagePreview = getLatestMessagePreview2(
10744
10748
  channel,