[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 max-input-height 66)
(def input-spacing-top 16) (def input-spacing-top 16)
(def console-chat-id "console")
(def crazy-math-message-id "crazy-math-message") (def crazy-math-message-id "crazy-math-message")
(def move-to-internal-failure-message-id "move-to-internal-failure-message") (def move-to-internal-failure-message-id "move-to-internal-failure-message")
(def passphrase-message-id "passphraze-message") (def passphrase-message-id "passphraze-message")

View File

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