From c51b5d56c4e2e98f785558f7dcfba668069696b1 Mon Sep 17 00:00:00 2001 From: Malek Date: Tue, 8 Nov 2022 16:02:23 +0100 Subject: [PATCH 1/3] Do not filter users post search Signed-off-by: Maximilian Malek --- src/components/views/dialogs/spotlight/SpotlightDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx index f000d3bf4ba..1cc244c19ed 100644 --- a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx +++ b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx @@ -408,7 +408,7 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n !entry.query?.some(q => q.includes(lcQuery)) ) return; // bail, does not match query } else if (isMemberResult(entry)) { - if (!entry.query?.some(q => q.includes(lcQuery))) return; // bail, does not match query + // Do not filter users } else if (isPublicRoomResult(entry)) { if (!entry.query?.some(q => q.includes(lcQuery))) return; // bail, does not match query } else { From 1eafd8d53a301ae8d8dfd5ca4c5066e1cd6e76d9 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 17 Jul 2023 14:45:57 +0100 Subject: [PATCH 2/3] Iterate --- .../dialogs/spotlight/SpotlightDialog.tsx | 3 ++- .../views/dialogs/SpotlightDialog-test.tsx | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx index ce6ed85f430..6d3cc56f333 100644 --- a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx +++ b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx @@ -399,7 +399,8 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n ) return; // bail, does not match query } else if (isMemberResult(entry)) { - // Do not filter users + // Do not filter users as we rely on the server to filter them for us. + // The server may filter based on fields we do not have access to, e.g. e-mail addresses. } else if (isPublicRoomResult(entry)) { if (!entry.query?.some((q) => q.includes(lcQuery))) return; // bail, does not match query } else { diff --git a/test/components/views/dialogs/SpotlightDialog-test.tsx b/test/components/views/dialogs/SpotlightDialog-test.tsx index 28572253092..d842ecb727a 100644 --- a/test/components/views/dialogs/SpotlightDialog-test.tsx +++ b/test/components/views/dialogs/SpotlightDialog-test.tsx @@ -338,6 +338,27 @@ describe("Spotlight Dialog", () => { }); }); + it("should not filter out users sent by the server", async () => { + mocked(mockedClient.searchUserDirectory).mockResolvedValue({ + results: [ + { user_id: "@user1:server", display_name: "User Alpha", avatar_url: "mxc://1/avatar" }, + { user_id: "@user2:server", display_name: "User Beta", avatar_url: "mxc://2/avatar" }, + ], + limited: false, + }); + + render( null} />); + // search is debounced + jest.advanceTimersByTime(200); + await flushPromisesWithFakeTimers(); + + const content = document.querySelector("#mx_SpotlightDialog_content")!; + const options = content.querySelectorAll("li.mx_SpotlightDialog_option"); + expect(options.length).toBeGreaterThanOrEqual(2); + expect(options[0]).toHaveTextContent("User Alpha"); + expect(options[1]).toHaveTextContent("User Beta"); + }); + it("should start a DM when clicking a person", async () => { render( Date: Mon, 17 Jul 2023 16:03:43 +0100 Subject: [PATCH 3/3] Iterate --- cypress/e2e/spotlight/spotlight.spec.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/cypress/e2e/spotlight/spotlight.spec.ts b/cypress/e2e/spotlight/spotlight.spec.ts index 507fc2d75fb..2274fe75dd0 100644 --- a/cypress/e2e/spotlight/spotlight.spec.ts +++ b/cypress/e2e/spotlight/spotlight.spec.ts @@ -345,8 +345,7 @@ describe("Spotlight", () => { cy.spotlightFilter(Filter.People); cy.spotlightSearch().clear().type(bot2Name); cy.spotlightResults().should("have.length", 1); - cy.spotlightResults().eq(0).should("contain", bot2Name); - cy.spotlightResults().eq(0).click(); + cy.spotlightResults().contains(bot2Name).click(); }) .then(() => { cy.roomHeaderName().should("contain", bot2Name); @@ -361,9 +360,7 @@ describe("Spotlight", () => { cy.openSpotlightDialog().within(() => { cy.spotlightFilter(Filter.People); cy.spotlightSearch().clear().type(bot2Name); - cy.spotlightResults().should("have.length", 1); - cy.spotlightResults().eq(0).should("contain", bot2Name); - cy.spotlightResults().eq(0).click(); + cy.spotlightResults().contains(bot2Name).click(); }); // Send first message to actually start DM @@ -390,11 +387,10 @@ describe("Spotlight", () => { cy.spotlightFilter(Filter.People); cy.spotlightSearch().clear().type(bot1.getUserId()); cy.wait(1000); // wait for the dialog code to settle - cy.spotlightResults().should("have.length", 2); cy.contains( ".mx_SpotlightDialog_section.mx_SpotlightDialog_results .mx_SpotlightDialog_option", groupDm.name, - ); + ).should("exist"); }); // Search for ByteBot by id, should return group DM and user @@ -402,11 +398,10 @@ describe("Spotlight", () => { cy.spotlightFilter(Filter.People); cy.spotlightSearch().clear().type(bot2.getUserId()); cy.wait(1000); // wait for the dialog code to settle - cy.spotlightResults().should("have.length", 2); cy.contains( ".mx_SpotlightDialog_section.mx_SpotlightDialog_results .mx_SpotlightDialog_option", groupDm.name, - ); + ).should("exist"); }); }); }); @@ -436,9 +431,7 @@ describe("Spotlight", () => { .within(() => { cy.spotlightFilter(Filter.People); cy.spotlightSearch().clear().type(bot2Name); - cy.wait(3000); // wait for the dialog code to settle - cy.spotlightResults().should("have.length", 1); - cy.spotlightResults().eq(0).should("contain", bot2Name); + cy.spotlightResults().should("contain", bot2Name); cy.get(".mx_SpotlightDialog_startGroupChat").should("contain", "Start a group chat"); cy.get(".mx_SpotlightDialog_startGroupChat").click(); })