Skip to content

Commit bab5d36

Browse files
committed
perf: use throttled message copying everywhere
1 parent 9668334 commit bab5d36

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ const ChannelWithContext = <
746746
* This is done until we remove the newMessageStateUpdateThrottleInterval prop.
747747
*/
748748

749-
const copyMsgsStateFromChannel = useMemo(
749+
const copyMessagesStateFromChannelThrottled = useMemo(
750750
() =>
751751
throttle(
752752
() => {
@@ -776,6 +776,7 @@ const ChannelWithContext = <
776776
);
777777

778778
const handleEvent: EventHandler<StreamChatGenerics> = (event) => {
779+
console.log('SHOULD SYNC: ', event.type);
779780
if (shouldSyncChannel) {
780781
/**
781782
* Ignore user.watching.start and user.watching.stop as we should not copy the entire state when
@@ -830,11 +831,11 @@ const ChannelWithContext = <
830831
// only update channel state if the events are not the previously subscribed useEffect's subscription events
831832
if (channel && channel.initialized) {
832833
if (event.type === 'message.new') {
833-
copyMsgsStateFromChannel();
834+
copyMessagesStateFromChannelThrottled();
834835
return;
835836
}
836837

837-
if (event.type === 'message.read') {
838+
if (event.type === 'message.read' || event.type === 'notification.mark_read') {
838839
return;
839840
}
840841

@@ -1190,7 +1191,7 @@ const ChannelWithContext = <
11901191
}
11911192

11921193
channel.state.addMessageSorted(updatedMessage, true);
1193-
copyMsgsStateFromChannel(channel);
1194+
copyMessagesStateFromChannelThrottled();
11941195

11951196
if (thread && updatedMessage.parent_id) {
11961197
extraState.threadMessages = channel.state.threads[updatedMessage.parent_id] || [];
@@ -1205,7 +1206,7 @@ const ChannelWithContext = <
12051206
if (channel) {
12061207
channel.state.removeMessage(oldMessage);
12071208
channel.state.addMessageSorted(newMessage, true);
1208-
copyMsgsStateFromChannel(channel);
1209+
copyMessagesStateFromChannelThrottled();
12091210

12101211
if (thread && newMessage.parent_id) {
12111212
const threadMessages = channel.state.threads[newMessage.parent_id] || [];
@@ -1505,7 +1506,7 @@ const ChannelWithContext = <
15051506
) => {
15061507
if (channel) {
15071508
channel.state.removeMessage(message);
1508-
copyMsgsStateFromChannel(channel);
1509+
copyMessagesStateFromChannelThrottled();
15091510

15101511
if (thread) {
15111512
setThreadMessages(channel.state.threads[thread.id] || []);
@@ -1545,7 +1546,7 @@ const ChannelWithContext = <
15451546
user: client.user,
15461547
});
15471548

1548-
copyMsgsStateFromChannel(channel);
1549+
copyMessagesStateFromChannelThrottled();
15491550

15501551
const sendReactionResponse = await DBSyncManager.queueTask<StreamChatGenerics>({
15511552
client,
@@ -1631,7 +1632,7 @@ const ChannelWithContext = <
16311632
user: client.user,
16321633
});
16331634

1634-
copyMsgsStateFromChannel(channel);
1635+
copyMessagesStateFromChannelThrottled();
16351636

16361637
await DBSyncManager.queueTask<StreamChatGenerics>({
16371638
client,

0 commit comments

Comments
 (0)