Skip to content

Commit

Permalink
fix: Use qualified Ids when matching users for search filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc committed Nov 1, 2023
1 parent 945cb70 commit 8130e04
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/script/components/UserSearchableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,13 @@ const UserSearchableList: React.FC<UserListProps> = ({
// 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,
);
Expand Down
8 changes: 8 additions & 0 deletions src/script/conversation/ConversationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions src/script/page/LeftSidebar/panels/StartUI/PeopleTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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());
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 8130e04

Please sign in to comment.