mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
refactor: Rename EnteredLoginParam::load() and save() to load_legacy() and save_legacy()
This commit is contained in:
@@ -76,7 +76,7 @@ impl Context {
|
|||||||
/// Deprecated since 2025-02; use `add_transport_from_qr()`
|
/// Deprecated since 2025-02; use `add_transport_from_qr()`
|
||||||
/// or `add_or_update_transport()` instead.
|
/// or `add_or_update_transport()` instead.
|
||||||
pub async fn configure(&self) -> Result<()> {
|
pub async fn configure(&self) -> Result<()> {
|
||||||
let mut param = EnteredLoginParam::load(self).await?;
|
let mut param = EnteredLoginParam::load_legacy(self).await?;
|
||||||
|
|
||||||
self.add_transport_inner(&mut param).await
|
self.add_transport_inner(&mut param).await
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ impl Context {
|
|||||||
progress!(self, 0, Some(error_msg.clone()));
|
progress!(self, 0, Some(error_msg.clone()));
|
||||||
bail!(error_msg);
|
bail!(error_msg);
|
||||||
} else {
|
} else {
|
||||||
param.save(self).await?;
|
param.save_legacy(self).await?;
|
||||||
progress!(self, 1000);
|
progress!(self, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,10 +138,11 @@ pub struct EnteredLoginParam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EnteredLoginParam {
|
impl EnteredLoginParam {
|
||||||
/// Loads entered account settings.
|
/// Loads entered account settings
|
||||||
|
/// that were set by the deprecated `configured_*` configs.
|
||||||
///
|
///
|
||||||
/// This is a legacy API for loading from separate config parameters.
|
/// This is only needed by tests and clients using the old CFFI API.
|
||||||
pub(crate) async fn load(context: &Context) -> Result<Self> {
|
pub(crate) async fn load_legacy(context: &Context) -> Result<Self> {
|
||||||
let addr = context
|
let addr = context
|
||||||
.get_config(Config::Addr)
|
.get_config(Config::Addr)
|
||||||
.await?
|
.await?
|
||||||
@@ -241,7 +242,10 @@ impl EnteredLoginParam {
|
|||||||
|
|
||||||
/// Saves entered account settings,
|
/// Saves entered account settings,
|
||||||
/// so that they can be prefilled if the user wants to configure the server again.
|
/// so that they can be prefilled if the user wants to configure the server again.
|
||||||
pub(crate) async fn save(&self, context: &Context) -> Result<()> {
|
///
|
||||||
|
/// This is needed in case a UI is not yet updated, and still uses `get_config("mail_pw")` etc.
|
||||||
|
/// in order to prefill the entered account settings.
|
||||||
|
pub(crate) async fn save_legacy(&self, context: &Context) -> Result<()> {
|
||||||
context.set_config(Config::Addr, Some(&self.addr)).await?;
|
context.set_config(Config::Addr, Some(&self.addr)).await?;
|
||||||
|
|
||||||
context
|
context
|
||||||
@@ -364,7 +368,7 @@ mod tests {
|
|||||||
.await?;
|
.await?;
|
||||||
t.set_config(Config::MailPw, Some("foobarbaz")).await?;
|
t.set_config(Config::MailPw, Some("foobarbaz")).await?;
|
||||||
|
|
||||||
let param = EnteredLoginParam::load(t).await?;
|
let param = EnteredLoginParam::load_legacy(t).await?;
|
||||||
assert_eq!(param.addr, "alice@example.org");
|
assert_eq!(param.addr, "alice@example.org");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
param.certificate_checks,
|
param.certificate_checks,
|
||||||
@@ -373,13 +377,13 @@ mod tests {
|
|||||||
|
|
||||||
t.set_config(Config::ImapCertificateChecks, Some("1"))
|
t.set_config(Config::ImapCertificateChecks, Some("1"))
|
||||||
.await?;
|
.await?;
|
||||||
let param = EnteredLoginParam::load(t).await?;
|
let param = EnteredLoginParam::load_legacy(t).await?;
|
||||||
assert_eq!(param.certificate_checks, EnteredCertificateChecks::Strict);
|
assert_eq!(param.certificate_checks, EnteredCertificateChecks::Strict);
|
||||||
|
|
||||||
// Fail to load invalid settings, but do not panic.
|
// Fail to load invalid settings, but do not panic.
|
||||||
t.set_config(Config::ImapCertificateChecks, Some("999"))
|
t.set_config(Config::ImapCertificateChecks, Some("999"))
|
||||||
.await?;
|
.await?;
|
||||||
assert!(EnteredLoginParam::load(t).await.is_err());
|
assert!(EnteredLoginParam::load_legacy(t).await.is_err());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -407,7 +411,7 @@ mod tests {
|
|||||||
certificate_checks: Default::default(),
|
certificate_checks: Default::default(),
|
||||||
oauth2: false,
|
oauth2: false,
|
||||||
};
|
};
|
||||||
param.save(&t).await?;
|
param.save_legacy(&t).await?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
t.get_config(Config::Addr).await?.unwrap(),
|
t.get_config(Config::Addr).await?.unwrap(),
|
||||||
"alice@example.org"
|
"alice@example.org"
|
||||||
@@ -416,7 +420,7 @@ mod tests {
|
|||||||
assert_eq!(t.get_config(Config::SendPw).await?, None);
|
assert_eq!(t.get_config(Config::SendPw).await?, None);
|
||||||
assert_eq!(t.get_config_int(Config::SendPort).await?, 2947);
|
assert_eq!(t.get_config_int(Config::SendPort).await?, 2947);
|
||||||
|
|
||||||
assert_eq!(EnteredLoginParam::load(&t).await?, param);
|
assert_eq!(EnteredLoginParam::load_legacy(&t).await?, param);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1919,7 +1919,7 @@ CREATE INDEX gossip_timestamp_index ON gossip_timestamp (chat_id, fingerprint);
|
|||||||
|
|
||||||
inc_and_check(&mut migration_version, 131)?;
|
inc_and_check(&mut migration_version, 131)?;
|
||||||
if dbversion < migration_version {
|
if dbversion < migration_version {
|
||||||
let entered_param = EnteredLoginParam::load(context).await?;
|
let entered_param = EnteredLoginParam::load_legacy(context).await?;
|
||||||
let configured_param = ConfiguredLoginParam::load_legacy(context).await?;
|
let configured_param = ConfiguredLoginParam::load_legacy(context).await?;
|
||||||
|
|
||||||
sql.execute_migration_transaction(
|
sql.execute_migration_transaction(
|
||||||
|
|||||||
Reference in New Issue
Block a user