From 5b69439d3d2a23f267cb1f81738aa07b4f93f95c Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sun, 4 Jun 2017 10:51:22 +0300 Subject: [PATCH] allows markup returned from bot's init function to be shown --- bots/demo_bot/bot.js | 16 +++++++++------- src/status_im/chat/handlers.cljs | 5 +++-- src/status_im/chat/handlers/input.cljs | 3 ++- src/status_im/chat/subs.cljs | 1 - 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/bots/demo_bot/bot.js b/bots/demo_bot/bot.js index 6653913c08..b52c56191f 100644 --- a/bots/demo_bot/bot.js +++ b/bots/demo_bot/bot.js @@ -56,14 +56,15 @@ function superSuggestion(params, context) { var validationText = ""; - if (isNaN(params.message)) { - validationText = "That's not a float number!"; - } else if (parseFloat(params.message) > balance) { - validationText = - "Input value is too big!" + - " You have only " + balance + " ETH on your balance!"; + if (typeof params !== 'undefined') { + if (isNaN(params.message)) { + validationText = "That's not a float number!"; + } else if (parseFloat(params.message) > balance) { + validationText = + "Input value is too big!" + + " You have only " + balance + " ETH on your balance!"; + } } - status.updateDb({ balance: balance, validationText: validationText @@ -75,6 +76,7 @@ function superSuggestion(params, context) { var cnt = 0; status.addListener("on-message-input-change", superSuggestion); +status.addListener("init", superSuggestion); status.addListener("on-message-send", function (params, context) { cnt++; if (isNaN(params.message)) { diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 57475e3da9..036eab2979 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -258,7 +258,7 @@ (init-console-chat true))))) (defmethod nav/preload-data! :chat - [{:keys [current-chat-id] :as db} [_ _ id]] + [{:keys [current-chat-id current-account-id] :as db} [_ _ id]] (let [chat-id (or id current-chat-id) messages (get-in db [:chats chat-id :messages]) command? (= :command (get-in db [:edit-mode chat-id])) @@ -271,7 +271,8 @@ call-init-command #(when (and (not was-opened?) bot-url) (status/call-function! {:chat-id chat-id - :function :init}))] + :function :init + :context {:from current-account-id}}))] (dispatch [:load-requests! chat-id]) ;; todo rewrite this. temporary fix for https://github.com/status-im/status-react/issues/607 #_(dispatch [:load-commands! chat-id]) diff --git a/src/status_im/chat/handlers/input.cljs b/src/status_im/chat/handlers/input.cljs index 0f682526bb..b5bf534e8c 100644 --- a/src/status_im/chat/handlers/input.cljs +++ b/src/status_im/chat/handlers/input.cljs @@ -103,7 +103,8 @@ suggestions (suggestions/get-command-suggestions db chat-text) global-commands (suggestions/get-global-command-suggestions db chat-text) {:keys [dapp?]} (get-in db [:contacts chat-id])] - (when (and dapp? (every? empty? [requests suggestions])) + (if (and dapp? (str/blank? chat-text)) + (dispatch [:set-in [:chats chat-id :parameter-boxes :message] nil]) (dispatch [::check-dapp-suggestions chat-id chat-text])) (-> db (assoc-in [:chats chat-id :request-suggestions] requests) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 354f62c527..f143f71be9 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -122,7 +122,6 @@ input-text (subscribe [:chat :input-text]) validation-messages (subscribe [:chat-ui-props :validation-messages])] (reaction (and @chat-parameter-box - (not (str/blank? @input-text)) (not @validation-messages) (not @show-suggestions?))))))