Skip to content

Commit 804cf6b

Browse files
committed
chore: cleanup
1 parent 1e17452 commit 804cf6b

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,11 @@ const ChannelWithContext = <
717717
* Its a map of filename to AbortController
718718
*/
719719
const uploadAbortControllerRef = useRef<Map<string, AbortController>>(new Map());
720+
/**
721+
* This ref keeps track of message IDs which have already been optimistically updated.
722+
* We need it to make sure we don't react on message.new/notification.message_new events
723+
* if this is indeed the case, as it's a full list update for nothing.
724+
*/
720725
const optimisticallyUpdatedNewMessages = useRef<Set<string>>(new Set());
721726

722727
const channelId = channel?.id || '';
@@ -839,15 +844,14 @@ const ChannelWithContext = <
839844
}
840845

841846
// only update channel state if the events are not the previously subscribed useEffect's subscription events
842-
console.log('EVENT: ', event);
843847
if (channel && channel.initialized) {
848+
// we skip the new message events if we've already done an optimistic update for the new message
844849
if (event.type === 'message.new' || event.type === 'notification.message_new') {
845850
const messageId = event.message?.id ?? '';
846851
if (
847852
event.user?.id !== client.userID ||
848853
!optimisticallyUpdatedNewMessages.current.has(messageId)
849854
) {
850-
console.log('INSIDE', Array.from(optimisticallyUpdatedNewMessages.current));
851855
copyMessagesStateFromChannelThrottled();
852856
}
853857
optimisticallyUpdatedNewMessages.current.delete(messageId);
@@ -859,7 +863,6 @@ const ChannelWithContext = <
859863
return;
860864
}
861865

862-
console.log('FULL STATE UPDATE');
863866
copyChannelState();
864867
}
865868
}
@@ -1426,6 +1429,7 @@ const ChannelWithContext = <
14261429
const updatedMessage = { ...message, cid: channel.cid };
14271430
updateMessage(updatedMessage);
14281431
threadInstance?.upsertReplyLocally?.({ message: updatedMessage });
1432+
optimisticallyUpdatedNewMessages.current.delete(message.id);
14291433

14301434
if (enableOfflineSupport) {
14311435
await dbApi.updateMessage({

package/src/components/MessageList/MessageList.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,6 @@ const MessageListWithContext = <
697697
if (!flatListRef.current) {
698698
return;
699699
}
700-
console.log('DOING IT HERE');
701700
clearTimeout(failScrollTimeoutId.current);
702701
scrollToIndexFailedRetryCountRef.current = 0;
703702
// keep track of this messageId, so that we dont scroll to again in useEffect for targeted message change
@@ -851,10 +850,6 @@ const MessageListWithContext = <
851850
],
852851
);
853852

854-
useEffect(() => {
855-
console.log('RENDER ITEM CHANGED OH NOOOO');
856-
}, [renderItem]);
857-
858853
/**
859854
* We are keeping full control on message pagination, and not relying on react-native for it.
860855
* The reasons being,
@@ -1368,10 +1363,6 @@ export const MessageList = <
13681363
const { loadMoreRecentThread, loadMoreThread, thread, threadInstance } =
13691364
useThreadContext<StreamChatGenerics>();
13701365

1371-
useEffect(() => {
1372-
console.log('MARK READ CHANGED');
1373-
}, [markRead]);
1374-
13751366
return (
13761367
<MessageListWithContext
13771368
{...{

package/src/components/MessageList/hooks/useMessageList.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useMemo } from 'react';
1+
import { useMemo } from 'react';
22

33
import type { ChannelState, MessageResponse } from 'stream-chat';
44

@@ -140,10 +140,6 @@ export const useMessageList = <
140140
readData,
141141
]);
142142

143-
useEffect(() => {
144-
console.log('PROCESSED LIST CHANGED', processedMessageList);
145-
}, [processedMessageList]);
146-
147143
return {
148144
/** Messages enriched with dates/readby/groups and also reversed in order */
149145
processedMessageList,

0 commit comments

Comments
 (0)