[fractal] API, register: Call functions directly instead of using the loop



commit 1602cb15e7dfe62f153da33569fcab740ade5d50
Author: Alejandro Domínguez <adomu net-c com>
Date:   Fri Apr 17 08:23:38 2020 +0200

    API, register: Call functions directly instead of using the loop

 fractal-gtk/src/appop/login.rs          | 15 +++++++++------
 fractal-matrix-api/src/backend/mod.rs   |  7 -------
 fractal-matrix-api/src/backend/types.rs |  1 -
 3 files changed, 9 insertions(+), 14 deletions(-)
---
diff --git a/fractal-gtk/src/appop/login.rs b/fractal-gtk/src/appop/login.rs
index 7dd23654..8ba4521c 100644
--- a/fractal-gtk/src/appop/login.rs
+++ b/fractal-gtk/src/appop/login.rs
@@ -1,7 +1,9 @@
 use log::error;
 
+use fractal_api::backend::register;
 use fractal_api::identifiers::UserId;
 use fractal_api::r0::AccessToken;
+use fractal_api::util::ResultExpectLog;
 
 use fractal_api::url::Url;
 
@@ -14,6 +16,7 @@ use crate::cache;
 
 use std::sync::mpsc::channel;
 use std::sync::mpsc::{Receiver, Sender};
+use std::thread;
 
 use crate::app::backend_loop;
 
@@ -178,12 +181,12 @@ impl AppOp {
     pub fn logout(&mut self) {
         let login_data = unwrap_or_unit_return!(self.login_data.clone());
         let _ = self.delete_pass("fractal");
-        self.backend
-            .send(BKCommand::Logout(
-                login_data.server_url,
-                login_data.access_token,
-            ))
-            .unwrap();
+        let tx = self.backend.clone();
+        thread::spawn(move || {
+            let query = register::logout(login_data.server_url, login_data.access_token);
+            tx.send(BKCommand::SendBKResponse(BKResponse::Logout(query)))
+                .expect_log("Connection closed");
+        });
         self.bk_logout();
         *self.room_back_history.borrow_mut() = vec![];
     }
diff --git a/fractal-matrix-api/src/backend/mod.rs b/fractal-matrix-api/src/backend/mod.rs
index 4bbba84a..8ddbe917 100644
--- a/fractal-matrix-api/src/backend/mod.rs
+++ b/fractal-matrix-api/src/backend/mod.rs
@@ -65,13 +65,6 @@ impl Backend {
             Ok(BKCommand::Login(user, passwd, server, id_url)) => {
                 register::login(self, user, passwd, server, id_url)
             }
-            Ok(BKCommand::Logout(server, access_token)) => {
-                thread::spawn(move || {
-                    let query = register::logout(server, access_token);
-                    tx.send(BKResponse::Logout(query))
-                        .expect_log("Connection closed");
-                });
-            }
             Ok(BKCommand::Register(user, passwd, server, id_url)) => {
                 register::register(self, user, passwd, server, id_url)
             }
diff --git a/fractal-matrix-api/src/backend/types.rs b/fractal-matrix-api/src/backend/types.rs
index 242cd731..47b2bf1d 100644
--- a/fractal-matrix-api/src/backend/types.rs
+++ b/fractal-matrix-api/src/backend/types.rs
@@ -21,7 +21,6 @@ use url::Url;
 #[derive(Debug)]
 pub enum BKCommand {
     Login(String, String, Url, Url),
-    Logout(Url, AccessToken),
     Register(String, String, Url, Url),
     Guest(Url, Url),
     Sync(Url, AccessToken, UserId, Option<String>, bool),


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