From 85363efba5ee13701eadb8cab63d3bad9c025058 Mon Sep 17 00:00:00 2001 From: Janne Mareike Koschinski Date: Fri, 15 Jul 2022 14:56:41 +0200 Subject: [PATCH] Prefer using the canonical alias in spotlight search (#9055) (#9059) * Prefer using the canonical alias in spotlight search Public rooms on other homeservers are not joinable via the roomId if they haven't been joined by other users on your homeserver. * Ensure we call the action with the room_alias * lint * Drop display * Always provide roomId * Add rationale to room_id, room_alias * whoops Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: Will Hunt Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- .../dialogs/spotlight/SpotlightDialog.tsx | 23 +++++++++++-------- src/dispatcher/payloads/ViewRoomPayload.ts | 4 +++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx index f14d29d8ca..a29adc151c 100644 --- a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx +++ b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx @@ -479,12 +479,12 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n // eslint-disable-next-line }, [results, filter]); - const viewRoom = (roomId: string, persist = false, viaKeyboard = false) => { + const viewRoom = (room: {roomId: string, roomAlias?: string}, persist = false, viaKeyboard = false) => { if (persist) { const recents = new Set(SettingsStore.getValue("SpotlightSearch.recentSearches", null).reverse()); // remove & add the room to put it at the end - recents.delete(roomId); - recents.add(roomId); + recents.delete(room.roomId); + recents.add(room.roomId); SettingsStore.setValue( "SpotlightSearch.recentSearches", @@ -496,9 +496,10 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n defaultDispatcher.dispatch({ action: Action.ViewRoom, - room_id: roomId, metricsTrigger: "WebUnifiedSearch", metricsViaKeyboard: viaKeyboard, + room_id: room.roomId, + room_alias: room.roomAlias, }); onFinished(); }; @@ -551,7 +552,7 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n id={`mx_SpotlightDialog_button_result_${result.room.roomId}`} key={`${Section[result.section]}-${result.room.roomId}`} onClick={(ev) => { - viewRoom(result.room.roomId, true, ev?.type !== "click"); + viewRoom({ roomId: result.room.roomId }, true, ev?.type !== "click"); }} {...ariaProperties} > @@ -598,7 +599,11 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n if (isPublicRoomResult(result)) { const clientRoom = cli.getRoom(result.publicRoom.room_id); const listener = (ev) => { - viewRoom(result.publicRoom.room_id, true, ev.type !== "click"); + const { publicRoom } = result; + viewRoom({ + roomAlias: publicRoom.canonical_alias || publicRoom.aliases?.[0], + roomId: publicRoom.room_id, + }, true, ev.type !== "click"); }; return (