fix: Display Config::MdnsEnabled as true by default (#5948)

This commit is contained in:
iequidoo
2024-09-02 20:02:58 -03:00
committed by iequidoo
parent 0a46e64971
commit c257482838

View File

@@ -129,6 +129,7 @@ pub enum Config {
/// True if Message Delivery Notifications (read receipts) should /// True if Message Delivery Notifications (read receipts) should
/// be sent and requested. /// be sent and requested.
#[strum(props(default = "1"))]
MdnsEnabled, MdnsEnabled,
/// True if "Sent" folder should be watched for changes. /// True if "Sent" folder should be watched for changes.
@@ -538,18 +539,15 @@ impl Context {
/// Returns whether MDNs should be requested. /// Returns whether MDNs should be requested.
pub(crate) async fn should_request_mdns(&self) -> Result<bool> { pub(crate) async fn should_request_mdns(&self) -> Result<bool> {
match self.get_config_bool_opt(Config::MdnsEnabled).await? { match self.config_exists(Config::MdnsEnabled).await? {
Some(val) => Ok(val), true => self.get_config_bool(Config::MdnsEnabled).await,
None => Ok(!self.get_config_bool(Config::Bot).await?), false => Ok(!self.get_config_bool(Config::Bot).await?),
} }
} }
/// Returns whether MDNs should be sent. /// Returns whether MDNs should be sent.
pub(crate) async fn should_send_mdns(&self) -> Result<bool> { pub(crate) async fn should_send_mdns(&self) -> Result<bool> {
Ok(self self.get_config_bool(Config::MdnsEnabled).await
.get_config_bool_opt(Config::MdnsEnabled)
.await?
.unwrap_or(true))
} }
/// Gets configured "delete_server_after" value. /// Gets configured "delete_server_after" value.
@@ -1006,9 +1004,13 @@ mod tests {
let t = &TestContext::new_alice().await; let t = &TestContext::new_alice().await;
assert!(t.should_request_mdns().await?); assert!(t.should_request_mdns().await?);
assert!(t.should_send_mdns().await?); assert!(t.should_send_mdns().await?);
// The setting should be displayed correctly.
assert!(t.get_config_bool(Config::MdnsEnabled).await?);
t.set_config_bool(Config::Bot, true).await?; t.set_config_bool(Config::Bot, true).await?;
assert!(!t.should_request_mdns().await?); assert!(!t.should_request_mdns().await?);
assert!(t.should_send_mdns().await?); assert!(t.should_send_mdns().await?);
assert!(t.get_config_bool(Config::MdnsEnabled).await?);
Ok(()) Ok(())
} }