From badbf766bb3b0e82cfbfb778900c377fe1aaf875 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Fri, 13 Jan 2023 15:47:26 -0300 Subject: [PATCH] Move event emitting for a new message to a separate function --- src/chat.rs | 16 +++++++++++----- src/receive_imf.rs | 6 +----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 0b54efc50..042f10b2d 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -545,6 +545,16 @@ impl ChatId { Ok(()) } + /// Emits an appropriate event for a message. `important` is whether a notification should be + /// shown. + pub(crate) fn emit_msg_event(self, context: &Context, msg_id: MsgId, important: bool) { + if important { + context.emit_incoming_msg(self, msg_id); + } else { + context.emit_msgs_changed(self, msg_id); + } + } + /// Deletes a chat. pub async fn delete(self, context: &Context) -> Result<()> { ensure!( @@ -3469,11 +3479,7 @@ pub async fn add_device_msg_with_importance( } if !msg_id.is_unset() { - if important { - context.emit_incoming_msg(chat_id, msg_id); - } else { - context.emit_msgs_changed(chat_id, msg_id); - } + chat_id.emit_msg_event(context, msg_id, important); } Ok(msg_id) diff --git a/src/receive_imf.rs b/src/receive_imf.rs index a28601cd4..55f099726 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -356,11 +356,7 @@ pub(crate) async fn receive_imf_inner( } else if !chat_id.is_trash() { let fresh = received_msg.state == MessageState::InFresh; for msg_id in &received_msg.msg_ids { - if incoming && fresh { - context.emit_incoming_msg(chat_id, *msg_id); - } else { - context.emit_msgs_changed(chat_id, *msg_id); - }; + chat_id.emit_msg_event(context, *msg_id, incoming && fresh); } }