fix login after logout when opening app from a notification
moves most of the fx that are suppose to happen only at app startup to an init/start-app fn so that init/initialize-app which is also called after logout doesn't repeat unecessary fxs
This commit is contained in:
parent
c36a0657e6
commit
f98e013cff
|
@ -56,7 +56,7 @@
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:init/app-started
|
:init/app-started
|
||||||
(fn [cofx _]
|
(fn [cofx _]
|
||||||
(init/initialize-keychain cofx)))
|
(init/start-app cofx)))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:init.callback/get-encryption-key-success
|
:init.callback/get-encryption-key-success
|
||||||
|
@ -665,11 +665,6 @@
|
||||||
(fn [cofx [_ event]]
|
(fn [cofx [_ event]]
|
||||||
(notifications/handle-push-notification cofx event)))
|
(notifications/handle-push-notification cofx event)))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
|
||||||
:notifications.callback/notification-stored
|
|
||||||
(fn [cofx _]
|
|
||||||
(accounts.login/user-login cofx)))
|
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:notifications.callback/get-fcm-token-success
|
:notifications.callback/get-fcm-token-success
|
||||||
(fn [{:keys [db]} [_ fcm-token]]
|
(fn [{:keys [db]} [_ fcm-token]]
|
||||||
|
|
|
@ -54,9 +54,20 @@
|
||||||
[cofx]
|
[cofx]
|
||||||
{:keychain/get-encryption-key [:init.callback/get-encryption-key-success]})
|
{:keychain/get-encryption-key [:init.callback/get-encryption-key-success]})
|
||||||
|
|
||||||
|
(fx/defn start-app [cofx]
|
||||||
|
(fx/merge cofx
|
||||||
|
{:init/get-device-UUID nil
|
||||||
|
:ui/listen-to-window-dimensions-change nil
|
||||||
|
:notifications/handle-initial-push-notification nil
|
||||||
|
:network/listen-to-network-status nil
|
||||||
|
:network/listen-to-connection-status nil
|
||||||
|
:hardwallet/check-nfc-support nil
|
||||||
|
:hardwallet/check-nfc-enabled nil}
|
||||||
|
(initialize-keychain)))
|
||||||
|
|
||||||
(fx/defn initialize-app-db
|
(fx/defn initialize-app-db
|
||||||
"Initialize db to initial state"
|
"Initialize db to initial state"
|
||||||
[{{:keys [status-module-initialized? view-id
|
[{{:keys [status-module-initialized? view-id hardwallet
|
||||||
network-status network peers-count peers-summary device-UUID]
|
network-status network peers-count peers-summary device-UUID]
|
||||||
:node/keys [status]
|
:node/keys [status]
|
||||||
:or {network (get app-db :network)}} :db}]
|
:or {network (get app-db :network)}} :db}]
|
||||||
|
@ -69,19 +80,13 @@
|
||||||
:node/status status
|
:node/status status
|
||||||
:network network
|
:network network
|
||||||
:device-UUID device-UUID
|
:device-UUID device-UUID
|
||||||
:view-id view-id)})
|
:view-id view-id
|
||||||
|
:hardwallet (select-keys hardwallet [:nfc-enabled? :nfc-supported?]))})
|
||||||
|
|
||||||
(fx/defn initialize-app
|
(fx/defn initialize-app
|
||||||
[cofx encryption-key]
|
[cofx encryption-key]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:init/get-device-UUID nil
|
{:init/init-store encryption-key}
|
||||||
:init/init-store encryption-key
|
|
||||||
:ui/listen-to-window-dimensions-change nil
|
|
||||||
:notifications/handle-initial-push-notification nil
|
|
||||||
:network/listen-to-network-status nil
|
|
||||||
:network/listen-to-connection-status nil
|
|
||||||
:hardwallet/check-nfc-support nil
|
|
||||||
:hardwallet/check-nfc-enabled nil}
|
|
||||||
(initialize-app-db)
|
(initialize-app-db)
|
||||||
(node/initialize nil)))
|
(node/initialize nil)))
|
||||||
|
|
||||||
|
@ -123,7 +128,14 @@
|
||||||
(let [{{:accounts/keys [accounts] :as db} :db} cofx]
|
(let [{{:accounts/keys [accounts] :as db} :db} cofx]
|
||||||
(if (empty? accounts)
|
(if (empty? accounts)
|
||||||
(navigation/navigate-to-clean cofx :intro nil)
|
(navigation/navigate-to-clean cofx :intro nil)
|
||||||
(let [{:keys [address photo-path name]} (first (sort-by :last-sign-in > (vals accounts)))]
|
(let [account-with-notification (first (keys (:push-notifications/stored db)))
|
||||||
|
selection-fn (if (not-empty account-with-notification)
|
||||||
|
#(filter (fn [account]
|
||||||
|
(= account-with-notification
|
||||||
|
(:public-key account)))
|
||||||
|
%)
|
||||||
|
#(sort-by :last-sign-in > %))
|
||||||
|
{:keys [address photo-path name]} (first (selection-fn (vals accounts)))]
|
||||||
(accounts.login/open-login cofx address photo-path name)))))
|
(accounts.login/open-login cofx address photo-path name)))))
|
||||||
|
|
||||||
(fx/defn load-accounts-and-initialize-views
|
(fx/defn load-accounts-and-initialize-views
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.react-native.js-dependencies :as rn]
|
[status-im.react-native.js-dependencies :as rn]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
|
[status-im.accounts.login.core :as accounts.login]
|
||||||
[status-im.chat.models :as chat-model]
|
[status-im.chat.models :as chat-model]
|
||||||
[status-im.utils.platform :as platform]
|
[status-im.utils.platform :as platform]
|
||||||
[status-im.utils.fx :as fx]))
|
[status-im.utils.fx :as fx]))
|
||||||
|
@ -73,26 +74,14 @@
|
||||||
(then #(log/debug "Notification channel created:" channel-id)
|
(then #(log/debug "Notification channel created:" channel-id)
|
||||||
#(log/error "Notification channel creation error:" channel-id %)))))
|
#(log/error "Notification channel creation error:" channel-id %)))))
|
||||||
|
|
||||||
(fx/defn store-event [{:keys [db] :as cofx} {:keys [from to]}]
|
|
||||||
(let [{:keys [address photo-path name]} (->> (get-in cofx [:db :accounts/accounts])
|
|
||||||
vals
|
|
||||||
(filter #(= (:public-key %) to))
|
|
||||||
first)]
|
|
||||||
(when address
|
|
||||||
{:db (assoc-in db [:push-notifications/stored to] from)
|
|
||||||
:dispatch [:notifications.callback/notification-stored address photo-path name]})))
|
|
||||||
|
|
||||||
(fx/defn handle-push-notification
|
(fx/defn handle-push-notification
|
||||||
[{:keys [db] :as cofx} {:keys [from to] :as event}]
|
[{:keys [db] :as cofx} {:keys [from to] :as event}]
|
||||||
(let [current-public-key (get-in cofx [:db :current-public-key])]
|
(let [current-public-key (get-in cofx [:db :current-public-key])]
|
||||||
(if current-public-key
|
(if (= to current-public-key)
|
||||||
;; TODO(yenda) why do we ignore the notification if
|
(fx/merge cofx
|
||||||
;; it is not for the current account ?
|
{:db (update db :push-notifications/stored dissoc to)}
|
||||||
(when (= to current-public-key)
|
(chat-model/navigate-to-chat from nil))
|
||||||
(fx/merge cofx
|
{:db (assoc-in db [:push-notifications/stored to] from)})))
|
||||||
{:db (update db :push-notifications/stored dissoc to)}
|
|
||||||
(chat-model/navigate-to-chat from nil)))
|
|
||||||
(store-event cofx event))))
|
|
||||||
|
|
||||||
(defn parse-notification-payload [s]
|
(defn parse-notification-payload [s]
|
||||||
(try
|
(try
|
||||||
|
|
Loading…
Reference in New Issue