diff --git a/bots/browse/bot.js b/bots/browse/bot.js index c05f6acb06..8f0eead99a 100644 --- a/bots/browse/bot.js +++ b/bots/browse/bot.js @@ -1,10 +1,6 @@ function browseSuggestions(params, context) { var url; - if (context["dapp-url"]) { - url = context["dapp-url"]; - } - if (params.url && params.url !== "undefined" && params.url != "") { url = params.url; if (!/^[a-zA-Z-_]+:/.test(url)) { diff --git a/resources/dapp.js b/resources/dapp.js deleted file mode 100644 index 77cf15ccbe..0000000000 --- a/resources/dapp.js +++ /dev/null @@ -1,33 +0,0 @@ -I18n.translations = { - en: { - browse_title: 'Browser', - browse_description: 'Open web browser' - } -}; - -status.command({ - name: "browse", - title: I18n.t('browse_title'), - description: I18n.t('browse_description'), - color: "#ffa500", - fullscreen: true, - params: [{ - name: "url", - optional: true, - type: status.types.TEXT - }], - onSend: function (params, context) { - var url = params.url || params.metadata.url; - if (!/^[a-zA-Z-_]+:/.test(url)) { - url = 'http://' + url; - } - - return { - title: params.metadata.name, - dynamicTitle: true, - markup: status.components.bridgedWebView(url) - }; - } -}); - -status.autorun("browse"); diff --git a/resources/status.js b/resources/status.js index 97d0d9b023..b13a96c909 100644 --- a/resources/status.js +++ b/resources/status.js @@ -150,9 +150,6 @@ var status = { registerFunction: function (name, fn) { _status_catalog.functions[name] = fn; }, - autorun: function (commandName) { - _status_catalog.autorun = commandName; - }, localizeNumber: function (num, del, sep) { return I18n.toNumber( num.replace(",", "."), diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 8829ec5a14..206ea3d292 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -240,7 +240,7 @@ db' (assoc db :current-chat-id chat-id) commands-loaded? (if js/goog.DEBUG false - (get-in db [:chats chat-id :commands-loaded]))] + (get-in db [:contacts chat-id :commands-loaded]))] (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]) @@ -442,13 +442,14 @@ (let [{:keys [clock-value]} (messages/get-by-id message-id)] (send-clock-value! db to message-id clock-value))))) -(register-handler :check-autorun +(register-handler :check-and-open-dapp! (u/side-effect! - (fn [{:keys [current-chat-id contacts] :as db}] - (let [autorun (get-in db [:chats current-chat-id :autorun])] - (when autorun + (fn [{:keys [current-chat-id global-commands contacts] :as db}] + (let [dapp-url (get-in db [:contacts current-chat-id :dapp-url])] + (when dapp-url (am/go - (dispatch [:select-chat-input-command {:name autorun}]) + (dispatch [:select-chat-input-command + (assoc (:browse global-commands) :prefill [dapp-url])]) (a/ parameter-index -1)) - (let [data (get-in db [:local-storage current-chat-id]) - path [(if (= :command type) :commands :responses) - name - :params - parameter-index - :suggestions] - args (-> (get-in db [:chats current-chat-id :input-text]) - (input-model/split-command-args) - (rest)) - params {:parameters {:args args} - :context (merge {:data data} - (input-model/command-dependent-context-params command))}] - (status/call-jail current-chat-id + (let [jail-id (or bot current-chat-id) + data (get-in db [:local-storage current-chat-id]) + path [(if (= :command type) :commands :responses) + name + :params + parameter-index + :suggestions] + args (-> (get-in db [:chats jail-id :input-text]) + (input-model/split-command-args) + (rest)) + params {:parameters {:args args} + :context (merge {:data data} + (input-model/command-dependent-context-params command))}] + (status/call-jail jail-id path params #(dispatch [:suggestions-handler diff --git a/src/status_im/chat/handlers/receive_message.cljs b/src/status_im/chat/handlers/receive_message.cljs index 69d8fec6bd..3995d8208f 100644 --- a/src/status_im/chat/handlers/receive_message.cljs +++ b/src/status_im/chat/handlers/receive_message.cljs @@ -98,7 +98,7 @@ (assoc-in db [:chats chat-id :last-message] message))) (defn commands-loaded? [db chat-id] - (get-in db [:chats chat-id :commands-loaded])) + (get-in db [:contacts chat-id :commands-loaded])) (def timeout 400) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 86d22114f3..bd964cec76 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -177,7 +177,7 @@ show-emoji? [:chat-ui-props :show-emoji?] layout-height [:get :layout-height] input-text [:chat :input-text]] - {:component-did-mount #(do (dispatch [:check-autorun]) + {:component-did-mount #(do (dispatch [:check-and-open-dapp!]) (dispatch [:update-suggestions])) :component-will-unmount #(dispatch [:set-chat-ui-props {:show-emoji? false}])} [view {:style st/chat-view diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index 6a757e2834..2ab882bade 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -39,14 +39,15 @@ (dispatch [::validate-hash params (js-res/get-resource bot-url)]) (and dapp? dapp-url) - (http-get (s/join "/" [dapp-url "commands.js"]) - (fn [response] - (and - (string? (.text response)) - (when-let [content-type (.. response -headers (get "Content-Type"))] - (s/includes? "application/javascript" content-type)))) - #(dispatch [::validate-hash whisper-identity %]) - #(dispatch [::validate-hash whisper-identity js-res/dapp-js])) + (let [url (s/join "/" [dapp-url "commands.js"])] + (http-get url + (fn [response] + (and + (string? (.text response)) + (when-let [content-type (.. response -headers (get "Content-Type"))] + (s/includes? "application/javascript" content-type)))) + #(dispatch [::validate-hash whisper-identity %]) + #(log/debug (str "command.js wasn't found at " url)))) :else (dispatch [::validate-hash params js-res/commands-js]))) @@ -107,7 +108,7 @@ (into {}))) (defn add-commands - [db [id _ {:keys [commands responses autorun]}]] + [db [id _ {:keys [commands responses]}]] (let [account @(subscribe [:get-current-account]) commands' (filter-forbidden-names account id commands) global-command (:global commands') @@ -115,12 +116,14 @@ responses' (filter-forbidden-names account id responses)] (cond-> db + true + (update-in [:contacts id] assoc + :commands-loaded true) + (get-in db [:chats id]) (update-in [:chats id] assoc :commands (mark-as :command commands'') :responses (mark-as :response responses') - :commands-loaded true - :autorun autorun :global-command global-command) global-command @@ -152,8 +155,8 @@ (reg-handler :check-and-load-commands! (u/side-effect! - (fn [{:keys [chats]} [identity callback]] - (if (get-in chats [identity :commands-loaded]) + (fn [{:keys [contacts]} [identity callback]] + (if (get-in contacts [identity :commands-loaded]) (callback) (dispatch [:load-commands! identity callback]))))) @@ -169,8 +172,8 @@ (reg-handler ::add-commands [(after save-commands-js!) (after save-global-command!) - (after #(dispatch [:check-autorun])) - (after #(dispatch [:update-suggestions])) + ;;(after #(dispatch [:check-and-open-dapp!])) + ;;(after #(dispatch [:update-suggestions])) (after (fn [_ [id]] (dispatch [:invoke-commands-loading-callbacks id]) (dispatch [:invoke-chat-loaded-callbacks id])))] diff --git a/src/status_im/utils/js_resources.cljs b/src/status_im/utils/js_resources.cljs index 15e762d19e..51e94556ea 100644 --- a/src/status_im/utils/js_resources.cljs +++ b/src/status_im/utils/js_resources.cljs @@ -34,8 +34,6 @@ (def status-js (str (slurp "resources/status.js") (slurp "resources/i18n.js"))) -(def dapp-js (str (slurp "resources/dapp.js"))) - (def webview-js (slurp "resources/webview.js")) (def jquery (str " if (typeof jQuery2 == 'undefined') {"