[fractal] Send typing event through matrix-sdk



commit 510c8acacd694e30d7f5457baff8e4ccbfd9e473
Author: Alejandro Domínguez <adomu net-c com>
Date:   Thu Aug 20 02:59:29 2020 +0200

    Send typing event through matrix-sdk

 fractal-gtk/src/appop/room.rs       | 13 ++++----
 fractal-gtk/src/backend/room.rs     | 26 +++++++---------
 fractal-matrix-api/src/meson.build  |  1 -
 fractal-matrix-api/src/r0.rs        |  1 -
 fractal-matrix-api/src/r0/typing.rs | 59 -------------------------------------
 5 files changed, 15 insertions(+), 85 deletions(-)
---
diff --git a/fractal-gtk/src/appop/room.rs b/fractal-gtk/src/appop/room.rs
index e65f70ae..d8990f63 100644
--- a/fractal-gtk/src/appop/room.rs
+++ b/fractal-gtk/src/appop/room.rs
@@ -739,7 +739,8 @@ impl AppOp {
     }
 
     pub fn send_typing(&mut self) {
-        let login_data = unwrap_or_unit_return!(self.login_data.clone());
+        let session_client =
+            unwrap_or_unit_return!(self.login_data.as_ref().map(|ld| ld.session_client.clone()));
         let active_room = unwrap_or_unit_return!(self.active_room.clone());
 
         let now = Instant::now();
@@ -750,13 +751,9 @@ impl AppOp {
             }
         }
         self.typing.insert(active_room.clone(), now);
-        thread::spawn(move || {
-            let query = room::send_typing(
-                login_data.session_client.homeserver().clone(),
-                login_data.access_token,
-                login_data.uid,
-                active_room,
-            );
+        RUNTIME.spawn(async move {
+            let query = room::send_typing(session_client, &active_room).await;
+
             if let Err(err) = query {
                 err.handle_error();
             }
diff --git a/fractal-gtk/src/backend/room.rs b/fractal-gtk/src/backend/room.rs
index ee7adc36..cef43499 100644
--- a/fractal-gtk/src/backend/room.rs
+++ b/fractal-gtk/src/backend/room.rs
@@ -34,6 +34,7 @@ use fractal_api::api::r0::message::get_message_events::Request as GetMessagesEve
 use fractal_api::api::r0::room::create_room::Request as CreateRoomRequest;
 use fractal_api::api::r0::room::create_room::RoomPreset;
 use fractal_api::api::r0::room::Visibility;
+use fractal_api::api::r0::typing::create_typing_event::Typing;
 use fractal_api::assign;
 use fractal_api::events::room::history_visibility::HistoryVisibility;
 use fractal_api::events::room::history_visibility::HistoryVisibilityEventContent;
@@ -75,9 +76,6 @@ use fractal_api::r0::tag::create_tag::Body as CreateTagBody;
 use fractal_api::r0::tag::create_tag::Parameters as CreateTagParameters;
 use fractal_api::r0::tag::delete_tag::request as delete_tag;
 use fractal_api::r0::tag::delete_tag::Parameters as DeleteTagParameters;
-use fractal_api::r0::typing::request as send_typing_notification;
-use fractal_api::r0::typing::Body as TypingNotificationBody;
-use fractal_api::r0::typing::Parameters as TypingNotificationParameters;
 use fractal_api::r0::AccessToken;
 
 use serde_json::value::to_raw_value;
@@ -326,27 +324,23 @@ pub fn send_msg(
 }
 
 #[derive(Debug)]
-pub struct SendTypingError(ReqwestError);
+pub struct SendTypingError(MatrixError);
 
-impl From<ReqwestError> for SendTypingError {
-    fn from(err: ReqwestError) -> Self {
+impl From<MatrixError> for SendTypingError {
+    fn from(err: MatrixError) -> Self {
         Self(err)
     }
 }
 
 impl HandleError for SendTypingError {}
 
-pub fn send_typing(
-    base: Url,
-    access_token: AccessToken,
-    user_id: UserId,
-    room_id: RoomId,
+pub async fn send_typing(
+    session_client: MatrixClient,
+    room_id: &RoomId,
 ) -> Result<(), SendTypingError> {
-    let params = TypingNotificationParameters { access_token };
-    let body = TypingNotificationBody::Typing(Duration::from_secs(4));
-
-    let request = send_typing_notification(base, &room_id, &user_id, &params, &body)?;
-    HTTP_CLIENT.get_client().execute(request)?;
+    session_client
+        .typing_notice(room_id, Typing::Yes(Duration::from_secs(4)))
+        .await?;
 
     Ok(())
 }
diff --git a/fractal-matrix-api/src/meson.build b/fractal-matrix-api/src/meson.build
index bd555ab6..242a84e4 100644
--- a/fractal-matrix-api/src/meson.build
+++ b/fractal-matrix-api/src/meson.build
@@ -46,7 +46,6 @@ api_sources = files(
   'r0/sync.rs',
   'r0/tag.rs',
   'r0/thirdparty.rs',
-  'r0/typing.rs',
   'identity.rs',
   'lib.rs',
   'r0.rs',
diff --git a/fractal-matrix-api/src/r0.rs b/fractal-matrix-api/src/r0.rs
index e9437ab7..944b24c5 100644
--- a/fractal-matrix-api/src/r0.rs
+++ b/fractal-matrix-api/src/r0.rs
@@ -14,7 +14,6 @@ pub mod state;
 pub mod sync;
 pub mod tag;
 pub mod thirdparty;
-pub mod typing;
 
 use serde::{Deserialize, Serialize, Serializer};
 use std::convert::TryFrom;


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