From de27f19c3a709747398e7a69e44026ffa8d5c29e Mon Sep 17 00:00:00 2001 From: Alisson Lauffer Date: Sat, 11 Feb 2023 08:05:17 -0300 Subject: [PATCH] message-row: Add initial support for replies chat --- src/components/avatar.rs | 12 +++++++++--- src/expressions.rs | 2 ++ src/session/content/chat_action_bar.rs | 8 ++++++++ src/session/content/message_row/bubble.rs | 17 +++++++++++++++-- src/session/content/message_row/mod.rs | 4 ++-- src/session/sidebar/row.rs | 2 +- src/tdlib/chat.rs | 4 ++++ src/tdlib/message.rs | 2 +- 8 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/components/avatar.rs b/src/components/avatar.rs index adce2402e..c3eb224cf 100644 --- a/src/components/avatar.rs +++ b/src/components/avatar.rs @@ -117,7 +117,7 @@ impl Avatar { closure!(|_: Self, item: Option, title: String| { item.as_ref() .and_then(|i| i.downcast_ref::()) - .filter(|chat| chat.is_own_chat()) + .filter(|chat| chat.is_own_chat() || chat.is_replies_chat()) // Workaround for having a blue AdwAvatar for Saved Messages chat .map(|_| "-".to_string()) .unwrap_or(title) @@ -137,9 +137,15 @@ impl Avatar { >| { item.as_ref() .and_then(|i| i.downcast_ref::()) - .filter(|chat| chat.is_own_chat()) + .filter(|chat| chat.is_own_chat() || chat.is_replies_chat()) // Show bookmark icon for Saved Messages chat - .map(|_| "user-bookmarks-symbolic") + .map(|chat| { + if chat.is_replies_chat() { + "mail-reply-sender-symbolic" + } else { + "user-bookmarks-symbolic" + } + }) })); icon_name_expression.bind(&*imp.avatar, "icon-name", Some(self)); diff --git a/src/expressions.rs b/src/expressions.rs index ff3404833..de412b7ce 100644 --- a/src/expressions.rs +++ b/src/expressions.rs @@ -22,6 +22,8 @@ pub(crate) fn chat_display_name(chat_expression: >k::Expression) -> gtk::Expre let is_deleted = args[3].get::().unwrap(); if chat.is_own_chat() { gettext("Saved Messages") + } else if chat.is_replies_chat() { + gettext("Replies") } else if is_deleted { gettext("Deleted Account") } else { diff --git a/src/session/content/chat_action_bar.rs b/src/session/content/chat_action_bar.rs index 4645973e8..cd8ed9179 100644 --- a/src/session/content/chat_action_bar.rs +++ b/src/session/content/chat_action_bar.rs @@ -760,6 +760,14 @@ impl ChatActionBar { imp.action_bar_stack.set_visible_child_name("entry"); } else if is_blocked { imp.action_bar_stack.set_visible_child_name("unblock"); + } else if chat.is_replies_chat() { + imp.action_bar_stack.set_visible_child_name("mute"); + + if self.is_chat_muted() { + imp.mute_button.set_label(&gettext("Unmute")); + } else { + imp.mute_button.set_label(&gettext("Mute")); + } } else { imp.action_bar_stack.set_visible_child_name("entry"); } diff --git a/src/session/content/message_row/bubble.rs b/src/session/content/message_row/bubble.rs index c3eefc7f5..c63087416 100644 --- a/src/session/content/message_row/bubble.rs +++ b/src/session/content/message_row/bubble.rs @@ -176,7 +176,7 @@ impl MessageBubble { let show_sender = if force_hide_sender { None - } else if message.chat().is_own_chat() { + } else if message.chat().is_own_chat() || message.chat().is_replies_chat() { if message.is_outgoing() { None } else { @@ -197,10 +197,23 @@ impl MessageBubble { None }; + let message_chat = if message.chat().is_replies_chat() { + if let Some(f) = message.forward_info() { + (f.origin().id().unwrap() != 0) + .then(|| message.chat().session().try_chat(f.origin().id().unwrap())) + .unwrap() + } else { + None + } + } else { + Some(message.chat()) + } + .unwrap_or(message.chat()); + // Handle MessageReply if message.reply_to_message_id() != 0 { let reply = MessageReply::new( - message.chat(), + message_chat, message.reply_to_message_id(), message.is_outgoing(), ); diff --git a/src/session/content/message_row/mod.rs b/src/session/content/message_row/mod.rs index 5508b5145..b01c6d350 100644 --- a/src/session/content/message_row/mod.rs +++ b/src/session/content/message_row/mod.rs @@ -213,7 +213,7 @@ impl MessageRow { if let Some(message) = message.downcast_ref::() { let show_avatar = if message.is_outgoing() { false - } else if message.chat().is_own_chat() { + } else if message.chat().is_own_chat() || message.chat().is_replies_chat() { message.forward_info().is_some() } else { match message.chat().type_() { @@ -241,7 +241,7 @@ impl MessageRow { } }; - if message.chat().is_own_chat() { + if message.chat().is_own_chat() || message.chat().is_replies_chat() { match message.forward_info().unwrap().origin() { MessageForwardOrigin::User(user) => { avatar.set_custom_text(None); diff --git a/src/session/sidebar/row.rs b/src/session/sidebar/row.rs index ef7272fd1..83aae43f8 100644 --- a/src/session/sidebar/row.rs +++ b/src/session/sidebar/row.rs @@ -571,7 +571,7 @@ fn sender_label(message: Message) -> Option { _ => return None, } - if message.chat().is_own_chat() { + if message.chat().is_own_chat() || message.chat().is_replies_chat() { if message.is_outgoing() { None } else { diff --git a/src/tdlib/chat.rs b/src/tdlib/chat.rs index d07d82df4..a3762648d 100644 --- a/src/tdlib/chat.rs +++ b/src/tdlib/chat.rs @@ -481,6 +481,10 @@ impl Chat { self.type_().user() == Some(&self.session().me()) } + pub(crate) fn is_replies_chat(&self) -> bool { + self.id() == 1271266957 || self.id() == 708513 + } + pub(crate) fn permissions(&self) -> BoxedChatPermissions { self.imp().permissions.borrow().to_owned().unwrap() } diff --git a/src/tdlib/message.rs b/src/tdlib/message.rs index f60921db7..42ba09e75 100644 --- a/src/tdlib/message.rs +++ b/src/tdlib/message.rs @@ -303,7 +303,7 @@ impl Message { } pub(crate) fn sender_display_name_expression(&self) -> gtk::Expression { - if self.chat().is_own_chat() { + if self.chat().is_own_chat() || self.chat().is_replies_chat() { self.forward_info() .map(MessageForwardInfo::origin) .map(|forward_origin| match forward_origin {