Skip to content

[WIP, help wanted] implement better second device setup #1954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions deltachat-ffi/deltachat.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ char* dc_get_blobdir (const dc_context_t* context);
* https://github.com/cracker0dks/basicwebrtc which some UIs have native support for.
* The type `jitsi:` may be handled by external apps.
* If no type is prefixed, the videochat is handled completely in a browser.
* - `dc_was_used_before` = Set during the configure process. If true, DC was used with this email account before
* and the user re-installed DC or is setting up a second device.
*
* If you want to retrieve a value, use dc_get_config().
*
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ pub enum Config {

/// address to webrtc instance to use for videochats
WebrtcInstance,

DcWasUsedBefore,
}

impl Context {
Expand Down
9 changes: 7 additions & 2 deletions src/configure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,20 @@ async fn configure(ctx: &Context, param: &mut LoginParam) -> Result<()> {
.await
.context("could not read INBOX status")?;

drop(imap);

let was_configured_before = ctx.sql.get_raw_config_bool(ctx, "configured").await;
progress!(ctx, 910);
// configuration success - write back the configured parameters with the
// "configured_" prefix; also write the "configured"-flag */
// the trailing underscore is correct
param.save_to_database(ctx, "configured_").await?;
ctx.sql.set_raw_config_bool(ctx, "configured", true).await?;

if !was_configured_before && imap.was_dc_used_before(ctx).await? {
ctx.set_config(Config::DcWasUsedBefore, Some("1")).await?;
}

drop(imap);

progress!(ctx, 920);

e2ee::ensure_secret_key_exists(ctx).await?;
Expand Down
22 changes: 22 additions & 0 deletions src/imap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use std::collections::BTreeMap;

use anyhow::Context as _;
use async_imap::{
error::Result as ImapResult,
types::{Capability, Fetch, Flag, Mailbox, Name, NameAttribute},
Expand Down Expand Up @@ -1319,6 +1320,27 @@ impl Imap {
info!(context, "FINISHED configuring IMAP-folders.");
Ok(())
}

pub(crate) async fn was_dc_used_before(&mut self, context: &Context) -> Result<bool> {
let self_addr = context
.get_config(Config::ConfiguredAddr)
.await
.context("was_dc_used_before: not configured")?;
for config in &[Config::ConfiguredInboxFolder, Config::ConfiguredMvboxFolder] {
if let Some(mailbox) = context.get_config(*config).await {
self.select_folder(context, Some(&mailbox)).await?;
if let Some(ref mut session) = self.session {
let query = format!(r#"HEADER Chat-Version "" FROM {}"#, self_addr);
if !session.search(query).await?.is_empty() {
info!(context, "Found outgoing chat msgs in {}.", &mailbox);
return Ok(true);
}
}
}
}
info!(context, "Did not find any outgoing chat msgs.");
Ok(false)
}
}

/// Try to get the folder meaning by the name of the folder only used if the server does not support XLIST.
Expand Down