Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rollup.module-exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default {
// Channel
Channel: 'src/modules/Channel/index.tsx',
'Channel/context': 'src/modules/Channel/context/ChannelProvider.tsx',
'Channel/hooks/useInitialMessagesFetch': 'src/modules/Channel/context/hooks/useInitialMessagesFetch.ts',
'Channel/utils/getMessagePartsInfo': 'src/modules/Channel/components/MessageList/getMessagePartsInfo.ts',
'Channel/utils/compareMessagesForGrouping': 'src/modules/Channel/context/compareMessagesForGrouping.ts',
'Channel/components/ChannelHeader': 'src/modules/Channel/components/ChannelHeader/index.tsx',
Expand Down
27 changes: 16 additions & 11 deletions src/modules/Channel/context/hooks/useInitialMessagesFetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useCallback, useEffect } from 'react';
import { MessageListParams, ReplyType } from '@sendbird/chat/message';

import * as utils from '../utils';
Expand Down Expand Up @@ -34,10 +34,17 @@ function useInitialMessagesFetch(
setIsScrolled,
}: UseInitialMessagesFetchOptions,
{ logger, scrollRef, messagesDispatcher }: UseInitialMessagesFetchParams,
) {
): () => void {
const channelUrl = currentGroupChannel?.url;

useEffect(() => {
/**
* useCallback(() => {}, [currentGroupChannel]) was buggy, that is why we did
* const channelUrl = currentGroupChannel && currentGroupChannel.url;
* useCallback(() => {}, [channelUrl])
* Again, this hook is supposed to execute when currentGroupChannel changes
* The 'channelUrl' here is not the same memory reference from Conversation.props
*/
const fetchMessages = useCallback(() => {
logger.info('Channel useInitialMessagesFetch: Setup started', currentGroupChannel);
setIsScrolled(false);
messagesDispatcher({
Expand Down Expand Up @@ -129,14 +136,12 @@ function useInitialMessagesFetch(
});
}
}, [channelUrl, userFilledMessageListQuery, initialTimeStamp]);
/**
* Note - useEffect(() => {}, [currentGroupChannel])
* was buggy, that is why we did
* const channelUrl = currentGroupChannel && currentGroupChannel.url;
* useEffect(() => {}, [channelUrl])
* Again, this hook is supposed to execute when currentGroupChannel changes
* The 'channelUrl' here is not the same memory reference from Conversation.props
*/

useEffect(() => {
fetchMessages();
}, [fetchMessages]);

return fetchMessages;
}

export default useInitialMessagesFetch;