From ea31f70b5b2746e2f185b0952a439373c4abda92 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 18 Apr 2017 12:31:55 +0300 Subject: [PATCH] fix #1030 --- src/status_im/chat/models/input.cljs | 19 ++++++++----------- src/status_im/chat/views/input/input.cljs | 11 +++++------ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/status_im/chat/models/input.cljs b/src/status_im/chat/models/input.cljs index b933d74ae3..42abf6a183 100644 --- a/src/status_im/chat/models/input.cljs +++ b/src/status_im/chat/models/input.cljs @@ -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) @@ -175,4 +172,4 @@ (str command const/spacing-char - (str/join const/spacing-char new-args)))) \ No newline at end of file + (str/join const/spacing-char new-args)))) diff --git a/src/status_im/chat/views/input/input.cljs b/src/status_im/chat/views/input/input.cljs index 17a0ba8ce0..4c9ea1b2f7 100644 --- a/src/status_im/chat/views/input/input.cljs +++ b/src/status_im/chat/views/input/input.cljs @@ -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])])]])