prevent unecessary :preview calls to jail

This commit is contained in:
Roman Volosovskyi 2017-06-01 10:46:12 +03:00 committed by Roman Volosovskyi
parent 30ef161afa
commit 45a08d7643
3 changed files with 10 additions and 3 deletions

View File

@ -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]))))))

View File

@ -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)

View File

@ -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 []