Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_report_ui: Add message preview to report modal.
PieterCK7338f0426ed9
diff --git a/web/src/message_list_view.ts b/web/src/message_list_view.tsindex bf725fd7e69..3b7243373ee 100644--- a/web/src/message_list_view.ts+++ b/web/src/message_list_view.ts@@ -231,7 +231,7 @@ function get_message_date_divider_data(opts: {};}-function get_timestr(message: Message): string {+export function get_timestr(message: Message): string {const time = new Date(message.timestamp * 1000);return timerender.stringify_time(time);}@@ -354,7 +354,7 @@ type SubscriptionMarkers = {subscribed?: boolean;just_unsubscribed?: boolean;};-function populate_group_from_message(+export function populate_group_from_message(message: Message,date_unchanged: boolean,year_changed: boolean,diff --git a/web/src/message_report.ts b/web/src/message_report.tsindex d0e5820f123..f7259f796ae 100644--- a/web/src/message_report.ts+++ b/web/src/message_report.ts@@ -9,17 +9,111 @@ import * as dialog_widget from "./dialog_widget.ts";import type {Option} from "./dropdown_widget.ts";import * as dropdown_widget from "./dropdown_widget.ts";import {$t_html} from "./i18n.ts";+import {+ type MessageContainer,+ type MessageGroup,+ get_timestr,+ populate_group_from_message,+} from "./message_list_view.ts";import type {Message} from "./message_store.ts";+import * as people from "./people.ts";import {realm} from "./state_data.ts";import * as ui_report from "./ui_report.ts";+import {toggle_user_card_popover_for_message} from "./user_card_popover.ts";++function register_message_preview_click_handlers(+ $message_preview_container: JQuery,+ sender_id: number,+): void {+ // This function registers click handlers and mouseover effects+ // for the message sender in the message preview container.+ // The logic here is partly from message_list_hover.ts, and+ // partly from user_card_popover.ts.++ $message_preview_container.on("mouseover", ".sender_info_hover", function (this: HTMLElement) {+ const $row = $(this).closest(".message_row");+ $row.addClass("sender_info_hovered");+ });++ $message_preview_container.on("mouseout", ".sender_info_hover", function (this: HTMLElement) {+ const $row = $(this).closest(".message_row");+ $row.removeClass("sender_info_hovered");+ });++ $message_preview_container.on(+ "click",+ ".sender_name, .inline-profile-picture-wrapper",+ function (this: HTMLElement, e) {+ e.stopPropagation();+ const user = people.get_by_user_id(sender_id);+ toggle_user_card_popover_for_message(this, user, sender_id, true);+ },+ );+}++function get_message_group_for_message_preview(message: Message): MessageGroup {+ // This creates a simpler recipient_row without element like the+ // topic menu and topic visibility policy menu.+ const message_group = populate_group_from_message(message, false, false, undefined);+ if (message_group.is_stream) {+ message_group.user_can_resolve_topic = false;+ message_group.is_topic_editable = false;+ }+ return message_group;+}++function get_message_container_for_preview(message: Message): MessageContainer {+ const computed_variables = {+ include_sender: true,+ // Message report preview will be automatically collapsed+ is_hidden: false,+ msg: message,+ sender_is_bot: people.sender_is_bot(message),+ sender_is_deactivated: people.sender_is_deactivated(message),+ sender_is_guest: people.sender_is_guest(message),+ should_add_guest_indicator_for_sender: people.should_add_guest_user_indicator(+ message.sender_id,+ ),+ small_avatar_url: people.small_avatar_url(message),+ status_message: "",+ timestr: get_timestr(message),+ want_date_divider: false,+ };+ const unused_variables = {+ date_divider_html: undefined,+ edited: false,+ include_recipient: false,+ last_edit_timestamp: undefined,+ last_moved_timestamp: undefined,+ mention_classname: undefined,+ message_edit_notices_alongside_sender: false,+ message_edit_notices_for_status_message: false,+ message_edit_notices_in_left_col: false,+ modified: false,+ moved: false,+ year_changed: false,+ };+ return {+ ...computed_variables,+ ...unused_variables,+ };+}export function show_message_report_modal(message: Message): void {- const html_body = render_report_message_modal({});+ const message_preview_body_args = get_message_container_for_preview(message);+ const html_body = render_report_message_modal({+ recipient_row_data: get_message_group_for_message_preview(message),+ message_container_data: {+ ...message_preview_body_args,+ message_list_id: "",+ },+ });let report_type_dropdown_widget: dropdown_widget.DropdownWidget;let $message_report_description: JQuery<HTMLTextAreaElement>;function message_report_post_render(): void {$message_report_description = $<HTMLTextAreaElement>("textarea#message-report-description");+ const $report_message_preview_container = $("#report-message-preview-container");function check_toggle_submit_button(): void {const selected_report_type = report_type_dropdown_widget.value();@@ -32,6 +126,11 @@ export function show_message_report_modal(message: Message): void {);}+ register_message_preview_click_handlers(+ $report_message_preview_container,+ message.sender_id,+ );+function get_message_report_types(): Option[] {return realm.server_report_message_types.map((report_type) => ({unique_id: report_type.key,diff --git a/web/src/user_card_popover.ts b/web/src/user_card_popover.tsindex 5138c455e3f..ac88241cb55 100644--- a/web/src/user_card_popover.ts+++ b/web/src/user_card_popover.ts@@ -529,7 +529,7 @@ function load_medium_avatar(user: User, $elt: JQuery): void {// user is the user whose profile to show.// sender_id is the user id of the sender for the message we are// showing the popover from.-function toggle_user_card_popover_for_message(+export function toggle_user_card_popover_for_message(element: HTMLElement,user: User,sender_id: number,diff --git a/web/styles/message_header.css b/web/styles/message_header.cssindex 9fbe6fade7d..60b300310fd 100644--- a/web/styles/message_header.css+++ b/web/styles/message_header.css@@ -108,6 +108,14 @@}}}++ #report-message-preview-container & {+ /* We don't need these effects applied for message preview in the report+ message modal. */+ box-shadow: none;+ border: 0;+ background: transparent;+ }}.message_header_private_message {diff --git a/web/styles/message_row.css b/web/styles/message_row.cssindex e05d872a8f4..c28e23b4871 100644--- a/web/styles/message_row.css+++ b/web/styles/message_row.css@@ -77,6 +77,12 @@cursor: pointer;}}++ #report-message-preview-container & {+ /* A message preview only contains a single row of message */+ border-radius: var(--last-message-row-border-radius);+ border: 1px solid var(--color-message-list-border);+ }}.messagebox {@@ -1242,6 +1248,17 @@margin-left: -50%;}+#report-message-preview-container {+ /* Hide most UI for interacting with a message in the report message preview UI. */+ .change_visibility_policy,+ .recipient-row-topic-menu,+ .message_controls,+ .message-reminders,+ .message_reactions {+ display: none;+ }+}+@container message-lists (width < $cq_ml_min) {.muted-message-notice {display: none;diff --git a/web/templates/report_message_modal.hbs b/web/templates/report_message_modal.hbsindex b908d6b8d0d..c00ac9dcbea 100644--- a/web/templates/report_message_modal.hbs+++ b/web/templates/report_message_modal.hbs@@ -2,6 +2,10 @@<p>{{t "Your report will be sent to the private moderation requests channel for this organization." }}</p>+ <div id="report-message-preview-container" class="input-group">+ {{> recipient_row recipient_row_data}}+ {{> single_message message_container_data}}+ </div><div class="input-group"><label class="report-type-wrapper modal-field-label">{{t "What's the problem with this message?" }}