compose: Jump to conversation where message was sent.

Removes two 'narrow_to_recipient' banners which were
shown after sending a message to a different conversation.

Now, the sender is narrowed to the conversation where
message was sent.

Fixes #29186.
This commit is contained in:
Prakhar Pratyush
2024-03-06 17:42:08 +05:30
committed by Tim Abbott
parent e959a392c9
commit e4cbca698d
10 changed files with 59 additions and 77 deletions

View File

@@ -116,35 +116,28 @@ export function get_muted_narrow(message: Message): string | undefined {
return undefined;
}
export function get_local_notify_mix_reason(message: Message): string | undefined {
export function is_local_mix(message: Message): boolean {
if (message_lists.current === undefined) {
// For non-message list views like Inbox, the message is not visible after sending it.
return undefined;
return true;
}
const $row = message_lists.current.get_row(message.id);
if ($row.length > 0) {
// If our message is in the current message list, we do
// not have a mix, so we are happy.
return undefined;
}
// offscreen because it is outside narrow
// we can only look for these on non-search (can_apply_locally) messages
// see also: exports.notify_messages_outside_current_search
const current_filter = narrow_state.filter();
if (
current_filter &&
current_filter.can_apply_locally() &&
!current_filter.predicate()(message)
) {
return $t({defaultMessage: "Sent! Your message is outside your current view."});
const $row = message_lists.current.get_row(message.id);
if (current_filter && current_filter.is_conversation_view() && $row.length > 0) {
// If our message is in the current conversation view, we do
// not have a mix, so we are happy.
return false;
}
return undefined;
return true;
}
export function notify_local_mixes(messages: Message[], need_user_to_scroll: boolean): void {
export function notify_local_mixes(
messages: Message[],
need_user_to_scroll: boolean,
{narrow_to_recipient}: {narrow_to_recipient: (message_id: number) => void},
): void {
/*
This code should only be called when we are displaying
messages sent by current client. It notifies users that
@@ -173,13 +166,13 @@ export function notify_local_mixes(messages: Message[], need_user_to_scroll: boo
continue;
}
let banner_text = get_local_notify_mix_reason(message);
const local_mix = is_local_mix(message);
const link_msg_id = message.id;
if (!banner_text) {
if (!local_mix) {
if (need_user_to_scroll) {
banner_text = $t({defaultMessage: "Sent!"});
const banner_text = $t({defaultMessage: "Sent!"});
const link_text = $t({defaultMessage: "Scroll down to view your message."});
notify_above_composebox(
banner_text,
@@ -197,18 +190,7 @@ export function notify_local_mixes(messages: Message[], need_user_to_scroll: boo
continue;
}
const link_text = $t(
{defaultMessage: "Go to {message_recipient}"},
{message_recipient: get_message_header(message)},
);
notify_above_composebox(
banner_text,
compose_banner.CLASSNAMES.narrow_to_recipient,
get_above_composebox_narrow_url(message),
link_msg_id,
link_text,
);
narrow_to_recipient(link_msg_id);
}
}
@@ -225,28 +207,6 @@ function get_above_composebox_narrow_url(message: Message): string {
return above_composebox_narrow_url;
}
// for callback when we have to check with the server if a message should be in
// the message_lists.current (!can_apply_locally; a.k.a. "a search").
export function notify_messages_outside_current_search(messages: Message[]): void {
for (const message of messages) {
if (!people.is_current_user(message.sender_email)) {
continue;
}
const above_composebox_narrow_url = get_above_composebox_narrow_url(message);
const link_text = $t(
{defaultMessage: "Narrow to {message_recipient}"},
{message_recipient: get_message_header(message)},
);
notify_above_composebox(
$t({defaultMessage: "Sent! Your recent message is outside the current search."}),
compose_banner.CLASSNAMES.narrow_to_recipient,
above_composebox_narrow_url,
message.id,
link_text,
);
}
}
export function reify_message_id(opts: {old_id: number; new_id: number}): void {
const old_id = opts.old_id;
const new_id = opts.new_id;