[fractal] BKResponse, register: remove error variants and compose over Result instead



commit ebd60d48c2b4cba9a50024a800f08e5c06486ebb
Author: Alejandro Domínguez <adomu net-c com>
Date:   Mon Aug 26 00:45:30 2019 +0200

    BKResponse, register: remove error variants and compose over Result instead

 fractal-gtk/src/app/backend_loop.rs        |  2 +-
 fractal-matrix-api/src/backend/register.rs | 21 +++++++++------------
 fractal-matrix-api/src/backend/types.rs    |  3 +--
 3 files changed, 11 insertions(+), 15 deletions(-)
---
diff --git a/fractal-gtk/src/app/backend_loop.rs b/fractal-gtk/src/app/backend_loop.rs
index d3ec32ef..6ade48f4 100644
--- a/fractal-gtk/src/app/backend_loop.rs
+++ b/fractal-gtk/src/app/backend_loop.rs
@@ -29,7 +29,7 @@ pub fn backend_loop(rx: Receiver<BKResponse>) {
                 Ok(BKResponse::Token(uid, tk, dev)) => {
                     APPOP!(bk_login, (uid, tk, dev));
                 }
-                Ok(BKResponse::Logout) => {
+                Ok(BKResponse::Logout(Ok(_))) => {
                     APPOP!(bk_logout);
                 }
                 Ok(BKResponse::Name(username)) => {
diff --git a/fractal-matrix-api/src/backend/register.rs b/fractal-matrix-api/src/backend/register.rs
index 83e0cfc8..5428f8a1 100644
--- a/fractal-matrix-api/src/backend/register.rs
+++ b/fractal-matrix-api/src/backend/register.rs
@@ -166,20 +166,17 @@ pub fn logout(bk: &Backend) {
                     .get_client()?
                     .execute(request)
                     .map_err(Into::into)
-            });
+            })
+            .and(Ok(()));
 
-        match query {
-            Ok(_) => {
-                data.lock().unwrap().user_id = Default::default();
-                data.lock().unwrap().access_token = Default::default();
-                data.lock().unwrap().since = None;
-                tx.send(BKResponse::Logout).expect_log("Connection closed");
-            }
-            Err(err) => {
-                tx.send(BKResponse::LogoutError(err))
-                    .expect_log("Connection closed");
-            }
+        if query.is_ok() {
+            data.lock().unwrap().user_id = Default::default();
+            data.lock().unwrap().access_token = Default::default();
+            data.lock().unwrap().since = None;
         }
+
+        tx.send(BKResponse::Logout(query))
+            .expect_log("Connection closed");
     });
 }
 
diff --git a/fractal-matrix-api/src/backend/types.rs b/fractal-matrix-api/src/backend/types.rs
index 709723e7..e7c7c451 100644
--- a/fractal-matrix-api/src/backend/types.rs
+++ b/fractal-matrix-api/src/backend/types.rs
@@ -89,7 +89,7 @@ pub enum BKCommand {
 pub enum BKResponse {
     ShutDown,
     Token(String, String, Option<String>),
-    Logout,
+    Logout(Result<(), Error>),
     Name(String),
     SetUserName(String),
     GetThreePID(Vec<ThirdPartyIdentifier>),
@@ -150,7 +150,6 @@ pub enum BKResponse {
     AvatarError(Error),
     SetUserAvatarError(Error),
     LoginError(Error),
-    LogoutError(Error),
     GuestLoginError(Error),
     SyncError(Error),
     RoomDetailError(Error),


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