Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12782] Re-open app on the last open chat #12873

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/status_im/async_storage/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

(def key->string str)

(defn- set-item! [key value]
(defn set-item! [key value]
(-> ^js async-storage
(.setItem (key->string key)
(clj->transit value))
Expand Down
117 changes: 66 additions & 51 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
rasom marked this conversation as resolved.
Show resolved Hide resolved
[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 @@ -193,8 +192,24 @@
(fx/defn on-will-focus
{:events [:screens/on-will-focus]
:interceptors [anon-metrics/interceptor]}
[cofx view-id]
[{:keys [db] :as cofx} view-id]
(fx/merge cofx
(cond
(= :chat view-id)
{::async-storage/set! {:chat-id (get-in cofx [:db :current-chat-id])
:key-uid (get-in cofx [:db :multiaccount :key-uid])}
:db (assoc db :screens/was-focused-once? true)}
rasom marked this conversation as resolved.
Show resolved Hide resolved

(= :login view-id)
{}

(not (get db :screens/was-focused-once?))
{:db (assoc db :screens/was-focused-once? true)}

:else
{::async-storage/set! {:chat-id nil
:key-uid nil}
:db (assoc db :screens/was-focused-once? true)})
#(case view-id
:keycard-settings (keycard/settings-screen-did-load %)
:reset-card (keycard/reset-card-screen-did-load %)
Expand Down
18 changes: 16 additions & 2 deletions src/status_im/multiaccounts/login/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,19 @@
(logging/set-log-level (:log-level multiaccount))
(notifications-center/get-activity-center-notifications-count))))

(re-frame/reg-fx
::open-last-chat
(fn [key-uid]
(async-storage/get-item
:chat-id
(fn [chat-id]
(when chat-id
(async-storage/get-item
:key-uid
(fn [stored-key-uid]
(when (= stored-key-uid key-uid)
(re-frame/dispatch [:chat.ui/navigate-to-chat chat-id])))))))))

(fx/defn get-chats-callback
{:events [::get-chats-callback]}
[{:keys [db] :as cofx}]
Expand All @@ -339,7 +352,8 @@
::initialize-wallet
(fn [accounts custom-tokens favourites]
(re-frame/dispatch [::initialize-wallet
accounts custom-tokens favourites]))}
accounts custom-tokens favourites]))
::open-last-chat (get-in db [:multiaccount :key-uid])}
notifications-enabled?
(assoc ::notifications/enable nil))
(transport/start-messenger)
Expand Down Expand Up @@ -381,7 +395,7 @@
config/metrics-enabled?)
(navigation/navigate-to :anon-metrics-opt-in {})

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

(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)))
4 changes: 3 additions & 1 deletion src/status_im/notifications/local.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns status-im.notifications.local
(:require [status-im.utils.fx :as fx]
(:require [status-im.async-storage.core :as async-storage]
[status-im.utils.fx :as fx]
[status-im.ethereum.decode :as decode]
["@react-native-community/push-notification-ios" :default pn-ios]
[status-im.notifications.android :as pn-android]
Expand Down Expand Up @@ -40,6 +41,7 @@

(defn handle-notification-press [{{deep-link :deepLink} :userInfo
interaction :userInteraction}]
(async-storage/set-item! (str :chat-id) nil)
(when (and deep-link
(or platform/ios?
(and platform/android? interaction)))
Expand Down
Loading