mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 05:16:28 +03:00
refactor: Move logins into SQL table (#6724)
Move all `configured_*` parameters into a new SQL table `transports`. All `configured_*` parameters are deprecated; the only exception is `configured_addr`, which is used to store the address of the primary transport. Currently, there can only ever be one primary transport (i.e. the `transports` table only ever has one row); this PR is not supposed to change DC's behavior in any meaningful way. This is a preparation for mt. --------- Co-authored-by: l <link2xt@testrun.org>
This commit is contained in:
@@ -35,7 +35,7 @@ use crate::login_param::{
|
||||
};
|
||||
use crate::message::Message;
|
||||
use crate::oauth2::get_oauth2_addr;
|
||||
use crate::provider::{Protocol, Socket, UsernamePattern};
|
||||
use crate::provider::{Protocol, Provider, Socket, UsernamePattern};
|
||||
use crate::qr::set_account_from_qr;
|
||||
use crate::smtp::Smtp;
|
||||
use crate::sync::Sync::*;
|
||||
@@ -63,7 +63,7 @@ macro_rules! progress {
|
||||
impl Context {
|
||||
/// Checks if the context is already configured.
|
||||
pub async fn is_configured(&self) -> Result<bool> {
|
||||
self.sql.get_raw_config_bool("configured").await
|
||||
self.sql.exists("SELECT COUNT(*) FROM transports", ()).await
|
||||
}
|
||||
|
||||
/// Configures this account with the currently provided parameters.
|
||||
@@ -181,9 +181,21 @@ impl Context {
|
||||
/// Use [Self::add_transport()] to add or change a transport
|
||||
/// and [Self::delete_transport()] to delete a transport.
|
||||
pub async fn list_transports(&self) -> Result<Vec<EnteredLoginParam>> {
|
||||
let param = EnteredLoginParam::load(self).await?;
|
||||
let transports = self
|
||||
.sql
|
||||
.query_map(
|
||||
"SELECT entered_param FROM transports",
|
||||
(),
|
||||
|row| row.get::<_, String>(0),
|
||||
|rows| {
|
||||
rows.flatten()
|
||||
.map(|s| Ok(serde_json::from_str(&s)?))
|
||||
.collect::<Result<Vec<EnteredLoginParam>>>()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(vec![param])
|
||||
Ok(transports)
|
||||
}
|
||||
|
||||
/// Removes the transport with the specified email address
|
||||
@@ -197,20 +209,20 @@ impl Context {
|
||||
info!(self, "Configure ...");
|
||||
|
||||
let old_addr = self.get_config(Config::ConfiguredAddr).await?;
|
||||
let configured_param = configure(self, param).await?;
|
||||
let provider = configure(self, param).await?;
|
||||
self.set_config_internal(Config::NotifyAboutWrongPw, Some("1"))
|
||||
.await?;
|
||||
on_configure_completed(self, configured_param, old_addr).await?;
|
||||
on_configure_completed(self, provider, old_addr).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn on_configure_completed(
|
||||
context: &Context,
|
||||
param: ConfiguredLoginParam,
|
||||
provider: Option<&'static Provider>,
|
||||
old_addr: Option<String>,
|
||||
) -> Result<()> {
|
||||
if let Some(provider) = param.provider {
|
||||
if let Some(provider) = provider {
|
||||
if let Some(config_defaults) = provider.config_defaults {
|
||||
for def in config_defaults {
|
||||
if !context.config_exists(def.key).await? {
|
||||
@@ -446,7 +458,7 @@ async fn get_configured_param(
|
||||
Ok(configured_login_param)
|
||||
}
|
||||
|
||||
async fn configure(ctx: &Context, param: &EnteredLoginParam) -> Result<ConfiguredLoginParam> {
|
||||
async fn configure(ctx: &Context, param: &EnteredLoginParam) -> Result<Option<&'static Provider>> {
|
||||
progress!(ctx, 1);
|
||||
|
||||
let ctx2 = ctx.clone();
|
||||
@@ -556,7 +568,11 @@ async fn configure(ctx: &Context, param: &EnteredLoginParam) -> Result<Configure
|
||||
}
|
||||
}
|
||||
|
||||
configured_param.save_as_configured_params(ctx).await?;
|
||||
let provider = configured_param.provider;
|
||||
configured_param
|
||||
.save_to_transports_table(ctx, param)
|
||||
.await?;
|
||||
|
||||
ctx.set_config_internal(Config::ConfiguredTimestamp, Some(&time().to_string()))
|
||||
.await?;
|
||||
|
||||
@@ -572,7 +588,7 @@ async fn configure(ctx: &Context, param: &EnteredLoginParam) -> Result<Configure
|
||||
ctx.sql.set_raw_config_bool("configured", true).await?;
|
||||
ctx.emit_event(EventType::AccountsItemChanged);
|
||||
|
||||
Ok(configured_param)
|
||||
Ok(provider)
|
||||
}
|
||||
|
||||
/// Retrieve available autoconfigurations.
|
||||
|
||||
Reference in New Issue
Block a user