Skip to content

Commit f3a38d7

Browse files
Simon-LauxJikstra
andauthored
Add get_contact_encryption_info and get_connectivity_html
Fix get_connectivity_html and get_encrinfo futures not being Send. See rust-lang/rust#101650 for more information. Co-authored-by: jikstra <[email protected]>
1 parent 8a30b7d commit f3a38d7

File tree

3 files changed

+46
-31
lines changed

3 files changed

+46
-31
lines changed

deltachat-jsonrpc/src/api/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,19 @@ impl CommandApi {
793793
}
794794
Ok(contacts)
795795
}
796+
797+
/// Get encryption info for a contact.
798+
/// Get a multi-line encryption info, containing your fingerprint and the
799+
/// fingerprint of the contact, used e.g. to compare the fingerprints for a simple out-of-band verification.
800+
async fn get_contact_encryption_info(
801+
&self,
802+
account_id: u32,
803+
contact_id: u32,
804+
) -> Result<String> {
805+
let ctx = self.get_context(account_id).await?;
806+
Contact::get_encrinfo(&ctx, ContactId::new(contact_id)).await
807+
}
808+
796809
// ---------------------------------------------
797810
// chat
798811
// ---------------------------------------------
@@ -858,6 +871,20 @@ impl CommandApi {
858871
Ok(ctx.get_connectivity().await as u32)
859872
}
860873

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

src/contact.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -896,11 +896,8 @@ impl Contact {
896896
EncryptPreference::Reset => stock_str::encr_none(context).await,
897897
};
898898

899-
ret += &format!(
900-
"{}.\n{}:",
901-
stock_message,
902-
stock_str::finger_prints(context).await
903-
);
899+
let finger_prints = stock_str::finger_prints(context).await;
900+
ret += &format!("{}.\n{}:", stock_message, finger_prints);
904901

905902
let fingerprint_self = SignedPublicKey::load_self(context)
906903
.await?

src/scheduler/connectivity.rs

+17-26
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ impl Context {
390390
// =============================================================================================
391391

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

@@ -432,10 +433,8 @@ impl Context {
432433
// Your last message was sent successfully
433434
// =============================================================================================
434435

435-
ret += &format!(
436-
"<h3>{}</h3><ul><li>",
437-
stock_str::outgoing_messages(self).await
438-
);
436+
let outgoing_messages = stock_str::outgoing_messages(self).await;
437+
ret += &format!("<h3>{}</h3><ul><li>", outgoing_messages);
439438
let detailed = smtp.get_detailed().await;
440439
ret += &*detailed.to_icon();
441440
ret += " ";
@@ -450,10 +449,8 @@ impl Context {
450449
// =============================================================================================
451450

452451
let domain = tools::EmailAddress::new(&self.get_primary_self_addr().await?)?.domain;
453-
ret += &format!(
454-
"<h3>{}</h3><ul>",
455-
stock_str::storage_on_domain(self, domain).await
456-
);
452+
let storage_on_domain = stock_str::storage_on_domain(self, domain).await;
453+
ret += &format!("<h3>{}</h3><ul>", storage_on_domain);
457454
let quota = self.quota.read().await;
458455
if let Some(quota) = &*quota {
459456
match &quota.recent {
@@ -473,30 +470,23 @@ impl Context {
473470
info!(self, "connectivity: root name hidden: \"{}\"", root_name);
474471
}
475472

473+
let messages = stock_str::messages(self).await;
474+
let part_of_total_used = stock_str::part_of_total_used(
475+
self,
476+
resource.usage.to_string(),
477+
resource.limit.to_string(),
478+
)
479+
.await;
476480
ret += &match &resource.name {
477481
Atom(resource_name) => {
478482
format!(
479483
"<b>{}:</b> {}",
480484
&*escaper::encode_minimal(resource_name),
481-
stock_str::part_of_total_used(
482-
self,
483-
resource.usage.to_string(),
484-
resource.limit.to_string()
485-
)
486-
.await,
485+
part_of_total_used
487486
)
488487
}
489488
Message => {
490-
format!(
491-
"<b>{}:</b> {}",
492-
stock_str::messages(self).await,
493-
stock_str::part_of_total_used(
494-
self,
495-
resource.usage.to_string(),
496-
resource.limit.to_string()
497-
)
498-
.await,
499-
)
489+
format!("<b>{}:</b> {}", part_of_total_used, messages)
500490
}
501491
Storage => {
502492
// do not use a special title needed for "Storage":
@@ -538,7 +528,8 @@ impl Context {
538528
self.schedule_quota_update().await?;
539529
}
540530
} else {
541-
ret += &format!("<li>{}</li>", stock_str::not_connected(self).await);
531+
let not_connected = stock_str::not_connected(self).await;
532+
ret += &format!("<li>{}</li>", not_connected);
542533
self.schedule_quota_update().await?;
543534
}
544535
ret += "</ul>";

0 commit comments

Comments
 (0)