[fractal] API: call set_room directly from AppOp



commit 6583471c374f27ae5a7a657b1ce10037b18a206f
Author: Alejandro Domínguez <adomu net-c com>
Date:   Fri Jun 12 06:54:11 2020 +0200

    API: call set_room directly from AppOp

 fractal-gtk/src/app/backend_loop.rs      |  7 ------
 fractal-gtk/src/appop/room.rs            | 43 +++++++++++++++++++++++++-------
 fractal-gtk/src/widgets/room_settings.rs |  2 +-
 fractal-matrix-api/src/backend/mod.rs    |  3 ---
 fractal-matrix-api/src/backend/room.rs   | 22 +---------------
 fractal-matrix-api/src/backend/types.rs  |  5 ++--
 6 files changed, 38 insertions(+), 44 deletions(-)
---
diff --git a/fractal-gtk/src/app/backend_loop.rs b/fractal-gtk/src/app/backend_loop.rs
index fb35823e..99806a24 100644
--- a/fractal-gtk/src/app/backend_loop.rs
+++ b/fractal-gtk/src/app/backend_loop.rs
@@ -43,13 +43,6 @@ pub fn backend_loop(rx: Receiver<BKResponse>) {
                     let clear_room_list = false;
                     APPOP!(set_rooms, (rooms, clear_room_list));
                 }
-                BKResponse::RoomDetail(Ok((room, key, value))) => {
-                    let v = Some(value);
-                    APPOP!(set_room_detail, (room, key, v));
-                }
-                BKResponse::RoomAvatar(Ok((room, avatar))) => {
-                    APPOP!(set_room_avatar, (room, avatar));
-                }
                 BKResponse::RoomMessages(Ok(msgs)) => {
                     APPOP!(show_room_messages, (msgs));
                 }
diff --git a/fractal-gtk/src/appop/room.rs b/fractal-gtk/src/appop/room.rs
index 0b7c89fc..50575edb 100644
--- a/fractal-gtk/src/appop/room.rs
+++ b/fractal-gtk/src/appop/room.rs
@@ -106,7 +106,7 @@ impl AppOp {
                             APPOP!(set_room_avatar, (room, avatar));
                         }
                         Err(err) => {
-                            tx.send(BKCommand::SendBKResponse(BKResponse::RoomAvatar(Err(err))))
+                            tx.send(BKCommand::SendBKResponse(BKResponse::RoomAvatarError(err)))
                                 .expect_log("Connection closed");
                         }
                     },
@@ -250,13 +250,38 @@ impl AppOp {
         self.roomlist.select(&active_room);
 
         // getting room details
-        self.backend
-            .send(BKCommand::SetRoom(
-                login_data.server_url.clone(),
-                login_data.access_token.clone(),
-                active_room.clone(),
-            ))
-            .unwrap();
+        let server_url = login_data.server_url.clone();
+        let access_token = login_data.access_token.clone();
+        let a_room = active_room.clone();
+        let tx = self.backend.clone();
+        thread::spawn(
+            move || match room::get_room_avatar(server_url, access_token, a_room) {
+                Ok((room, avatar)) => {
+                    APPOP!(set_room_avatar, (room, avatar));
+                }
+                Err(err) => {
+                    tx.send(BKCommand::SendBKResponse(BKResponse::RoomAvatarError(err)))
+                        .expect_log("Connection closed");
+                }
+            },
+        );
+
+        let server_url = login_data.server_url.clone();
+        let access_token = login_data.access_token.clone();
+        let a_room = active_room.clone();
+        let tx = self.backend.clone();
+        thread::spawn(move || {
+            match room::get_room_detail(server_url, access_token, a_room, "m.room.topic".into()) {
+                Ok((room, key, value)) => {
+                    let v = Some(value);
+                    APPOP!(set_room_detail, (room, key, v));
+                }
+                Err(err) => {
+                    tx.send(BKCommand::SendBKResponse(BKResponse::RoomDetailError(err)))
+                        .expect_log("Connection closed");
+                }
+            }
+        });
 
         /* create the intitial list of messages to fill the new room history */
         let mut messages = vec![];
@@ -707,7 +732,7 @@ impl AppOp {
                     APPOP!(set_room_avatar, (room, avatar));
                 }
                 Err(err) => {
-                    tx.send(BKCommand::SendBKResponse(BKResponse::RoomAvatar(Err(err))))
+                    tx.send(BKCommand::SendBKResponse(BKResponse::RoomAvatarError(err)))
                         .expect_log("Connection closed");
                 }
             }
diff --git a/fractal-gtk/src/widgets/room_settings.rs b/fractal-gtk/src/widgets/room_settings.rs
index 37f51637..38842a28 100644
--- a/fractal-gtk/src/widgets/room_settings.rs
+++ b/fractal-gtk/src/widgets/room_settings.rs
@@ -442,7 +442,7 @@ impl RoomSettings {
                     APPOP!(set_room_avatar, (room, avatar));
                 }
                 Err(err) => {
-                    tx.send(BKCommand::SendBKResponse(BKResponse::RoomAvatar(Err(err))))
+                    tx.send(BKCommand::SendBKResponse(BKResponse::RoomAvatarError(err)))
                         .expect_log("Connection closed");
                 }
             },
diff --git a/fractal-matrix-api/src/backend/mod.rs b/fractal-matrix-api/src/backend/mod.rs
index d4e11484..dabc1f76 100644
--- a/fractal-matrix-api/src/backend/mod.rs
+++ b/fractal-matrix-api/src/backend/mod.rs
@@ -65,9 +65,6 @@ impl Backend {
             }
 
             // Room module
-            Ok(BKCommand::SetRoom(server, access_token, room_id)) => {
-                room::set_room(self, server, access_token, room_id)
-            }
             Ok(BKCommand::AttachFile(server, access_token, msg)) => {
                 let r = room::attach_file(self, server, access_token, msg);
                 bkerror!(r, tx, BKResponse::AttachedFile);
diff --git a/fractal-matrix-api/src/backend/room.rs b/fractal-matrix-api/src/backend/room.rs
index b1905572..97476930 100644
--- a/fractal-matrix-api/src/backend/room.rs
+++ b/fractal-matrix-api/src/backend/room.rs
@@ -85,27 +85,7 @@ use crate::types::{Room, RoomMembership, RoomTag};
 
 use serde_json::Value as JsonValue;
 
-// FIXME: Remove this function, this is used only to request information we should already have
-// when opening a room
-pub fn set_room(bk: &Backend, server: Url, access_token: AccessToken, room_id: RoomId) {
-    let tx = bk.tx.clone();
-
-    thread::spawn(clone!(server, access_token, room_id => move || {
-        let query = get_room_avatar(server, access_token, room_id);
-        tx.send(BKResponse::RoomAvatar(query))
-            .expect_log("Connection closed");
-    }));
-
-    let tx = bk.tx.clone();
-
-    thread::spawn(move || {
-        let query = get_room_detail(server, access_token, room_id, "m.room.topic".into());
-        tx.send(BKResponse::RoomDetail(query))
-            .expect_log("Connection closed");
-    });
-}
-
-fn get_room_detail(
+pub fn get_room_detail(
     base: Url,
     access_token: AccessToken,
     room_id: RoomId,
diff --git a/fractal-matrix-api/src/backend/types.rs b/fractal-matrix-api/src/backend/types.rs
index cadde004..c018dceb 100644
--- a/fractal-matrix-api/src/backend/types.rs
+++ b/fractal-matrix-api/src/backend/types.rs
@@ -26,7 +26,6 @@ pub enum BKCommand {
         bool,
         u64,
     ),
-    SetRoom(Url, AccessToken, RoomId),
     ShutDown,
     AttachFile(Url, AccessToken, Message),
     SendBKResponse(BKResponse),
@@ -39,8 +38,6 @@ pub enum BKResponse {
     Sync(Result<String, (Error, u64)>),
     Rooms(Result<(Vec<Room>, Option<Room>), Error>),
     UpdateRooms(Result<Vec<Room>, Error>),
-    RoomDetail(Result<(RoomId, String, String), Error>),
-    RoomAvatar(Result<(RoomId, Option<Url>), Error>),
     NewRoomAvatar(RoomId),
     RoomMemberEvent(Event),
     RoomMessages(Result<Vec<Message>, Error>),
@@ -88,6 +85,8 @@ pub enum BKResponse {
     JoinRoomError(Error),
     DirectorySearchError(Error),
     NewRoomError(Error, RoomId),
+    RoomDetailError(Error),
+    RoomAvatarError(Error),
 }
 
 #[derive(Debug, Clone, Copy)]


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