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]]
(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
:get-current-chat-id
(fn [db]
@ -219,8 +232,10 @@
(fn [db [_ message-id]]
(get-in db [:message-data :preview message-id :markup])))
(reg-sub :get-message-preview
(fn [db [_ message-id]]
(let [preview (subscribe [:get-message-preview-markup message-id])]
(when-let [markup @preview]
(commands-utils/generate-hiccup markup)))))
(reg-sub
:get-message-preview
(fn [[_ message-id]]
[(subscribe [:get-message-preview-markup message-id])])
(fn [[markup]]
(when markup
(commands-utils/generate-hiccup markup))))

View File

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

View File

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