Skip to content

Commit

Permalink
fix: Still send MDNs from bots by default
Browse files Browse the repository at this point in the history
Fixup for 5ce44ad. It is good that read receipts are sent by bots to see the bot received the
message. Thanks to @adbenitez for pointing this out.
  • Loading branch information
iequidoo committed Aug 9, 2024
1 parent 745b33f commit 7c6d6a4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
20 changes: 15 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mimefactory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/smtp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 7c6d6a4

Please sign in to comment.