Skip to content

Commit

Permalink
[#8673] Temporay hide commands from chat and extensions
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
  • Loading branch information
flexsurfer committed Jul 30, 2019
1 parent 27b77a6 commit 447d37e
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DEFAULT_NETWORK=mainnet_rpc
DEV_BUILD=1
ERC20_CONTRACT_WARNINGS=1
ETHEREUM_DEV_CLUSTER=1
EXTENSIONS=1
EXTENSIONS=0
FLEET=eth.beta
GROUP_CHATS_ENABLED=1
HARDWALLET_ENABLED=0
Expand Down
2 changes: 1 addition & 1 deletion .env.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ DEBUG_WEBVIEW=1
DEFAULT_NETWORK=testnet_rpc
ERC20_CONTRACT_WARNINGS=1
ETHEREUM_DEV_CLUSTER=1
EXTENSIONS=1
EXTENSIONS=0
FLEET=eth.beta
GROUP_CHATS_ENABLED=1
LOG_LEVEL_STATUS_GO=info
Expand Down
2 changes: 1 addition & 1 deletion .env.jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ DEBUG_WEBVIEW=1
DEFAULT_NETWORK=mainnet_rpc
ERC20_CONTRACT_WARNINGS=1
ETHEREUM_DEV_CLUSTER=1
EXTENSIONS=1
EXTENSIONS=0
FLEET=eth.beta
GROUP_CHATS_ENABLED=1
HARDWALLET_ENABLED=0
Expand Down
2 changes: 1 addition & 1 deletion .env.nightly
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ DEBUG_WEBVIEW=1
DEFAULT_NETWORK=mainnet_rpc
ERC20_CONTRACT_WARNINGS=1
ETHEREUM_DEV_CLUSTER=1
EXTENSIONS=1
EXTENSIONS=0
FLEET=eth.beta
GROUP_CHATS_ENABLED=1
LOG_LEVEL_STATUS_GO=info
Expand Down
2 changes: 1 addition & 1 deletion .env.release
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ DEBUG_WEBVIEW=0
DEFAULT_NETWORK=mainnet_rpc
ERC20_CONTRACT_WARNINGS=0
ETHEREUM_DEV_CLUSTER=0
EXTENSIONS=1
EXTENSIONS=0
FLEET=eth.beta
GROUP_CHATS_ENABLED=1
LOG_LEVEL_STATUS_GO=
Expand Down
14 changes: 8 additions & 6 deletions src/status_im/chat/commands/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@
(and group-chat (not public?)) (conj :group-chats)
public? (conj :public-chats))
chat-access-scope #{chat-id}]
(reduce (fn [acc command-id]
(let [{:keys [type] :as command-props} (get id->command command-id)]
(assoc acc (protocol/id type) command-props)))
{}
(concat (get access-scope->command-id global-access-scope)
(get access-scope->command-id chat-access-scope)))))
;;TODO disable commands temporary for v1
{}
#_(reduce (fn [acc command-id]
(let [{:keys [type] :as command-props} (get id->command command-id)]
(assoc acc (protocol/id type) command-props)))
{}
(concat (get access-scope->command-id global-access-scope)
(get access-scope->command-id chat-access-scope)))))
25 changes: 14 additions & 11 deletions src/status_im/ui/screens/chat/message/message.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
[status-im.ui.screens.chat.styles.message.message :as style]
[status-im.ui.screens.chat.utils :as chat.utils]
[status-im.utils.contenthash :as contenthash]
[status-im.utils.platform :as platform])
[status-im.utils.platform :as platform]
[status-im.utils.config :as config])
(:require-macros [status-im.utils.views :refer [defview letsubs]]))

(defn install-extension-message [extension-id outgoing]
Expand All @@ -35,16 +36,18 @@
{:keys [contacts]} [:chats/current-chat]]
(let [{:keys [type] :as command} (commands-receiving/lookup-command-by-ref command-message id->command)
extension-id (get-in command-message [:content :params :extension-id])]
(if (and platform/mobile? extension-id
(extensions.module/valid-uri? extension-id)
(or (not type) (and type (satisfies? protocol/Extension type)
(not= extension-id (protocol/extension-id type)))))
;; Show install message only for mobile and if message contains extension id and there is no extension installed
;; or installed extension has differen extension id
[install-extension-message extension-id (:outgoing command-message)]
(if command
(commands/generate-preview command (commands/add-chat-contacts contacts command-message))
[react/text (str "Unhandled command: " (-> command-message :content :command-path first))])))))
;;TODO temporary disable commands for v1
[react/text (str "Unhandled command: " (-> command-message :content :command-path first))]
#_(if (and config/extensions-enabled? platform/mobile? extension-id
(extensions.module/valid-uri? extension-id)
(or (not type) (and type (satisfies? protocol/Extension type)
(not= extension-id (protocol/extension-id type)))))
;; Show install message only for mobile and if message contains extension id and there is no extension installed
;; or installed extension has differen extension id
[install-extension-message extension-id (:outgoing command-message)]
(if command
(commands/generate-preview command (commands/add-chat-contacts contacts command-message))
[react/text (str "Unhandled command: " (-> command-message :content :command-path first))])))))

(defview message-timestamp
[t justify-timestamp? outgoing command? content content-type]
Expand Down
9 changes: 5 additions & 4 deletions src/status_im/ui/screens/profile/contact/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
:accessibility-label :start-conversation-button}
(not (#{:none :paid} tribute-status))
(assoc :subtext tribute-label))
{:label (i18n/label :t/send-transaction)
:icon :main-icons/send
:action #(re-frame/dispatch [:profile/send-transaction public-key])
:accessibility-label :send-transaction-button}
;;TODO hide temporary for v1
#_{:label (i18n/label :t/send-transaction)
:icon :main-icons/send
:action #(re-frame/dispatch [:profile/send-transaction public-key])
:accessibility-label :send-transaction-button}
{:label (i18n/label :t/share-profile-link)
:icon :main-icons/share
:action #(re-frame/dispatch [:profile/share-profile-link public-key])
Expand Down
17 changes: 9 additions & 8 deletions src/status_im/ui/screens/wallet/components/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,15 @@

(defn- on-choose-recipient [contact-only? request?]
(list-selection/show {:title (i18n/label :t/wallet-choose-recipient)
:options (concat
[{:label (i18n/label :t/recent-recipients)
:action #(re-frame/dispatch [:navigate-to :recent-recipients {:request? request?}])}]
(when-not contact-only?
[{:label (i18n/label :t/scan-qr)
:action request-camera-permissions}
{:label (i18n/label :t/recipient-code)
:action #(re-frame/dispatch [:navigate-to :contact-code])}]))}))
;;TODO temporary hide for v1
#_(concat
[{:label (i18n/label :t/recent-recipients)
:action #(re-frame/dispatch [:navigate-to :recent-recipients {:request? request?}])}]
(when-not contact-only?))
:options [{:label (i18n/label :t/scan-qr)
:action request-camera-permissions}
{:label (i18n/label :t/recipient-code)
:action #(re-frame/dispatch [:navigate-to :contact-code])}]}))

(defn recipient-selector [{:keys [name address disabled? contact-only? request? modal?]}]
[cartouche {:on-press #(on-choose-recipient contact-only? request?)
Expand Down
13 changes: 7 additions & 6 deletions src/status_im/ui/screens/wallet/request/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@
:button-style {:margin-vertical 20 :margin-horizontal 16}
:accessibility-label :share-address-button
:label (i18n/label :t/share-address)}]
[components.common/button {:on-press #(do
(re-frame/dispatch [:hide-popover])
(re-frame/dispatch [:navigate-to :wallet-send-transaction-request]))
:accessibility-label :sent-transaction-request-button
:label (i18n/label :t/send-transaction-request)
:background? false}]]]))
;;TODO temporary hide for v1
#_[components.common/button {:on-press #(do
(re-frame/dispatch [:hide-popover])
(re-frame/dispatch [:navigate-to :wallet-send-transaction-request]))
:accessibility-label :sent-transaction-request-button
:label (i18n/label :t/send-transaction-request)
:background? false}]]]))
48 changes: 24 additions & 24 deletions test/cljs/status_im/test/chat/commands/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,30 @@
(is (contains? (get-in fx [:db :access-scope->command-id #{:public-chats}])
(core/command-id AnotherTestCommandInstance))))))

(deftest chat-commands-test
(let [fx (core/load-commands {:db {}} #{TestCommandInstance AnotherTestCommandInstance})]
(testing "That relevant commands are looked up for chat"
(is (= #{TestCommandInstance AnotherTestCommandInstance}
(into #{}
(map (comp :type second))
(core/chat-commands (get-in fx [:db :id->command])
(get-in fx [:db :access-scope->command-id])
{:chat-id "topic"
:group-chat true
:public? true}))))
(is (= #{TestCommandInstance}
(into #{}
(map (comp :type second))
(core/chat-commands (get-in fx [:db :id->command])
(get-in fx [:db :access-scope->command-id])
{:chat-id "group"
:group-chat true}))))
(is (= #{TestCommandInstance}
(into #{}
(map (comp :type second))
(core/chat-commands (get-in fx [:db :id->command])
(get-in fx [:db :access-scope->command-id])
{:chat-id "contact"})))))))
#_(deftest chat-commands-test
(let [fx (core/load-commands {:db {}} #{TestCommandInstance AnotherTestCommandInstance})]
(testing "That relevant commands are looked up for chat"
(is (= #{TestCommandInstance AnotherTestCommandInstance}
(into #{}
(map (comp :type second))
(core/chat-commands (get-in fx [:db :id->command])
(get-in fx [:db :access-scope->command-id])
{:chat-id "topic"
:group-chat true
:public? true}))))
(is (= #{TestCommandInstance}
(into #{}
(map (comp :type second))
(core/chat-commands (get-in fx [:db :id->command])
(get-in fx [:db :access-scope->command-id])
{:chat-id "group"
:group-chat true}))))
(is (= #{TestCommandInstance}
(into #{}
(map (comp :type second))
(core/chat-commands (get-in fx [:db :id->command])
(get-in fx [:db :access-scope->command-id])
{:chat-id "contact"})))))))

(def contacts #{"0x0471b2be1e8b971f75b571ba047baa58e2f40f67dad38f6381b2382df43f7176b1813bf372af4cd8451ed9063213029378b9fbc7db792d496e1a6161c42d999edf"
"0x04b790f2c3f4079f35a1fa396465ceb243cc446c9af211d0a1774f869eb9632a67a6e664e24075ec5c5a8a95a509a2a8173dbfeb88af372e784a37fecc1b5c0ba5"
Expand Down
42 changes: 21 additions & 21 deletions test/cljs/status_im/test/chat/commands/input.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@
(is (= "" (input/join-command-args [""])))
(is (= "/send 1.0 \"John Doe\"" (input/join-command-args ["/send" "1.0" "John Doe"]))))

(deftest selected-chat-command-test
(let [fx (core/load-commands {:db {}} #{test-core/TestCommandInstance test-core/AnotherTestCommandInstance})
commands (core/chat-commands (get-in fx [:db :id->command])
(get-in fx [:db :access-scope->command-id])
{:chat-id "contact"})]
(testing "Text not beggining with the command special charactes `/` is recognised"
(is (not (input/selected-chat-command "test-command 1" nil commands))))
(testing "Command not matching any available commands is not recognised as well"
(is (not (input/selected-chat-command "/another-test-command" nil commands))))
(testing "Available correctly entered command is recognised"
(is (= test-core/TestCommandInstance
(get (input/selected-chat-command "/test-command" nil commands) :type))))
(testing "Command completion and param position are determined as well"
(let [{:keys [current-param-position command-completion]}
(input/selected-chat-command "/test-command 1 " 17 commands)]
(is (= 1 current-param-position))
(is (= :less-then-needed command-completion)))
(let [{:keys [current-param-position command-completion]}
(input/selected-chat-command "/test-command 1 2 3" 20 commands)]
(is (= 2 current-param-position))
(is (= :complete command-completion))))))
#_(deftest selected-chat-command-test
(let [fx (core/load-commands {:db {}} #{test-core/TestCommandInstance test-core/AnotherTestCommandInstance})
commands (core/chat-commands (get-in fx [:db :id->command])
(get-in fx [:db :access-scope->command-id])
{:chat-id "contact"})]
(testing "Text not beggining with the command special charactes `/` is recognised"
(is (not (input/selected-chat-command "test-command 1" nil commands))))
(testing "Command not matching any available commands is not recognised as well"
(is (not (input/selected-chat-command "/another-test-command" nil commands))))
(testing "Available correctly entered command is recognised"
(is (= test-core/TestCommandInstance
(get (input/selected-chat-command "/test-command" nil commands) :type))))
(testing "Command completion and param position are determined as well"
(let [{:keys [current-param-position command-completion]}
(input/selected-chat-command "/test-command 1 " 17 commands)]
(is (= 1 current-param-position))
(is (= :less-then-needed command-completion)))
(let [{:keys [current-param-position command-completion]}
(input/selected-chat-command "/test-command 1 2 3" 20 commands)]
(is (= 2 current-param-position))
(is (= :complete command-completion))))))

(deftest set-command-parameter-test
(testing "Setting command parameter correctly updates the text input"
Expand Down

0 comments on commit 447d37e

Please sign in to comment.