This commit is contained in:
Roman Volosovskyi 2017-04-18 12:31:55 +03:00 committed by Roman Volosovskyi
parent ae73ccac58
commit ea31f70b5b
2 changed files with 13 additions and 17 deletions

View File

@ -13,16 +13,13 @@
(dec (count text)))))
(defn possible-chat-actions [db chat-id]
(let [{:keys [commands requests]} (get-in db [:chats chat-id])
commands (mapv (fn [[_ command]]
(vector command :any))
commands)
responses (mapv (fn [{:keys [message-id type]}]
(vector
(get-in db [:chats chat-id :responses type])
message-id))
requests)]
(into commands responses)))
(let [{:keys [commands requests responses]} (get-in db [:chats chat-id])
commands' (into {} (map (fn [[k v]] [k [v :any]]) commands))
responses' (into {} (map (fn [{:keys [message-id type]}]
[type [(get responses type) message-id]])
requests))]
(vals (merge commands' responses'))))
(defn split-command-args [command-text]
(let [space? (text-ends-with-space? command-text)

View File

@ -35,6 +35,7 @@
(defview commands-view []
[commands [:chat :command-suggestions]
responses [:chat :responses]
requests [:chat :request-suggestions]
show-suggestions? [:show-suggestions?]]
[view style/commands-root
@ -49,13 +50,11 @@
[scroll-view {:horizontal true
:showsHorizontalScrollIndicator false
:keyboardShouldPersistTaps true}
(let [commands (mapv (fn [[_ command]] (select-keys command [:name :prefill])) commands)
requests (map (fn [request] (select-keys request [:name :prefill])) requests)
all (->> (into commands requests)
(distinct)
(map-indexed vector))]
(let [requests-names (map :type requests)
all-commands (merge (into {} commands) (select-keys responses requests-names))
all-commands-indexed (map-indexed vector (vals all-commands))]
[view style/commands
(for [[index command] all]
(for [[index command] all-commands-indexed]
^{:key (str "command-" index)}
[command-view (= index 0) command])])]])