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.
This commit is contained in:
iequidoo
2024-08-09 12:39:35 -03:00
committed by iequidoo
parent 745b33f174
commit 7c6d6a4b12
4 changed files with 18 additions and 8 deletions

View File

@@ -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<bool> {
/// Returns whether MDNs should be requested.
pub(crate) async fn should_request_mdns(&self) -> Result<bool> {
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<bool> {
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(())
}

View File

@@ -1769,7 +1769,7 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> 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

View File

@@ -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;
}

View File

@@ -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<bool> {
if !context.mdns_enabled().await? {
if !context.should_send_mdns().await? {
context.sql.execute("DELETE FROM smtp_mdns", []).await?;
return Ok(false);
}