mirror of
https://github.com/chatmail/core.git
synced 2026-05-24 17:26:30 +03:00
Make last_msg_in_chat_encrypted a member function
This commit is contained in:
committed by
holger krekel
parent
10ceddfa67
commit
36a2569537
46
src/chat.rs
46
src/chat.rs
@@ -202,6 +202,28 @@ impl Chat {
|
|||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn last_msg_in_chat_encrypted(&self, context: &Context, sql: &Sql) -> bool {
|
||||||
|
let packed: Option<String> = sql.query_get_value(
|
||||||
|
context,
|
||||||
|
"SELECT param \
|
||||||
|
FROM msgs WHERE timestamp=(SELECT MAX(timestamp) FROM msgs WHERE chat_id=?) \
|
||||||
|
ORDER BY id DESC;",
|
||||||
|
params![self.id as i32],
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Some(ref packed) = packed {
|
||||||
|
match packed.parse::<Params>() {
|
||||||
|
Ok(param) => param.exists(Param::GuaranteeE2ee),
|
||||||
|
Err(err) => {
|
||||||
|
error!(context, "invalid params stored: '{}', {:?}", packed, err);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_profile_image(&self, context: &Context) -> Option<PathBuf> {
|
pub fn get_profile_image(&self, context: &Context) -> Option<PathBuf> {
|
||||||
if let Some(image_rel) = self.param.get(Param::ProfileImage) {
|
if let Some(image_rel) = self.param.get(Param::ProfileImage) {
|
||||||
if !image_rel.is_empty() {
|
if !image_rel.is_empty() {
|
||||||
@@ -404,7 +426,7 @@ impl Chat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if can_encrypt
|
if can_encrypt
|
||||||
&& (all_mutual || last_msg_in_chat_encrypted(context, &context.sql, self.id))
|
&& (all_mutual || self.last_msg_in_chat_encrypted(context, &context.sql))
|
||||||
{
|
{
|
||||||
msg.param.set_int(Param::GuaranteeE2ee, 1);
|
msg.param.set_int(Param::GuaranteeE2ee, 1);
|
||||||
}
|
}
|
||||||
@@ -904,28 +926,6 @@ fn prepare_msg_common(context: &Context, chat_id: u32, msg: &mut Message) -> Res
|
|||||||
Ok(msg.id)
|
Ok(msg.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn last_msg_in_chat_encrypted(context: &Context, sql: &Sql, chat_id: u32) -> bool {
|
|
||||||
let packed: Option<String> = sql.query_get_value(
|
|
||||||
context,
|
|
||||||
"SELECT param \
|
|
||||||
FROM msgs WHERE timestamp=(SELECT MAX(timestamp) FROM msgs WHERE chat_id=?) \
|
|
||||||
ORDER BY id DESC;",
|
|
||||||
params![chat_id as i32],
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(ref packed) = packed {
|
|
||||||
match packed.parse::<Params>() {
|
|
||||||
Ok(param) => param.exists(Param::GuaranteeE2ee),
|
|
||||||
Err(err) => {
|
|
||||||
error!(context, "invalid params stored: '{}', {:?}", packed, err);
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns whether a contact is in a chat or not.
|
/// Returns whether a contact is in a chat or not.
|
||||||
pub fn is_contact_in_chat(context: &Context, chat_id: u32, contact_id: u32) -> bool {
|
pub fn is_contact_in_chat(context: &Context, chat_id: u32, contact_id: u32) -> bool {
|
||||||
/* this function works for group and for normal chats, however, it is more useful for group chats.
|
/* this function works for group and for normal chats, however, it is more useful for group chats.
|
||||||
|
|||||||
Reference in New Issue
Block a user