mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 09:56:35 +03:00
add alias handling
This commit is contained in:
23
src/chat.rs
23
src/chat.rs
@@ -3481,6 +3481,29 @@ pub async fn get_chat_contacts(context: &Context, chat_id: ChatId) -> Result<Vec
|
||||
Ok(list)
|
||||
}
|
||||
|
||||
/// Returns a vector of contact IDs for given chat ID where the contact is not SELF.
|
||||
pub async fn get_other_chat_contacts(context: &Context, chat_id: ChatId) -> Result<Vec<ContactId>> {
|
||||
// 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::<Result<Vec<_>, _>>().map_err(Into::into),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(list)
|
||||
}
|
||||
|
||||
/// Creates a group chat with a given `name`.
|
||||
pub async fn create_group_chat(
|
||||
context: &Context,
|
||||
|
||||
@@ -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<String>) {
|
||||
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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user