[fractal] Get 3PID contacts through matrix-sdk



commit ad230ba82d98ebae11b447e0687318cfdaea746b
Author: Alejandro Domínguez <adomu net-c com>
Date:   Sun Sep 13 07:06:01 2020 +0200

    Get 3PID contacts through matrix-sdk

 fractal-gtk/src/appop/account.rs                   | 17 +++++------
 fractal-gtk/src/backend/user.rs                    | 20 +++++--------
 fractal-matrix-api/src/meson.build                 |  1 -
 fractal-matrix-api/src/r0/contact.rs               |  1 -
 .../src/r0/contact/get_identifiers.rs              | 34 ----------------------
 5 files changed, 15 insertions(+), 58 deletions(-)
---
diff --git a/fractal-gtk/src/appop/account.rs b/fractal-gtk/src/appop/account.rs
index bd39b8db..1ddf6d19 100644
--- a/fractal-gtk/src/appop/account.rs
+++ b/fractal-gtk/src/appop/account.rs
@@ -14,8 +14,8 @@ use crate::widgets;
 use crate::widgets::AvatarExt;
 
 use crate::cache::{download_to_cache, remove_from_cache};
-use fractal_api::r0::contact::get_identifiers::ThirdPartyIdentifier;
-use fractal_api::r0::Medium;
+use fractal_api::api::r0::contact::get_contacts::ThirdPartyIdentifier;
+use fractal_api::thirdparty::Medium;
 
 use super::LoginData;
 
@@ -25,12 +25,10 @@ impl AppOp {
     }
 
     pub fn get_three_pid(&self) {
-        let login_data = unwrap_or_unit_return!(self.login_data.clone());
-        thread::spawn(move || {
-            match user::get_threepid(
-                login_data.session_client.homeserver().clone(),
-                login_data.access_token,
-            ) {
+        let session_client =
+            unwrap_or_unit_return!(self.login_data.as_ref().map(|ld| ld.session_client.clone()));
+        RUNTIME.spawn(async move {
+            match user::get_threepid(session_client).await {
                 Ok(list) => {
                     let l = Some(list);
                     APPOP!(set_three_pid, (l));
@@ -433,7 +431,7 @@ impl AppOp {
                             );
                         }
                     }
-                    Medium::MsIsdn => {
+                    Medium::MSISDN => {
                         if first_phone {
                             empty_phone.update(Some(item.address));
                             let entry = widgets::Address::new(widgets::AddressType::Phone, &self)
@@ -461,6 +459,7 @@ impl AppOp {
                             );
                         }
                     }
+                    medium => log::warn!("Medium type not managed: {:?}", medium),
                 }
             }
         }
diff --git a/fractal-gtk/src/backend/user.rs b/fractal-gtk/src/backend/user.rs
index 8ac3d430..3c614d83 100644
--- a/fractal-gtk/src/backend/user.rs
+++ b/fractal-gtk/src/backend/user.rs
@@ -15,6 +15,8 @@ use std::path::PathBuf;
 
 use super::room::AttachedFileError;
 use crate::model::member::Member;
+use fractal_api::api::r0::contact::get_contacts::Request as GetContactsRequest;
+use fractal_api::api::r0::contact::get_contacts::ThirdPartyIdentifier;
 use fractal_api::api::r0::profile::get_display_name::Request as GetDisplayNameRequest;
 use fractal_api::api::r0::profile::get_profile::Request as GetProfileRequest;
 use fractal_api::api::r0::profile::set_avatar_url::Request as SetAvatarUrlRequest;
@@ -38,10 +40,6 @@ use fractal_api::r0::contact::create::Parameters as AddThreePIDParameters;
 use fractal_api::r0::contact::delete::request as delete_contact;
 use fractal_api::r0::contact::delete::Body as DeleteThreePIDBody;
 use fractal_api::r0::contact::delete::Parameters as DeleteThreePIDParameters;
-use fractal_api::r0::contact::get_identifiers::request as get_identifiers;
-use fractal_api::r0::contact::get_identifiers::Parameters as ThirdPartyIDParameters;
-use fractal_api::r0::contact::get_identifiers::Response as ThirdPartyIDResponse;
-use fractal_api::r0::contact::get_identifiers::ThirdPartyIdentifier;
 use fractal_api::r0::contact::request_verification_token_email::request as 
request_contact_verification_token_email;
 use fractal_api::r0::contact::request_verification_token_email::Body as EmailTokenBody;
 use fractal_api::r0::contact::request_verification_token_email::Parameters as EmailTokenParameters;
@@ -109,8 +107,8 @@ pub async fn set_username(
 #[derive(Debug)]
 pub struct GetThreePIDError;
 
-impl From<ReqwestError> for GetThreePIDError {
-    fn from(_: ReqwestError) -> Self {
+impl From<MatrixError> for GetThreePIDError {
+    fn from(_: MatrixError) -> Self {
         Self
     }
 }
@@ -126,14 +124,10 @@ impl HandleError for GetThreePIDError {
     }
 }
 
-pub fn get_threepid(
-    base: Url,
-    access_token: AccessToken,
+pub async fn get_threepid(
+    session_client: MatrixClient,
 ) -> Result<Vec<ThirdPartyIdentifier>, GetThreePIDError> {
-    let params = ThirdPartyIDParameters { access_token };
-
-    let request = get_identifiers(base, &params)?;
-    let response: ThirdPartyIDResponse = HTTP_CLIENT.get_client().execute(request)?.json()?;
+    let response = session_client.send(GetContactsRequest::new()).await?;
 
     Ok(response.threepids)
 }
diff --git a/fractal-matrix-api/src/meson.build b/fractal-matrix-api/src/meson.build
index 7cea3e92..1a0f3b20 100644
--- a/fractal-matrix-api/src/meson.build
+++ b/fractal-matrix-api/src/meson.build
@@ -10,7 +10,6 @@ api_sources = files(
   'r0/account/register.rs',
   'r0/contact/create.rs',
   'r0/contact/delete.rs',
-  'r0/contact/get_identifiers.rs',
   'r0/contact/request_verification_token_email.rs',
   'r0/contact/request_verification_token_msisdn.rs',
   'r0/server/domain_info.rs',
diff --git a/fractal-matrix-api/src/r0/contact.rs b/fractal-matrix-api/src/r0/contact.rs
index 972b7381..839045d1 100644
--- a/fractal-matrix-api/src/r0/contact.rs
+++ b/fractal-matrix-api/src/r0/contact.rs
@@ -1,5 +1,4 @@
 pub mod create;
 pub mod delete;
-pub mod get_identifiers;
 pub mod request_verification_token_email;
 pub mod request_verification_token_msisdn;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]