From 7842d5165c972d73d408f77b1e098e8f897b3f7e Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 15 Jul 2022 12:22:40 +0100 Subject: [PATCH] Prefer using the canonical alias in spotlight search (#9055) * 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> --- .../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 51e65b4248..4bf7b57239 100644 --- a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx +++ b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx @@ -480,12 +480,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", @@ -497,9 +497,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(); }; @@ -555,7 +556,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"); }} endAdornment={} {...ariaProperties} @@ -603,7 +604,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 (