From 5f7ca4ff9afcd02feff74601a5412bcd4a07b211 Mon Sep 17 00:00:00 2001 From: Septias Date: Sat, 2 Nov 2024 09:53:02 +0100 Subject: [PATCH] add alias handling --- src/chat.rs | 23 +++++++++++++++++++++++ src/mimeparser.rs | 9 +++++++++ src/receive_imf.rs | 8 ++++++++ src/stock_str.rs | 2 +- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/chat.rs b/src/chat.rs index 9d36f30d8..30c432aaa 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3481,6 +3481,29 @@ pub async fn get_chat_contacts(context: &Context, chat_id: ChatId) -> Result Result> { + // Normal chats do not include SELF. Group chats do (as it may happen that one is deleted from a + // groupchat but the chats stays visible, moreover, this makes displaying lists easier) + + let list = context + .sql + .query_map( + "SELECT cc.contact_id + FROM chats_contacts cc + LEFT JOIN contacts c + ON c.id=cc.contact_id + WHERE cc.chat_id=? AND c.id!=1 + ORDER BY c.id=1, c.last_seen DESC, c.id DESC;", + (chat_id,), + |row| row.get::<_, ContactId>(0), + |ids| ids.collect::, _>>().map_err(Into::into), + ) + .await?; + + Ok(list) +} + /// Creates a group chat with a given `name`. pub async fn create_group_chat( context: &Context, diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 93ac53651..662b8c7f4 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -770,6 +770,15 @@ impl MimeMessage { Ok(()) } + /// Set different sender name for a message. + /// This overrides the name set by the `set_config()`-option `displayname`. + pub fn set_override_sender_name(&mut self, name: Option) { + self.parts.iter_mut().for_each(|part| { + part.param + .set_optional(Param::OverrideSenderDisplayname, name.clone()); + }); + } + async fn avatar_action_from_header( &mut self, context: &Context, diff --git a/src/receive_imf.rs b/src/receive_imf.rs index f3d513a60..1a6ee0135 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1807,6 +1807,14 @@ async fn lookup_chat_by_reply( // If this was a private message just to self, it was probably a private reply. // It should not go into the group then, but into the private chat. if is_probably_private_reply(context, to_ids, from_id, mime_parser, parent_chat.id).await? { + // If the parent chat is a 1:1 chat, then the message should go to the 1:1 chat. + if to_ids.len() == 1 { + let name = chat::get_other_chat_contacts(context, parent_chat_id).await?[0]; + if from_id != *name { + mime_parser.set_override_sender_name(Some(name.get_stock_name(context).await)); + } + return Ok(Some((parent_chat.id, parent_chat.blocked))); + } return Ok(None); } diff --git a/src/stock_str.rs b/src/stock_str.rs index d03cc193d..bf925d8fd 100644 --- a/src/stock_str.rs +++ b/src/stock_str.rs @@ -542,7 +542,7 @@ impl ContactId { } /// Get contact name, e.g. `Bob`, or `bob@exmple.net` if no name is set. - async fn get_stock_name(self, context: &Context) -> String { + pub async fn get_stock_name(self, context: &Context) -> String { Contact::get_by_id(context, self) .await .map(|contact| contact.get_display_name().to_string())