Skip to content

Commit

Permalink
# This is a combination of 2 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

Command scopes

# This is the commit message #2:

Scopes update
  • Loading branch information
alwx committed Aug 11, 2017
1 parent 6a56b60 commit 56d4dd5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 30 deletions.
9 changes: 7 additions & 2 deletions bots/browse/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions bots/console/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions bots/wallet/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down
4 changes: 2 additions & 2 deletions env/dev/env/android/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 10 additions & 2 deletions resources/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/status_im/chat/handlers/input.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
35 changes: 18 additions & 17 deletions src/status_im/commands/handlers/loading.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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)]
Expand All @@ -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]
Expand Down

0 comments on commit 56d4dd5

Please sign in to comment.