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

Prefer using the canonical alias in spotlight search #9055

Merged
merged 8 commits into from
Jul 15, 2022
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/components/views/dialogs/spotlight/SpotlightDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,12 @@ const SpotlightDialog: React.FC<IProps> = ({ 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",
Expand All @@ -497,9 +497,10 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n

defaultDispatcher.dispatch<ViewRoomPayload>({
action: Action.ViewRoom,
room_id: roomId,
metricsTrigger: "WebUnifiedSearch",
metricsViaKeyboard: viaKeyboard,
room_id: room.roomId,
room_alias: room.roomAlias,
});
onFinished();
};
Expand Down Expand Up @@ -555,7 +556,7 @@ const SpotlightDialog: React.FC<IProps> = ({ 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={<RoomResultContextMenus room={result.room} />}
{...ariaProperties}
Expand Down Expand Up @@ -603,7 +604,11 @@ const SpotlightDialog: React.FC<IProps> = ({ 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,
}, false, ev.type !== "click");
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
};
return (
<Option
Expand Down Expand Up @@ -782,7 +787,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
id={`mx_SpotlightDialog_button_result_${room.room_id}`}
key={room.room_id}
onClick={(ev) => {
viewRoom(room.room_id, true, ev?.type !== "click");
viewRoom({ roomId: room.room_id }, true, ev?.type !== "click");
}}
>
<BaseAvatar
Expand Down Expand Up @@ -974,7 +979,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
id={`mx_SpotlightDialog_button_recentSearch_${room.roomId}`}
key={room.roomId}
onClick={(ev) => {
viewRoom(room.roomId, true, ev?.type !== "click");
viewRoom({ roomId: room.roomId }, true, ev?.type !== "click");
}}
endAdornment={<RoomResultContextMenus room={room} />}
{...ariaProperties}
Expand Down Expand Up @@ -1016,7 +1021,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
title={room.name}
key={room.roomId}
onClick={(ev) => {
viewRoom(room.roomId, false, ev.type !== "click");
viewRoom({ roomId: room.roomId }, false, ev.type !== "click");
}}
>
<DecoratedRoomAvatar room={room} avatarSize={32} tooltipProps={{ tabIndex: -1 }} />
Expand Down