From 8a76f2e10d5ed115b5bbe3db00c356f9b3631428 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Fri, 9 Sep 2022 21:35:17 +0200 Subject: [PATCH 1/5] jsonrpc: add two functions, but they don't compile yet, being not "threadsafe" --- deltachat-jsonrpc/src/api/mod.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/deltachat-jsonrpc/src/api/mod.rs b/deltachat-jsonrpc/src/api/mod.rs index bd936406e9..71f97316d8 100644 --- a/deltachat-jsonrpc/src/api/mod.rs +++ b/deltachat-jsonrpc/src/api/mod.rs @@ -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 { + let ctx = self.get_context(account_id).await?; + Contact::get_encrinfo(&ctx, ContactId::new(contact_id)).await + } + // --------------------------------------------- // chat // --------------------------------------------- @@ -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 { + let ctx = self.get_context(account_id).await?; + ctx.get_connectivity_html().await + } + // --------------------------------------------- // webxdc // --------------------------------------------- From 07b2720ad3cc14dea2bb6ca70c2c30d49684cd47 Mon Sep 17 00:00:00 2001 From: jikstra Date: Sat, 10 Sep 2022 15:36:53 +0200 Subject: [PATCH 2/5] Make get_connectivity_html future Send --- src/scheduler/connectivity.rs | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/scheduler/connectivity.rs b/src/scheduler/connectivity.rs index 4fe16c90ba..59c0f090cf 100644 --- a/src/scheduler/connectivity.rs +++ b/src/scheduler/connectivity.rs @@ -390,7 +390,8 @@ impl Context { // ============================================================================================= let watched_folders = get_watched_folder_configs(self).await?; - ret += &format!("

{}

    ", stock_str::incoming_messages(self).await); + let incoming_messages = stock_str::incoming_messages(self).await; + ret += &format!("

    {}

      ", incoming_messages); for (folder, state) in &folders_states { let mut folder_added = false; @@ -432,9 +433,10 @@ impl Context { // Your last message was sent successfully // ============================================================================================= + let outgoing_messages = stock_str::outgoing_messages(self).await; ret += &format!( "

      {}

      • ", - stock_str::outgoing_messages(self).await + outgoing_messages ); let detailed = smtp.get_detailed().await; ret += &*detailed.to_icon(); @@ -450,9 +452,10 @@ impl Context { // ============================================================================================= let domain = tools::EmailAddress::new(&self.get_primary_self_addr().await?)?.domain; + let storage_on_domain = stock_str::storage_on_domain(self, domain).await; ret += &format!( "

        {}

          ", - stock_str::storage_on_domain(self, domain).await + storage_on_domain ); let quota = self.quota.read().await; if let Some(quota) = &*quota { @@ -473,29 +476,26 @@ impl Context { info!(self, "connectivity: root name hidden: \"{}\"", root_name); } + let part_of_total_used = stock_str::part_of_total_used( + self, + resource.usage.to_string(), + resource.limit.to_string() + ) + .await; + let messages = stock_str::messages(self).await; ret += &match &resource.name { Atom(resource_name) => { format!( "{}: {}", &*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!( "{}: {}", - stock_str::messages(self).await, - stock_str::part_of_total_used( - self, - resource.usage.to_string(), - resource.limit.to_string() - ) - .await, + part_of_total_used, + messages ) } Storage => { @@ -538,7 +538,8 @@ impl Context { self.schedule_quota_update().await?; } } else { - ret += &format!("
        • {}
        • ", stock_str::not_connected(self).await); + let not_connected = stock_str::not_connected(self).await; + ret += &format!("
        • {}
        • ", not_connected); self.schedule_quota_update().await?; } ret += "
        "; From b884ae36c20212f8a6ae0e6057f9a5008c722b86 Mon Sep 17 00:00:00 2001 From: jikstra Date: Sat, 10 Sep 2022 15:41:13 +0200 Subject: [PATCH 3/5] Make get_encrinfo Future Send --- src/contact.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/contact.rs b/src/contact.rs index 66b25b7cd8..8851bb5b08 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -896,10 +896,11 @@ impl Contact { EncryptPreference::Reset => stock_str::encr_none(context).await, }; + let finger_prints = stock_str::finger_prints(context).await; ret += &format!( "{}.\n{}:", stock_message, - stock_str::finger_prints(context).await + finger_prints ); let fingerprint_self = SignedPublicKey::load_self(context) From f3fa918ad5c48b016e1d4a8e2beeb8821ae33940 Mon Sep 17 00:00:00 2001 From: jikstra Date: Sat, 10 Sep 2022 15:42:18 +0200 Subject: [PATCH 4/5] Reorder two variables --- src/scheduler/connectivity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scheduler/connectivity.rs b/src/scheduler/connectivity.rs index 59c0f090cf..43653d5b80 100644 --- a/src/scheduler/connectivity.rs +++ b/src/scheduler/connectivity.rs @@ -476,13 +476,13 @@ 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; - let messages = stock_str::messages(self).await; ret += &match &resource.name { Atom(resource_name) => { format!( From c155bff0c43efd665e6bfca78b35e589a366af45 Mon Sep 17 00:00:00 2001 From: jikstra Date: Sat, 10 Sep 2022 15:44:38 +0200 Subject: [PATCH 5/5] cargo fmt --- src/contact.rs | 6 +----- src/scheduler/connectivity.rs | 26 ++++++++------------------ 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/contact.rs b/src/contact.rs index 8851bb5b08..079b015b0d 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -897,11 +897,7 @@ impl Contact { }; let finger_prints = stock_str::finger_prints(context).await; - ret += &format!( - "{}.\n{}:", - stock_message, - finger_prints - ); + ret += &format!("{}.\n{}:", stock_message, finger_prints); let fingerprint_self = SignedPublicKey::load_self(context) .await? diff --git a/src/scheduler/connectivity.rs b/src/scheduler/connectivity.rs index 43653d5b80..880c2760a6 100644 --- a/src/scheduler/connectivity.rs +++ b/src/scheduler/connectivity.rs @@ -434,10 +434,7 @@ impl Context { // ============================================================================================= let outgoing_messages = stock_str::outgoing_messages(self).await; - ret += &format!( - "

        {}

        • ", - outgoing_messages - ); + ret += &format!("

          {}

          • ", outgoing_messages); let detailed = smtp.get_detailed().await; ret += &*detailed.to_icon(); ret += " "; @@ -453,10 +450,7 @@ impl Context { let domain = tools::EmailAddress::new(&self.get_primary_self_addr().await?)?.domain; let storage_on_domain = stock_str::storage_on_domain(self, domain).await; - ret += &format!( - "

            {}

              ", - storage_on_domain - ); + ret += &format!("

              {}

                ", storage_on_domain); let quota = self.quota.read().await; if let Some(quota) = &*quota { match "a.recent { @@ -478,11 +472,11 @@ impl Context { 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; + self, + resource.usage.to_string(), + resource.limit.to_string(), + ) + .await; ret += &match &resource.name { Atom(resource_name) => { format!( @@ -492,11 +486,7 @@ impl Context { ) } Message => { - format!( - "{}: {}", - part_of_total_used, - messages - ) + format!("{}: {}", part_of_total_used, messages) } Storage => { // do not use a special title needed for "Storage":