[fractal] Search user directory through matrix-sdk
- From: Alexandre Franke <afranke src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] Search user directory through matrix-sdk
- Date: Tue, 1 Dec 2020 20:22:00 +0000 (UTC)
commit 82a8451863cb2369d6362e231ff786be329472cc
Author: Alejandro DomÃnguez <adomu net-c com>
Date: Sun Sep 6 01:05:32 2020 +0200
Search user directory through matrix-sdk
fractal-gtk/src/appop/member.rs | 13 ++++-----
fractal-gtk/src/backend/user.rs | 32 +++++++-------------
fractal-gtk/src/model/member.rs | 4 +--
fractal-matrix-api/src/meson.build | 2 --
fractal-matrix-api/src/r0.rs | 5 ----
fractal-matrix-api/src/r0/search.rs | 1 -
fractal-matrix-api/src/r0/search/user.rs | 50 --------------------------------
7 files changed, 18 insertions(+), 89 deletions(-)
---
diff --git a/fractal-gtk/src/appop/member.rs b/fractal-gtk/src/appop/member.rs
index 2ffad084..b7e85676 100644
--- a/fractal-gtk/src/appop/member.rs
+++ b/fractal-gtk/src/appop/member.rs
@@ -9,9 +9,9 @@ use gtk::prelude::*;
use std::collections::HashMap;
use std::convert::TryFrom;
-use std::thread;
use crate::actions::AppState;
+use crate::app::RUNTIME;
use crate::appop::AppOp;
use crate::widgets;
use crate::App;
@@ -191,13 +191,10 @@ impl AppOp {
}
pub fn search_invite_user(&self, term: String) {
- let login_data = unwrap_or_unit_return!(self.login_data.clone());
- thread::spawn(move || {
- match user::search(
- login_data.session_client.homeserver().clone(),
- login_data.access_token,
- term,
- ) {
+ let session_client =
+ unwrap_or_unit_return!(self.login_data.as_ref().map(|ld| ld.session_client.clone()));
+ RUNTIME.spawn(async move {
+ match user::search(session_client, &term).await {
Ok(users) => {
APPOP!(user_search_finished, (users));
}
diff --git a/fractal-gtk/src/backend/user.rs b/fractal-gtk/src/backend/user.rs
index ce2979f9..1ba462eb 100644
--- a/fractal-gtk/src/backend/user.rs
+++ b/fractal-gtk/src/backend/user.rs
@@ -1,7 +1,7 @@
use fractal_api::identifiers::UserId;
use fractal_api::reqwest::Error as ReqwestError;
use fractal_api::url::{ParseError as UrlError, Url};
-use fractal_api::Client as MatrixClient;
+use fractal_api::{Client as MatrixClient, Error as MatrixError};
use std::fs;
use std::io::Error as IoError;
@@ -20,6 +20,7 @@ use std::sync::mpsc::Sender;
use std::thread;
use crate::model::member::Member;
+use fractal_api::api::r0::user_directory::search_users::Request as UserDirectoryRequest;
use fractal_api::identity::r0::association::msisdn::submit_token::request as submit_phone_token_req;
use fractal_api::identity::r0::association::msisdn::submit_token::Body as SubmitPhoneTokenBody;
use fractal_api::identity::r0::association::msisdn::submit_token::Response as SubmitPhoneTokenResponse;
@@ -65,10 +66,6 @@ use fractal_api::r0::profile::set_avatar_url::Parameters as SetAvatarUrlParamete
use fractal_api::r0::profile::set_display_name::request as set_display_name;
use fractal_api::r0::profile::set_display_name::Body as SetDisplayNameBody;
use fractal_api::r0::profile::set_display_name::Parameters as SetDisplayNameParameters;
-use fractal_api::r0::search::user::request as user_directory;
-use fractal_api::r0::search::user::Body as UserDirectoryBody;
-use fractal_api::r0::search::user::Parameters as UserDirectoryParameters;
-use fractal_api::r0::search::user::Response as UserDirectoryResponse;
use fractal_api::r0::AccessToken;
use fractal_api::r0::Medium;
use fractal_api::r0::ThreePIDCredentials;
@@ -593,13 +590,13 @@ pub fn get_user_info_async(
#[derive(Debug)]
pub enum UserSearchError {
- Reqwest(ReqwestError),
+ Matrix(MatrixError),
ParseUrl(UrlError),
}
-impl From<ReqwestError> for UserSearchError {
- fn from(err: ReqwestError) -> Self {
- Self::Reqwest(err)
+impl From<MatrixError> for UserSearchError {
+ fn from(err: MatrixError) -> Self {
+ Self::Matrix(err)
}
}
@@ -611,19 +608,12 @@ impl From<UrlError> for UserSearchError {
impl HandleError for UserSearchError {}
-pub fn search(
- base: Url,
- access_token: AccessToken,
- search_term: String,
+pub async fn search(
+ session_client: MatrixClient,
+ search_term: &str,
) -> Result<Vec<Member>, UserSearchError> {
- let params = UserDirectoryParameters { access_token };
- let body = UserDirectoryBody {
- search_term,
- ..Default::default()
- };
-
- let request = user_directory(base, ¶ms, &body)?;
- let response: UserDirectoryResponse = HTTP_CLIENT.get_client().execute(request)?.json()?;
+ let request = UserDirectoryRequest::new(search_term);
+ let response = session_client.send(request).await?;
response
.results
diff --git a/fractal-gtk/src/model/member.rs b/fractal-gtk/src/model/member.rs
index 614dc6d2..20d869c2 100644
--- a/fractal-gtk/src/model/member.rs
+++ b/fractal-gtk/src/model/member.rs
@@ -1,6 +1,6 @@
use either::Either;
+use fractal_api::api::r0::user_directory::search_users::User;
use fractal_api::identifiers::UserId;
-use fractal_api::r0::search::user::User;
use fractal_api::r0::sync::get_joined_members::RoomMember;
use fractal_api::url::{ParseError as UrlError, Url};
use serde::{Deserialize, Serialize};
@@ -44,7 +44,7 @@ impl TryFrom<User> for Member {
alias: user.display_name,
avatar: user
.avatar_url
- .filter(|url| !url.is_empty())
+ .filter(|a| !a.is_empty())
.map(|url| Url::parse(&url))
.transpose()?
.map(Either::Left),
diff --git a/fractal-matrix-api/src/meson.build b/fractal-matrix-api/src/meson.build
index 577689b9..f074fdea 100644
--- a/fractal-matrix-api/src/meson.build
+++ b/fractal-matrix-api/src/meson.build
@@ -20,7 +20,6 @@ api_sources = files(
'r0/profile/set_avatar_url.rs',
'r0/profile/set_display_name.rs',
'r0/redact/redact_event.rs',
- 'r0/search/user.rs',
'r0/server/domain_info.rs',
'r0/state/create_state_events_for_key.rs',
'r0/state/get_state_events_for_key.rs',
@@ -36,7 +35,6 @@ api_sources = files(
'r0/media.rs',
'r0/profile.rs',
'r0/redact.rs',
- 'r0/search.rs',
'r0/server.rs',
'r0/state.rs',
'r0/sync.rs',
diff --git a/fractal-matrix-api/src/r0.rs b/fractal-matrix-api/src/r0.rs
index 635b07f4..9a941d22 100644
--- a/fractal-matrix-api/src/r0.rs
+++ b/fractal-matrix-api/src/r0.rs
@@ -6,7 +6,6 @@ pub mod media;
pub mod profile;
pub mod pushrules;
pub mod redact;
-pub mod search;
pub mod server;
pub mod state;
pub mod sync;
@@ -103,7 +102,3 @@ impl From<String> for AccessToken {
Self(token)
}
}
-
-pub(crate) fn u64_is_10(number: &u64) -> bool {
- number == &10
-}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]