From 45a08d7643779280ca0a88f9ee02c83873d0a7b4 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 1 Jun 2017 10:46:12 +0300 Subject: [PATCH] prevent unecessary :preview calls to jail --- src/status_im/chat/handlers/commands.cljs | 7 +++++++ src/status_im/chat/handlers/receive_message.cljs | 2 +- src/status_im/chat/views/message/message.cljs | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/status_im/chat/handlers/commands.cljs b/src/status_im/chat/handlers/commands.cljs index 2d88bbabc3..828e2c95ef 100644 --- a/src/status_im/chat/handlers/commands.cljs +++ b/src/status_im/chat/handlers/commands.cljs @@ -45,3 +45,10 @@ [:read-external-storage] #(dispatch [:initialize-geth])]) (log/debug "ignoring command: " command))))) + +(handlers/register-handler :request-command-preview + (handlers/side-effect! + (fn [db [_ {:keys [message-id] :as message}]] + (let [previews (get-in db [:message-data :preview])] + (when-not (contains? previews message-id) + (dispatch [:request-command-data message :preview])))))) diff --git a/src/status_im/chat/handlers/receive_message.cljs b/src/status_im/chat/handlers/receive_message.cljs index 02b811d1a1..2bd8c2c821 100644 --- a/src/status_im/chat/handlers/receive_message.cljs +++ b/src/status_im/chat/handlers/receive_message.cljs @@ -49,7 +49,7 @@ (dispatch [:upsert-chat! {:chat-id chat-id' :group-chat group-chat?}]) (when (get-in message [:content :command]) - (dispatch [:request-command-data message :preview])) + (dispatch [:request-command-preview message])) (dispatch [::add-message chat-id' message']) (dispatch [::set-last-message message']) (when (= (:content-type message') content-type-command-request) diff --git a/src/status_im/chat/views/message/message.cljs b/src/status_im/chat/views/message/message.cljs index ddce1699b2..ee4eae0655 100644 --- a/src/status_im/chat/views/message/message.cljs +++ b/src/status_im/chat/views/message/message.cljs @@ -383,10 +383,10 @@ (r/create-class {:component-will-mount (fn [] - (let [{:keys [bot] :as command} (get-in message [:content]) + (let [{:keys [bot command] :as content} (get-in message [:content]) message' (assoc message :jail-id bot)] (when (and command (not @preview)) - (dispatch [:request-command-data message' :preview])))) + (dispatch [:request-command-preview message'])))) :component-did-mount (fn []