Skip to content

Commit

Permalink
Add get_contact_encryption_info and get_connectivity_html
Browse files Browse the repository at this point in the history
Fix get_connectivity_html and get_encrinfo futures not being Send. See rust-lang/rust#101650 for more information.

Co-authored-by: jikstra <jikstra@disroot.org>
  • Loading branch information
Simon-Laux and Jikstra committed Sep 11, 2022
1 parent 3ce522b commit 4b70134
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 31 deletions.
27 changes: 27 additions & 0 deletions deltachat-jsonrpc/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,19 @@ impl CommandApi {
}
Ok(contacts)
}

/// Get encryption info for a contact.
/// Get a multi-line encryption info, containing your fingerprint and the
/// fingerprint of the contact, used e.g. to compare the fingerprints for a simple out-of-band verification.
async fn get_contact_encryption_info(
&self,
account_id: u32,
contact_id: u32,
) -> Result<String> {
let ctx = self.get_context(account_id).await?;
Contact::get_encrinfo(&ctx, ContactId::new(contact_id)).await
}

// ---------------------------------------------
// chat
// ---------------------------------------------
Expand Down Expand Up @@ -858,6 +871,20 @@ impl CommandApi {
Ok(ctx.get_connectivity().await as u32)
}

/// Get an overview of the current connectivity, and possibly more statistics.
/// Meant to give the user more insight about the current status than
/// the basic connectivity info returned by get_connectivity(); show this
/// e.g., if the user taps on said basic connectivity info.
///
/// If this page changes, a #DC_EVENT_CONNECTIVITY_CHANGED will be emitted.
///
/// This comes as an HTML from the core so that we can easily improve it
/// and the improvement instantly reaches all UIs.
async fn get_connectivity_html(&self, account_id: u32) -> Result<String> {
let ctx = self.get_context(account_id).await?;
ctx.get_connectivity_html().await
}

// ---------------------------------------------
// webxdc
// ---------------------------------------------
Expand Down
7 changes: 2 additions & 5 deletions src/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,11 +896,8 @@ impl Contact {
EncryptPreference::Reset => stock_str::encr_none(context).await,
};

ret += &format!(
"{}.\n{}:",
stock_message,
stock_str::finger_prints(context).await
);
let finger_prints = stock_str::finger_prints(context).await;
ret += &format!("{}.\n{}:", stock_message, finger_prints);

let fingerprint_self = SignedPublicKey::load_self(context)
.await?
Expand Down
43 changes: 17 additions & 26 deletions src/scheduler/connectivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ impl Context {
// =============================================================================================

let watched_folders = get_watched_folder_configs(self).await?;
ret += &format!("<h3>{}</h3><ul>", stock_str::incoming_messages(self).await);
let incoming_messages = stock_str::incoming_messages(self).await;
ret += &format!("<h3>{}</h3><ul>", incoming_messages);
for (folder, state) in &folders_states {
let mut folder_added = false;

Expand Down Expand Up @@ -432,10 +433,8 @@ impl Context {
// Your last message was sent successfully
// =============================================================================================

ret += &format!(
"<h3>{}</h3><ul><li>",
stock_str::outgoing_messages(self).await
);
let outgoing_messages = stock_str::outgoing_messages(self).await;
ret += &format!("<h3>{}</h3><ul><li>", outgoing_messages);
let detailed = smtp.get_detailed().await;
ret += &*detailed.to_icon();
ret += " ";
Expand All @@ -450,10 +449,8 @@ impl Context {
// =============================================================================================

let domain = tools::EmailAddress::new(&self.get_primary_self_addr().await?)?.domain;
ret += &format!(
"<h3>{}</h3><ul>",
stock_str::storage_on_domain(self, domain).await
);
let storage_on_domain = stock_str::storage_on_domain(self, domain).await;
ret += &format!("<h3>{}</h3><ul>", storage_on_domain);
let quota = self.quota.read().await;
if let Some(quota) = &*quota {
match &quota.recent {
Expand All @@ -473,30 +470,23 @@ impl Context {
info!(self, "connectivity: root name hidden: \"{}\"", root_name);
}

let messages = stock_str::messages(self).await;
let part_of_total_used = stock_str::part_of_total_used(
self,
resource.usage.to_string(),
resource.limit.to_string(),
)
.await;
ret += &match &resource.name {
Atom(resource_name) => {
format!(
"<b>{}:</b> {}",
&*escaper::encode_minimal(resource_name),
stock_str::part_of_total_used(
self,
resource.usage.to_string(),
resource.limit.to_string()
)
.await,
part_of_total_used
)
}
Message => {
format!(
"<b>{}:</b> {}",
stock_str::messages(self).await,
stock_str::part_of_total_used(
self,
resource.usage.to_string(),
resource.limit.to_string()
)
.await,
)
format!("<b>{}:</b> {}", part_of_total_used, messages)
}
Storage => {
// do not use a special title needed for "Storage":
Expand Down Expand Up @@ -538,7 +528,8 @@ impl Context {
self.schedule_quota_update().await?;
}
} else {
ret += &format!("<li>{}</li>", stock_str::not_connected(self).await);
let not_connected = stock_str::not_connected(self).await;
ret += &format!("<li>{}</li>", not_connected);
self.schedule_quota_update().await?;
}
ret += "</ul>";
Expand Down

0 comments on commit 4b70134

Please sign in to comment.