Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
recent_view: Extract function to get avatar context.
Aman Agrawala05cbfa0c9e4
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.tsindex 983047f9fdc..1272e84490d 100644--- a/web/src/recent_view_ui.ts+++ b/web/src/recent_view_ui.ts@@ -540,6 +540,43 @@ export function get_pm_tooltip_data(user_ids_string: string): buddy_data.TitleDa};}+type AvatarsContext = {+ senders: people.SenderInfo[];+ other_sender_names_html: string;+ other_senders_count: number;+};++function get_avatars_context(all_senders: number[]): AvatarsContext {+ const senders = all_senders.slice(-max_avatars);+ const extra_sender_ids = all_senders.slice(0, -max_avatars);+ const displayed_other_senders = extra_sender_ids.slice(-MAX_EXTRA_SENDERS);+ const other_senders_count = Math.max(0, all_senders.length - max_avatars);+ // Collect extra sender fullname for tooltip+ const displayed_other_names = people.get_display_full_names(displayed_other_senders.reverse());+ if (extra_sender_ids.length > MAX_EXTRA_SENDERS) {+ // We display only 10 extra senders in tooltips,+ // and just display remaining number of senders.+ const remaining_senders = extra_sender_ids.length - MAX_EXTRA_SENDERS;+ // Pluralization syntax from:+ // https://formatjs.io/docs/core-concepts/icu-syntax/#plural-format+ displayed_other_names.push(+ $t(+ {+ defaultMessage:+ "and {remaining_senders, plural, one {1 other} other {# others}}.",+ },+ {remaining_senders},+ ),+ );+ }++ return {+ senders: people.sender_info_for_recent_view_row(senders),+ other_sender_names_html: displayed_other_names.map((name) => _.escape(name)).join("<br />"),+ other_senders_count,+ };+}+type ConversationContext = {full_last_msg_date_time: string;conversation_key: string;@@ -595,9 +632,6 @@ function format_conversation(conversation_data: ConversationData): ConversationCconst last_msg_time = timerender.relative_time_string_from_date(time);const is_private = last_msg.type === "private";let all_senders;- let senders;- let displayed_other_senders;- let extra_sender_ids;let stream_context;let dm_context;@@ -632,11 +666,6 @@ function format_conversation(conversation_data: ConversationData): ConversationC// we provide our handlebars with senders in opposite order.// Display in most recent sender first order.all_senders = recent_senders.get_topic_recent_senders(stream_id, topic).reverse();- senders = all_senders.slice(-max_avatars);-- // Collect extra sender fullname for tooltip- extra_sender_ids = all_senders.slice(0, -max_avatars);- displayed_other_senders = extra_sender_ids.slice(-MAX_EXTRA_SENDERS);stream_context = {stream_id,@@ -695,10 +724,6 @@ function format_conversation(conversation_data: ConversationData): ConversationC// styling, but it's important to not destroy the information of "who's actually// talked".all_senders = recent_senders.get_pm_recent_senders(user_ids_string).participants.reverse();- senders = all_senders.slice(-max_avatars);- // Collect extra senders fullname for tooltip.- extra_sender_ids = all_senders.slice(0, -max_avatars);- displayed_other_senders = extra_sender_ids.slice(-MAX_EXTRA_SENDERS);dm_context = {user_ids_string,@@ -711,36 +736,15 @@ function format_conversation(conversation_data: ConversationData): ConversationC};}- const displayed_other_names = people.get_display_full_names(displayed_other_senders.reverse());-- if (extra_sender_ids.length > MAX_EXTRA_SENDERS) {- // We display only 10 extra senders in tooltips,- // and just display remaining number of senders.- const remaining_senders = extra_sender_ids.length - MAX_EXTRA_SENDERS;- // Pluralization syntax from:- // https://formatjs.io/docs/core-concepts/icu-syntax/#plural-format- displayed_other_names.push(- $t(- {- defaultMessage:- "and {remaining_senders, plural, one {1 other} other {# others}}.",- },- {remaining_senders},- ),- );- }-const shared_context = {full_last_msg_date_time,conversation_key,unread_count,last_msg_time,- senders: people.sender_info_for_recent_view_row(senders),- other_senders_count: Math.max(0, all_senders.length - max_avatars),- other_sender_names_html: displayed_other_names.map((name) => _.escape(name)).join("<br />"),last_msg_url: hash_util.by_conversation_and_time_url(last_msg),is_spectator: page_params.is_spectator,column_indexes: COLUMNS,+ ...get_avatars_context(all_senders),};if (is_private) {assert(dm_context !== undefined);