Skip to content

Commit

Permalink
[#12782] Re-open app on the last open chat
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Dec 2, 2021
1 parent 816f15f commit 3e2f54b
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 69 deletions.
102 changes: 52 additions & 50 deletions src/status_im/events.cljs
Original file line number Diff line number Diff line change
@@ -1,65 +1,64 @@
(ns status-im.events
(:require [re-frame.core :as re-frame]
[status-im.chat.models :as chat]
[status-im.i18n.i18n :as i18n]
[status-im.mailserver.core :as mailserver]
[status-im.multiaccounts.core :as multiaccounts]
[status-im.ui.components.react :as react]
[status-im.utils.fx :as fx]
status-im.utils.logging.core
(:require clojure.set
[re-frame.core :as re-frame]
status-im.add-new.core
[status-im.anon-metrics.core :as anon-metrics]
[status-im.async-storage.core :as async-storage]
status-im.backup.core
[status-im.wallet.core :as wallet]
[status-im.keycard.core :as keycard]
[status-im.utils.dimensions :as dimensions]
[status-im.multiaccounts.biometric.core :as biometric]
status-im.bootnodes.core
status-im.bottom-sheet.core
status-im.browser.core
status-im.browser.permissions
[status-im.chat.models :as chat]
status-im.chat.models.images
status-im.chat.models.input
status-im.chat.models.loading
status-im.chat.models.transport
[status-im.constants :as constants]
[status-im.native-module.core :as status]
[status-im.ui.components.permissions :as permissions]
[status-im.utils.utils :as utils]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.anon-metrics.core :as anon-metrics]
[status-im.utils.universal-links.core :as universal-links]
clojure.set
status-im.contact.block
status-im.contact.chat
status-im.contact.core
status-im.currency.core
status-im.navigation
status-im.utils.universal-links.core
status-im.wallet.custom-tokens.core
status-im.waku.core
status-im.wallet.choose-recipient.core
status-im.wallet.accounts.core
status-im.popover.core
status-im.visibility-status-popover.core
status-im.visibility-status-updates.core
status-im.bottom-sheet.core
status-im.add-new.core
status-im.search.core
[status-im.ethereum.json-rpc :as json-rpc]
status-im.ethereum.subscriptions
status-im.fleet.core
status-im.http.core
status-im.profile.core
status-im.chat.models.images
status-im.ui.screens.privacy-and-security-settings.events
[status-im.i18n.i18n :as i18n]
status-im.init.core
[status-im.keycard.core :as keycard]
status-im.log-level.core
status-im.mailserver.constants
[status-im.mailserver.core :as mailserver]
[status-im.multiaccounts.biometric.core :as biometric]
[status-im.multiaccounts.core :as multiaccounts]
status-im.multiaccounts.login.core
status-im.multiaccounts.logout.core
status-im.multiaccounts.update.core
[status-im.native-module.core :as status]
[status-im.navigation :as navigation]
status-im.notifications-center.core
status-im.pairing.core
status-im.popover.core
status-im.profile.core
status-im.search.core
status-im.signals.core
status-im.stickers.core
status-im.transport.core
status-im.init.core
status-im.log-level.core
status-im.mailserver.constants
status-im.ethereum.subscriptions
status-im.fleet.core
status-im.contact.block
status-im.contact.core
status-im.contact.chat
status-im.chat.models.input
status-im.chat.models.loading
status-im.bootnodes.core
status-im.browser.core
status-im.browser.permissions
status-im.chat.models.transport
status-im.notifications-center.core
[status-im.navigation :as navigation]))
[status-im.ui.components.permissions :as permissions]
[status-im.ui.components.react :as react]
status-im.ui.screens.privacy-and-security-settings.events
[status-im.utils.dimensions :as dimensions]
[status-im.utils.fx :as fx]
status-im.utils.logging.core
[status-im.utils.universal-links.core :as universal-links]
[status-im.utils.utils :as utils]
status-im.visibility-status-popover.core
status-im.visibility-status-updates.core
status-im.waku.core
status-im.wallet.accounts.core
status-im.wallet.choose-recipient.core
[status-im.wallet.core :as wallet]
status-im.wallet.custom-tokens.core))

(re-frame/reg-fx
:dismiss-keyboard
Expand Down Expand Up @@ -195,6 +194,9 @@
:interceptors [anon-metrics/interceptor]}
[cofx view-id]
(fx/merge cofx
(if (= :chat view-id)
{::async-storage/set! {:chat-id (get-in cofx [:db :current-chat-id])}}
{::async-storage/set! {:chat-id nil}})
#(case view-id
:keycard-settings (keycard/settings-screen-did-load %)
:reset-card (keycard/reset-card-screen-did-load %)
Expand Down
10 changes: 9 additions & 1 deletion src/status_im/multiaccounts/login/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@
keychain/auth-method-biometric
keychain/auth-method-password))))

(defn check-chat-id []
(async-storage/get-item
:chat-id
(fn [chat-id]
(when chat-id
(re-frame/dispatch [:chat.ui/navigate-to-chat chat-id])))))

(defn redirect-to-root
"Decides which root should be initialised depending on user and app state"
[db]
Expand All @@ -381,7 +388,8 @@
config/metrics-enabled?)
(navigation/navigate-to :anon-metrics-opt-in {})

:else (re-frame/dispatch [:init-root :chat-stack]))))
:else (do (re-frame/dispatch [:init-root :chat-stack])
(check-chat-id)))))

(fx/defn login-only-events
[{:keys [db] :as cofx} key-uid password save-password?]
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/navigation.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns status-im.navigation
(:require [status-im.utils.fx :as fx]
[status-im.anon-metrics.core :as anon-metrics]))
(:require [status-im.anon-metrics.core :as anon-metrics]
[status-im.utils.fx :as fx]))

(defn- all-screens-params [db view screen-params]
(cond-> db
Expand Down
36 changes: 28 additions & 8 deletions src/status_im/navigation/core.cljs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
(ns status-im.navigation.core
(:require
["react-native" :as rn]
["react-native-gesture-handler" :refer (gestureHandlerRootHOC)]
["react-native-navigation" :refer (Navigation)]
[quo.components.text-input :as quo.text-input]
[quo.design-system.colors :as quo.colors]
[re-frame.core :as re-frame]
[status-im.ui.screens.views :as views]
[status-im.utils.platform :as platform]
[status-im.navigation.roots :as roots]
[status-im.ui.components.react :as react]
[quo.components.text-input :as quo.text-input]
[status-im.ui.components.icons.icons :as icons]
[quo.design-system.colors :as quo.colors]
[status-im.ui.components.react :as react]
[status-im.ui.screens.views :as views]
[status-im.utils.fx :as fx]
["react-native-navigation" :refer (Navigation)]
["react-native-gesture-handler" :refer (gestureHandlerRootHOC)]
["react-native" :as rn]))
[status-im.utils.platform :as platform]
[taoensso.timbre :as log]))

(def debug? ^boolean js/goog.DEBUG)

Expand All @@ -26,6 +27,7 @@

;; REGISTER COMPONENT (LAZY)
(defn reg-comp [key]
(log/debug "reg-comp" key)
(if-let [comp (get views/components (keyword key))]
(.registerComponent Navigation key (fn [] (views/component comp)))
(let [screen (views/screen key)]
Expand All @@ -35,6 +37,7 @@
(.setLazyComponentRegistrator Navigation reg-comp))

(defn dismiss-all-modals []
(log/debug "dissmiss-all-modals")
(when @curr-modal
(reset! curr-modal false)
(reset! dissmissing true)
Expand All @@ -44,6 +47,7 @@

;; PUSH SCREEN
(defn navigate [comp]
(log/debug "NAVIGATE" comp)
(let [{:keys [options]} (get views/screens comp)]
(.push Navigation
(name @root-comp-id)
Expand All @@ -57,6 +61,7 @@

;; OPEN MODAL
(defn update-modal-topbar-options [options]
(log/debug "update-modal-topbar-options" options)
(merge options
(roots/merge-top-bar {:elevation 0
:noBorder true
Expand All @@ -68,6 +73,7 @@
options)))

(defn open-modal [comp]
(log/debug "open-modal" comp)
(let [{:keys [options]} (get views/screens comp)]
(if @dissmissing
(reset! dissmissing comp)
Expand All @@ -88,6 +94,7 @@

;; DISSMISS MODAL
(defn dissmissModal []
(log/debug "dissmissModal")
(reset! dissmissing true)
(.dismissModal Navigation (name (last @modals))))

Expand All @@ -105,6 +112,7 @@
(handler)))))))

(defn set-view-id [view-id]
(log/debug "set-view-id" view-id)
(when-let [{:keys [on-focus]} (get views/screens view-id)]
(re-frame/dispatch [:set :view-id view-id])
(re-frame/dispatch [:screens/on-will-focus view-id])
Expand Down Expand Up @@ -135,6 +143,7 @@
(.events Navigation)
(fn [^js evn]
(let [view-id (keyword (.-componentName evn))]
(log/debug "screen-appear-reg" view-id)
(when (get views/screens view-id)
(when (and (not= view-id :bottom-sheet)
(not= view-id :popover)
Expand All @@ -159,20 +168,23 @@
(re-frame/reg-fx
:init-root-fx
(fn [new-root-id]
(log/debug :init-root-fx new-root-id)
(reset! root-comp-id new-root-id)
(reset! root-id @root-comp-id)
(.setRoot Navigation (clj->js (get (roots/roots) new-root-id)))))

(re-frame/reg-fx
:init-root-with-component-fx
(fn [[new-root-id new-root-comp-id]]
(log/debug :init-root-with-component-fx new-root-id new-root-comp-id)
(reset! root-comp-id new-root-comp-id)
(reset! root-id @root-comp-id)
(.setRoot Navigation (clj->js (get (roots/roots) new-root-id)))))

(fx/defn set-multiaccount-root
{:events [::set-multiaccount-root]}
[{:keys [db]}]
(log/debug :set-multiaccounts-root)
(let [key-uid (get-in db [:multiaccounts/login :key-uid])
keycard-account? (boolean (get-in db [:multiaccounts/multiaccounts
key-uid
Expand All @@ -192,6 +204,7 @@
(.hide ^js splash-screen))))

(defn get-screen-component [comp]
(log/debug :get-screen-component comp)
(let [{:keys [options]} (get views/screens comp)]
{:component {:id comp
:name comp
Expand All @@ -203,6 +216,7 @@
(re-frame/reg-fx
:set-stack-root-fx
(fn [[stack comp]]
(log/debug :set-stack-root-fx stack comp)
(.setStackRoot Navigation
(name stack)
(clj->js (if (vector? comp)
Expand All @@ -225,6 +239,7 @@
(re-frame/reg-fx
:change-tab-fx
(fn [tab]
(log/debug :change-tab-fx)
(reset! root-comp-id (get tab-root-ids (get tab-key-idx tab)))
(.mergeOptions Navigation "tabs-stack" (clj->js {:bottomTabs {:currentTabIndex (get tab-key-idx tab)}}))
;;when we change tab we want to dismiss all modals
Expand All @@ -234,6 +249,7 @@
(re-frame/reg-fx
:change-tab-count-fx
(fn [[tab cnt]]
(log/debug :change-tab-count-fx tab cnt)
(.mergeOptions Navigation
(name (get tab-root-ids (get tab-key-idx tab)))
(clj->js {:bottomTab (cond
Expand All @@ -253,6 +269,7 @@
(re-frame/reg-fx
:pop-to-root-tab-fx
(fn [comp]
(log/debug :pop-to-root-tab-fx comp)
(dismiss-all-modals)
(.popToRoot Navigation (name comp))))

Expand Down Expand Up @@ -343,17 +360,20 @@
(re-frame/reg-fx
:navigate-to-fx
(fn [key]
(log/debug :navigate-to-fx key)
(navigate key)))

(re-frame/reg-fx
:navigate-back-fx
(fn []
(log/debug :navigate-back-fx)
(if @curr-modal
(dissmissModal)
(.pop Navigation (name @root-comp-id)))))

(re-frame/reg-fx
:navigate-replace-fx
(fn [view-id]
(log/debug :navigate-replace-fx view-id)
(.pop Navigation (name @root-comp-id))
(navigate view-id)))
19 changes: 11 additions & 8 deletions src/status_im/utils/fx.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@
(swap! handlers/handler-nesting-level inc))
(let [[first-arg & rest-args] args
initial-fxs? (map? first-arg)
fx-fns (if initial-fxs? rest-args args)]
(clojure.core/reduce (fn [fxs fx-fn]
(let [updated-cofx (update-db cofx fxs)]
(if fx-fn
(safe-merge fxs (fx-fn updated-cofx))
fxs)))
(if initial-fxs? first-arg {:db db})
fx-fns)))
fx-fns (if initial-fxs? rest-args args)
res
(clojure.core/reduce (fn [fxs fx-fn]
(let [updated-cofx (update-db cofx fxs)]
(if fx-fn
(safe-merge fxs (fx-fn updated-cofx))
fxs)))
(if initial-fxs? first-arg {:db db})
fx-fns)]
(swap! handlers/handler-nesting-level dec)
res))

0 comments on commit 3e2f54b

Please sign in to comment.