Skip to content

Commit

Permalink
[refs #3210] remove unnecessary reads from Realm for messages
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
  • Loading branch information
dmitryn authored and flexsurfer committed Feb 21, 2018
1 parent 8abdd77 commit d799396
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/status_im/chat/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
19 changes: 8 additions & 11 deletions src/status_im/chat/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -237,26 +236,24 @@

(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})))

;; 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
Expand Down

0 comments on commit d799396

Please sign in to comment.