Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Do not filter users post search #9556

Merged
merged 5 commits into from
Jul 17, 2023
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
!entry.query?.some(q => q.includes(lcQuery))
) return; // bail, does not match query
} else if (isMemberResult(entry)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to remove the if statement completely

if (!entry.query?.some(q => q.includes(lcQuery))) return; // bail, does not match query
// Do not filter users
Copy link
Member

@t3chguy t3chguy Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment needs to say WHY (because we rely on the server to filter DIRECTORY results for us)

Copy link
Contributor

@HarHarLinks HarHarLinks Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate why clientside filtering is done in the first place? I think the spec suggests nothing of the kind, and I think additional validation seems superfluous since the server should be trustworthy enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a copy-pasta, but you'd need to ask whomever wrote it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HarHarLinks and me investigated it further and found the following:

The component has different sources for the users: (1) the results from the user profile endpoint and (2) all users that joined any room that I am in.

(1) was already server-side filtered using the user entered query:

useDebouncedCallback(filter === Filter.People, searchPeople, searchParams);

(2) is not pre-filtered, but every user is added to the possible user results:

for (const user of [...findVisibleRoomMembers(cli, msc3946ProcessDynamicPredecessor), ...users]) {
// Make sure we don't have any user more than once
if (alreadyAddedUserIds.has(user.userId)) continue;
alreadyAddedUserIds.add(user.userId);
userResults.push(toMemberResult(user));
}

The conditional in discussion is thus required to filter the users in (2):

} else if (isMemberResult(entry)) {
if (!entry.query?.some((q) => q.includes(lcQuery))) return; // bail, does not match query

However, this line will also filter the results that were already filtered by the server. This shouldn't be necessary because I would assume that we can trust that the homeserver returns proper results.

Proposal

We would propose some refactorings to remove the double-filtering of the server results:

  // ...
+ const localUsers = findVisibleRoomMembers(cli, msc3946ProcessDynamicPredecessor).filter(... apply the filtering by trimmedQuery ...);
+ for (const user of [...localUsers, ...users]) {
- for (const user of [...findVisibleRoomMembers(cli, msc3946ProcessDynamicPredecessor), ...users]) {
      // Make sure we don't have any user more than once
      if (alreadyAddedUserIds.has(user.userId)) continue;
      alreadyAddedUserIds.add(user.userId);
  
      userResults.push(toMemberResult(user));
  }
  
  // ...

With this change, the filtering of the possibleResults can be skipped:

- } else if (isMemberResult(entry)) {
-   if (!entry.query?.some((q) => q.includes(lcQuery))) return; // bail, does not match query

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further, we suggest to add our use-case to the tests.

} else if (isPublicRoomResult(entry)) {
if (!entry.query?.some(q => q.includes(lcQuery))) return; // bail, does not match query
} else {
Expand Down