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:
parent
742b21ca46
commit
7842d5165c
2 changed files with 17 additions and 10 deletions
|
@ -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",
|
||||
|
@ -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();
|
||||
};
|
||||
|
@ -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}
|
||||
|
@ -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,
|
||||
}, true, ev.type !== "click");
|
||||
};
|
||||
return (
|
||||
<Option
|
||||
|
@ -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
|
||||
|
@ -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}
|
||||
|
@ -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 }} />
|
||||
|
|
|
@ -26,7 +26,9 @@ import { IOpts } from "../../createRoom";
|
|||
export interface ViewRoomPayload extends Pick<ActionPayload, "action"> {
|
||||
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_alias?: string;
|
||||
|
||||
|
|
Loading…
Reference in a new issue