From 36a256953713a1014119aa1f48f9f89d4f395163 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sat, 11 Jan 2020 21:26:52 +0300 Subject: [PATCH] Make last_msg_in_chat_encrypted a member function --- src/chat.rs | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index df1b309b0..f085196d5 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -202,6 +202,28 @@ impl Chat { .ok() } + fn last_msg_in_chat_encrypted(&self, context: &Context, sql: &Sql) -> bool { + let packed: Option = 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::() { + 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 { if let Some(image_rel) = self.param.get(Param::ProfileImage) { if !image_rel.is_empty() { @@ -404,7 +426,7 @@ impl Chat { } 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); } @@ -904,28 +926,6 @@ fn prepare_msg_common(context: &Context, chat_id: u32, msg: &mut Message) -> Res Ok(msg.id) } -fn last_msg_in_chat_encrypted(context: &Context, sql: &Sql, chat_id: u32) -> bool { - let packed: Option = 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::() { - 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. 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.