From 49a53645fb9002ac038e89160aa259ddec2c6c3c Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Tue, 27 Mar 2018 14:58:43 +0200 Subject: [PATCH] Make Andy happy again (by fixing debug mode) Signed-off-by: Julien Eluard --- src/status_im/chat/events/commands.cljs | 6 ++--- src/status_im/chat/events/input.cljs | 2 +- src/status_im/chat/events/send_message.cljs | 11 ++++----- src/status_im/chat/models/message.cljs | 26 +++++++++++---------- src/status_im/commands/handlers/jail.cljs | 13 ++++------- src/status_im/protocol/web3/delivery.cljs | 1 - src/status_im/protocol/web3/transport.cljs | 1 - src/status_im/utils/handlers.cljs | 6 ++--- 8 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/status_im/chat/events/commands.cljs b/src/status_im/chat/events/commands.cljs index 75ad74f86f..dc870c12ea 100644 --- a/src/status_im/chat/events/commands.cljs +++ b/src/status_im/chat/events/commands.cljs @@ -1,7 +1,5 @@ (ns status-im.chat.events.commands - (:require [cljs.reader :as reader] - [clojure.string :as str] - [re-frame.core :as re-frame] + (:require [re-frame.core :as re-frame] [taoensso.timbre :as log] [status-im.utils.handlers :as handlers] [status-im.i18n :as i18n] @@ -69,7 +67,7 @@ (handlers/register-handler-fx :execute-command-immediately [re-frame/trim-v] - (fn [_ [{command-name :name :as command}]] + (fn [_ [{command-name :name}]] (case (keyword command-name) :grant-permissions {:dispatch [:request-permissions diff --git a/src/status_im/chat/events/input.cljs b/src/status_im/chat/events/input.cljs index 07b7588d2f..3c001674cc 100644 --- a/src/status_im/chat/events/input.cljs +++ b/src/status_im/chat/events/input.cljs @@ -367,7 +367,7 @@ (handlers/register-handler-fx ::send-command message-model/send-interceptors - (fn [{:keys [db] :as cofx} [{:keys [command] :as command-message}]] + (fn [{:keys [db] :as cofx} [command-message]] (let [{:keys [current-public-key current-chat-id] :accounts/keys [current-account-id]} db new-db (-> (model/set-chat-ui-props db {:sending-in-progress? false}) (clear-seq-arguments) diff --git a/src/status_im/chat/events/send_message.cljs b/src/status_im/chat/events/send_message.cljs index e59a734239..e172494ab2 100644 --- a/src/status_im/chat/events/send_message.cljs +++ b/src/status_im/chat/events/send_message.cljs @@ -1,12 +1,11 @@ (ns status-im.chat.events.send-message - (:require [re-frame.core :as re-frame] + (:require [taoensso.timbre :as log] + [re-frame.core :as re-frame] [status-im.chat.models.message :as message-model] - [status-im.constants :as constants] [status-im.native-module.core :as status] [status-im.protocol.core :as protocol] [status-im.utils.handlers :as handlers] - [status-im.utils.types :as types] - [taoensso.timbre :as log])) + [status-im.utils.types :as types])) (re-frame/reg-fx :send-notification @@ -36,8 +35,8 @@ (handlers/register-handler-fx :chat-send-message/send-command message-model/send-interceptors - (fn [cofx [add-to-chat-id params]] - (message-model/send-command cofx add-to-chat-id params))) + (fn [cofx [_ params]] + (message-model/send-command cofx params))) (handlers/register-handler-fx :chat-send-message/from-jail diff --git a/src/status_im/chat/models/message.cljs b/src/status_im/chat/models/message.cljs index 0018d1f8b0..15ad7ace6a 100644 --- a/src/status_im/chat/models/message.cljs +++ b/src/status_im/chat/models/message.cljs @@ -1,11 +1,11 @@ (ns status-im.chat.models.message (:require [re-frame.core :as re-frame] [status-im.constants :as constants] + [status-im.utils.core :as utils] [status-im.chat.events.console :as console-events] [status-im.chat.events.requests :as requests-events] [status-im.chat.models :as chat-model] - [status-im.chat.models.commands :as commands-model] - [status-im.utils.clocks :as clocks-utils])) + [status-im.chat.models.commands :as commands-model])) (defn- get-current-account [{:accounts/keys [accounts current-account-id]}] @@ -267,7 +267,7 @@ :show? true})) (defn send-command - [{{:keys [current-public-key chats] :as db} :db :keys [now random-id-seq] :as cofx} add-to-chat-id params] + [{{:keys [current-public-key chats]} :db :keys [now random-id-seq] :as cofx} params] (let [{{:keys [handler-data command] :as content} :command @@ -299,15 +299,18 @@ (update fx' :dispatch-n into events)))))) (defn invoke-console-command-handler - [{:keys [db] :as cofx} {:keys [chat-id command] :as command-params}] + [{:keys [db] :as cofx} {:keys [command] :as command-params}] (let [fx-fn (get console-events/console-commands->fx (-> command :command :name)) fx (fx-fn cofx command)] - (merge fx (send-command (assoc cofx :db (or (:db fx) db)) chat-id command-params)))) + (let [command (send-command (assoc cofx :db (or (:db fx) db)) command-params) + dn (concat (:dispatch-n fx) (:dispatch-n command))] + ;; Make sure `dispatch-n` do not collide + ;; TODO (jeluard) Refactor to rely on merge-fx and reduce creation of `dispatch-n` + (merge {:dispatch-n dn} (dissoc fx :dispatch-n) (dissoc command :dispatch-n))))) (defn invoke-command-handlers - [{{:keys [bot-db] - :accounts/keys [accounts current-account-id] - :contacts/keys [contacts] :as db} :db} + [{{:accounts/keys [accounts current-account-id] + :contacts/keys [contacts]} :db} {{:keys [command params id]} :command :keys [chat-id address] :as orig-params}] @@ -315,7 +318,6 @@ handler-type (if (= :command type) :commands :responses) to (get-in contacts [chat-id :address]) identity (or owner-id bot chat-id) - bot-db (get bot-db (or bot chat-id)) ;; TODO what's actually semantic difference between `:parameters` and `:context` ;; and do we have some clear API for both ? seems very messy and unorganized now jail-params {:parameters params @@ -333,8 +335,8 @@ [[:command-handler! chat-id orig-params jail-response]]))}})) (defn process-command - [{:keys [db] :as cofx} {:keys [command message chat-id] :as params}] - (let [{:keys [command] :as content} command] + [cofx {:keys [command chat-id] :as params}] + (let [{:keys [command]} command] (cond (and (= constants/console-chat-id chat-id) (console-events/commands-names (:name command))) @@ -344,4 +346,4 @@ (invoke-command-handlers cofx params) :else - (send-command cofx chat-id params)))) + (send-command cofx params)))) diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs index b354ae258a..81c25ec8af 100644 --- a/src/status_im/commands/handlers/jail.cljs +++ b/src/status_im/commands/handlers/jail.cljs @@ -5,14 +5,13 @@ [status-im.utils.utils :refer [show-popup]] [status-im.utils.types :as types] [status-im.commands.utils :refer [reg-handler]] - [status-im.ui.components.react :as r] [status-im.constants :refer [console-chat-id]] [status-im.i18n :refer [get-contact-translated]] [taoensso.timbre :as log] [status-im.data-store.local-storage :as local-storage])) (defn command-handler! - [_ [chat-id + [_ [_ {:keys [command] :as params} {:keys [result error]}]] (let [{:keys [returned]} result @@ -23,19 +22,17 @@ (dispatch [:set-chat-ui-props {:validation-messages markup}])) result - (let [command' (assoc command :handler-data returned) - params' (assoc params :command command')] - (dispatch [:chat-send-message/send-command chat-id params'])) + (dispatch [:chat-send-message/send-command (assoc-in params [:command :handler-data] returned)]) (not (or error handler-error)) - (dispatch [:chat-send-message/send-command chat-id params]) + (dispatch [:chat-send-message/send-command params]) :else nil))) (defn suggestions-handler! [{:keys [chats] :as db} [{:keys [chat-id bot-id default-db command parameter-index result]}]] - (let [{:keys [markup height] :as returned} (get-in result [:result :returned]) + (let [{:keys [markup] :as returned} (get-in result [:result :returned]) contains-markup? (contains? returned :markup) current-input (get-in chats [chat-id :input-text]) path (if command @@ -49,7 +46,7 @@ :db default-db}]))))) (defn suggestions-events-handler! - [{:keys [bot-db] :as db} [bot-id [n & data :as ev] val]] + [{:keys [bot-db]} [bot-id [n & data] val]] (log/debug "Suggestion event: " n (first data) val) (case (keyword n) :set-command-argument diff --git a/src/status_im/protocol/web3/delivery.cljs b/src/status_im/protocol/web3/delivery.cljs index 57e2515c9b..a92fec7aa0 100644 --- a/src/status_im/protocol/web3/delivery.cljs +++ b/src/status_im/protocol/web3/delivery.cljs @@ -89,7 +89,6 @@ (defn add-pending-message! [web3 message] {:pre [(valid? :protocol/message message)]} - (debug :add-pending-message! message) ;; encryption can take some time, better to run asynchronously (async/go (async/>! pending-message-queue [web3 message]))) diff --git a/src/status_im/protocol/web3/transport.cljs b/src/status_im/protocol/web3/transport.cljs index 12bd387f02..1fe18e8974 100644 --- a/src/status_im/protocol/web3/transport.cljs +++ b/src/status_im/protocol/web3/transport.cljs @@ -15,6 +15,5 @@ (defn post-message! [web3 message callback] {:pre [(valid? :shh/message message)]} - (debug :post-message message) (let [shh (u/shh web3)] (.post shh (clj->js message) callback))) diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index 180b9bf9a9..230279aefd 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -20,9 +20,9 @@ (defn- pretty-print-event [ctx] (let [[first second] (get-coeffect ctx :event)] - (if (map? second) - first - (str first " " second)))) + (if (or (string? second) (keyword? second) (boolean? second)) + (str first " " second) + first))) (def debug-handlers-names "Interceptor which logs debug information to js/console for each event."