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))))) (dec (count text)))))
(defn possible-chat-actions [db chat-id] (defn possible-chat-actions [db chat-id]
(let [{:keys [commands requests]} (get-in db [:chats chat-id]) (let [{:keys [commands requests responses]} (get-in db [:chats chat-id])
commands (mapv (fn [[_ command]]
(vector command :any)) commands' (into {} (map (fn [[k v]] [k [v :any]]) commands))
commands) responses' (into {} (map (fn [{:keys [message-id type]}]
responses (mapv (fn [{:keys [message-id type]}] [type [(get responses type) message-id]])
(vector requests))]
(get-in db [:chats chat-id :responses type]) (vals (merge commands' responses'))))
message-id))
requests)]
(into commands responses)))
(defn split-command-args [command-text] (defn split-command-args [command-text]
(let [space? (text-ends-with-space? command-text) (let [space? (text-ends-with-space? command-text)

View File

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