From f165492b337d3bf4d904db724be8e3d4e3a10ec7 Mon Sep 17 00:00:00 2001 From: alwx Date: Tue, 16 May 2017 16:24:51 +0300 Subject: [PATCH] Devtools 3.0 support --- src/status_im/chat/handlers.cljs | 5 ++- src/status_im/commands/handlers/loading.cljs | 3 +- src/status_im/debug/handlers.cljs | 41 +++++++++++--------- src/status_im/utils/utils.cljs | 3 +- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 08729dae41..57475e3da9 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -372,8 +372,9 @@ (register-handler :upsert-chat! (fn [db [_ {:keys [chat-id] :as opts}]] (let [chat (if (chats/exists? chat-id) - (let [chat (chats/get-by-id chat-id)] - (assoc chat :timestamp (random/timestamp))) + (-> (chats/get-by-id chat-id) + (assoc :timestamp (random/timestamp)) + (merge opts)) (prepare-chat db chat-id opts))] (chats/save chat) (update-in db [:chats chat-id] merge chat)))) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index 38c5fe289d..15484017dc 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -15,7 +15,8 @@ [status-im.utils.js-resources :as js-res] [status-im.utils.random :as random] [status-im.chat.sign-up :as sign-up] - [status-im.bots.constants :as bots-constants])) + [status-im.bots.constants :as bots-constants] + [status-im.utils.datetime :as time])) (defn load-commands! diff --git a/src/status_im/debug/handlers.cljs b/src/status_im/debug/handlers.cljs index 367dd4b140..251a7aca7c 100644 --- a/src/status_im/debug/handlers.cljs +++ b/src/status_im/debug/handlers.cljs @@ -38,48 +38,53 @@ (register-handler :debug-request (u/side-effect! (fn [{:keys [web3]} [_ {url :url - {:keys [encoded]} :postData :as d}]] + {:keys [encoded]} :postData}]] (try (let [json (->> (.toAscii web3 encoded) (.parse js/JSON)) obj (js->clj json :keywordize-keys true)] (case url - "/add-dapp" (dispatch [:debug-add-dapp obj]) - "/remove-dapp" (dispatch [:debug-remove-dapp obj]) - "/dapp-changed" (dispatch [:debug-dapp-changed obj]) - "/switch-node" (dispatch [:debug-switch-node obj]) + "/add-dapp" (dispatch [:debug-add-contact obj]) + "/remove-dapp" (dispatch [:debug-remove-contact obj]) + "/dapp-changed" (dispatch [:debug-contact-changed obj]) + "/switch-node" (dispatch [:debug-switch-node obj]) :default)) (catch js/Error e (log/debug "Error: " e)))))) -(register-handler :debug-add-dapp +(register-handler :debug-add-contact (u/side-effect! - (fn [{:keys [contacts]} [_ {:keys [name whisper-identity dapp-url] :as dapp-data}]] + (fn [{:keys [contacts]} [_ {:keys [name whisper-identity dapp-url bot-url] :as dapp-data}]] (when (and name whisper-identity - dapp-url + (or dapp-url bot-url) (or (not (get contacts whisper-identity)) (get-in contacts [whisper-identity :debug?]))) (let [dapp (merge dapp-data {:dapp? true :debug? true})] - (dispatch [:add-chat whisper-identity {:name name - :debug? true}]) - (dispatch [:add-contacts [dapp]])))))) + (dispatch [:upsert-chat! {:chat-id whisper-identity + :name name + :debug? true}]) + (if (get contacts whisper-identity) + (dispatch [:update-contact! dapp]) + (dispatch [:add-contacts [dapp]]))))))) -(register-handler :debug-remove-dapp +(register-handler :debug-remove-contact (u/side-effect! (fn [{:keys [chats]} [_ {:keys [whisper-identity]}]] (when (get-in chats [whisper-identity :debug?]) (dispatch [:remove-chat whisper-identity])) (dispatch [:remove-contact whisper-identity #(and (:dapp? %) (:debug? %))])))) -(register-handler :debug-dapp-changed +(register-handler :debug-contact-changed (u/side-effect! - (fn [{:keys [webview-bridge current-chat-id chats]} [_ {:keys [whisper-identity]}]] - (when (and (= current-chat-id whisper-identity) - (get-in chats [whisper-identity :debug?]) - webview-bridge) - (.reload webview-bridge))))) + (fn [{:keys [webview-bridge current-chat-id contacts]} [_ {:keys [whisper-identity] :as dapp-data}]] + (when (get-in contacts [whisper-identity :debug?]) + (when (and (= current-chat-id whisper-identity) + webview-bridge) + (.reload webview-bridge)) + (when (get-in contacts [whisper-identity :bot-url]) + (dispatch [:load-commands! whisper-identity])))))) (register-handler :debug-switch-node (u/side-effect! diff --git a/src/status_im/utils/utils.cljs b/src/status_im/utils/utils.cljs index d3212d0f4c..14758e9593 100644 --- a/src/status_im/utils/utils.cljs +++ b/src/status_im/utils/utils.cljs @@ -43,7 +43,8 @@ ([url on-success on-error] (http-get url nil on-success on-error)) ([url valid-response? on-success on-error] - (-> (.fetch js/window url (clj->js {:method "GET"})) + (-> (.fetch js/window url (clj->js {:method "GET" + :headers {"Cache-Control" "no-cache"}})) (.then (fn [response] (log response) (let [ok? (.-ok response)