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>
This commit is contained in:
Will Hunt 2022-07-15 12:22:40 +01:00 committed by GitHub
parent 742b21ca46
commit 7842d5165c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View file

@ -480,12 +480,12 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
// eslint-disable-next-line // eslint-disable-next-line
}, [results, filter]); }, [results, filter]);
const viewRoom = (roomId: string, persist = false, viaKeyboard = false) => { const viewRoom = (room: {roomId: string, roomAlias?: string}, persist = false, viaKeyboard = false) => {
if (persist) { if (persist) {
const recents = new Set(SettingsStore.getValue("SpotlightSearch.recentSearches", null).reverse()); const recents = new Set(SettingsStore.getValue("SpotlightSearch.recentSearches", null).reverse());
// remove & add the room to put it at the end // remove & add the room to put it at the end
recents.delete(roomId); recents.delete(room.roomId);
recents.add(roomId); recents.add(room.roomId);
SettingsStore.setValue( SettingsStore.setValue(
"SpotlightSearch.recentSearches", "SpotlightSearch.recentSearches",
@ -497,9 +497,10 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
defaultDispatcher.dispatch<ViewRoomPayload>({ defaultDispatcher.dispatch<ViewRoomPayload>({
action: Action.ViewRoom, action: Action.ViewRoom,
room_id: roomId,
metricsTrigger: "WebUnifiedSearch", metricsTrigger: "WebUnifiedSearch",
metricsViaKeyboard: viaKeyboard, metricsViaKeyboard: viaKeyboard,
room_id: room.roomId,
room_alias: room.roomAlias,
}); });
onFinished(); onFinished();
}; };
@ -555,7 +556,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
id={`mx_SpotlightDialog_button_result_${result.room.roomId}`} id={`mx_SpotlightDialog_button_result_${result.room.roomId}`}
key={`${Section[result.section]}-${result.room.roomId}`} key={`${Section[result.section]}-${result.room.roomId}`}
onClick={(ev) => { onClick={(ev) => {
viewRoom(result.room.roomId, true, ev?.type !== "click"); viewRoom({ roomId: result.room.roomId }, true, ev?.type !== "click");
}} }}
endAdornment={<RoomResultContextMenus room={result.room} />} endAdornment={<RoomResultContextMenus room={result.room} />}
{...ariaProperties} {...ariaProperties}
@ -603,7 +604,11 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
if (isPublicRoomResult(result)) { if (isPublicRoomResult(result)) {
const clientRoom = cli.getRoom(result.publicRoom.room_id); const clientRoom = cli.getRoom(result.publicRoom.room_id);
const listener = (ev) => { 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 ( return (
<Option <Option
@ -782,7 +787,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
id={`mx_SpotlightDialog_button_result_${room.room_id}`} id={`mx_SpotlightDialog_button_result_${room.room_id}`}
key={room.room_id} key={room.room_id}
onClick={(ev) => { onClick={(ev) => {
viewRoom(room.room_id, true, ev?.type !== "click"); viewRoom({ roomId: room.room_id }, true, ev?.type !== "click");
}} }}
> >
<BaseAvatar <BaseAvatar
@ -974,7 +979,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
id={`mx_SpotlightDialog_button_recentSearch_${room.roomId}`} id={`mx_SpotlightDialog_button_recentSearch_${room.roomId}`}
key={room.roomId} key={room.roomId}
onClick={(ev) => { onClick={(ev) => {
viewRoom(room.roomId, true, ev?.type !== "click"); viewRoom({ roomId: room.roomId }, true, ev?.type !== "click");
}} }}
endAdornment={<RoomResultContextMenus room={room} />} endAdornment={<RoomResultContextMenus room={room} />}
{...ariaProperties} {...ariaProperties}
@ -1016,7 +1021,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
title={room.name} title={room.name}
key={room.roomId} key={room.roomId}
onClick={(ev) => { 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 }} /> <DecoratedRoomAvatar room={room} avatarSize={32} tooltipProps={{ tabIndex: -1 }} />

View file

@ -26,7 +26,9 @@ import { IOpts } from "../../createRoom";
export interface ViewRoomPayload extends Pick<ActionPayload, "action"> { export interface ViewRoomPayload extends Pick<ActionPayload, "action"> {
action: Action.ViewRoom; action: Action.ViewRoom;
// either of room_id or room_alias must be specified // either or both of room_id or room_alias must be specified
// where possible, a room_id should be provided with a room_alias as it reduces
// the number of API calls required.
room_id?: string; room_id?: string;
room_alias?: string; room_alias?: string;