[#8673] Temporay hide commands from chat and extensions

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Andrey Shovkoplyas 2019-07-30 15:38:54 +02:00
parent 27b77a6dc9
commit 447d37e5ca
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
12 changed files with 93 additions and 85 deletions

2
.env
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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=

View File

@ -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)))))

View File

@ -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]
@ -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]

View File

@ -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])

View File

@ -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?)

View File

@ -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}]]]))

View File

@ -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"

View File

@ -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"