Fixes #4309: Do not allow empty command to be sent

This commit is contained in:
pacamara 2018-05-26 12:52:31 +01:00 committed by Roman Volosovskyi
parent 750b95afd6
commit 71867a9674
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
1 changed files with 9 additions and 4 deletions

View File

@ -15,6 +15,10 @@
(animation/timing spin-value {:toValue to-spin-value (animation/timing spin-value {:toValue to-spin-value
:duration 300}))))) :duration 300})))))
(defn sendable? [input-text]
(let [trimmed (string/trim input-text)]
(not (or (string/blank? trimmed) (= trimmed "/")))))
(defview send-button-view [] (defview send-button-view []
(letsubs [command-completion [:command-completion] (letsubs [command-completion [:command-completion]
selected-command [:selected-chat-command] selected-command [:selected-chat-command]
@ -24,10 +28,11 @@
:command-completion command-completion})] :command-completion command-completion})]
{:component-did-update on-update} {:component-did-update on-update}
(let [{:keys [hide-send-button sequential-params]} (:command selected-command)] (let [{:keys [hide-send-button sequential-params]} (:command selected-command)]
(when (and (not (string/blank? input-text)) (when
(or (not selected-command) (and (sendable? input-text)
(some #{:complete :less-than-needed} [command-completion])) (or (not selected-command)
(not hide-send-button)) (some #{:complete :less-than-needed} [command-completion]))
(not hide-send-button))
[react/touchable-highlight {:on-press #(if sequential-params [react/touchable-highlight {:on-press #(if sequential-params
(do (do
(when-not (string/blank? seq-arg-input-text) (when-not (string/blank? seq-arg-input-text)