diff --git a/bots/browse/bot.js b/bots/browse/bot.js index 52174e2bf02..70472d10441 100644 --- a/bots/browse/bot.js +++ b/bots/browse/bot.js @@ -34,9 +34,14 @@ function browse(params, context) { } status.command({ - name: "global", + name: "browse", title: I18n.t('browse_title'), - registeredOnly: true, + scope: { + registeredOnly: true, + personalChats: true, + groupChats: true, + isGlobal: true + }, description: I18n.t('browse_description'), color: "#ffa500", fullscreen: true, diff --git a/bots/console/bot.js b/bots/console/bot.js index 34d55d097ec..f4fe2298bda 100644 --- a/bots/console/bot.js +++ b/bots/console/bot.js @@ -455,7 +455,9 @@ function phoneSuggestions(params, context) { var phoneConfig = { name: "phone", - registeredOnly: true, + scope: { + registeredOnly: true + }, icon: "phone_white", color: "#5bb2a2", title: I18n.t('phone_title'), @@ -540,7 +542,9 @@ status.command({ title: I18n.t('faucet_title'), description: I18n.t('faucet_description'), color: "#7099e6", - registeredOnly: true, + scope: { + registeredOnly: true + }, params: [{ name: "url", type: status.types.TEXT, @@ -611,7 +615,9 @@ status.command({ title: I18n.t('debug_mode_title'), description: I18n.t('debug_mode_description'), color: "#7099e6", - registeredOnly: true, + scope: { + registeredOnly: true + }, params: [{ name: "mode", suggestions: debugSuggestions, diff --git a/bots/wallet/bot.js b/bots/wallet/bot.js index bc32d494035..c9a9daeed35 100644 --- a/bots/wallet/bot.js +++ b/bots/wallet/bot.js @@ -460,6 +460,12 @@ function shortPreviewSend(params, context) { var send = { name: "send", + scope: { + isGlobal: true, + personalChats: true, + groupChats: true, + canUseForDApps: false + }, icon: "money_white", color: "#5fc48d", title: I18n.t('send_title'), @@ -493,6 +499,12 @@ var paramsRequest = [ status.command({ name: "request", + scope: { + isGlobal: true, + personalChats: true, + groupChats: true, + canUseForDApps: false + }, color: "#5fc48d", title: I18n.t('request_title'), description: I18n.t('request_description'), diff --git a/env/dev/env/android/main.cljs b/env/dev/env/android/main.cljs index ebf4294df3c..4e3da6e3d8f 100644 --- a/env/dev/env/android/main.cljs +++ b/env/dev/env/android/main.cljs @@ -15,10 +15,10 @@ (re-frame.core/dispatch [:load-commands!])) (figwheel/watch-and-reload - :websocket-url "ws://10.0.3.2:3449/figwheel-ws" + :websocket-url "ws://localhost:3449/figwheel-ws" :heads-up-display false :jsload-callback callback) -(rr/enable-re-frisk-remote! {:host "10.0.3.2:4567" :pre-send (fn [db] (update db :chats #(into {} %)))}) +(rr/enable-re-frisk-remote! {:host "localhost:4567" :pre-send (fn [db] (update db :chats #(into {} %)))}) (core/init) diff --git a/resources/status.js b/resources/status.js index a917113788e..f1069790430 100644 --- a/resources/status.js +++ b/resources/status.js @@ -26,8 +26,7 @@ Command.prototype.create = function (com) { this.title = com.title; this.description = com.description; this.handler = com.handler; - this["has-handler"] = com.handler != null; - this["registered-only"] = com.registeredOnly; + this["has-handler"] = com.handler !== null; this.validator = com.validator; this.color = com.color; this.icon = com.icon; @@ -41,6 +40,15 @@ Command.prototype.create = function (com) { this["execute-immediately?"] = com.executeImmediately; this["sequential-params"] = com.sequentialParams; this["hide-send-button"] = com.hideSendButton; + + // scope + this["scope"] = {}; + this["scope"]["global?"] = com["scope"] != null && com["scope"]["isGlobal"] === true; + this["scope"]["registered-only?"] = com["scope"] != null && com["scope"]["registeredOnly"] === true; + this["scope"]["personal-chats?"] = com["scope"] == null || com["scope"]["personalChats"] === true; + this["scope"]["group-chats?"] = com["scope"] == null || com["scope"]["groupChats"] === true; + this["scope"]["can-use-for-dapps?"] = com["scope"] == null || com["scope"]["canUseForDApps"] === true; + this.addToCatalog(); return this; diff --git a/src/status_im/chat/handlers/input.cljs b/src/status_im/chat/handlers/input.cljs index 2c47ce233ad..1ebb96b9f21 100644 --- a/src/status_im/chat/handlers/input.cljs +++ b/src/status_im/chat/handlers/input.cljs @@ -114,9 +114,9 @@ (= type :grant-permissions)))) commands (suggestions/get-command-suggestions db chat-text) global-commands (suggestions/get-global-command-suggestions db chat-text) - all-commands (->> (into global-commands commands) - (remove (fn [[k {:keys [hidden?]}]] hidden?)) - (into {})) + all-commands (->> (into global-commands commands) + (remove (fn [[k {:keys [hidden?]}]] hidden?)) + (into {})) {:keys [dapp?]} (get-in db [:contacts/contacts chat-id])] (when dapp? (if (str/blank? chat-text) @@ -153,7 +153,7 @@ :to to} (input-model/command-dependent-context-params current-chat-id command))}] (status/call-jail - {:jail-id (or bot owner-id current-chat-id) + {:jail-id (or owner-id current-chat-id) :path path :params params :callback #(dispatch [:received-bot-response diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index a76ee66b787..66780fe2c4b 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -50,13 +50,10 @@ bot-url dapp?]} :contact :as params}]] - (if bot-url + (when bot-url (if-let [resource (js-res/get-resource bot-url)] (dispatch [::validate-hash params resource]) - (http-get-commands params bot-url)) - (when-not dapp? - ;; TODO: this part should be removed in the future - (dispatch [::validate-hash params js-res/wallet-js])))) + (http-get-commands params bot-url)))) (defn dispatch-loaded! [db [{{:keys [whisper-identity]} :contact @@ -106,14 +103,13 @@ (defn filter-commands [account {:keys [contacts chat-id] :as chat} commands] (->> commands - (remove (fn [[_ {:keys [registered-only name]}]] + (remove (fn [[_ {:keys [scope name :as c]}]] (and (not (:address account)) (not= name "global") - registered-only))) - ;; TODO: this part should be removed because it's much better to provide the ability to do this in the API - (map (fn [[k {:keys [name] :as v}]] - [k (assoc v :hidden? (and (some #{name} ["send" "request"]) - (= chat-id wallet-chat-id)))])) + (:registered-only? scope)))) + ;; TODO(alwx): SCOOOOPE + (remove (fn [[_ {:keys [scope]}]] + )) (remove (fn [[k _]] (and (= (count contacts) 1) (not= console-chat-id (get (first contacts) :identity)) @@ -139,8 +135,15 @@ chat (get chats id) commands' (filter-commands account chat commands) responses' (filter-commands account chat responses) - global-command (:global commands') - commands'' (each-merge (apply dissoc commands' [:init :global]) + global-commands (->> commands' + (filter (fn [[_ {:keys [scope]}]] + (:global? scope))) + (map (fn [[k v]] + [k (assoc v :bot (name k) + :owner-id id + :type :command)])) + (into {})) + commands'' (each-merge (apply dissoc commands' (into [:init] (keys global-commands))) {:type :command :owner-id id}) mailman-commands (get-mailmans-commands db)] @@ -154,10 +157,8 @@ :owner-id id}) :subscriptions subscriptions) - global-command - (update :global-commands assoc (keyword id) - (assoc global-command :bot id - :type :command)) + true + (update :global-commands merge global-commands) (= id bots-constants/mailman-bot) (update :contacts/contacts (fn [contacts]