[fractal] Clear app back history when logging out



commit 19f4de618d6bd235343d197a5d5340ffd049bba3
Author: Sonja Heinze <sonjaleaheinze gmail com>
Date:   Tue Feb 18 20:48:03 2020 +0100

    Clear app back history when logging out
    
    The app back history stores the history of states that are relevant for the
    action taken when pressing the back button; unless being in the log-in
    environment which is handled through a separate back history.
    
    Before, when logging out, the app back history was not cleared. Therefore,
    when logging out, logging back in, going e.g. into settings and then
    clicking the back button, Fractal would go into the room the user was in
    before logging out.
    
    Now, the app back history gets cleared when logging out.

 fractal-gtk/src/actions/global.rs | 40 +++++++++++++++++++--------------------
 fractal-gtk/src/appop/login.rs    |  1 +
 fractal-gtk/src/appop/mod.rs      |  2 ++
 3 files changed, 23 insertions(+), 20 deletions(-)
---
diff --git a/fractal-gtk/src/actions/global.rs b/fractal-gtk/src/actions/global.rs
index ae8aaaba..09280f94 100644
--- a/fractal-gtk/src/actions/global.rs
+++ b/fractal-gtk/src/actions/global.rs
@@ -201,9 +201,7 @@ pub fn new(app: &gtk::Application, op: &Arc<Mutex<AppOp>>) {
         }
     }));
 
-    /* Store the history of views so we can go back to it, this will be kept alive by the back
-     * callback */
-    let back_history: Rc<RefCell<Vec<AppState>>> = Rc::new(RefCell::new(vec![]));
+    let back_history = op.lock().unwrap().room_back_history.clone();
 
     let back_weak = Rc::downgrade(&back_history);
     account.connect_activate(clone!(op => move |_, _| {
@@ -258,26 +256,28 @@ pub fn new(app: &gtk::Application, op: &Arc<Mutex<AppOp>>) {
         back.borrow_mut().push(AppState::MediaViewer);
     });
 
-    // back_history is moved into this closure to keep it alive as long the action exists
+    let back_weak = Rc::downgrade(&back_history);
     back.connect_activate(move |_, _| {
-        // Remove the current state form the store
-        back_history.borrow_mut().pop();
-        if let Some(state) = back_history.borrow().last() {
-            debug!("Go back to state {:?}", state);
-            if let Some(op) = App::get_op() {
-                let mut op = op.lock().unwrap();
-                op.set_state(state.clone());
-            }
-        } else {
-            // Falback when there is no back history
-            debug!("There is no state to go back to. Go back to state NoRoom");
-            if let Some(op) = App::get_op() {
-                let mut op = op.lock().unwrap();
-                if op.login_data.is_some() {
-                    op.set_state(AppState::NoRoom);
+        back_weak.upgrade().map(|back| {
+            // Remove the current state form the store
+            back.borrow_mut().pop();
+            if let Some(state) = back.borrow().last() {
+                debug!("Go back to state {:?}", state);
+                if let Some(op) = App::get_op() {
+                    let mut op = op.lock().unwrap();
+                    op.set_state(state.clone());
+                }
+            } else {
+                // Falback when there is no back history
+                debug!("There is no state to go back to. Go back to state NoRoom");
+                if let Some(op) = App::get_op() {
+                    let mut op = op.lock().unwrap();
+                    if op.login_data.is_some() {
+                        op.set_state(AppState::NoRoom);
+                    }
                 }
             }
-        }
+        });
     });
 
     let app_weak = app.downgrade();
diff --git a/fractal-gtk/src/appop/login.rs b/fractal-gtk/src/appop/login.rs
index 0050017d..7dd23654 100644
--- a/fractal-gtk/src/appop/login.rs
+++ b/fractal-gtk/src/appop/login.rs
@@ -185,5 +185,6 @@ impl AppOp {
             ))
             .unwrap();
         self.bk_logout();
+        *self.room_back_history.borrow_mut() = vec![];
     }
 }
diff --git a/fractal-gtk/src/appop/mod.rs b/fractal-gtk/src/appop/mod.rs
index aa3e8cfe..87c71c06 100644
--- a/fractal-gtk/src/appop/mod.rs
+++ b/fractal-gtk/src/appop/mod.rs
@@ -79,6 +79,7 @@ pub struct AppOp {
 
     pub state: AppState,
     pub since: Option<String>,
+    pub room_back_history: Rc<RefCell<Vec<AppState>>>,
 
     pub invitation_roomid: Option<RoomId>,
     pub md_enabled: bool,
@@ -111,6 +112,7 @@ impl AppOp {
             msg_queue: vec![],
             sending_message: false,
             state: AppState::Login,
+            room_back_history: Rc::new(RefCell::new(vec![])),
             roomlist: widgets::RoomList::new(None, None),
             since: None,
             unsent_messages: HashMap::new(),


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