console commands/responses
This commit is contained in:
parent
8474729695
commit
61b6599bd3
|
@ -68,7 +68,7 @@
|
||||||
(update-input-text db text))
|
(update-input-text db text))
|
||||||
|
|
||||||
(defn update-command [db [_ text]]
|
(defn update-command [db [_ text]]
|
||||||
(let [{:keys [command]} (suggestions/check-suggestion db text)]
|
(let [[command] (suggestions/check-suggestion db text)]
|
||||||
(commands/set-chat-command db command)))
|
(commands/set-chat-command db command)))
|
||||||
|
|
||||||
(register-handler :set-chat-input-text
|
(register-handler :set-chat-input-text
|
||||||
|
@ -99,7 +99,7 @@
|
||||||
(defn prepare-message
|
(defn prepare-message
|
||||||
[{:keys [identity current-chat-id] :as db} _]
|
[{:keys [identity current-chat-id] :as db} _]
|
||||||
(let [text (get-in db [:chats current-chat-id :input-text])
|
(let [text (get-in db [:chats current-chat-id :input-text])
|
||||||
{:keys [command]} (suggestions/check-suggestion db (str text " "))
|
[command] (suggestions/check-suggestion db (str text " "))
|
||||||
message (check-author-direction
|
message (check-author-direction
|
||||||
db current-chat-id
|
db current-chat-id
|
||||||
{:msg-id (random/id)
|
{:msg-id (random/id)
|
||||||
|
|
|
@ -20,10 +20,7 @@
|
||||||
[{:keys [current-chat-id] :as db} text]
|
[{:keys [current-chat-id] :as db} text]
|
||||||
(let [commands (get-in db [:chats current-chat-id :commands])]
|
(let [commands (get-in db [:chats current-chat-id :commands])]
|
||||||
(if (suggestion? text)
|
(if (suggestion? text)
|
||||||
;; TODO change 'commands' to 'suggestions'
|
(filter (fn [[_ v]] ((can-be-suggested? text) v)) commands)
|
||||||
(->> commands
|
|
||||||
vals
|
|
||||||
(filter (can-be-suggested? text)))
|
|
||||||
[])))
|
[])))
|
||||||
|
|
||||||
(defn get-command [db text]
|
(defn get-command [db text]
|
||||||
|
@ -55,10 +52,10 @@
|
||||||
(defn check-suggestion [db message]
|
(defn check-suggestion [db message]
|
||||||
(when-let [suggestion-text (when (string? message)
|
(when-let [suggestion-text (when (string? message)
|
||||||
(re-matches #"^![^\s]+\s" message))]
|
(re-matches #"^![^\s]+\s" message))]
|
||||||
(let [suggestion-text' (s/trim suggestion-text)
|
(let [suggestion-text' (s/trim suggestion-text)]
|
||||||
[suggestion] (filter #(= suggestion-text' (:text %))
|
(->> (get-commands db)
|
||||||
(get-commands db))]
|
(filter #(= suggestion-text' (->> % second :name (str "!"))))
|
||||||
suggestion)))
|
first))))
|
||||||
|
|
||||||
(defn typing-command? [db]
|
(defn typing-command? [db]
|
||||||
(-> db
|
(-> db
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
[content-suggestions-view]
|
[content-suggestions-view]
|
||||||
[view st/command-input-container
|
[view st/command-input-container
|
||||||
[view (st/command-text-container command)
|
[view (st/command-text-container command)
|
||||||
[text {:style st/command-text} (:text command)]]
|
[text {:style st/command-text} (str "!" (:name command))]]
|
||||||
[text-input (merge {:style st/command-input
|
[text-input (merge {:style st/command-input
|
||||||
:autoFocus true
|
:autoFocus true
|
||||||
:onChangeText set-input-message
|
:onChangeText set-input-message
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
(dispatch [:set-response-chat-command msg-id (:command command)]))
|
(dispatch [:set-response-chat-command msg-id (:command command)]))
|
||||||
|
|
||||||
(defn label [{:keys [command]}]
|
(defn label [{:keys [command]}]
|
||||||
(->> (name command)
|
(->> (when command (name command))
|
||||||
(str "request-")))
|
(str "request-")))
|
||||||
|
|
||||||
(defn message-content-command-request
|
(defn message-content-command-request
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
[view st/staged-command-background
|
[view st/staged-command-background
|
||||||
[view st/staged-command-info-container
|
[view st/staged-command-info-container
|
||||||
[view (st/staged-command-text-container command)
|
[view (st/staged-command-text-container command)
|
||||||
[text {:style st/staged-command-text} (:text command)]]
|
[text {:style st/staged-command-text} (str "!" (:name command))]]
|
||||||
[touchable-highlight {:style st/staged-command-cancel
|
[touchable-highlight {:style st/staged-command-cancel
|
||||||
:onPress #(cancel-command-input staged-command)}
|
:onPress #(cancel-command-input staged-command)}
|
||||||
[image {:source res/icon-close-gray
|
[image {:source res/icon-close-gray
|
||||||
|
|
|
@ -14,17 +14,18 @@
|
||||||
(dispatch [:set-chat-command command]))
|
(dispatch [:set-chat-command command]))
|
||||||
|
|
||||||
(defn suggestion-list-item
|
(defn suggestion-list-item
|
||||||
[{:keys [description]
|
[[command {:keys [description]
|
||||||
label :name
|
name :name
|
||||||
:as suggestion}]
|
:as suggestion}]]
|
||||||
|
(let [label (str "!" name)]
|
||||||
[touchable-highlight
|
[touchable-highlight
|
||||||
{:onPress #(set-command-input (keyword label))}
|
{:onPress #(set-command-input command)}
|
||||||
[view st/suggestion-container
|
[view st/suggestion-container
|
||||||
[view st/suggestion-sub-container
|
[view st/suggestion-sub-container
|
||||||
[view (st/suggestion-background suggestion)
|
[view (st/suggestion-background suggestion)
|
||||||
[text {:style st/suggestion-text} label]]
|
[text {:style st/suggestion-text} label]]
|
||||||
[text {:style st/value-text} label]
|
[text {:style st/value-text} label]
|
||||||
[text {:style st/description-text} description]]]])
|
[text {:style st/description-text} description]]]]))
|
||||||
|
|
||||||
(defn render-row [row _ _]
|
(defn render-row [row _ _]
|
||||||
(list-item [suggestion-list-item row]))
|
(list-item [suggestion-list-item row]))
|
||||||
|
|
|
@ -51,11 +51,28 @@
|
||||||
(defn json->clj [json]
|
(defn json->clj [json]
|
||||||
(js->clj (.parse js/JSON json) :keywordize-keys true))
|
(js->clj (.parse js/JSON json) :keywordize-keys true))
|
||||||
|
|
||||||
|
;; todo remove this
|
||||||
|
(def res {:commands {:location {:description "Send location"
|
||||||
|
:color "#9a5dcf"
|
||||||
|
:name "location"}
|
||||||
|
:phone {:description "Send phone number"
|
||||||
|
:color "#5fc48d"
|
||||||
|
:name "phone"}
|
||||||
|
:help {:description "Help" :color "#9a5dcf" :name "help"}}
|
||||||
|
:responses {:money {:description "Send money" :color "#5fc48d" :name "money"}
|
||||||
|
:confirmation-code {:description "Confirmation code"
|
||||||
|
:color "#7099e6"
|
||||||
|
:name "confirmationCode"}
|
||||||
|
:keypair-password {:description ""
|
||||||
|
:color "#7099e6"
|
||||||
|
:name "keypair-password"}}})
|
||||||
|
|
||||||
(defn parse-commands! [_ [identity file]]
|
(defn parse-commands! [_ [identity file]]
|
||||||
(parse file
|
(parse file
|
||||||
(fn [result]
|
(fn [result]
|
||||||
(let [commands (json->clj result)]
|
(let [commands (json->clj result)]
|
||||||
(dispatch [::add-commands identity file commands])))
|
;; todo use commands from jail
|
||||||
|
(dispatch [::add-commands identity file res])))
|
||||||
#(dispatch [::loading-failed! identity ::error-in-jail %])))
|
#(dispatch [::loading-failed! identity ::error-in-jail %])))
|
||||||
|
|
||||||
(defn validate-hash
|
(defn validate-hash
|
||||||
|
|
|
@ -96,7 +96,6 @@
|
||||||
(remove #(identities (:whisper-identity %)))
|
(remove #(identities (:whisper-identity %)))
|
||||||
(map #(vector (:whisper-identity %) %))
|
(map #(vector (:whisper-identity %) %))
|
||||||
(into {}))]
|
(into {}))]
|
||||||
(println new-contacts')
|
|
||||||
(-> db
|
(-> db
|
||||||
(update :contacts merge new-contacts')
|
(update :contacts merge new-contacts')
|
||||||
(assoc :new-contacts (vals new-contacts')))))
|
(assoc :new-contacts (vals new-contacts')))))
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
(defn get-content-suggestions [db command text]
|
(defn get-content-suggestions [db command text]
|
||||||
(or (when command
|
(or (when command
|
||||||
(when-let [command-suggestions ((:command command) suggestions)]
|
(when-let [command-suggestions ((keyword (:name command)) suggestions)]
|
||||||
(filterv (fn [s]
|
(filterv (fn [s]
|
||||||
(and (.startsWith (:value s) (or text ""))
|
(and (.startsWith (:value s) (or text ""))
|
||||||
(not= (:value s) text)))
|
(not= (:value s) text)))
|
||||||
|
|
|
@ -35,16 +35,6 @@
|
||||||
:icon {:uri "icon_lock_gray"}
|
:icon {:uri "icon_lock_gray"}
|
||||||
:suggestion true
|
:suggestion true
|
||||||
:handler #(dispatch [:sign-up-confirm %])}
|
:handler #(dispatch [:sign-up-confirm %])}
|
||||||
{:command :send
|
|
||||||
:text "!send"
|
|
||||||
:description (label :t/send-command-description)
|
|
||||||
:color "#9a5dcf"
|
|
||||||
:suggestion true}
|
|
||||||
{:command :request
|
|
||||||
:text "!request"
|
|
||||||
:description (label :t/request-command-description)
|
|
||||||
:color "#48ba30"
|
|
||||||
:suggestion true}
|
|
||||||
{:command :keypair-password
|
{:command :keypair-password
|
||||||
:text "!keypair-password"
|
:text "!keypair-password"
|
||||||
:description (label :t/keypair-password-command-description)
|
:description (label :t/keypair-password-command-description)
|
||||||
|
@ -59,13 +49,11 @@
|
||||||
:color "#9a5dcf"
|
:color "#9a5dcf"
|
||||||
:suggestion true}])
|
:suggestion true}])
|
||||||
|
|
||||||
(defn get-commands [db]
|
(defn get-commands [{:keys [current-chat-id] :as db}]
|
||||||
;; todo: temp. must be '(get db :commands)'
|
(or (get-in db [:chats current-chat-id :commands]) {}))
|
||||||
;; (get db :commands)
|
|
||||||
commands)
|
|
||||||
|
|
||||||
(defn get-command [db command-key]
|
(defn get-command [db command-key]
|
||||||
(first (filter #(= command-key (:command %)) (get-commands db))))
|
((get-commands db) command-key))
|
||||||
|
|
||||||
(defn find-command [commands command-key]
|
(defn find-command [commands command-key]
|
||||||
(first (filter #(= command-key (:command %)) commands)))
|
(first (filter #(= command-key (:command %)) commands)))
|
||||||
|
@ -126,4 +114,4 @@
|
||||||
(update content :command #(find-command commands (keyword %))))
|
(update content :command #(find-command commands (keyword %))))
|
||||||
|
|
||||||
(defn parse-command-request [commands content]
|
(defn parse-command-request [commands content]
|
||||||
(update content :command #(find-command commands (keyword %))))
|
(update content :command #((keyword %) commands)))
|
||||||
|
|
Loading…
Reference in New Issue