diff --git a/lib/shared/farcaster/farcaster-hooks.js b/lib/shared/farcaster/farcaster-hooks.js --- a/lib/shared/farcaster/farcaster-hooks.js +++ b/lib/shared/farcaster/farcaster-hooks.js @@ -38,6 +38,7 @@ import type { GetCommFCUsersForFIDs } from '../../hooks/user-identities-hooks.js'; import { isLoggedIn } from '../../selectors/user-selectors.js'; import { useTunnelbroker } from '../../tunnelbroker/tunnelbroker-context.js'; +import { messageTypes } from '../../types/message-types-enum.js'; import type { RawMessageInfo } from '../../types/message-types.js'; import { messageTruncationStatus, @@ -1197,6 +1198,28 @@ const currentlyFetchedConversations = React.useRef>(new Set()); const { addLog } = useDebugLogs(); + const fetchConversation = React.useCallback( + async (farcasterMessage: FarcasterMessage, withMessages: boolean) => { + currentlyFetchedConversations.current.add( + farcasterMessage.conversationId, + ); + const updates = new BatchedUpdates(); + await fetchConversationWithMessages( + farcasterMessage.conversationId, + withMessages ? Number.POSITIVE_INFINITY : 0, + updates, + ); + dispatch({ + type: processFarcasterOpsActionType, + payload: updates.getReduxPayload(), + }); + currentlyFetchedConversations.current.delete( + farcasterMessage.conversationId, + ); + }, + [dispatch, fetchConversationWithMessages], + ); + return React.useCallback( async (farcasterMessage: FarcasterMessage) => { const threadID = farcasterThreadIDFromConversationID( @@ -1209,22 +1232,7 @@ farcasterMessage.conversationId, ) ) { - currentlyFetchedConversations.current.add( - farcasterMessage.conversationId, - ); - const updates = new BatchedUpdates(); - await fetchConversationWithMessages( - farcasterMessage.conversationId, - Number.POSITIVE_INFINITY, - updates, - ); - dispatch({ - type: processFarcasterOpsActionType, - payload: updates.getReduxPayload(), - }); - currentlyFetchedConversations.current.delete( - farcasterMessage.conversationId, - ); + await fetchConversation(farcasterMessage, true); return; } @@ -1250,6 +1258,19 @@ ); } + const isMembershipAddition = rawMessageInfos.some( + msg => + msg.type === messageTypes.ADD_MEMBERS || + msg.type === messageTypes.REMOVE_MEMBERS || + msg.type === messageTypes.CHANGE_ROLE || + msg.type === messageTypes.LEAVE_THREAD || + msg.type === messageTypes.JOIN_THREAD, + ); + + if (isMembershipAddition) { + await fetchConversation(farcasterMessage, false); + } + const userIDs = userFIDs.map(fid => userIDFromFID(`${fid}`)); const updates: Array = []; @@ -1275,7 +1296,7 @@ [ addLog, dispatch, - fetchConversationWithMessages, + fetchConversation, fetchMessage, fetchUsersByFIDs, threadInfos,