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

Commit d9d0b84

Browse files
authored
Revert "Do not filter users post search (#9556)" (#11288)
1 parent ba90e0b commit d9d0b84

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

cypress/e2e/spotlight/spotlight.spec.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ describe("Spotlight", () => {
345345
cy.spotlightFilter(Filter.People);
346346
cy.spotlightSearch().clear().type(bot2Name);
347347
cy.spotlightResults().should("have.length", 1);
348-
cy.spotlightResults().contains(bot2Name).click();
348+
cy.spotlightResults().eq(0).should("contain", bot2Name);
349+
cy.spotlightResults().eq(0).click();
349350
})
350351
.then(() => {
351352
cy.roomHeaderName().should("contain", bot2Name);
@@ -360,7 +361,9 @@ describe("Spotlight", () => {
360361
cy.openSpotlightDialog().within(() => {
361362
cy.spotlightFilter(Filter.People);
362363
cy.spotlightSearch().clear().type(bot2Name);
363-
cy.spotlightResults().contains(bot2Name).click();
364+
cy.spotlightResults().should("have.length", 1);
365+
cy.spotlightResults().eq(0).should("contain", bot2Name);
366+
cy.spotlightResults().eq(0).click();
364367
});
365368

366369
// Send first message to actually start DM
@@ -387,21 +390,23 @@ describe("Spotlight", () => {
387390
cy.spotlightFilter(Filter.People);
388391
cy.spotlightSearch().clear().type(bot1.getUserId());
389392
cy.wait(1000); // wait for the dialog code to settle
393+
cy.spotlightResults().should("have.length", 2);
390394
cy.contains(
391395
".mx_SpotlightDialog_section.mx_SpotlightDialog_results .mx_SpotlightDialog_option",
392396
groupDm.name,
393-
).should("exist");
397+
);
394398
});
395399

396400
// Search for ByteBot by id, should return group DM and user
397401
cy.openSpotlightDialog().within(() => {
398402
cy.spotlightFilter(Filter.People);
399403
cy.spotlightSearch().clear().type(bot2.getUserId());
400404
cy.wait(1000); // wait for the dialog code to settle
405+
cy.spotlightResults().should("have.length", 2);
401406
cy.contains(
402407
".mx_SpotlightDialog_section.mx_SpotlightDialog_results .mx_SpotlightDialog_option",
403408
groupDm.name,
404-
).should("exist");
409+
);
405410
});
406411
});
407412
});
@@ -431,7 +436,9 @@ describe("Spotlight", () => {
431436
.within(() => {
432437
cy.spotlightFilter(Filter.People);
433438
cy.spotlightSearch().clear().type(bot2Name);
434-
cy.spotlightResults().should("contain", bot2Name);
439+
cy.wait(3000); // wait for the dialog code to settle
440+
cy.spotlightResults().should("have.length", 1);
441+
cy.spotlightResults().eq(0).should("contain", bot2Name);
435442
cy.get(".mx_SpotlightDialog_startGroupChat").should("contain", "Start a group chat");
436443
cy.get(".mx_SpotlightDialog_startGroupChat").click();
437444
})

src/components/views/dialogs/spotlight/SpotlightDialog.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
399399
)
400400
return; // bail, does not match query
401401
} else if (isMemberResult(entry)) {
402-
// Do not filter users as we rely on the server to filter them for us.
403-
// The server may filter based on fields we do not have access to, e.g. e-mail addresses.
402+
if (!entry.query?.some((q) => q.includes(lcQuery))) return; // bail, does not match query
404403
} else if (isPublicRoomResult(entry)) {
405404
if (!entry.query?.some((q) => q.includes(lcQuery))) return; // bail, does not match query
406405
} else {

test/components/views/dialogs/SpotlightDialog-test.tsx

-21
Original file line numberDiff line numberDiff line change
@@ -338,27 +338,6 @@ describe("Spotlight Dialog", () => {
338338
});
339339
});
340340

341-
it("should not filter out users sent by the server", async () => {
342-
mocked(mockedClient.searchUserDirectory).mockResolvedValue({
343-
results: [
344-
{ user_id: "@user1:server", display_name: "User Alpha", avatar_url: "mxc://1/avatar" },
345-
{ user_id: "@user2:server", display_name: "User Beta", avatar_url: "mxc://2/avatar" },
346-
],
347-
limited: false,
348-
});
349-
350-
render(<SpotlightDialog initialFilter={Filter.People} initialText="Alpha" onFinished={() => null} />);
351-
// search is debounced
352-
jest.advanceTimersByTime(200);
353-
await flushPromisesWithFakeTimers();
354-
355-
const content = document.querySelector("#mx_SpotlightDialog_content")!;
356-
const options = content.querySelectorAll("li.mx_SpotlightDialog_option");
357-
expect(options.length).toBeGreaterThanOrEqual(2);
358-
expect(options[0]).toHaveTextContent("User Alpha");
359-
expect(options[1]).toHaveTextContent("User Beta");
360-
});
361-
362341
it("should start a DM when clicking a person", async () => {
363342
render(
364343
<SpotlightDialog

0 commit comments

Comments
 (0)