From 97bcf1d9a0fad2dc63dabbabbf87ad11897055d8 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Sun, 10 Apr 2022 15:51:38 +0100 Subject: [PATCH 01/23] fix matrix search link --- src/components/structures/RoomDirectory.tsx | 11 +++++++++-- src/components/structures/RoomSearch.tsx | 6 +++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/structures/RoomDirectory.tsx b/src/components/structures/RoomDirectory.tsx index 5577bc29e70..73cdc0f8da9 100644 --- a/src/components/structures/RoomDirectory.tsx +++ b/src/components/structures/RoomDirectory.tsx @@ -43,6 +43,7 @@ import { Action } from "../../dispatcher/actions"; import PosthogTrackers from "../../PosthogTrackers"; import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload"; import { PublicRoomTile } from "../views/rooms/PublicRoomTile"; +import { filter } from "jszip"; const LAST_SERVER_KEY = "mx_last_room_directory_server"; const LAST_INSTANCE_KEY = "mx_last_room_directory_instance"; @@ -164,6 +165,10 @@ export default class RoomDirectory extends React.Component { this.getMoreRooms(); }; + private transformSearchTerm(term: string): string { + return term.substring(term.lastIndexOf("#")); + }; + private getMoreRooms(): Promise { if (!MatrixClientPeg.get()) return Promise.resolve(false); @@ -186,7 +191,7 @@ export default class RoomDirectory extends React.Component { opts.third_party_instance_id = this.state.instanceId as string; } if (this.nextBatch) opts.since = this.nextBatch; - if (filterString) opts.filter = { generic_search_term: filterString }; + if (filterString) opts.filter = { generic_search_term: this.transformSearchTerm(filterString) }; return MatrixClientPeg.get().publicRooms(opts).then((data) => { if ( filterString != this.state.filterString || @@ -203,8 +208,10 @@ export default class RoomDirectory extends React.Component { return false; } + this.nextBatch = data.next_batch; this.setState((s) => ({ + ...s, publicRooms: [...s.publicRooms, ...(data.chunk || [])], loading: false, @@ -322,7 +329,7 @@ export default class RoomDirectory extends React.Component { private onFilterChange = (alias: string) => { this.setState({ - filterString: alias?.trim() || "", + filterString: this.transformSearchTerm(alias?.trim()) || "", }); // don't send the request for a little bit, diff --git a/src/components/structures/RoomSearch.tsx b/src/components/structures/RoomSearch.tsx index 94212927641..6d540d33e08 100644 --- a/src/components/structures/RoomSearch.tsx +++ b/src/components/structures/RoomSearch.tsx @@ -134,9 +134,13 @@ export default class RoomSearch extends React.PureComponent { } }; + private transformSearchTerm(term: string): string { + return term.substring(term.lastIndexOf("#")); + }; + private onChange = () => { if (this.elementRef.current?.tagName !== "INPUT") return; - this.setState({ query: (this.elementRef.current as HTMLInputElement).value }); + this.setState({ query: this.transformSearchTerm((this.elementRef.current as HTMLInputElement).value) }); }; private onFocus = (ev: React.FocusEvent) => { From 604a6ed369cb75528908a97f042e6962ea7cdf29 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Sun, 10 Apr 2022 16:04:42 +0100 Subject: [PATCH 02/23] fix matrix search link Signed-off-by: Boluwatife Omosowon --- src/components/structures/RoomDirectory.tsx | 11 ++--------- src/components/structures/RoomSearch.tsx | 6 +----- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/components/structures/RoomDirectory.tsx b/src/components/structures/RoomDirectory.tsx index 73cdc0f8da9..5577bc29e70 100644 --- a/src/components/structures/RoomDirectory.tsx +++ b/src/components/structures/RoomDirectory.tsx @@ -43,7 +43,6 @@ import { Action } from "../../dispatcher/actions"; import PosthogTrackers from "../../PosthogTrackers"; import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload"; import { PublicRoomTile } from "../views/rooms/PublicRoomTile"; -import { filter } from "jszip"; const LAST_SERVER_KEY = "mx_last_room_directory_server"; const LAST_INSTANCE_KEY = "mx_last_room_directory_instance"; @@ -165,10 +164,6 @@ export default class RoomDirectory extends React.Component { this.getMoreRooms(); }; - private transformSearchTerm(term: string): string { - return term.substring(term.lastIndexOf("#")); - }; - private getMoreRooms(): Promise { if (!MatrixClientPeg.get()) return Promise.resolve(false); @@ -191,7 +186,7 @@ export default class RoomDirectory extends React.Component { opts.third_party_instance_id = this.state.instanceId as string; } if (this.nextBatch) opts.since = this.nextBatch; - if (filterString) opts.filter = { generic_search_term: this.transformSearchTerm(filterString) }; + if (filterString) opts.filter = { generic_search_term: filterString }; return MatrixClientPeg.get().publicRooms(opts).then((data) => { if ( filterString != this.state.filterString || @@ -208,10 +203,8 @@ export default class RoomDirectory extends React.Component { return false; } - this.nextBatch = data.next_batch; this.setState((s) => ({ - ...s, publicRooms: [...s.publicRooms, ...(data.chunk || [])], loading: false, @@ -329,7 +322,7 @@ export default class RoomDirectory extends React.Component { private onFilterChange = (alias: string) => { this.setState({ - filterString: this.transformSearchTerm(alias?.trim()) || "", + filterString: alias?.trim() || "", }); // don't send the request for a little bit, diff --git a/src/components/structures/RoomSearch.tsx b/src/components/structures/RoomSearch.tsx index 6d540d33e08..94212927641 100644 --- a/src/components/structures/RoomSearch.tsx +++ b/src/components/structures/RoomSearch.tsx @@ -134,13 +134,9 @@ export default class RoomSearch extends React.PureComponent { } }; - private transformSearchTerm(term: string): string { - return term.substring(term.lastIndexOf("#")); - }; - private onChange = () => { if (this.elementRef.current?.tagName !== "INPUT") return; - this.setState({ query: this.transformSearchTerm((this.elementRef.current as HTMLInputElement).value) }); + this.setState({ query: (this.elementRef.current as HTMLInputElement).value }); }; private onFocus = (ev: React.FocusEvent) => { From 9ba6051fc3fff165323cade51660707b26406aa8 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Sun, 10 Apr 2022 16:50:34 +0100 Subject: [PATCH 03/23] fix: allow full link search Signed-off-by: Boluwatife Omosowon --- src/components/structures/RoomDirectory.tsx | 8 ++++++-- src/components/structures/RoomSearch.tsx | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/structures/RoomDirectory.tsx b/src/components/structures/RoomDirectory.tsx index 5577bc29e70..9b75ff7812b 100644 --- a/src/components/structures/RoomDirectory.tsx +++ b/src/components/structures/RoomDirectory.tsx @@ -164,6 +164,10 @@ export default class RoomDirectory extends React.Component { this.getMoreRooms(); }; + private transformSearchTerm(term: string): string { + return term.substring(term.lastIndexOf("#")); + }; + private getMoreRooms(): Promise { if (!MatrixClientPeg.get()) return Promise.resolve(false); @@ -186,7 +190,7 @@ export default class RoomDirectory extends React.Component { opts.third_party_instance_id = this.state.instanceId as string; } if (this.nextBatch) opts.since = this.nextBatch; - if (filterString) opts.filter = { generic_search_term: filterString }; + if (filterString) opts.filter = { generic_search_term: this.transformSearchTerm(filterString) }; return MatrixClientPeg.get().publicRooms(opts).then((data) => { if ( filterString != this.state.filterString || @@ -322,7 +326,7 @@ export default class RoomDirectory extends React.Component { private onFilterChange = (alias: string) => { this.setState({ - filterString: alias?.trim() || "", + filterString: this.transformSearchTerm(alias?.trim()) || "", }); // don't send the request for a little bit, diff --git a/src/components/structures/RoomSearch.tsx b/src/components/structures/RoomSearch.tsx index 94212927641..6d540d33e08 100644 --- a/src/components/structures/RoomSearch.tsx +++ b/src/components/structures/RoomSearch.tsx @@ -134,9 +134,13 @@ export default class RoomSearch extends React.PureComponent { } }; + private transformSearchTerm(term: string): string { + return term.substring(term.lastIndexOf("#")); + }; + private onChange = () => { if (this.elementRef.current?.tagName !== "INPUT") return; - this.setState({ query: (this.elementRef.current as HTMLInputElement).value }); + this.setState({ query: this.transformSearchTerm((this.elementRef.current as HTMLInputElement).value) }); }; private onFocus = (ev: React.FocusEvent) => { From 9d10d95882feae1713d28feae4b1e4cf8472be1c Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Sun, 10 Apr 2022 17:42:25 +0100 Subject: [PATCH 04/23] fix: allow full link search on new search feature Signed-off-by: Boluwatife Omosowon --- src/components/views/dialogs/SpotlightDialog.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/views/dialogs/SpotlightDialog.tsx b/src/components/views/dialogs/SpotlightDialog.tsx index f579e262875..6461f8ac927 100644 --- a/src/components/views/dialogs/SpotlightDialog.tsx +++ b/src/components/views/dialogs/SpotlightDialog.tsx @@ -230,6 +230,10 @@ export const useWebSearchMetrics = (numResults: number, queryLength: number, via }, [numResults, queryLength, viaSpotlight]); }; +function transformSearchTerm(term: string): string { + return term.substring(term.lastIndexOf("#")); +}; + const SpotlightDialog: React.FC = ({ initialText = "", onFinished }) => { const cli = MatrixClientPeg.get(); const rovingContext = useContext(RovingTabIndexContext); @@ -305,7 +309,7 @@ const SpotlightDialog: React.FC = ({ initialText = "", onFinished }) => const [spaceResults, spaceResultsLoading] = useSpaceResults(activeSpace, query); const setQuery = (e: ChangeEvent): void => { - const newQuery = e.currentTarget.value; + const newQuery = transformSearchTerm(e.currentTarget.value); _setQuery(newQuery); setImmediate(() => { From 85c9d663311e4d105029edbe96aabc93243de07e Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Sun, 10 Apr 2022 18:22:47 +0100 Subject: [PATCH 05/23] improve transformSearchTerm function Signed-off-by: Boluwatife Omosowon --- src/components/structures/RoomDirectory.tsx | 2 +- src/components/structures/RoomSearch.tsx | 2 +- src/components/views/dialogs/SpotlightDialog.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/structures/RoomDirectory.tsx b/src/components/structures/RoomDirectory.tsx index 9b75ff7812b..5a6ac03a08c 100644 --- a/src/components/structures/RoomDirectory.tsx +++ b/src/components/structures/RoomDirectory.tsx @@ -165,7 +165,7 @@ export default class RoomDirectory extends React.Component { }; private transformSearchTerm(term: string): string { - return term.substring(term.lastIndexOf("#")); + return term.substring(term.indexOf("#") +2); }; private getMoreRooms(): Promise { diff --git a/src/components/structures/RoomSearch.tsx b/src/components/structures/RoomSearch.tsx index 6d540d33e08..a5a0cd45b0d 100644 --- a/src/components/structures/RoomSearch.tsx +++ b/src/components/structures/RoomSearch.tsx @@ -135,7 +135,7 @@ export default class RoomSearch extends React.PureComponent { }; private transformSearchTerm(term: string): string { - return term.substring(term.lastIndexOf("#")); + return term.substring(term.indexOf("#") +2); }; private onChange = () => { diff --git a/src/components/views/dialogs/SpotlightDialog.tsx b/src/components/views/dialogs/SpotlightDialog.tsx index 6461f8ac927..2799407f024 100644 --- a/src/components/views/dialogs/SpotlightDialog.tsx +++ b/src/components/views/dialogs/SpotlightDialog.tsx @@ -231,7 +231,7 @@ export const useWebSearchMetrics = (numResults: number, queryLength: number, via }; function transformSearchTerm(term: string): string { - return term.substring(term.lastIndexOf("#")); + return term.substring(term.indexOf("#") +2); }; const SpotlightDialog: React.FC = ({ initialText = "", onFinished }) => { From 225bcab0037b3ecc83b547993872cf4c55983a5d Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Sun, 10 Apr 2022 20:15:55 +0100 Subject: [PATCH 06/23] improve transformSearchTerm function Signed-off-by: Boluwatife Omosowon --- src/components/structures/RoomDirectory.tsx | 9 ++---- src/components/structures/RoomSearch.tsx | 8 ++--- .../views/dialogs/SpotlightDialog.tsx | 4 +-- src/utils/SearchInput.ts | 31 +++++++++++++++++++ 4 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 src/utils/SearchInput.ts diff --git a/src/components/structures/RoomDirectory.tsx b/src/components/structures/RoomDirectory.tsx index 5a6ac03a08c..d46616a62fd 100644 --- a/src/components/structures/RoomDirectory.tsx +++ b/src/components/structures/RoomDirectory.tsx @@ -43,6 +43,7 @@ import { Action } from "../../dispatcher/actions"; import PosthogTrackers from "../../PosthogTrackers"; import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload"; import { PublicRoomTile } from "../views/rooms/PublicRoomTile"; +import { transformSearchTerm } from "../../utils/SearchInput"; const LAST_SERVER_KEY = "mx_last_room_directory_server"; const LAST_INSTANCE_KEY = "mx_last_room_directory_instance"; @@ -164,10 +165,6 @@ export default class RoomDirectory extends React.Component { this.getMoreRooms(); }; - private transformSearchTerm(term: string): string { - return term.substring(term.indexOf("#") +2); - }; - private getMoreRooms(): Promise { if (!MatrixClientPeg.get()) return Promise.resolve(false); @@ -190,7 +187,7 @@ export default class RoomDirectory extends React.Component { opts.third_party_instance_id = this.state.instanceId as string; } if (this.nextBatch) opts.since = this.nextBatch; - if (filterString) opts.filter = { generic_search_term: this.transformSearchTerm(filterString) }; + if (filterString) opts.filter = { generic_search_term: transformSearchTerm(filterString) }; return MatrixClientPeg.get().publicRooms(opts).then((data) => { if ( filterString != this.state.filterString || @@ -326,7 +323,7 @@ export default class RoomDirectory extends React.Component { private onFilterChange = (alias: string) => { this.setState({ - filterString: this.transformSearchTerm(alias?.trim()) || "", + filterString: transformSearchTerm(alias?.trim()) || "", }); // don't send the request for a little bit, diff --git a/src/components/structures/RoomSearch.tsx b/src/components/structures/RoomSearch.tsx index a5a0cd45b0d..9313ea50878 100644 --- a/src/components/structures/RoomSearch.tsx +++ b/src/components/structures/RoomSearch.tsx @@ -34,6 +34,8 @@ import Modal from "../../Modal"; import SpotlightDialog from "../views/dialogs/SpotlightDialog"; import { ALTERNATE_KEY_NAME, KeyBindingAction } from "../../accessibility/KeyboardShortcuts"; import ToastStore from "../../stores/ToastStore"; +import { transformSearchTerm } from "../../utils/SearchInput"; + interface IProps { isMinimized: boolean; @@ -134,13 +136,11 @@ export default class RoomSearch extends React.PureComponent { } }; - private transformSearchTerm(term: string): string { - return term.substring(term.indexOf("#") +2); - }; + private onChange = () => { if (this.elementRef.current?.tagName !== "INPUT") return; - this.setState({ query: this.transformSearchTerm((this.elementRef.current as HTMLInputElement).value) }); + this.setState({ query: transformSearchTerm((this.elementRef.current as HTMLInputElement).value) }); }; private onFocus = (ev: React.FocusEvent) => { diff --git a/src/components/views/dialogs/SpotlightDialog.tsx b/src/components/views/dialogs/SpotlightDialog.tsx index 2799407f024..30ee4bd5658 100644 --- a/src/components/views/dialogs/SpotlightDialog.tsx +++ b/src/components/views/dialogs/SpotlightDialog.tsx @@ -74,6 +74,7 @@ import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts"; import { PosthogAnalytics } from "../../../PosthogAnalytics"; import { getCachedRoomIDForAlias } from "../../../RoomAliasCache"; import { roomContextDetailsText, spaceContextDetailsText } from "../../../utils/i18n-helpers"; +import { transformSearchTerm } from "../../../utils/SearchInput"; const MAX_RECENT_SEARCHES = 10; const SECTION_LIMIT = 50; // only show 50 results per section for performance reasons @@ -230,9 +231,6 @@ export const useWebSearchMetrics = (numResults: number, queryLength: number, via }, [numResults, queryLength, viaSpotlight]); }; -function transformSearchTerm(term: string): string { - return term.substring(term.indexOf("#") +2); -}; const SpotlightDialog: React.FC = ({ initialText = "", onFinished }) => { const cli = MatrixClientPeg.get(); diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts new file mode 100644 index 00000000000..f0521037121 --- /dev/null +++ b/src/utils/SearchInput.ts @@ -0,0 +1,31 @@ +/* +Copyright 2021 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + +/** + * Strips a string of https://matrix.to/#/ + * eg https://matrix.to/#/#element-dev:matrix.org returns #element-dev:matrix.org + * + * @param {string} term The searchterm . + * @returns {string} Modifies string if it contains with https://matrix.to/#/ . + */ + +export function transformSearchTerm(term: string): string { + if (/https:\/\/matrix.to\/#\//.test(term)) { + term = term.replace("https://matrix.to/#/", ""); + } + return term; +} From 4c6e4c0a2f109627263e4ff09bf17f2ec309ed6e Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Fri, 15 Apr 2022 17:58:55 +0100 Subject: [PATCH 07/23] add review changes --- src/components/structures/RoomSearch.tsx | 6 +----- src/components/views/dialogs/SpotlightDialog.tsx | 1 - src/utils/SearchInput.ts | 5 +---- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/components/structures/RoomSearch.tsx b/src/components/structures/RoomSearch.tsx index 9313ea50878..94212927641 100644 --- a/src/components/structures/RoomSearch.tsx +++ b/src/components/structures/RoomSearch.tsx @@ -34,8 +34,6 @@ import Modal from "../../Modal"; import SpotlightDialog from "../views/dialogs/SpotlightDialog"; import { ALTERNATE_KEY_NAME, KeyBindingAction } from "../../accessibility/KeyboardShortcuts"; import ToastStore from "../../stores/ToastStore"; -import { transformSearchTerm } from "../../utils/SearchInput"; - interface IProps { isMinimized: boolean; @@ -136,11 +134,9 @@ export default class RoomSearch extends React.PureComponent { } }; - - private onChange = () => { if (this.elementRef.current?.tagName !== "INPUT") return; - this.setState({ query: transformSearchTerm((this.elementRef.current as HTMLInputElement).value) }); + this.setState({ query: (this.elementRef.current as HTMLInputElement).value }); }; private onFocus = (ev: React.FocusEvent) => { diff --git a/src/components/views/dialogs/SpotlightDialog.tsx b/src/components/views/dialogs/SpotlightDialog.tsx index 30ee4bd5658..502af43ea63 100644 --- a/src/components/views/dialogs/SpotlightDialog.tsx +++ b/src/components/views/dialogs/SpotlightDialog.tsx @@ -231,7 +231,6 @@ export const useWebSearchMetrics = (numResults: number, queryLength: number, via }, [numResults, queryLength, viaSpotlight]); }; - const SpotlightDialog: React.FC = ({ initialText = "", onFinished }) => { const cli = MatrixClientPeg.get(); const rovingContext = useContext(RovingTabIndexContext); diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index f0521037121..e0d8e909bcd 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -1,5 +1,5 @@ /* -Copyright 2021 The Matrix.org Foundation C.I.C. +Copyright 2022 Boluwatife Omosowon boluomosowon@gmail.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -13,8 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - - /** * Strips a string of https://matrix.to/#/ * eg https://matrix.to/#/#element-dev:matrix.org returns #element-dev:matrix.org @@ -22,7 +20,6 @@ limitations under the License. * @param {string} term The searchterm . * @returns {string} Modifies string if it contains with https://matrix.to/#/ . */ - export function transformSearchTerm(term: string): string { if (/https:\/\/matrix.to\/#\//.test(term)) { term = term.replace("https://matrix.to/#/", ""); From bef2ac589d89dae81c58734fc762a710ac295873 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Sat, 16 Apr 2022 22:20:45 +0100 Subject: [PATCH 08/23] Signed-off-by: Boluwatife Omosowon added review correction changed the transformSearchTerm function to use parsePermaLink removed extra spaces --- src/components/structures/RoomDirectory.tsx | 1 - src/utils/SearchInput.ts | 21 +++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/structures/RoomDirectory.tsx b/src/components/structures/RoomDirectory.tsx index d46616a62fd..302505d20a2 100644 --- a/src/components/structures/RoomDirectory.tsx +++ b/src/components/structures/RoomDirectory.tsx @@ -325,7 +325,6 @@ export default class RoomDirectory extends React.Component { this.setState({ filterString: transformSearchTerm(alias?.trim()) || "", }); - // don't send the request for a little bit, // no point hammering the server with a // request for every keystroke, let the diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index e0d8e909bcd..18c00257ab3 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -13,16 +13,17 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ + +import { parsePermalink } from "../utils/permalinks/Permalinks"; + /** - * Strips a string of https://matrix.to/#/ - * eg https://matrix.to/#/#element-dev:matrix.org returns #element-dev:matrix.org - * - * @param {string} term The searchterm . - * @returns {string} Modifies string if it contains with https://matrix.to/#/ . + * Return the roomId or alias of an element or matrix room link + * E.g https://matrix.to/#/#element-dev:matrix.org returns #element-dev:matrix.org + * @param {string} searchTerm The searchterm . + * @returns {string} Tranforms the string to its roomid or alias if it is a matrix or element link. */ -export function transformSearchTerm(term: string): string { - if (/https:\/\/matrix.to\/#\//.test(term)) { - term = term.replace("https://matrix.to/#/", ""); - } - return term; +export function transformSearchTerm(searchTerm: string): string { + const parseLink = parsePermalink(searchTerm); + if (parseLink) return parseLink.roomIdOrAlias; + return searchTerm; } From 1dba9197840ed8ad99f521552477be36618c02dd Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Sat, 16 Apr 2022 22:48:41 +0100 Subject: [PATCH 09/23] add angle brackets to copyright email title --- src/utils/SearchInput.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index 18c00257ab3..46006d4b3d6 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -1,5 +1,5 @@ /* -Copyright 2022 Boluwatife Omosowon boluomosowon@gmail.com +Copyright 2022 Boluwatife Omosowon Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From c26fbf2bcc177f9a4b8852d2c2e7719238717360 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Sun, 17 Apr 2022 12:54:04 +0100 Subject: [PATCH 10/23] removed extra space Signed-off-by: Boluwatife Omosowon --- src/utils/SearchInput.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index 46006d4b3d6..b965cf7b1dc 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -1,5 +1,5 @@ /* -Copyright 2022 Boluwatife Omosowon +Copyright 2022 Boluwatife Omosowon Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ import { parsePermalink } from "../utils/permalinks/Permalinks"; /** * Return the roomId or alias of an element or matrix room link * E.g https://matrix.to/#/#element-dev:matrix.org returns #element-dev:matrix.org - * @param {string} searchTerm The searchterm . + * @param {string} searchTerm The searchterm. * @returns {string} Tranforms the string to its roomid or alias if it is a matrix or element link. */ export function transformSearchTerm(searchTerm: string): string { From 3adaca098b18a3aaaeef558b8f5f74e7ca037944 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon <59070723+bolu-tife@users.noreply.github.com> Date: Mon, 6 Mar 2023 21:10:57 +0100 Subject: [PATCH 11/23] Update src/utils/SearchInput.ts Co-authored-by: Travis Ralston --- src/utils/SearchInput.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index b965cf7b1dc..48b0161134b 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -17,10 +17,11 @@ limitations under the License. import { parsePermalink } from "../utils/permalinks/Permalinks"; /** - * Return the roomId or alias of an element or matrix room link + * Parse a search string and return either a room ID/alias or the original search term if it does + * not look like a permalink. * E.g https://matrix.to/#/#element-dev:matrix.org returns #element-dev:matrix.org - * @param {string} searchTerm The searchterm. - * @returns {string} Tranforms the string to its roomid or alias if it is a matrix or element link. + * @param {string} searchTerm The search term. + * @returns {string} The room ID or alias, or the original search term if it doesn't look like a permalink. */ export function transformSearchTerm(searchTerm: string): string { const parseLink = parsePermalink(searchTerm); From 2dfea1141500f94fbbabdd409bb469bb2be9d86f Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Tue, 7 Mar 2023 17:18:42 +0100 Subject: [PATCH 12/23] fixed spolight dialog search for room and user links --- src/components/views/dialogs/spotlight/SpotlightDialog.tsx | 3 ++- src/utils/SearchInput.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx index ab7c5397de8..3ad1ad325d9 100644 --- a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx +++ b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx @@ -93,6 +93,7 @@ import { shouldShowFeedback } from "../../../../utils/Feedback"; import RoomAvatar from "../../avatars/RoomAvatar"; import { useFeatureEnabled } from "../../../../hooks/useSettings"; import { filterBoolean } from "../../../../utils/arrays"; +import { transformSearchTerm } from "../../../../utils/SearchInput"; const MAX_RECENT_SEARCHES = 10; const SECTION_LIMIT = 50; // only show 50 results per section for performance reasons @@ -469,7 +470,7 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n const [spaceResults, spaceResultsLoading] = useSpaceResults(activeSpace ?? undefined, query); const setQuery = (e: ChangeEvent): void => { - const newQuery = e.currentTarget.value; + const newQuery = transformSearchTerm(e.currentTarget.value); _setQuery(newQuery); }; useEffect(() => { diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index 48b0161134b..6b622292360 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -1,5 +1,5 @@ /* -Copyright 2022 Boluwatife Omosowon +Copyright 2023 Boluwatife Omosowon Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,6 +25,6 @@ import { parsePermalink } from "../utils/permalinks/Permalinks"; */ export function transformSearchTerm(searchTerm: string): string { const parseLink = parsePermalink(searchTerm); - if (parseLink) return parseLink.roomIdOrAlias; + if (parseLink) return parseLink.primaryEntityId; return searchTerm; } From 23b9f10d7bdccd26be6e2d4833c7cb1ec34f1f0c Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Tue, 7 Mar 2023 21:43:00 +0100 Subject: [PATCH 13/23] added tests for transformSearchTerm --- src/components/views/rooms/SearchBar.tsx | 2 + src/utils/SearchInput.ts | 4 +- test/utils/SearchInput-test.ts | 62 ++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 test/utils/SearchInput-test.ts diff --git a/src/components/views/rooms/SearchBar.tsx b/src/components/views/rooms/SearchBar.tsx index 7f5fa794711..eb4b55462b5 100644 --- a/src/components/views/rooms/SearchBar.tsx +++ b/src/components/views/rooms/SearchBar.tsx @@ -24,6 +24,7 @@ import { PosthogScreenTracker } from "../../../PosthogTrackers"; import { getKeyBindingsManager } from "../../../KeyBindingsManager"; import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts"; import SearchWarning, { WarningKind } from "../elements/SearchWarning"; +import { transformSearchTerm } from "../../../utils/SearchInput"; interface IProps { onCancelClick: () => void; @@ -79,6 +80,7 @@ export default class SearchBar extends React.Component { private onSearch = (): void => { if (!this.searchTerm.current?.value.trim()) return; + this.searchTerm.current.value = transformSearchTerm(this.searchTerm.current.value); this.props.onSearch(this.searchTerm.current.value, this.state.scope); }; diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index 6b622292360..e2f8e6a8fde 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { parsePermalink } from "../utils/permalinks/Permalinks"; +import { parsePermalink } from "./permalinks/Permalinks"; /** - * Parse a search string and return either a room ID/alias or the original search term if it does + * Parse a search string and return either a room ID/alias/userId or the original search term if it does * not look like a permalink. * E.g https://matrix.to/#/#element-dev:matrix.org returns #element-dev:matrix.org * @param {string} searchTerm The search term. diff --git a/test/utils/SearchInput-test.ts b/test/utils/SearchInput-test.ts new file mode 100644 index 00000000000..916ef157e28 --- /dev/null +++ b/test/utils/SearchInput-test.ts @@ -0,0 +1,62 @@ +/* +Copyright 2023 Boluwatife Omosowon + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +import { mocked } from "jest-mock"; + +import { parsePermalink } from "../../src/utils/permalinks/Permalinks"; +import { transformSearchTerm } from "../../src/utils/SearchInput"; + +jest.mock("../../src/utils/permalinks/Permalinks"); + +const searchTerm = "search term"; +const roomLink = "https://matrix.to/#/#element-dev:matrix.org"; +const userLink = "https://matrix.to/#/@element-dev:matrix.org"; + +const parserLink = { + roomLink: "#element-dev:matrix.org", + userLink: "@element-dev:matrix.org", + searchTerm: null, +}; + +describe("transforming search term", () => { + it("should return the roomIdOrAlias if the search term was a room permalink", () => { + mocked(parsePermalink).mockReturnValue({ + primaryEntityId: parserLink.roomLink, + roomIdOrAlias: parserLink.roomLink, + eventId: "", + userId: "", + viaServers: [], + sigil: "", + }); + expect(transformSearchTerm(roomLink)).toBe(parserLink.roomLink); + }); + + it("should return the userId if the search term was a userId permalink", () => { + mocked(parsePermalink).mockReturnValue({ + primaryEntityId: parserLink.userLink, + roomIdOrAlias: "", + eventId: "", + userId: parserLink.userLink, + viaServers: [], + sigil: "", + }); + expect(transformSearchTerm(userLink)).toBe(parserLink.userLink); + }); + + it("should return the original search term if the search term was not a permalink", () => { + mocked(parsePermalink).mockReturnValue(null); + expect(transformSearchTerm(searchTerm)).toBe(searchTerm); + }); +}); From 897a099b583fd06b9de20b6ce13d8b055035ae43 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Tue, 7 Mar 2023 22:58:57 +0100 Subject: [PATCH 14/23] removed transformSearchTerm from room search bar --- src/components/views/rooms/SearchBar.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/views/rooms/SearchBar.tsx b/src/components/views/rooms/SearchBar.tsx index eb4b55462b5..7f5fa794711 100644 --- a/src/components/views/rooms/SearchBar.tsx +++ b/src/components/views/rooms/SearchBar.tsx @@ -24,7 +24,6 @@ import { PosthogScreenTracker } from "../../../PosthogTrackers"; import { getKeyBindingsManager } from "../../../KeyBindingsManager"; import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts"; import SearchWarning, { WarningKind } from "../elements/SearchWarning"; -import { transformSearchTerm } from "../../../utils/SearchInput"; interface IProps { onCancelClick: () => void; @@ -80,7 +79,6 @@ export default class SearchBar extends React.Component { private onSearch = (): void => { if (!this.searchTerm.current?.value.trim()) return; - this.searchTerm.current.value = transformSearchTerm(this.searchTerm.current.value); this.props.onSearch(this.searchTerm.current.value, this.state.scope); }; From 9877e29bd1b5f5cebcb3edda2276fa9d838d49cd Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Mon, 1 May 2023 22:26:28 +0100 Subject: [PATCH 15/23] replaces two test cases to one that should return the primaryEntityId if the search term was a permalink --- test/utils/SearchInput-test.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/test/utils/SearchInput-test.ts b/test/utils/SearchInput-test.ts index 916ef157e28..7470272af67 100644 --- a/test/utils/SearchInput-test.ts +++ b/test/utils/SearchInput-test.ts @@ -22,16 +22,14 @@ jest.mock("../../src/utils/permalinks/Permalinks"); const searchTerm = "search term"; const roomLink = "https://matrix.to/#/#element-dev:matrix.org"; -const userLink = "https://matrix.to/#/@element-dev:matrix.org"; const parserLink = { roomLink: "#element-dev:matrix.org", - userLink: "@element-dev:matrix.org", searchTerm: null, }; describe("transforming search term", () => { - it("should return the roomIdOrAlias if the search term was a room permalink", () => { + it("should return the primaryEntityId if the search term was a permalink", () => { mocked(parsePermalink).mockReturnValue({ primaryEntityId: parserLink.roomLink, roomIdOrAlias: parserLink.roomLink, @@ -43,18 +41,6 @@ describe("transforming search term", () => { expect(transformSearchTerm(roomLink)).toBe(parserLink.roomLink); }); - it("should return the userId if the search term was a userId permalink", () => { - mocked(parsePermalink).mockReturnValue({ - primaryEntityId: parserLink.userLink, - roomIdOrAlias: "", - eventId: "", - userId: parserLink.userLink, - viaServers: [], - sigil: "", - }); - expect(transformSearchTerm(userLink)).toBe(parserLink.userLink); - }); - it("should return the original search term if the search term was not a permalink", () => { mocked(parsePermalink).mockReturnValue(null); expect(transformSearchTerm(searchTerm)).toBe(searchTerm); From a8364e63ea0a72623d2fda5ad1801c288025a2c9 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Wed, 3 May 2023 11:21:10 +0100 Subject: [PATCH 16/23] corrected ts issues --- src/utils/SearchInput.ts | 2 +- test/utils/SearchInput-test.ts | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index e2f8e6a8fde..5bdd217a39b 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -23,7 +23,7 @@ import { parsePermalink } from "./permalinks/Permalinks"; * @param {string} searchTerm The search term. * @returns {string} The room ID or alias, or the original search term if it doesn't look like a permalink. */ -export function transformSearchTerm(searchTerm: string): string { +export function transformSearchTerm(searchTerm: string): string | null { const parseLink = parsePermalink(searchTerm); if (parseLink) return parseLink.primaryEntityId; return searchTerm; diff --git a/test/utils/SearchInput-test.ts b/test/utils/SearchInput-test.ts index 7470272af67..8543fa594e8 100644 --- a/test/utils/SearchInput-test.ts +++ b/test/utils/SearchInput-test.ts @@ -20,28 +20,25 @@ import { transformSearchTerm } from "../../src/utils/SearchInput"; jest.mock("../../src/utils/permalinks/Permalinks"); -const searchTerm = "search term"; -const roomLink = "https://matrix.to/#/#element-dev:matrix.org"; - -const parserLink = { - roomLink: "#element-dev:matrix.org", - searchTerm: null, -}; - describe("transforming search term", () => { it("should return the primaryEntityId if the search term was a permalink", () => { + const roomLink = "https://matrix.to/#/#element-dev:matrix.org"; + const parsedPermalink = "#element-dev:matrix.org" + mocked(parsePermalink).mockReturnValue({ - primaryEntityId: parserLink.roomLink, - roomIdOrAlias: parserLink.roomLink, + primaryEntityId: parsedPermalink, + roomIdOrAlias: parsedPermalink, eventId: "", userId: "", viaServers: [], sigil: "", }); - expect(transformSearchTerm(roomLink)).toBe(parserLink.roomLink); + + expect(transformSearchTerm(roomLink)).toBe(parsedPermalink); }); it("should return the original search term if the search term was not a permalink", () => { + const searchTerm = "search term"; mocked(parsePermalink).mockReturnValue(null); expect(transformSearchTerm(searchTerm)).toBe(searchTerm); }); From f42aea97e066f6a4d996c103b5ab44b7ff108358 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Wed, 3 May 2023 18:38:00 +0100 Subject: [PATCH 17/23] changed type of transformSearchTerm to string --- src/utils/SearchInput.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index 5bdd217a39b..a334749f81e 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -23,8 +23,8 @@ import { parsePermalink } from "./permalinks/Permalinks"; * @param {string} searchTerm The search term. * @returns {string} The room ID or alias, or the original search term if it doesn't look like a permalink. */ -export function transformSearchTerm(searchTerm: string): string | null { +export function transformSearchTerm(searchTerm: string): string { const parseLink = parsePermalink(searchTerm); - if (parseLink) return parseLink.primaryEntityId; + if (parseLink) return parseLink.primaryEntityId ?? ""; return searchTerm; } From a973adf6996bbf807f9f346fc14c2cd2ee21a566 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Fri, 5 May 2023 10:25:35 +0100 Subject: [PATCH 18/23] changed return value from empty string to the original search term if the primaryEntityId of the parsedLink is null --- src/utils/SearchInput.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index a334749f81e..b7b109569a8 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -25,6 +25,6 @@ import { parsePermalink } from "./permalinks/Permalinks"; */ export function transformSearchTerm(searchTerm: string): string { const parseLink = parsePermalink(searchTerm); - if (parseLink) return parseLink.primaryEntityId ?? ""; + if (parseLink) return parseLink.primaryEntityId ?? searchTerm; return searchTerm; } From 89d76361bda053a5aa50f86b5e7fb5a6b955818d Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Fri, 5 May 2023 10:28:03 +0100 Subject: [PATCH 19/23] changed return value from empty string to the original search term if the primaryEntityId of the parsedLink is null --- src/utils/SearchInput.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index b7b109569a8..4d23796e44e 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -25,6 +25,6 @@ import { parsePermalink } from "./permalinks/Permalinks"; */ export function transformSearchTerm(searchTerm: string): string { const parseLink = parsePermalink(searchTerm); - if (parseLink) return parseLink.primaryEntityId ?? searchTerm; + if (parseLink) return parseLink?.primaryEntityId ?? searchTerm; return searchTerm; } From 377fd9324854e14db9ceedfb790ec17be6142297 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Fri, 5 May 2023 16:02:31 +0100 Subject: [PATCH 20/23] refactored transformSearchTerm and added a new test case --- src/utils/SearchInput.ts | 3 +-- test/utils/SearchInput-test.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index 4d23796e44e..ad111022433 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -25,6 +25,5 @@ import { parsePermalink } from "./permalinks/Permalinks"; */ export function transformSearchTerm(searchTerm: string): string { const parseLink = parsePermalink(searchTerm); - if (parseLink) return parseLink?.primaryEntityId ?? searchTerm; - return searchTerm; + return parseLink?.primaryEntityId ?? searchTerm; } diff --git a/test/utils/SearchInput-test.ts b/test/utils/SearchInput-test.ts index 8543fa594e8..0016149f9f5 100644 --- a/test/utils/SearchInput-test.ts +++ b/test/utils/SearchInput-test.ts @@ -37,6 +37,21 @@ describe("transforming search term", () => { expect(transformSearchTerm(roomLink)).toBe(parsedPermalink); }); + it("should return the original search term if the search term is a permalink and the primaryEntityId is null", () => { + const searchTerm = "https://matrix.to/#/#random-link:matrix.org"; + + mocked(parsePermalink).mockReturnValue({ + primaryEntityId: null, + roomIdOrAlias: null, + eventId: "", + userId: "", + viaServers: [], + sigil: "", + }); + + expect(transformSearchTerm(searchTerm)).toBe(searchTerm); + }); + it("should return the original search term if the search term was not a permalink", () => { const searchTerm = "search term"; mocked(parsePermalink).mockReturnValue(null); From bd055d58f2c9a6f1f9fc7d644c5bafa498aaac81 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Fri, 5 May 2023 16:06:17 +0100 Subject: [PATCH 21/23] rewrote transformSearchTerm doc --- src/utils/SearchInput.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index ad111022433..f9b251e7d16 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -17,11 +17,12 @@ limitations under the License. import { parsePermalink } from "./permalinks/Permalinks"; /** - * Parse a search string and return either a room ID/alias/userId or the original search term if it does - * not look like a permalink. + * Returns the primaryEntityId(roomIdOrAlias or userId) if the search term + * is a permalink and the primaryEntityId is not null. Otherwise, it returns + * the original search term. * E.g https://matrix.to/#/#element-dev:matrix.org returns #element-dev:matrix.org * @param {string} searchTerm The search term. - * @returns {string} The room ID or alias, or the original search term if it doesn't look like a permalink. + * @returns {string} The roomId, alias, userId, or the original search term */ export function transformSearchTerm(searchTerm: string): string { const parseLink = parsePermalink(searchTerm); From 682d3f8b4f9d898c6d2463aa54da5377e246db7c Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Fri, 5 May 2023 16:11:51 +0100 Subject: [PATCH 22/23] changed mocked return values of test case - should return the original search term if the search term is a permalink and the primaryEntityId is null --- test/utils/SearchInput-test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/utils/SearchInput-test.ts b/test/utils/SearchInput-test.ts index 0016149f9f5..9b787194828 100644 --- a/test/utils/SearchInput-test.ts +++ b/test/utils/SearchInput-test.ts @@ -43,10 +43,10 @@ describe("transforming search term", () => { mocked(parsePermalink).mockReturnValue({ primaryEntityId: null, roomIdOrAlias: null, - eventId: "", - userId: "", - viaServers: [], - sigil: "", + eventId: null, + userId: null, + viaServers: null, + sigil: "?", }); expect(transformSearchTerm(searchTerm)).toBe(searchTerm); From 825e1ceb77d7a94e70947ee3fd134baecce1f3da Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Fri, 5 May 2023 16:21:46 +0100 Subject: [PATCH 23/23] lint corrections --- src/utils/SearchInput.ts | 2 +- test/utils/SearchInput-test.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/SearchInput.ts b/src/utils/SearchInput.ts index f9b251e7d16..04b6d1bc43d 100644 --- a/src/utils/SearchInput.ts +++ b/src/utils/SearchInput.ts @@ -17,7 +17,7 @@ limitations under the License. import { parsePermalink } from "./permalinks/Permalinks"; /** - * Returns the primaryEntityId(roomIdOrAlias or userId) if the search term + * Returns the primaryEntityId(roomIdOrAlias or userId) if the search term * is a permalink and the primaryEntityId is not null. Otherwise, it returns * the original search term. * E.g https://matrix.to/#/#element-dev:matrix.org returns #element-dev:matrix.org diff --git a/test/utils/SearchInput-test.ts b/test/utils/SearchInput-test.ts index 9b787194828..0f863973629 100644 --- a/test/utils/SearchInput-test.ts +++ b/test/utils/SearchInput-test.ts @@ -23,7 +23,7 @@ jest.mock("../../src/utils/permalinks/Permalinks"); describe("transforming search term", () => { it("should return the primaryEntityId if the search term was a permalink", () => { const roomLink = "https://matrix.to/#/#element-dev:matrix.org"; - const parsedPermalink = "#element-dev:matrix.org" + const parsedPermalink = "#element-dev:matrix.org"; mocked(parsePermalink).mockReturnValue({ primaryEntityId: parsedPermalink, @@ -33,7 +33,7 @@ describe("transforming search term", () => { viaServers: [], sigil: "", }); - + expect(transformSearchTerm(roomLink)).toBe(parsedPermalink); }); @@ -48,7 +48,7 @@ describe("transforming search term", () => { viaServers: null, sigil: "?", }); - + expect(transformSearchTerm(searchTerm)).toBe(searchTerm); });