feat: Disable MDNs for bots by default

- To avoid receiving undecryptable MDNs by bots and replying to them if the bot's key changes.
- MDNs from bots don't look useful in general, usually the user expects some reply from the bot, not
  just that the message is read.
This commit is contained in:
iequidoo
2024-08-06 18:35:10 -03:00
committed by iequidoo
parent f03ffa7641
commit 5ce44ade17
4 changed files with 29 additions and 18 deletions

View File

@@ -129,7 +129,6 @@ pub enum Config {
/// True if Message Delivery Notifications (read receipts) should
/// be sent and requested.
#[strum(props(default = "1"))]
MdnsEnabled,
/// True if "Sent" folder should be watched for changes.
@@ -515,6 +514,14 @@ 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> {
match self.get_config_bool_opt(Config::MdnsEnabled).await? {
Some(val) => Ok(val),
None => Ok(!self.get_config_bool(Config::Bot).await?),
}
}
/// Gets configured "delete_server_after" value.
///
/// `None` means never delete the message, `Some(0)` means delete
@@ -964,6 +971,15 @@ mod tests {
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_mdns_enabled() -> Result<()> {
let t = &TestContext::new_alice().await;
assert!(t.mdns_enabled().await?);
t.set_config_bool(Config::Bot, true).await?;
assert!(!t.mdns_enabled().await?);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_sync() -> Result<()> {
let alice0 = TestContext::new_alice().await;
@@ -990,7 +1006,6 @@ mod tests {
// Reset to default. Test that it's not synced because defaults may differ across client
// versions.
alice0.set_config(Config::MdnsEnabled, None).await?;
assert_eq!(alice0.get_config_bool(Config::MdnsEnabled).await?, true);
alice0.set_config_bool(Config::MdnsEnabled, false).await?;
sync(&alice0, &alice1).await;
assert_eq!(alice1.get_config_bool(Config::MdnsEnabled).await?, false);