diff --git a/lib/hooks/user-identities-hooks.js b/lib/hooks/user-identities-hooks.js --- a/lib/hooks/user-identities-hooks.js +++ b/lib/hooks/user-identities-hooks.js @@ -3,7 +3,10 @@ import * as React from 'react'; import { useFindUserIdentities } from '../actions/find-user-identities-actions.js'; -import { userHasDeviceList } from '../shared/thread-utils.js'; +import { + userHasDeviceList, + useHasThickThreadWithUser, +} from '../shared/thread-utils.js'; import { useSelector } from '../utils/redux-utils.js'; function useUsersSupportThickThreads(): ( @@ -11,6 +14,7 @@ ) => Promise<$ReadOnlySet> { const findUserIdentities = useFindUserIdentities(); const auxUserInfos = useSelector(state => state.auxUserStore.auxUserInfos); + const hasThickThreadWithUser = useHasThickThreadWithUser(); return React.useCallback( async (userIDs: $ReadOnlyArray) => { @@ -18,7 +22,10 @@ const usersNeedingFetch = []; for (const userID of userIDs) { - if (userHasDeviceList(userID, auxUserInfos)) { + if ( + userHasDeviceList(userID, auxUserInfos) || + hasThickThreadWithUser(userID) + ) { usersSupportingThickThreads.add(userID); } else { usersNeedingFetch.push(userID); @@ -34,7 +41,7 @@ } return usersSupportingThickThreads; }, - [auxUserInfos, findUserIdentities], + [auxUserInfos, findUserIdentities, hasThickThreadWithUser], ); } diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js --- a/lib/shared/thread-utils.js +++ b/lib/shared/thread-utils.js @@ -37,6 +37,7 @@ pendingToRealizedThreadIDsSelector, threadInfosSelectorForThreadType, onScreenThreadInfos, + thickRawThreadInfosSelector, } from '../selectors/thread-selectors.js'; import { getRelativeMemberInfos, @@ -1895,6 +1896,19 @@ ); } +function useHasThickThreadWithUser(): (userID: string) => boolean { + const thickThreadInfos = useSelector(thickRawThreadInfosSelector); + + return React.useCallback( + (userID: string): boolean => { + return values(thickThreadInfos).some(thread => { + return userIsMember(thread, userID); + }); + }, + [thickThreadInfos], + ); +} + export { threadHasPermission, useCommunityRootMembersToRole, @@ -1965,4 +1979,5 @@ deviceListIsNonEmpty, deviceListCanBeRequestedForUser, expectedAccountDeletionUpdateTimeout, + useHasThickThreadWithUser, };