mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
Make it more performant
This commit is contained in:
28
src/chat.rs
28
src/chat.rs
@@ -3134,12 +3134,7 @@ pub async fn send_text_msg(
|
|||||||
/// Returns true if the message can be edited.
|
/// Returns true if the message can be edited.
|
||||||
pub async fn can_send_edit_request(context: &Context, msg_id: MsgId) -> Result<bool> {
|
pub async fn can_send_edit_request(context: &Context, msg_id: MsgId) -> Result<bool> {
|
||||||
let msg = Message::load_from_db(context, msg_id).await?;
|
let msg = Message::load_from_db(context, msg_id).await?;
|
||||||
if msg.from_id != ContactId::SELF
|
if !can_send_edit_request_for_msg(&msg) {
|
||||||
|| msg.is_info()
|
|
||||||
|| msg.viewtype == Viewtype::VideochatInvitation
|
|
||||||
|| msg.has_html()
|
|
||||||
|| msg.text.is_empty()
|
|
||||||
{
|
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
let chat = Chat::load_from_db(context, msg.get_chat_id()).await?;
|
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<b
|
|||||||
Ok(can_send)
|
Ok(can_send)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn can_send_edit_request_for_msg(msg: &Message) -> 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.
|
/// 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<()> {
|
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");
|
ensure!(!new_text.trim().is_empty(), "Edited text cannot be empty");
|
||||||
|
|
||||||
let mut original_msg = Message::load_from_db(context, msg_id).await?;
|
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 {
|
if original_msg.text == new_text {
|
||||||
info!(context, "Text unchanged.");
|
info!(context, "Text unchanged.");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|||||||
Reference in New Issue
Block a user