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

This commit is contained in:
Roman Volosovskyi 2021-12-02 12:45:00 +02:00
parent cd111aeeec
commit 646add59b8
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
7 changed files with 132 additions and 78 deletions

View File

@ -9,7 +9,7 @@
(def key->string str) (def key->string str)
(defn- set-item! [key value] (defn set-item! [key value]
(-> ^js async-storage (-> ^js async-storage
(.setItem (key->string key) (.setItem (key->string key)
(clj->transit value)) (clj->transit value))

View File

@ -1,65 +1,64 @@
(ns status-im.events (ns status-im.events
(:require [re-frame.core :as re-frame] (:require clojure.set
[status-im.chat.models :as chat] [re-frame.core :as re-frame]
[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
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.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.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.add-new.core
status-im.search.core [status-im.anon-metrics.core :as anon-metrics]
status-im.http.core [status-im.async-storage.core :as async-storage]
status-im.profile.core status-im.backup.core
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.images
status-im.ui.screens.privacy-and-security-settings.events status-im.chat.models.input
status-im.chat.models.loading
status-im.chat.models.transport
[status-im.constants :as constants]
status-im.contact.block
status-im.contact.chat
status-im.contact.core
status-im.currency.core
[status-im.ethereum.json-rpc :as json-rpc]
status-im.ethereum.subscriptions
status-im.fleet.core
status-im.http.core
[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.login.core
status-im.multiaccounts.logout.core status-im.multiaccounts.logout.core
status-im.multiaccounts.update.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.pairing.core
status-im.popover.core
status-im.profile.core
status-im.search.core
status-im.signals.core status-im.signals.core
status-im.stickers.core status-im.stickers.core
status-im.transport.core status-im.transport.core
status-im.init.core [status-im.ui.components.permissions :as permissions]
status-im.log-level.core [status-im.ui.components.react :as react]
status-im.mailserver.constants status-im.ui.screens.privacy-and-security-settings.events
status-im.ethereum.subscriptions [status-im.utils.dimensions :as dimensions]
status-im.fleet.core [status-im.utils.fx :as fx]
status-im.contact.block status-im.utils.logging.core
status-im.contact.core [status-im.utils.universal-links.core :as universal-links]
status-im.contact.chat [status-im.utils.utils :as utils]
status-im.chat.models.input status-im.visibility-status-popover.core
status-im.chat.models.loading status-im.visibility-status-updates.core
status-im.bootnodes.core status-im.waku.core
status-im.browser.core status-im.wallet.accounts.core
status-im.browser.permissions status-im.wallet.choose-recipient.core
status-im.chat.models.transport [status-im.wallet.core :as wallet]
status-im.notifications-center.core status-im.wallet.custom-tokens.core))
[status-im.navigation :as navigation]))
(re-frame/reg-fx (re-frame/reg-fx
:dismiss-keyboard :dismiss-keyboard
@ -193,8 +192,24 @@
(fx/defn on-will-focus (fx/defn on-will-focus
{:events [:screens/on-will-focus] {:events [:screens/on-will-focus]
:interceptors [anon-metrics/interceptor]} :interceptors [anon-metrics/interceptor]}
[cofx view-id] [{:keys [db] :as cofx} view-id]
(fx/merge cofx (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)}
(= :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 #(case view-id
:keycard-settings (keycard/settings-screen-did-load %) :keycard-settings (keycard/settings-screen-did-load %)
:reset-card (keycard/reset-card-screen-did-load %) :reset-card (keycard/reset-card-screen-did-load %)

View File

@ -325,6 +325,19 @@
(logging/set-log-level (:log-level multiaccount)) (logging/set-log-level (:log-level multiaccount))
(notifications-center/get-activity-center-notifications-count)))) (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 (fx/defn get-chats-callback
{:events [::get-chats-callback]} {:events [::get-chats-callback]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
@ -339,7 +352,8 @@
::initialize-wallet ::initialize-wallet
(fn [accounts custom-tokens favourites] (fn [accounts custom-tokens favourites]
(re-frame/dispatch [::initialize-wallet (re-frame/dispatch [::initialize-wallet
accounts custom-tokens favourites]))} accounts custom-tokens favourites]))
::open-last-chat (get-in db [:multiaccount :key-uid])}
notifications-enabled? notifications-enabled?
(assoc ::notifications/enable nil)) (assoc ::notifications/enable nil))
(transport/start-messenger) (transport/start-messenger)
@ -381,7 +395,7 @@
config/metrics-enabled?) config/metrics-enabled?)
(navigation/navigate-to :anon-metrics-opt-in {}) (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 (fx/defn login-only-events
[{:keys [db] :as cofx} key-uid password save-password?] [{:keys [db] :as cofx} key-uid password save-password?]

View File

@ -1,6 +1,6 @@
(ns status-im.navigation (ns status-im.navigation
(:require [status-im.utils.fx :as fx] (:require [status-im.anon-metrics.core :as anon-metrics]
[status-im.anon-metrics.core :as anon-metrics])) [status-im.utils.fx :as fx]))
(defn- all-screens-params [db view screen-params] (defn- all-screens-params [db view screen-params]
(cond-> db (cond-> db

View File

@ -1,17 +1,18 @@
(ns status-im.navigation.core (ns status-im.navigation.core
(:require (:require
[re-frame.core :as re-frame] ["react-native" :as rn]
[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.utils.fx :as fx]
["react-native-navigation" :refer (Navigation)]
["react-native-gesture-handler" :refer (gestureHandlerRootHOC)] ["react-native-gesture-handler" :refer (gestureHandlerRootHOC)]
["react-native" :as rn])) ["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.navigation.roots :as roots]
[status-im.ui.components.icons.icons :as icons]
[status-im.ui.components.react :as react]
[status-im.ui.screens.views :as views]
[status-im.utils.fx :as fx]
[status-im.utils.platform :as platform]
[taoensso.timbre :as log]))
(def debug? ^boolean js/goog.DEBUG) (def debug? ^boolean js/goog.DEBUG)
@ -26,6 +27,7 @@
;; REGISTER COMPONENT (LAZY) ;; REGISTER COMPONENT (LAZY)
(defn reg-comp [key] (defn reg-comp [key]
(log/debug "reg-comp" key)
(if-let [comp (get views/components (keyword key))] (if-let [comp (get views/components (keyword key))]
(.registerComponent Navigation key (fn [] (views/component comp))) (.registerComponent Navigation key (fn [] (views/component comp)))
(let [screen (views/screen key)] (let [screen (views/screen key)]
@ -35,6 +37,7 @@
(.setLazyComponentRegistrator Navigation reg-comp)) (.setLazyComponentRegistrator Navigation reg-comp))
(defn dismiss-all-modals [] (defn dismiss-all-modals []
(log/debug "dissmiss-all-modals")
(when @curr-modal (when @curr-modal
(reset! curr-modal false) (reset! curr-modal false)
(reset! dissmissing true) (reset! dissmissing true)
@ -44,6 +47,7 @@
;; PUSH SCREEN ;; PUSH SCREEN
(defn navigate [comp] (defn navigate [comp]
(log/debug "NAVIGATE" comp)
(let [{:keys [options]} (get views/screens comp)] (let [{:keys [options]} (get views/screens comp)]
(.push Navigation (.push Navigation
(name @root-comp-id) (name @root-comp-id)
@ -57,6 +61,7 @@
;; OPEN MODAL ;; OPEN MODAL
(defn update-modal-topbar-options [options] (defn update-modal-topbar-options [options]
(log/debug "update-modal-topbar-options" options)
(merge options (merge options
(roots/merge-top-bar {:elevation 0 (roots/merge-top-bar {:elevation 0
:noBorder true :noBorder true
@ -68,6 +73,7 @@
options))) options)))
(defn open-modal [comp] (defn open-modal [comp]
(log/debug "open-modal" comp)
(let [{:keys [options]} (get views/screens comp)] (let [{:keys [options]} (get views/screens comp)]
(if @dissmissing (if @dissmissing
(reset! dissmissing comp) (reset! dissmissing comp)
@ -88,6 +94,7 @@
;; DISSMISS MODAL ;; DISSMISS MODAL
(defn dissmissModal [] (defn dissmissModal []
(log/debug "dissmissModal")
(reset! dissmissing true) (reset! dissmissing true)
(.dismissModal Navigation (name (last @modals)))) (.dismissModal Navigation (name (last @modals))))
@ -105,6 +112,7 @@
(handler))))))) (handler)))))))
(defn set-view-id [view-id] (defn set-view-id [view-id]
(log/debug "set-view-id" view-id)
(when-let [{:keys [on-focus]} (get views/screens view-id)] (when-let [{:keys [on-focus]} (get views/screens view-id)]
(re-frame/dispatch [:set :view-id view-id]) (re-frame/dispatch [:set :view-id view-id])
(re-frame/dispatch [:screens/on-will-focus view-id]) (re-frame/dispatch [:screens/on-will-focus view-id])
@ -135,6 +143,7 @@
(.events Navigation) (.events Navigation)
(fn [^js evn] (fn [^js evn]
(let [view-id (keyword (.-componentName evn))] (let [view-id (keyword (.-componentName evn))]
(log/debug "screen-appear-reg" view-id)
(when (get views/screens view-id) (when (get views/screens view-id)
(when (and (not= view-id :bottom-sheet) (when (and (not= view-id :bottom-sheet)
(not= view-id :popover) (not= view-id :popover)
@ -159,6 +168,7 @@
(re-frame/reg-fx (re-frame/reg-fx
:init-root-fx :init-root-fx
(fn [new-root-id] (fn [new-root-id]
(log/debug :init-root-fx new-root-id)
(reset! root-comp-id new-root-id) (reset! root-comp-id new-root-id)
(reset! root-id @root-comp-id) (reset! root-id @root-comp-id)
(.setRoot Navigation (clj->js (get (roots/roots) new-root-id))))) (.setRoot Navigation (clj->js (get (roots/roots) new-root-id)))))
@ -166,6 +176,7 @@
(re-frame/reg-fx (re-frame/reg-fx
:init-root-with-component-fx :init-root-with-component-fx
(fn [[new-root-id new-root-comp-id]] (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-comp-id new-root-comp-id)
(reset! root-id @root-comp-id) (reset! root-id @root-comp-id)
(.setRoot Navigation (clj->js (get (roots/roots) new-root-id))))) (.setRoot Navigation (clj->js (get (roots/roots) new-root-id)))))
@ -173,6 +184,7 @@
(fx/defn set-multiaccount-root (fx/defn set-multiaccount-root
{:events [::set-multiaccount-root]} {:events [::set-multiaccount-root]}
[{:keys [db]}] [{:keys [db]}]
(log/debug :set-multiaccounts-root)
(let [key-uid (get-in db [:multiaccounts/login :key-uid]) (let [key-uid (get-in db [:multiaccounts/login :key-uid])
keycard-account? (boolean (get-in db [:multiaccounts/multiaccounts keycard-account? (boolean (get-in db [:multiaccounts/multiaccounts
key-uid key-uid
@ -192,6 +204,7 @@
(.hide ^js splash-screen)))) (.hide ^js splash-screen))))
(defn get-screen-component [comp] (defn get-screen-component [comp]
(log/debug :get-screen-component comp)
(let [{:keys [options]} (get views/screens comp)] (let [{:keys [options]} (get views/screens comp)]
{:component {:id comp {:component {:id comp
:name comp :name comp
@ -203,6 +216,7 @@
(re-frame/reg-fx (re-frame/reg-fx
:set-stack-root-fx :set-stack-root-fx
(fn [[stack comp]] (fn [[stack comp]]
(log/debug :set-stack-root-fx stack comp)
(.setStackRoot Navigation (.setStackRoot Navigation
(name stack) (name stack)
(clj->js (if (vector? comp) (clj->js (if (vector? comp)
@ -225,6 +239,7 @@
(re-frame/reg-fx (re-frame/reg-fx
:change-tab-fx :change-tab-fx
(fn [tab] (fn [tab]
(log/debug :change-tab-fx)
(reset! root-comp-id (get tab-root-ids (get tab-key-idx tab))) (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)}})) (.mergeOptions Navigation "tabs-stack" (clj->js {:bottomTabs {:currentTabIndex (get tab-key-idx tab)}}))
;;when we change tab we want to dismiss all modals ;;when we change tab we want to dismiss all modals
@ -234,6 +249,7 @@
(re-frame/reg-fx (re-frame/reg-fx
:change-tab-count-fx :change-tab-count-fx
(fn [[tab cnt]] (fn [[tab cnt]]
(log/debug :change-tab-count-fx tab cnt)
(.mergeOptions Navigation (.mergeOptions Navigation
(name (get tab-root-ids (get tab-key-idx tab))) (name (get tab-root-ids (get tab-key-idx tab)))
(clj->js {:bottomTab (cond (clj->js {:bottomTab (cond
@ -253,6 +269,7 @@
(re-frame/reg-fx (re-frame/reg-fx
:pop-to-root-tab-fx :pop-to-root-tab-fx
(fn [comp] (fn [comp]
(log/debug :pop-to-root-tab-fx comp)
(dismiss-all-modals) (dismiss-all-modals)
(.popToRoot Navigation (name comp)))) (.popToRoot Navigation (name comp))))
@ -343,11 +360,13 @@
(re-frame/reg-fx (re-frame/reg-fx
:navigate-to-fx :navigate-to-fx
(fn [key] (fn [key]
(log/debug :navigate-to-fx key)
(navigate key))) (navigate key)))
(re-frame/reg-fx (re-frame/reg-fx
:navigate-back-fx :navigate-back-fx
(fn [] (fn []
(log/debug :navigate-back-fx)
(if @curr-modal (if @curr-modal
(dissmissModal) (dissmissModal)
(.pop Navigation (name @root-comp-id))))) (.pop Navigation (name @root-comp-id)))))
@ -355,5 +374,6 @@
(re-frame/reg-fx (re-frame/reg-fx
:navigate-replace-fx :navigate-replace-fx
(fn [view-id] (fn [view-id]
(log/debug :navigate-replace-fx view-id)
(.pop Navigation (name @root-comp-id)) (.pop Navigation (name @root-comp-id))
(navigate view-id))) (navigate view-id)))

View File

@ -1,5 +1,6 @@
(ns status-im.notifications.local (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] [status-im.ethereum.decode :as decode]
["@react-native-community/push-notification-ios" :default pn-ios] ["@react-native-community/push-notification-ios" :default pn-ios]
[status-im.notifications.android :as pn-android] [status-im.notifications.android :as pn-android]
@ -40,6 +41,7 @@
(defn handle-notification-press [{{deep-link :deepLink} :userInfo (defn handle-notification-press [{{deep-link :deepLink} :userInfo
interaction :userInteraction}] interaction :userInteraction}]
(async-storage/set-item! (str :chat-id) nil)
(when (and deep-link (when (and deep-link
(or platform/ios? (or platform/ios?
(and platform/android? interaction))) (and platform/android? interaction)))

View File

@ -51,11 +51,14 @@
(swap! handlers/handler-nesting-level inc)) (swap! handlers/handler-nesting-level inc))
(let [[first-arg & rest-args] args (let [[first-arg & rest-args] args
initial-fxs? (map? first-arg) initial-fxs? (map? first-arg)
fx-fns (if initial-fxs? rest-args args)] fx-fns (if initial-fxs? rest-args args)
(clojure.core/reduce (fn [fxs fx-fn] res
(let [updated-cofx (update-db cofx fxs)] (clojure.core/reduce (fn [fxs fx-fn]
(if fx-fn (let [updated-cofx (update-db cofx fxs)]
(safe-merge fxs (fx-fn updated-cofx)) (if fx-fn
fxs))) (safe-merge fxs (fx-fn updated-cofx))
(if initial-fxs? first-arg {:db db}) fxs)))
fx-fns))) (if initial-fxs? first-arg {:db db})
fx-fns)]
(swap! handlers/handler-nesting-level dec)
res))