From d799396851f80353358c7258422473af0ca5c500 Mon Sep 17 00:00:00 2001 From: Dmitry Novotochinov Date: Thu, 8 Feb 2018 14:51:51 +0300 Subject: [PATCH] [refs #3210] remove unnecessary reads from Realm for messages Signed-off-by: Andrey Shovkoplyas --- src/status_im/chat/constants.cljs | 1 + src/status_im/chat/events.cljs | 19 ++++++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/status_im/chat/constants.cljs b/src/status_im/chat/constants.cljs index 4d984c6644..b5abbc8485 100644 --- a/src/status_im/chat/constants.cljs +++ b/src/status_im/chat/constants.cljs @@ -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") diff --git a/src/status_im/chat/events.cljs b/src/status_im/chat/events.cljs index 5076d9fbfe..9d0e4059f1 100644 --- a/src/status_im/chat/events.cljs +++ b/src/status_im/chat/events.cljs @@ -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