fix /request preview

fix duplication of /send command in suggestions
This commit is contained in:
Roman Volosovskyi 2017-10-19 22:05:44 +02:00
parent 2a166c3a37
commit 4c4cf7a5e4
3 changed files with 57 additions and 45 deletions

View File

@ -53,6 +53,19 @@
(fn [[chats id] [_ k chat-id]] (fn [[chats id] [_ k chat-id]]
(get-in chats [(or chat-id id) k]))) (get-in chats [(or chat-id id) k])))
(defn get-suggested-commands
[[commands requests]]
(let [vec->map-by-name #(into {} (map vector (map :name %) %))
commands-map (vec->map-by-name commands)
requests-map (vec->map-by-name requests)]
(vals (merge commands-map requests-map))))
(reg-sub
:get-suggested-commands
:<- [:chat :possible-commands]
:<- [:chat :possible-requests]
get-suggested-commands)
(reg-sub (reg-sub
:get-current-chat-id :get-current-chat-id
(fn [db] (fn [db]
@ -219,8 +232,10 @@
(fn [db [_ message-id]] (fn [db [_ message-id]]
(get-in db [:message-data :preview message-id :markup]))) (get-in db [:message-data :preview message-id :markup])))
(reg-sub :get-message-preview (reg-sub
(fn [db [_ message-id]] :get-message-preview
(let [preview (subscribe [:get-message-preview-markup message-id])] (fn [[_ message-id]]
(when-let [markup @preview] [(subscribe [:get-message-preview-markup message-id])])
(commands-utils/generate-hiccup markup))))) (fn [[markup]]
(when markup
(commands-utils/generate-hiccup markup))))

View File

@ -35,8 +35,7 @@
(chat-utils/command-name command)]]]) (chat-utils/command-name command)]]])
(defview commands-view [] (defview commands-view []
[commands [:chat :possible-commands] [all-commands [:get-suggested-commands]
requests [:chat :possible-requests]
show-suggestions? [:show-suggestions?]] show-suggestions? [:show-suggestions?]]
[view style/commands-root [view style/commands-root
[view style/command-list-icon-container [view style/command-list-icon-container
@ -48,11 +47,10 @@
[scroll-view {:horizontal true [scroll-view {:horizontal true
:showsHorizontalScrollIndicator false :showsHorizontalScrollIndicator false
:keyboardShouldPersistTaps :always} :keyboardShouldPersistTaps :always}
(let [all-commands (apply conj commands requests)]
[view style/commands [view style/commands
(for [[index command] (map-indexed vector all-commands)] (for [[index command] (map-indexed vector all-commands)]
^{:key (str "command-" index)} ^{:key (str "command-" index)}
[command-view (= index 0) command])])]]) [command-view (= index 0) command])]]])
(defn- basic-text-input [_] (defn- basic-text-input [_]
(let [input-text (subscribe [:chat :input-text]) (let [input-text (subscribe [:chat :input-text])

View File

@ -72,13 +72,12 @@
[icon command-icon st/command-request-image])]]))}))) [icon command-icon st/command-request-image])]]))})))
(defview message-content-command-request (defview message-content-command-request
[{:keys [message-id chat-id]}] [{:keys [message-id chat-id content from incoming-group] :as message}]
(letsubs [commands [:get-commands-for-chat chat-id] (letsubs [commands [:get-commands-for-chat chat-id]
requests [:chat-actions :possible-requests] requests [:chat-actions :possible-requests]
answered? [:is-request-answered? message-id] answered? [:is-request-answered? message-id]
status-initialized? [:get :status-module-initialized?] status-initialized? [:get :status-module-initialized?]
markup [:get-message-preview message-id]] markup [:get-message-preview message-id]]
(fn [{:keys [message-id content from incoming-group] :as message}]
(let [{:keys [prefill prefill-bot-db prefillBotDb params] (let [{:keys [prefill prefill-bot-db prefillBotDb params]
text-content :text} content text-content :text} content
{:keys [command content]} (commands/replace-name-with-request message commands requests) {:keys [command content]} (commands/replace-name-with-request message commands requests)
@ -105,4 +104,4 @@
[text {:style st/style-sub-text [text {:style st/style-sub-text
:font :default} :font :default}
(:request-text command)]]) (:request-text command)]])
[request-button message-id command on-press-handler]])))) [request-button message-id command on-press-handler]])))