mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 06:16:30 +03:00
refactor: Chat::is_encrypted(): Make one query instead of two for 1:1 chats
This commit is contained in:
29
src/chat.rs
29
src/chat.rs
@@ -1886,16 +1886,25 @@ impl Chat {
|
|||||||
let is_encrypted = self.is_protected()
|
let is_encrypted = self.is_protected()
|
||||||
|| match self.typ {
|
|| match self.typ {
|
||||||
Chattype::Single => {
|
Chattype::Single => {
|
||||||
let chat_contact_ids = get_chat_contacts(context, self.id).await?;
|
match context
|
||||||
if let Some(contact_id) = chat_contact_ids.first() {
|
.sql
|
||||||
if *contact_id == ContactId::DEVICE {
|
.query_row_optional(
|
||||||
true
|
"SELECT cc.contact_id, c.fingerprint<>''
|
||||||
} else {
|
FROM chats_contacts cc LEFT JOIN contacts c
|
||||||
let contact = Contact::get_by_id(context, *contact_id).await?;
|
ON c.id=cc.contact_id
|
||||||
contact.is_key_contact()
|
WHERE cc.chat_id=?
|
||||||
}
|
",
|
||||||
} else {
|
(self.id,),
|
||||||
true
|
|row| {
|
||||||
|
let id: ContactId = row.get(0)?;
|
||||||
|
let is_key: bool = row.get(1)?;
|
||||||
|
Ok((id, is_key))
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
|
Some((id, is_key)) => is_key || id == ContactId::DEVICE,
|
||||||
|
None => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Chattype::Group => {
|
Chattype::Group => {
|
||||||
|
|||||||
Reference in New Issue
Block a user