[refs #3210] remove unnecessary reads from Realm for messages

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Dmitry Novotochinov 2018-02-08 14:51:51 +03:00 committed by Andrey Shovkoplyas
parent 8abdd77fb4
commit d799396851
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
2 changed files with 9 additions and 11 deletions

View File

@ -8,6 +8,7 @@
(def max-input-height 66)
(def input-spacing-top 16)
(def console-chat-id "console")
(def crazy-math-message-id "crazy-math-message")
(def move-to-internal-failure-message-id "move-to-internal-failure-message")
(def passphrase-message-id "passphraze-message")

View File

@ -7,7 +7,6 @@
[status-im.chat.models :as model]
[status-im.chat.console :as console-chat]
[status-im.chat.constants :as chat-const]
[status-im.data-store.messages :as msg-store]
[status-im.data-store.contacts :as contacts-store]
[status-im.data-store.chats :as chats-store]
[status-im.data-store.contacts :as contacts-store]
@ -32,7 +31,7 @@
:stored-unviewed-messages
(fn [cofx _]
(assoc cofx :stored-unviewed-messages
(msg-store/get-unviewed (-> cofx :db :current-public-key)))))
(messages-store/get-unviewed (-> cofx :db :current-public-key)))))
(re-frame/reg-cofx
:get-stored-message
@ -237,9 +236,9 @@
(handlers/register-handler-fx
:show-mnemonic
[(re-frame/inject-cofx :get-stored-message) re-frame/trim-v]
(fn [{:keys [get-stored-message]} [mnemonic signing-phrase]]
(let [crazy-math-message? (get-stored-message chat-const/crazy-math-message-id)
[re-frame/trim-v]
(fn [{:keys [db]} [mnemonic signing-phrase]]
(let [crazy-math-message? (contains? (get-in db [:chats chat-const/console-chat-id]) chat-const/crazy-math-message-id)
messages-events (->> (console-chat/passphrase-messages mnemonic signing-phrase crazy-math-message?)
(mapv #(vector :chat-received-message/add %)))]
{:dispatch-n messages-events})))
@ -247,16 +246,14 @@
;; TODO(alwx): can be simplified
(handlers/register-handler-fx
:account-generation-message
[(re-frame/inject-cofx :get-stored-message)]
(fn [{:keys [get-stored-message]} _]
(when-not (get-stored-message chat-const/passphrase-message-id)
(fn [{:keys [db]} _]
(when-not (contains? (get-in db [:chats chat-const/console-chat-id]) chat-const/passphrase-message-id)
{:dispatch [:chat-received-message/add console-chat/account-generation-message]})))
(handlers/register-handler-fx
:move-to-internal-failure-message
[(re-frame/inject-cofx :get-stored-message)]
(fn [{:keys [get-stored-message]} _]
(when-not (get-stored-message chat-const/move-to-internal-failure-message-id)
(fn [{:keys [db]} _]
(when-not (contains? (get-in db [:chats chat-const/console-chat-id]) chat-const/move-to-internal-failure-message-id)
{:dispatch [:chat-received-message/add console-chat/move-to-internal-failure-message]})))
(handlers/register-handler-fx