fix cyclic deps related to status-im.transport.message.v1.* namespaces;
move account-update to sparate ns; fix a few more cyclic deps;
This commit is contained in:
parent
ac2d622127
commit
8cd77653f4
|
@ -2,7 +2,7 @@
|
|||
(:require [status-im.constants :as constants]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.chat.console :as console-chat]
|
||||
[status-im.ui.screens.accounts.events :as accounts-events]
|
||||
[status-im.ui.screens.accounts.utils :as account.utils]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.i18n :as i18n]
|
||||
[goog.string :as gstring]
|
||||
|
@ -67,7 +67,7 @@
|
|||
:content (i18n/label :t/debug-enabled)
|
||||
:content-type constants/text-content-type})]]
|
||||
[[:stop-debugging]])}
|
||||
(accounts-events/account-update {:debug? debug?
|
||||
(account.utils/account-update {:debug? debug?
|
||||
:last-updated now}))))})
|
||||
|
||||
(def commands-names (set (keys console-commands->fx)))
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
(ns status-im.chat.events.requests
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.utils.handlers :as handlers]))
|
||||
[status-im.constants :as constants]))
|
||||
|
||||
;; Functions
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
(ns status-im.chat.models
|
||||
(:require [status-im.ui.components.styles :as styles]
|
||||
[status-im.utils.gfycat.core :as gfycat]
|
||||
[status-im.utils.handlers :as handlers]))
|
||||
[status-im.utils.gfycat.core :as gfycat]))
|
||||
|
||||
(defn set-chat-ui-props
|
||||
"Updates ui-props in active chat by merging provided kvs into them"
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
[status-im.transport.inbox :as inbox]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.transport.db :as transport.db]))
|
||||
[status-im.transport.db :as transport.db]
|
||||
[status-im.transport.utils :as transport.utils]))
|
||||
|
||||
(defn init-whisper
|
||||
"Initialises whisper protocol by:
|
||||
|
@ -61,13 +62,7 @@
|
|||
(fn [js-error js-message]
|
||||
(re-frame/dispatch [:protocol/receive-whisper-message js-error js-message chat-id])))))
|
||||
|
||||
(defn unsubscribe-from-chat
|
||||
"Unsubscribe from chat on transport layer"
|
||||
[chat-id {:keys [db]}]
|
||||
(let [filter (get-in db [:transport/chats chat-id :filter])]
|
||||
{:db (update db :transport/chats dissoc chat-id)
|
||||
:data-store.transport/delete chat-id
|
||||
:shh/remove-filter filter}))
|
||||
(def unsubscribe-from-chat transport.utils/unsubscribe-from-chat)
|
||||
|
||||
(defn stop-whisper
|
||||
"Stops whisper protocol by removing all existing shh filters
|
||||
|
|
|
@ -11,7 +11,11 @@
|
|||
[cljs.reader :as reader]
|
||||
[status-im.transport.message.transit :as transit]
|
||||
[status-im.transport.shh :as shh]
|
||||
[status-im.transport.filters :as filters]))
|
||||
[status-im.transport.filters :as filters]
|
||||
[status-im.transport.message.core :as message]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.transport.message.v1.contact :as v1.contact]
|
||||
[status-im.transport.message.v1.group-chat :as v1.group-chat]))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:protocol/receive-whisper-message
|
||||
|
@ -35,3 +39,101 @@
|
|||
[re-frame/trim-v]
|
||||
(fn [{:keys [db] :as cofx} [err]]
|
||||
(log/error :send-status-message-error err)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:contact/send-new-sym-key
|
||||
(fn [{:keys [db random-id] :as cofx} [_ {:keys [chat-id topic message sym-key sym-key-id]}]]
|
||||
(let [{:keys [web3 current-public-key]} db
|
||||
chat-transport-info (-> (get-in db [:transport/chats chat-id])
|
||||
(assoc :sym-key-id sym-key-id)
|
||||
;;TODO (yenda) remove once go implements persistence
|
||||
(assoc :sym-key sym-key))]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
|
||||
:shh/add-filter {:web3 web3
|
||||
:sym-key-id sym-key-id
|
||||
:topic topic
|
||||
:chat-id chat-id}
|
||||
:data-store.transport/save {:chat-id chat-id
|
||||
:chat chat-transport-info}}
|
||||
(message/send (v1.contact/NewContactKey. sym-key topic message)
|
||||
chat-id)))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:contact/add-new-sym-key
|
||||
(fn [{:keys [db] :as cofx} [_ {:keys [sym-key-id sym-key chat-id topic message]}]]
|
||||
(let [{:keys [web3 current-public-key]} db
|
||||
chat-transport-info (-> (get-in db [:transport/chats chat-id])
|
||||
(assoc :sym-key-id sym-key-id)
|
||||
;;TODO (yenda) remove once go implements persistence
|
||||
(assoc :sym-key sym-key))]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
|
||||
:shh/add-filter {:web3 web3
|
||||
:sym-key-id sym-key-id
|
||||
:topic topic
|
||||
:chat-id chat-id}
|
||||
:data-store.transport/save {:chat-id chat-id
|
||||
:chat chat-transport-info}}
|
||||
(message/receive message chat-id chat-id)))))
|
||||
|
||||
#_(handlers/register-handler-fx
|
||||
:send-test-message
|
||||
(fn [cofx [this timer chat-id n]]
|
||||
(if (zero? n)
|
||||
(println "Time: " (str (- (inst-ms (js/Date.)) @timer)))
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:dispatch [this timer chat-id (dec n)]}
|
||||
(message/send (protocol/map->Message {:content (str n)
|
||||
:content-type "text/plain"
|
||||
:message-type :user-message
|
||||
:clock-value n
|
||||
:timestamp (str (inst-ms (js/Date.)))})
|
||||
chat-id)))))
|
||||
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:group/unsubscribe-from-chat
|
||||
[re-frame/trim-v]
|
||||
(fn [cofx [chat-id]]
|
||||
(transport/unsubscribe-from-chat chat-id cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:group/send-new-sym-key
|
||||
[re-frame/trim-v]
|
||||
;; this is the event that is called when we want to send a message that required first
|
||||
;; some async operations
|
||||
(fn [{:keys [db] :as cofx} [{:keys [chat-id message sym-key sym-key-id]}]]
|
||||
(let [{:keys [web3]} db]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
|
||||
:shh/add-filter {:web3 web3
|
||||
:sym-key-id sym-key-id
|
||||
:topic (transport.utils/get-topic chat-id)
|
||||
:chat-id chat-id}
|
||||
:data-store.transport/save {:chat-id chat-id
|
||||
:chat (-> (get-in db [:transport/chats chat-id])
|
||||
(assoc :sym-key-id sym-key-id)
|
||||
;;TODO (yenda) remove once go implements persistence
|
||||
(assoc :sym-key sym-key))}}
|
||||
(message/send (v1.group-chat/NewGroupKey. chat-id sym-key message) chat-id)))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:group/add-new-sym-key
|
||||
[re-frame/trim-v (re-frame/inject-cofx :random-id)]
|
||||
(fn [{:keys [db] :as cofx} [{:keys [sym-key-id sym-key chat-id signature message]}]]
|
||||
(let [{:keys [web3 current-public-key]} db
|
||||
fx {:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
|
||||
:shh/add-filter {:web3 web3
|
||||
:sym-key-id sym-key-id
|
||||
:topic (transport.utils/get-topic chat-id)
|
||||
:chat-id chat-id}
|
||||
:data-store.transport/save {:chat-id chat-id
|
||||
:chat (-> (get-in db [:transport/chats chat-id])
|
||||
(assoc :sym-key-id sym-key-id)
|
||||
;;TODO (yenda) remove once go implements persistence
|
||||
(assoc :sym-key sym-key))}}]
|
||||
;; if new sym-key is wrapping some message, call receive on it as well, if not just update the transport layer
|
||||
(if message
|
||||
(handlers-macro/merge-fx cofx fx (message/receive message chat-id signature))
|
||||
fx))))
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
[status-im.transport.message.v1.protocol :as protocol]
|
||||
[status-im.transport.utils :as transport.utils]
|
||||
[status-im.ui.screens.contacts.core :as contacts]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]))
|
||||
|
||||
(defrecord NewContactKey [sym-key topic message]
|
||||
|
@ -16,11 +15,12 @@
|
|||
cofx))
|
||||
(receive [this chat-id signature cofx]
|
||||
(let [on-success (fn [sym-key sym-key-id]
|
||||
(re-frame/dispatch [::add-new-sym-key {:sym-key-id sym-key-id
|
||||
:sym-key sym-key
|
||||
:chat-id chat-id
|
||||
:topic topic
|
||||
:message message}]))]
|
||||
(re-frame/dispatch [:contact/add-new-sym-key
|
||||
{:sym-key-id sym-key-id
|
||||
:sym-key sym-key
|
||||
:chat-id chat-id
|
||||
:topic topic
|
||||
:message message}]))]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:shh/add-new-sym-key {:web3 (get-in cofx [:db :web3])
|
||||
:sym-key sym-key
|
||||
|
@ -33,11 +33,12 @@
|
|||
(let [message-id (transport.utils/message-id this)
|
||||
topic (transport.utils/get-topic random-id)
|
||||
on-success (fn [sym-key sym-key-id]
|
||||
(re-frame/dispatch [::send-new-sym-key {:sym-key-id sym-key-id
|
||||
:sym-key sym-key
|
||||
:chat-id chat-id
|
||||
:topic topic
|
||||
:message this}]))]
|
||||
(re-frame/dispatch [:contact/send-new-sym-key
|
||||
{:sym-key-id sym-key-id
|
||||
:sym-key sym-key
|
||||
:chat-id chat-id
|
||||
:topic topic
|
||||
:message this}]))]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:shh/get-new-sym-key {:web3 (:web3 db)
|
||||
:on-success on-success}}
|
||||
|
@ -82,54 +83,3 @@
|
|||
(contacts/receive-contact-update chat-id
|
||||
signature
|
||||
this))))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
::send-new-sym-key
|
||||
(fn [{:keys [db random-id] :as cofx} [_ {:keys [chat-id topic message sym-key sym-key-id]}]]
|
||||
(let [{:keys [web3 current-public-key]} db
|
||||
chat-transport-info (-> (get-in db [:transport/chats chat-id])
|
||||
(assoc :sym-key-id sym-key-id)
|
||||
;;TODO (yenda) remove once go implements persistence
|
||||
(assoc :sym-key sym-key))]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
|
||||
:shh/add-filter {:web3 web3
|
||||
:sym-key-id sym-key-id
|
||||
:topic topic
|
||||
:chat-id chat-id}
|
||||
:data-store.transport/save {:chat-id chat-id
|
||||
:chat chat-transport-info}}
|
||||
(message/send (NewContactKey. sym-key topic message)
|
||||
chat-id)))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
::add-new-sym-key
|
||||
(fn [{:keys [db] :as cofx} [_ {:keys [sym-key-id sym-key chat-id topic message]}]]
|
||||
(let [{:keys [web3 current-public-key]} db
|
||||
chat-transport-info (-> (get-in db [:transport/chats chat-id])
|
||||
(assoc :sym-key-id sym-key-id)
|
||||
;;TODO (yenda) remove once go implements persistence
|
||||
(assoc :sym-key sym-key))]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
|
||||
:shh/add-filter {:web3 web3
|
||||
:sym-key-id sym-key-id
|
||||
:topic topic
|
||||
:chat-id chat-id}
|
||||
:data-store.transport/save {:chat-id chat-id
|
||||
:chat chat-transport-info}}
|
||||
(message/receive message chat-id chat-id)))))
|
||||
|
||||
#_(handlers/register-handler-fx
|
||||
:send-test-message
|
||||
(fn [cofx [this timer chat-id n]]
|
||||
(if (zero? n)
|
||||
(println "Time: " (str (- (inst-ms (js/Date.)) @timer)))
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:dispatch [this timer chat-id (dec n)]}
|
||||
(message/send (protocol/map->Message {:content (str n)
|
||||
:content-type "text/plain"
|
||||
:message-type :user-message
|
||||
:clock-value n
|
||||
:timestamp (str (inst-ms (js/Date.)))})
|
||||
chat-id)))))
|
||||
|
|
|
@ -2,14 +2,12 @@
|
|||
status-im.transport.message.v1.group-chat
|
||||
(:require [clojure.set :as set]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.transport.message.core :as message]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.ui.screens.group.core :as group]
|
||||
[status-im.chat.models :as models.chat]
|
||||
[status-im.chat.models.message :as models.message]
|
||||
[status-im.transport.core :as transport]
|
||||
[status-im.transport.message.v1.protocol :as protocol]
|
||||
[status-im.transport.utils :as transport.utils]))
|
||||
|
||||
|
@ -100,7 +98,7 @@
|
|||
(models.chat/upsert-chat {:chat-id chat-id
|
||||
:removed-from-at now
|
||||
:is-active false})
|
||||
(transport/unsubscribe-from-chat chat-id))
|
||||
(transport.utils/unsubscribe-from-chat chat-id))
|
||||
(handlers-macro/merge-fx cofx
|
||||
(models.message/receive
|
||||
(models.message/system-message chat-id random-id now
|
||||
|
@ -133,48 +131,3 @@
|
|||
(group/participants-removed chat-id #{signature})
|
||||
(send-new-group-key nil chat-id))))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
::unsubscribe-from-chat
|
||||
[re-frame/trim-v]
|
||||
(fn [cofx [chat-id]]
|
||||
(transport/unsubscribe-from-chat chat-id cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
::send-new-sym-key
|
||||
[re-frame/trim-v]
|
||||
;; this is the event that is called when we want to send a message that required first
|
||||
;; some async operations
|
||||
(fn [{:keys [db] :as cofx} [{:keys [chat-id message sym-key sym-key-id]}]]
|
||||
(let [{:keys [web3]} db]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
|
||||
:shh/add-filter {:web3 web3
|
||||
:sym-key-id sym-key-id
|
||||
:topic (transport.utils/get-topic chat-id)
|
||||
:chat-id chat-id}
|
||||
:data-store.transport/save {:chat-id chat-id
|
||||
:chat (-> (get-in db [:transport/chats chat-id])
|
||||
(assoc :sym-key-id sym-key-id)
|
||||
;;TODO (yenda) remove once go implements persistence
|
||||
(assoc :sym-key sym-key))}}
|
||||
(message/send (NewGroupKey. chat-id sym-key message) chat-id)))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
::add-new-sym-key
|
||||
[re-frame/trim-v (re-frame/inject-cofx :random-id)]
|
||||
(fn [{:keys [db] :as cofx} [{:keys [sym-key-id sym-key chat-id signature message]}]]
|
||||
(let [{:keys [web3 current-public-key]} db
|
||||
fx {:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
|
||||
:shh/add-filter {:web3 web3
|
||||
:sym-key-id sym-key-id
|
||||
:topic (transport.utils/get-topic chat-id)
|
||||
:chat-id chat-id}
|
||||
:data-store.transport/save {:chat-id chat-id
|
||||
:chat (-> (get-in db [:transport/chats chat-id])
|
||||
(assoc :sym-key-id sym-key-id)
|
||||
;;TODO (yenda) remove once go implements persistence
|
||||
(assoc :sym-key sym-key))}}]
|
||||
;; if new sym-key is wrapping some message, call receive on it as well, if not just update the transport layer
|
||||
(if message
|
||||
(handlers-macro/merge-fx cofx fx (message/receive message chat-id signature))
|
||||
fx))))
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
[status-im.chat.core :as chat]
|
||||
[status-im.transport.message-cache :as message-cache]
|
||||
[status-im.transport.db :as transport.db]
|
||||
[status-im.transport.core :as transport]
|
||||
[status-im.transport.message.core :as message]
|
||||
[status-im.transport.utils :as transport.utils]))
|
||||
|
||||
|
|
|
@ -25,17 +25,18 @@
|
|||
(protocol/init-chat chat-id)))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
::add-new-sym-key
|
||||
(fn [{:keys [db] :as cofx} [_ {:keys [sym-key-id sym-key chat-id]}]]
|
||||
(let [{:keys [web3]} db]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
|
||||
:shh/add-filter {:web3 web3
|
||||
:sym-key-id sym-key-id
|
||||
:topic (transport.utils/get-topic chat-id)
|
||||
:chat-id chat-id}
|
||||
:data-store.transport/save {:chat-id chat-id
|
||||
:chat (-> (get-in db [:transport/chats chat-id])
|
||||
(assoc :sym-key-id sym-key-id)
|
||||
;;TODO (yenda) remove once go implements persistence
|
||||
(assoc :sym-key sym-key))}}))))
|
||||
::add-new-sym-key
|
||||
(fn [{:keys [db] :as cofx} [_ {:keys [sym-key-id sym-key chat-id]}]]
|
||||
(let [{:keys [web3]} db]
|
||||
(handlers-macro/merge-fx
|
||||
cofx
|
||||
{:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
|
||||
:shh/add-filter {:web3 web3
|
||||
:sym-key-id sym-key-id
|
||||
:topic (transport.utils/get-topic chat-id)
|
||||
:chat-id chat-id}
|
||||
:data-store.transport/save {:chat-id chat-id
|
||||
:chat (-> (get-in db [:transport/chats chat-id])
|
||||
(assoc :sym-key-id sym-key-id)
|
||||
;;TODO (yenda) remove once go implements persistence
|
||||
(assoc :sym-key sym-key))}}))))
|
||||
|
|
|
@ -5,6 +5,14 @@
|
|||
[clojure.string :as string]
|
||||
[status-im.js-dependencies :as dependencies]))
|
||||
|
||||
(defn unsubscribe-from-chat
|
||||
"Unsubscribe from chat on transport layer"
|
||||
[chat-id {:keys [db]}]
|
||||
(let [filter (get-in db [:transport/chats chat-id :filter])]
|
||||
{:db (update db :transport/chats dissoc chat-id)
|
||||
:data-store.transport/delete chat-id
|
||||
:shh/remove-filter filter}))
|
||||
|
||||
(defn from-utf8 [s]
|
||||
(.fromUtf8 dependencies/Web3.prototype s))
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
[status-im.utils.gfycat.core :refer [generate-gfy]]
|
||||
[status-im.utils.hex :as utils.hex]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.transport.message.v1.contact :as message.contact]
|
||||
[status-im.transport.message.core :as transport]
|
||||
status-im.ui.screens.accounts.create.navigation
|
||||
[status-im.chat.models :as chat.models]))
|
||||
[status-im.chat.models :as chat.models]
|
||||
[status-im.ui.screens.accounts.utils :as accounts.utils]))
|
||||
|
||||
;;;; COFX
|
||||
|
||||
|
@ -111,21 +111,6 @@
|
|||
{:db (assoc db :account/account new-account)
|
||||
:data-store/save-account new-account}))
|
||||
|
||||
(defn account-update
|
||||
"Takes effects (containing :db) + new account fields, adds all effects necessary for account update.
|
||||
Optionally, one can specify event to be dispatched after fields are persisted."
|
||||
([new-account-fields cofx]
|
||||
(account-update new-account-fields nil cofx))
|
||||
([new-account-fields after-update-event {:keys [db] :as cofx}]
|
||||
(let [current-account (:account/account db)
|
||||
new-account (merge current-account new-account-fields)
|
||||
fx {:db (assoc db :account/account new-account)
|
||||
:data-store/save-account (assoc new-account :after-update-event after-update-event)}
|
||||
{:keys [name photo-path]} new-account]
|
||||
(if (or (:name new-account-fields) (:photo-path new-account-fields))
|
||||
(handlers-macro/merge-fx cofx fx (transport/send (message.contact/ContactUpdate. name photo-path) nil))
|
||||
fx))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:send-account-update-if-needed
|
||||
(fn [{:keys [db now] :as cofx} _]
|
||||
|
@ -135,7 +120,7 @@
|
|||
(when needs-update?
|
||||
;; TODO(janherich): this is very strange and misleading, need to figure out why it'd necessary to update
|
||||
;; account with network update when last update was more then week ago
|
||||
(account-update nil cofx)))))
|
||||
(accounts.utils/account-update nil cofx)))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:account-set-name
|
||||
|
@ -143,7 +128,7 @@
|
|||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc-in db [:accounts/create :show-welcome?] true)
|
||||
:dispatch [:navigate-to-clean :usage-data [:account-finalized]]}
|
||||
(account-update {:name (:name create)}))))
|
||||
(accounts.utils/account-update {:name (:name create)}))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:account-finalized
|
||||
|
@ -160,7 +145,7 @@
|
|||
(handlers/register-handler-fx
|
||||
:update-sign-in-time
|
||||
(fn [{db :db now :now :as cofx} _]
|
||||
(account-update {:last-sign-in now} cofx)))
|
||||
(accounts.utils/account-update {:last-sign-in now} cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:reset-account-creation
|
||||
|
@ -170,4 +155,4 @@
|
|||
(handlers/register-handler-fx
|
||||
:switch-dev-mode
|
||||
(fn [cofx [_ dev-mode]]
|
||||
(account-update {:dev-mode? dev-mode} cofx)))
|
||||
(accounts.utils/account-update {:dev-mode? dev-mode} cofx)))
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
(ns status-im.ui.screens.accounts.utils
|
||||
(:require [status-im.transport.message.core :as transport]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.transport.message.v1.contact :as message.contact]))
|
||||
|
||||
|
||||
(defn account-update
|
||||
"Takes effects (containing :db) + new account fields, adds all effects necessary for account update.
|
||||
Optionally, one can specify event to be dispatched after fields are persisted."
|
||||
([new-account-fields cofx]
|
||||
(account-update new-account-fields nil cofx))
|
||||
([new-account-fields after-update-event {{:accounts/keys [accounts current-account-id] :as db} :db :as cofx}]
|
||||
(let [current-account (get accounts current-account-id)
|
||||
new-account (merge current-account new-account-fields)
|
||||
fx {:db (assoc-in db [:accounts/accounts current-account-id] new-account)
|
||||
:data-store/save-account (assoc new-account :after-update-event after-update-event)}
|
||||
{:keys [name photo-path]} new-account]
|
||||
(if (or (:name new-account-fields) (:photo-path new-account-fields))
|
||||
(handlers-macro/merge-fx cofx fx (transport/send (message.contact/ContactUpdate. name photo-path) nil))
|
||||
fx))))
|
|
@ -2,7 +2,7 @@
|
|||
(:require [re-frame.core :refer [dispatch dispatch-sync after] :as re-frame]
|
||||
[status-im.utils.handlers :refer [register-handler] :as handlers]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.ui.screens.accounts.events :as accounts-events]
|
||||
[status-im.ui.screens.accounts.utils :as accounts.utils]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.utils.ethereum.core :as utils]
|
||||
[status-im.transport.core :as transport]))
|
||||
|
@ -30,10 +30,10 @@
|
|||
(handlers/register-handler-fx
|
||||
::save-network
|
||||
(fn [{:keys [db now] :as cofx} [_ network]]
|
||||
(handlers-macro/merge-fx cofx
|
||||
(accounts-events/account-update {:network network
|
||||
:last-updated now}
|
||||
[::close-application]))))
|
||||
(handlers-macro/merge-fx cofx
|
||||
(accounts.utils/account-update {:network network
|
||||
:last-updated now}
|
||||
[::close-application]))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:connect-network
|
||||
|
@ -46,8 +46,8 @@
|
|||
{:dispatch-n [[:load-accounts]
|
||||
[:navigate-to-clean :accounts]]}
|
||||
(transport/stop-whisper)
|
||||
(accounts-events/account-update {:network network
|
||||
:last-updated now}))
|
||||
(accounts.utils/account-update {:network network
|
||||
:last-updated now}))
|
||||
{:show-confirmation {:title (i18n/label :t/close-app-title)
|
||||
:content (i18n/label :t/close-app-content)
|
||||
:confirm-button-text (i18n/label :t/close-app-button)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
[status-im.ui.components.react :refer [show-image-picker]]
|
||||
[status-im.chat.constants :as chat-const]
|
||||
[status-im.ui.screens.profile.navigation]
|
||||
[status-im.ui.screens.accounts.events :as accounts-events]
|
||||
[status-im.ui.screens.accounts.utils :as accounts.utils]
|
||||
[status-im.chat.events :as chat-events]
|
||||
[status-im.chat.events.input :as input-events]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
|
@ -80,7 +80,7 @@
|
|||
{:photo-path photo-path}))]
|
||||
(handlers-macro/merge-fx cofx
|
||||
(clear-profile)
|
||||
(accounts-events/account-update cleaned-edit)))))
|
||||
(accounts.utils/account-update cleaned-edit)))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:group-chat-profile/start-editing
|
||||
|
@ -112,4 +112,4 @@
|
|||
(fn [{:keys [db] :as cofx} _]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (update db :my-profile/seed assoc :step :finish :error nil :word nil)}
|
||||
(accounts-events/account-update {:seed-backed-up? true}))))
|
||||
(accounts.utils/account-update {:seed-backed-up? true}))))
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
(ns status-im.ui.screens.usage-data.events
|
||||
(:require [status-im.utils.handlers :as handlers]
|
||||
[status-im.ui.screens.accounts.events :as accounts]))
|
||||
[status-im.ui.screens.accounts.utils :as accounts.utils]))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:help-improve-handler
|
||||
(fn [{db :db} [_ yes? next]]
|
||||
(merge (accounts/account-update {:sharing-usage-data? yes?} {:db db})
|
||||
(merge (accounts.utils/account-update {:sharing-usage-data? yes?} {:db db})
|
||||
{:dispatch (or next [:navigate-to-clean :home])})))
|
||||
|
|
Loading…
Reference in New Issue