Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Don't jump to sent message conversation if setting disabled.
Prakhar Pratyushab13b7f6fad0
diff --git a/web/src/compose_banner.ts b/web/src/compose_banner.tsindex fba4a0451d3..900a9f53074 100644--- a/web/src/compose_banner.ts+++ b/web/src/compose_banner.ts@@ -24,6 +24,7 @@ const MESSAGE_SENT_CLASSNAMES = {message_scheduled_success_compose_banner: "message_scheduled_success_compose_banner",automatic_new_visibility_policy: "automatic_new_visibility_policy",jump_to_sent_message_conversation: "jump_to_sent_message_conversation",+ narrow_to_recipient: "narrow_to_recipient",};// Technically, unmute_topic_notification is a message sent banner, but// it has distinct behavior / look - it has an associated action button,diff --git a/web/src/compose_notifications.ts b/web/src/compose_notifications.tsindex 2e71aa78963..e8882956016 100644--- a/web/src/compose_notifications.ts+++ b/web/src/compose_notifications.ts@@ -16,6 +16,7 @@ import * as narrow_state from "./narrow_state";import * as onboarding_steps from "./onboarding_steps";import * as people from "./people";import * as stream_data from "./stream_data";+import {user_settings} from "./user_settings";import * as user_topics from "./user_topics";export function notify_unmute(muted_narrow: string, stream_id: number, topic_name: string): void {@@ -118,9 +119,13 @@ export function get_muted_narrow(message: Message): string | undefined {return undefined;}-export function is_local_mix(message: Message): boolean {+export function should_jump_to_sent_message_conversation(message: Message): boolean {+ if (!user_settings.web_navigate_to_sent_message) {+ return false;+ }+if (message_lists.current === undefined) {- // For non-message list views like Inbox, the message is not visible after sending it.+ // Non-message list views like Inbox.return true;}@@ -140,6 +145,37 @@ export function is_local_mix(message: Message): boolean {return true;}+function should_show_narrow_to_recipient_banner(message: Message): boolean {+ if (user_settings.web_navigate_to_sent_message) {+ return false;+ }++ if (message_lists.current === undefined) {+ // Non-message list views like Inbox.+ return false;+ }++ const $row = message_lists.current.get_row(message.id);+ if ($row.length > 0) {+ // Our message is in the current message list.+ return false;+ }++ // offscreen because it is outside narrow+ // we can only look for these on non-search (can_apply_locally) messages+ // see also: notify_messages_outside_current_search+ const current_filter = narrow_state.filter();+ if (+ current_filter &&+ current_filter.can_apply_locally() &&+ !current_filter.predicate()(message)+ ) {+ return true;+ }++ return false;+}+export function notify_local_mixes(messages: Message[],need_user_to_scroll: boolean,@@ -173,11 +209,12 @@ export function notify_local_mixes(continue;}- const local_mix = is_local_mix(message);+ const jump_to_sent_message_conversation = should_jump_to_sent_message_conversation(message);+ const show_narrow_to_recipient_banner = should_show_narrow_to_recipient_banner(message);const link_msg_id = message.id;- if (!local_mix) {+ if (!jump_to_sent_message_conversation && !show_narrow_to_recipient_banner) {if (need_user_to_scroll) {const banner_text = $t({defaultMessage: "Sent!"});const link_text = $t({defaultMessage: "Scroll down to view your message."});@@ -197,6 +234,24 @@ export function notify_local_mixes(continue;}+ if (show_narrow_to_recipient_banner) {+ const banner_text = $t({+ defaultMessage: "Sent! Your message is outside your current view.",+ });+ 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,+ );+ continue;+ }+narrow_to_recipient(link_msg_id);if (onboarding_steps.ONE_TIME_NOTICES_TO_DISPLAY.has("jump_to_conversation_banner")) {@@ -227,6 +282,28 @@ 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;diff --git a/web/src/message_events.js b/web/src/message_events.jsindex c63000c6f2c..cd5b56964c3 100644--- a/web/src/message_events.js+++ b/web/src/message_events.js@@ -56,10 +56,14 @@ function maybe_add_narrowed_messages(messages, msg_list, callback, attempt = 1)}let new_messages = [];+ const elsewhere_messages = [];+for (const elem of messages) {if (Object.hasOwn(data.messages, elem.id)) {util.set_match_data(elem, data.messages[elem.id]);new_messages.push(elem);+ } else {+ elsewhere_messages.push(elem);}}@@ -77,6 +81,7 @@ function maybe_add_narrowed_messages(messages, msg_list, callback, attempt = 1)callback(new_messages, msg_list);unread_ops.process_visible();+ compose_notifications.notify_messages_outside_current_search(elsewhere_messages);},error(xhr) {if (!narrow_state.is_message_feed_visible() || msg_list !== message_lists.current) {