diff --git a/src/script/components/UserSearchableList.tsx b/src/script/components/UserSearchableList.tsx index ef988ee58b7..0b747dae1fa 100644 --- a/src/script/components/UserSearchableList.tsx +++ b/src/script/components/UserSearchableList.tsx @@ -98,14 +98,13 @@ const UserSearchableList: React.FC = ({ // Filter all list items if a filter is provided useEffect(() => { - const connectedUsers = conversationState.connectedUsers(); const {query: normalizedQuery} = searchRepository.normalizeQuery(filter); const results = searchRepository .searchUserInSet(filter, users) .filter( user => user.isMe || - connectedUsers.includes(user) || + conversationState.hasConversationWith(user) || teamRepository.isSelfConnectedTo(user.id) || user.username() === normalizedQuery, ); diff --git a/src/script/conversation/ConversationState.ts b/src/script/conversation/ConversationState.ts index dddd57f785a..38ebaf54c70 100644 --- a/src/script/conversation/ConversationState.ts +++ b/src/script/conversation/ConversationState.ts @@ -195,6 +195,14 @@ export class ConversationState { }); } + /** + * indicate whether the selfUser has a conversation with this other user + * @param user the user to check + */ + hasConversationWith(user: User) { + return this.connectedUsers().some(connectedUser => matchQualifiedIds(connectedUser.qualifiedId, user.qualifiedId)); + } + isSelfConversation(conversationId: QualifiedId): boolean { const selfConversationIds: QualifiedId[] = [this.selfProteusConversation(), this.selfMLSConversation()] .filter((conversation): conversation is Conversation => !!conversation) diff --git a/src/script/page/LeftSidebar/panels/StartUI/PeopleTab.tsx b/src/script/page/LeftSidebar/panels/StartUI/PeopleTab.tsx index 206e268c476..8dc822a55c1 100644 --- a/src/script/page/LeftSidebar/panels/StartUI/PeopleTab.tsx +++ b/src/script/page/LeftSidebar/panels/StartUI/PeopleTab.tsx @@ -101,10 +101,10 @@ export const PeopleTab = ({ const [hasFederationError, setHasFederationError] = useState(false); const currentSearchQuery = useRef(''); - const {connectedUsers} = useKoSubscribableChildren(conversationState, ['connectedUsers']); const {inTeam} = useKoSubscribableChildren(selfUser, ['inTeam']); const getLocalUsers = (unfiltered?: boolean) => { + const connectedUsers = conversationState.connectedUsers(); if (!canSearchUnconnectedUsers) { return connectedUsers; } @@ -118,7 +118,9 @@ export const PeopleTab = ({ contacts = unfiltered ? teamUsers - : teamUsers.filter(user => connectedUsers.includes(user) || teamRepository.isSelfConnectedTo(user.id)); + : teamUsers.filter( + user => conversationState.hasConversationWith(user) || teamRepository.isSelfConnectedTo(user.id), + ); } return contacts.filter(user => user.isAvailable()); @@ -178,9 +180,11 @@ export const PeopleTab = ({ const localSearchSources = getLocalUsers(true); const contactResults = searchRepository.searchUserInSet(searchQuery, localSearchSources); - const connectedUsers = conversationState.connectedUsers(); const filteredResults = contactResults.filter( - user => connectedUsers.includes(user) || teamRepository.isSelfConnectedTo(user.id) || user.username() === query, + user => + conversationState.hasConversationWith(user) || + teamRepository.isSelfConnectedTo(user.id) || + user.username() === query, ); const localSearchResults: SearchResultsData = {