From 48c9945be5fb19c2eeba1f10828d20686a45fbb0 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Mon, 24 Feb 2025 14:12:10 +0100 Subject: [PATCH] Make it more performant --- src/chat.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 49ea4b75f..d7f08fed1 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3134,12 +3134,7 @@ pub async fn send_text_msg( /// Returns true if the message can be edited. pub async fn can_send_edit_request(context: &Context, msg_id: MsgId) -> Result { let msg = Message::load_from_db(context, msg_id).await?; - if msg.from_id != ContactId::SELF - || msg.is_info() - || msg.viewtype == Viewtype::VideochatInvitation - || msg.has_html() - || msg.text.is_empty() - { + if !can_send_edit_request_for_msg(&msg) { return Ok(false); } let chat = Chat::load_from_db(context, msg.get_chat_id()).await?; @@ -3147,15 +3142,28 @@ pub async fn can_send_edit_request(context: &Context, msg_id: MsgId) -> Result bool { + if msg.from_id != ContactId::SELF + || msg.is_info() + || msg.viewtype == Viewtype::VideochatInvitation + || msg.has_html() + || msg.text.is_empty() + { + return false; + } + true +} + /// Sends chat members a request to edit the given message's text. pub async fn send_edit_request(context: &Context, msg_id: MsgId, new_text: String) -> Result<()> { - ensure!( - can_send_edit_request(context, msg_id).await?, - "Message cannot be edited" - ); ensure!(!new_text.trim().is_empty(), "Edited text cannot be empty"); let mut original_msg = Message::load_from_db(context, msg_id).await?; + ensure!( + can_send_edit_request_for_msg(&original_msg), + "Message cannot be edited" + ); + if original_msg.text == new_text { info!(context, "Text unchanged."); return Ok(());