[fractal] Remove since from Backend



commit 49de0df18ddb87cfe13c03b95a78806c59a7d91f
Author: Alejandro Domínguez <adomu net-c com>
Date:   Mon Dec 9 06:11:43 2019 +0100

    Remove since from Backend

 fractal-gtk/src/appop/login.rs             |  1 +
 fractal-gtk/src/appop/mod.rs               |  1 -
 fractal-matrix-api/src/backend/mod.rs      | 11 ++++----
 fractal-matrix-api/src/backend/register.rs | 42 +++++++-----------------------
 fractal-matrix-api/src/backend/sync.rs     | 17 +-----------
 fractal-matrix-api/src/backend/types.rs    |  3 ---
 6 files changed, 17 insertions(+), 58 deletions(-)
---
diff --git a/fractal-gtk/src/appop/login.rs b/fractal-gtk/src/appop/login.rs
index 2cad9027..8d4a9485 100644
--- a/fractal-gtk/src/appop/login.rs
+++ b/fractal-gtk/src/appop/login.rs
@@ -46,6 +46,7 @@ impl AppOp {
 
         self.set_state(AppState::NoRoom);
         self.device_id = self.device_id.clone().or(device);
+        self.since = None;
         self.get_username();
 
         // initial sync, we're shoing some feedback to the user
diff --git a/fractal-gtk/src/appop/mod.rs b/fractal-gtk/src/appop/mod.rs
index 7469f26c..00844ca3 100644
--- a/fractal-gtk/src/appop/mod.rs
+++ b/fractal-gtk/src/appop/mod.rs
@@ -138,7 +138,6 @@ impl AppOp {
         //        Only the access token should be used.
         if let Ok((username, password, server, id_url)) = self.get_pass() {
             if let Ok((Some(access_token), uid)) = self.get_token() {
-                self.backend.send(BKCommand::SetUserID).unwrap();
                 self.bk_login(uid, access_token, self.device_id.clone(), server, id_url);
             } else {
                 self.connect(username, password, server, id_url);
diff --git a/fractal-matrix-api/src/backend/mod.rs b/fractal-matrix-api/src/backend/mod.rs
index cd2c713c..6ce1a033 100644
--- a/fractal-matrix-api/src/backend/mod.rs
+++ b/fractal-matrix-api/src/backend/mod.rs
@@ -41,7 +41,6 @@ impl Backend {
             scalar_url: Url::parse("https://scalar.vector.im";)
                 .expect("Wrong scalar_url value in BackendData"),
             sticker_widget: None,
-            since: None,
             rooms_since: String::new(),
             join_to_room: String::new(),
             m_direct: HashMap::new(),
@@ -90,13 +89,16 @@ impl Backend {
                 register::login(self, user, passwd, server, id_url)
             }
             Ok(BKCommand::Logout(server, access_token)) => {
-                register::logout(self, 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)
             }
             Ok(BKCommand::Guest(server, id_url)) => register::guest(self, server, id_url),
-            Ok(BKCommand::SetUserID) => register::set_uid(self),
 
             // User module
             Ok(BKCommand::GetUsername(server, uid)) => {
@@ -222,9 +224,6 @@ impl Backend {
             Ok(BKCommand::Sync(server, access_token, uid, since, initial)) => {
                 sync::sync(self, server, access_token, uid, since, initial)
             }
-            Ok(BKCommand::SyncForced(server, access_token, uid)) => {
-                sync::force_sync(self, server, access_token, uid)
-            }
 
             // Room module
             Ok(BKCommand::GetRoomMembers(server, access_token, room)) => {
diff --git a/fractal-matrix-api/src/backend/register.rs b/fractal-matrix-api/src/backend/register.rs
index fe717b91..a03b343c 100644
--- a/fractal-matrix-api/src/backend/register.rs
+++ b/fractal-matrix-api/src/backend/register.rs
@@ -29,7 +29,6 @@ use crate::backend::types::Backend;
 
 pub fn guest(bk: &Backend, server: Url, id_url: Url) {
     let tx = bk.tx.clone();
-    let data = bk.data.clone();
 
     let params = RegisterParameters {
         kind: RegistrationKind::Guest,
@@ -53,7 +52,6 @@ pub fn guest(bk: &Backend, server: Url, id_url: Url) {
                 let dev = response.device_id;
 
                 if let Some(tk) = response.access_token {
-                    data.lock().unwrap().since = None;
                     tx.send(BKResponse::Token(uid, tk, dev, server, id_url))  // TODO: Use UserId and 
DeviceId
                         .expect_log("Connection closed");
                     tx.send(BKResponse::Rooms(vec![], None))
@@ -73,7 +71,6 @@ pub fn guest(bk: &Backend, server: Url, id_url: Url) {
 
 pub fn login(bk: &Backend, user: String, password: String, server: Url, id_url: Url) {
     let tx = bk.tx.clone();
-    let data = bk.data.clone();
 
     let body = if globals::EMAIL_RE.is_match(&user) {
         LoginBody {
@@ -111,7 +108,6 @@ pub fn login(bk: &Backend, user: String, password: String, server: Url, id_url:
                 let dev = response.device_id;
 
                 if let (Some(tk), false) = (response.access_token, uid.is_empty()) {
-                    data.lock().unwrap().since = None;
                     tx.send(BKResponse::Token(uid, tk, dev, server, id_url))  // TODO: Use UserId and 
DeviceId
                         .expect_log("Connection closed");
                 } else {
@@ -127,38 +123,21 @@ pub fn login(bk: &Backend, user: String, password: String, server: Url, id_url:
     });
 }
 
-pub fn set_uid(bk: &Backend) {
-    bk.data.lock().unwrap().since = None;
-}
-
-pub fn logout(bk: &Backend, server: Url, access_token: AccessToken) {
-    let data = bk.data.clone();
-    let tx = bk.tx.clone();
-
+pub fn logout(server: Url, access_token: AccessToken) -> Result<(), Error> {
     let params = LogoutParameters { access_token };
 
-    thread::spawn(move || {
-        let query = logout_req(server, &params)
-            .map_err(Into::into)
-            .and_then(|request| {
-                HTTP_CLIENT
-                    .get_client()?
-                    .execute(request)
-                    .map_err(Into::into)
-            })
-            .and(Ok(()));
-
-        if query.is_ok() {
-            data.lock().unwrap().since = None;
-        }
-
-        tx.send(BKResponse::Logout(query))
-            .expect_log("Connection closed");
-    });
+    logout_req(server, &params)
+        .map_err(Into::into)
+        .and_then(|request| {
+            HTTP_CLIENT
+                .get_client()?
+                .execute(request)
+                .map_err(Into::into)
+        })
+        .and(Ok(()))
 }
 
 pub fn register(bk: &Backend, user: String, password: String, server: Url, id_url: Url) {
-    let data = bk.data.clone();
     let tx = bk.tx.clone();
 
     let params = Default::default();
@@ -185,7 +164,6 @@ pub fn register(bk: &Backend, user: String, password: String, server: Url, id_ur
                 let dev = response.device_id;
 
                 if let Some(tk) = response.access_token {
-                    data.lock().unwrap().since = None;
                     tx.send(BKResponse::Token(uid, tk, dev, server, id_url))  // TODO: Use UserId
                         .expect_log("Connection closed");
                 }
diff --git a/fractal-matrix-api/src/backend/sync.rs b/fractal-matrix-api/src/backend/sync.rs
index ce0ebc0c..4c520be7 100644
--- a/fractal-matrix-api/src/backend/sync.rs
+++ b/fractal-matrix-api/src/backend/sync.rs
@@ -35,21 +35,12 @@ pub fn sync(
     base: Url,
     access_token: AccessToken,
     userid: String,
-    new_since: Option<String>,
+    since: Option<String>,
     initial: bool,
 ) {
     let tx = bk.tx.clone();
     let data = bk.data.clone();
 
-    let since = bk
-        .data
-        .lock()
-        .unwrap()
-        .since
-        .clone()
-        .filter(|s| !s.is_empty())
-        .or(new_since);
-
     let (timeout, filter) = if !initial {
         (time::Duration::from_secs(30), Default::default())
     } else {
@@ -255,7 +246,6 @@ pub fn sync(
                 }
 
                 let next_batch = response.next_batch;
-                data.lock().unwrap().since = Some(next_batch.clone()).filter(|s| !s.is_empty());
                 tx.send(BKResponse::Sync(Ok(next_batch)))
                     .expect_log("Connection closed");
             }
@@ -270,8 +260,3 @@ pub fn sync(
         }
     });
 }
-
-pub fn force_sync(bk: &Backend, base: Url, access_token: AccessToken, user_id: String) {
-    bk.data.lock().unwrap().since = None;
-    sync(bk, base, access_token, user_id, None, true)
-}
diff --git a/fractal-matrix-api/src/backend/types.rs b/fractal-matrix-api/src/backend/types.rs
index 4a7058cf..b772e29e 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),
-    SetUserID,
     Logout(Url, AccessToken),
     #[allow(dead_code)]
     Register(String, String, Url, Url),
@@ -40,7 +39,6 @@ pub enum BKCommand {
     GetAvatar(Url, String),
     SetUserAvatar(Url, AccessToken, String, String),
     Sync(Url, AccessToken, String, Option<String>, bool),
-    SyncForced(Url, AccessToken, String),
     GetRoomMembers(Url, AccessToken, String),
     GetRoomMessages(Url, AccessToken, String, String),
     GetRoomMessagesFromMsg(Url, AccessToken, String, Message),
@@ -159,7 +157,6 @@ pub struct BackendData {
     pub scalar_token: Option<String>,
     pub scalar_url: Url,
     pub sticker_widget: Option<String>,
-    pub since: Option<String>,
     pub rooms_since: String,
     pub join_to_room: String,
     pub m_direct: HashMap<String, Vec<String>>,


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