From 7c6d6a4b12ff04f9d9ff3b64ba4f5774538076fc Mon Sep 17 00:00:00 2001 From: iequidoo Date: Fri, 9 Aug 2024 12:39:35 -0300 Subject: [PATCH] fix: Still send MDNs from bots by default Fixup for 5ce44ade1. It is good that read receipts are sent by bots to see the bot received the message. Thanks to @adbenitez for pointing this out. --- src/config.rs | 20 +++++++++++++++----- src/message.rs | 2 +- src/mimefactory.rs | 2 +- src/smtp.rs | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index 978becda3b..08c884589a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -514,14 +514,22 @@ impl Context { && !self.get_config_bool(Config::Bot).await?) } - /// Returns whether MDNs should be requested and sent. - pub(crate) async fn mdns_enabled(&self) -> Result { + /// Returns whether MDNs should be requested. + pub(crate) async fn should_request_mdns(&self) -> Result { match self.get_config_bool_opt(Config::MdnsEnabled).await? { Some(val) => Ok(val), None => Ok(!self.get_config_bool(Config::Bot).await?), } } + /// Returns whether MDNs should be sent. + pub(crate) async fn should_send_mdns(&self) -> Result { + Ok(self + .get_config_bool_opt(Config::MdnsEnabled) + .await? + .unwrap_or(true)) + } + /// Gets configured "delete_server_after" value. /// /// `None` means never delete the message, `Some(0)` means delete @@ -972,11 +980,13 @@ mod tests { } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] - async fn test_mdns_enabled() -> Result<()> { + async fn test_mdns_default_behaviour() -> Result<()> { let t = &TestContext::new_alice().await; - assert!(t.mdns_enabled().await?); + assert!(t.should_request_mdns().await?); + assert!(t.should_send_mdns().await?); t.set_config_bool(Config::Bot, true).await?; - assert!(!t.mdns_enabled().await?); + assert!(!t.should_request_mdns().await?); + assert!(t.should_send_mdns().await?); Ok(()) } diff --git a/src/message.rs b/src/message.rs index 6637a11299..9b1790e9fe 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1769,7 +1769,7 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec) -> Result<()> if curr_blocked == Blocked::Not && curr_param.get_bool(Param::WantsMdn).unwrap_or_default() && curr_param.get_cmd() == SystemMessage::Unknown - && context.mdns_enabled().await? + && context.should_send_mdns().await? { context .sql diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 2796e51eec..154c1b3fd8 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -186,7 +186,7 @@ impl MimeFactory { if !msg.is_system_message() && msg.param.get_int(Param::Reaction).unwrap_or_default() == 0 - && context.mdns_enabled().await? + && context.should_request_mdns().await? { req_mdn = true; } diff --git a/src/smtp.rs b/src/smtp.rs index 7bbe732647..1c7db83ef6 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -631,7 +631,7 @@ async fn send_mdn_rfc724_mid( /// Tries to send a single MDN. Returns true if more MDNs should be sent. async fn send_mdn(context: &Context, smtp: &mut Smtp) -> Result { - if !context.mdns_enabled().await? { + if !context.should_send_mdns().await? { context.sql.execute("DELETE FROM smtp_mdns", []).await?; return Ok(false); }