search: Link messages in search results to near view.

Previously clicking on a message in search results opened
the compose box. This was not great, because search views
show messages outside of their context, and replying to a
message without the context of possible more recent
messages sent to that narrow can result in a bad experience.

This commit prevents the composebox from opening on click and instead
moves the user to a near view for the message, and similarly with the
enter keyboard shortcut.

Fixes #21217.
This commit is contained in:
evykassirer
2023-06-01 21:40:36 -07:00
committed by Tim Abbott
parent 61d4670f9a
commit cb5441a6b0
2 changed files with 36 additions and 3 deletions

View File

@@ -23,6 +23,7 @@ import * as message_edit from "./message_edit";
import * as message_lists from "./message_lists";
import * as message_store from "./message_store";
import * as narrow from "./narrow";
import * as narrow_state from "./narrow_state";
import * as navigate from "./navigate";
import {page_params} from "./page_params";
import * as pm_list from "./pm_list";
@@ -184,6 +185,21 @@ export function initialize() {
return;
}
// Clicks on a message from search results should bring the
// user to the message's near view instead of opening the
// compose box.
const current_filter = narrow_state.filter();
if (current_filter !== undefined && !current_filter.supports_collapsing_recipients()) {
const message = message_store.get(id);
if (message === undefined) {
// This might happen for locally echoed messages, for example.
return;
}
window.location = hash_util.by_conversation_and_time_url(message);
return;
}
if (page_params.is_spectator) {
return;
}