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

Commit 85363ef

Browse files
justjanneHalf-Shott3chguy
authored
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 <[email protected]> Co-authored-by: Will Hunt <[email protected]> Co-authored-by: Michael Telatynski <[email protected]>
1 parent 7b744cd commit 85363ef

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,12 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
479479
// eslint-disable-next-line
480480
}, [results, filter]);
481481

482-
const viewRoom = (roomId: string, persist = false, viaKeyboard = false) => {
482+
const viewRoom = (room: {roomId: string, roomAlias?: string}, persist = false, viaKeyboard = false) => {
483483
if (persist) {
484484
const recents = new Set(SettingsStore.getValue("SpotlightSearch.recentSearches", null).reverse());
485485
// remove & add the room to put it at the end
486-
recents.delete(roomId);
487-
recents.add(roomId);
486+
recents.delete(room.roomId);
487+
recents.add(room.roomId);
488488

489489
SettingsStore.setValue(
490490
"SpotlightSearch.recentSearches",
@@ -496,9 +496,10 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
496496

497497
defaultDispatcher.dispatch<ViewRoomPayload>({
498498
action: Action.ViewRoom,
499-
room_id: roomId,
500499
metricsTrigger: "WebUnifiedSearch",
501500
metricsViaKeyboard: viaKeyboard,
501+
room_id: room.roomId,
502+
room_alias: room.roomAlias,
502503
});
503504
onFinished();
504505
};
@@ -551,7 +552,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
551552
id={`mx_SpotlightDialog_button_result_${result.room.roomId}`}
552553
key={`${Section[result.section]}-${result.room.roomId}`}
553554
onClick={(ev) => {
554-
viewRoom(result.room.roomId, true, ev?.type !== "click");
555+
viewRoom({ roomId: result.room.roomId }, true, ev?.type !== "click");
555556
}}
556557
{...ariaProperties}
557558
>
@@ -598,7 +599,11 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
598599
if (isPublicRoomResult(result)) {
599600
const clientRoom = cli.getRoom(result.publicRoom.room_id);
600601
const listener = (ev) => {
601-
viewRoom(result.publicRoom.room_id, true, ev.type !== "click");
602+
const { publicRoom } = result;
603+
viewRoom({
604+
roomAlias: publicRoom.canonical_alias || publicRoom.aliases?.[0],
605+
roomId: publicRoom.room_id,
606+
}, true, ev.type !== "click");
602607
};
603608
return (
604609
<Option
@@ -777,7 +782,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
777782
id={`mx_SpotlightDialog_button_result_${room.room_id}`}
778783
key={room.room_id}
779784
onClick={(ev) => {
780-
viewRoom(room.room_id, true, ev?.type !== "click");
785+
viewRoom({ roomId: room.room_id }, true, ev?.type !== "click");
781786
}}
782787
>
783788
<BaseAvatar
@@ -967,7 +972,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
967972
id={`mx_SpotlightDialog_button_recentSearch_${room.roomId}`}
968973
key={room.roomId}
969974
onClick={(ev) => {
970-
viewRoom(room.roomId, true, ev?.type !== "click");
975+
viewRoom({ roomId: room.roomId }, true, ev?.type !== "click");
971976
}}
972977
{...ariaProperties}
973978
>
@@ -1008,7 +1013,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
10081013
title={room.name}
10091014
key={room.roomId}
10101015
onClick={(ev) => {
1011-
viewRoom(room.roomId, false, ev.type !== "click");
1016+
viewRoom({ roomId: room.roomId }, false, ev.type !== "click");
10121017
}}
10131018
>
10141019
<DecoratedRoomAvatar room={room} avatarSize={32} tooltipProps={{ tabIndex: -1 }} />

src/dispatcher/payloads/ViewRoomPayload.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import { IOpts } from "../../createRoom";
2626
export interface ViewRoomPayload extends Pick<ActionPayload, "action"> {
2727
action: Action.ViewRoom;
2828

29-
// either of room_id or room_alias must be specified
29+
// either or both of room_id or room_alias must be specified
30+
// where possible, a room_id should be provided with a room_alias as it reduces
31+
// the number of API calls required.
3032
room_id?: string;
3133
room_alias?: string;
3234

0 commit comments

Comments
 (0)