fix /request preview
fix duplication of /send command in suggestions
This commit is contained in:
parent
2a166c3a37
commit
4c4cf7a5e4
|
@ -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))))
|
||||
|
|
|
@ -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])])]])
|
||||
[view style/commands
|
||||
(for [[index command] (map-indexed vector all-commands)]
|
||||
^{:key (str "command-" index)}
|
||||
[command-view (= index 0) command])]]])
|
||||
|
||||
(defn- basic-text-input [_]
|
||||
(let [input-text (subscribe [:chat :input-text])
|
||||
|
|
|
@ -72,37 +72,36 @@
|
|||
[icon command-icon st/command-request-image])]]))})))
|
||||
|
||||
(defview message-content-command-request
|
||||
[{:keys [message-id chat-id]}]
|
||||
(letsubs [commands [:get-commands-for-chat chat-id]
|
||||
requests [:chat-actions :possible-requests]
|
||||
answered? [:is-request-answered? message-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)
|
||||
command (if (and params command)
|
||||
(merge command {:prefill prefill
|
||||
:prefill-bot-db (or prefill-bot-db prefillBotDb)})
|
||||
command)
|
||||
on-press-handler (if (:execute-immediately? command)
|
||||
#(dispatch [:execute-command-immediately command])
|
||||
(when (and (not answered?) status-initialized?)
|
||||
#(set-chat-command message-id command)))]
|
||||
[view st/command-request-view
|
||||
[touchable-highlight
|
||||
{:on-press on-press-handler}
|
||||
[view st/command-request-message-view
|
||||
(if (and markup
|
||||
(not (string? markup)))
|
||||
[view markup]
|
||||
[text {:style st/style-message-text
|
||||
:font :default}
|
||||
(or text-content markup content)])]]
|
||||
(when (:request-text command)
|
||||
[view st/command-request-text-view
|
||||
[text {:style st/style-sub-text
|
||||
:font :default}
|
||||
(:request-text command)]])
|
||||
[request-button message-id command on-press-handler]]))))
|
||||
markup [:get-message-preview message-id]]
|
||||
(let [{:keys [prefill prefill-bot-db prefillBotDb params]
|
||||
text-content :text} content
|
||||
{:keys [command content]} (commands/replace-name-with-request message commands requests)
|
||||
command (if (and params command)
|
||||
(merge command {:prefill prefill
|
||||
:prefill-bot-db (or prefill-bot-db prefillBotDb)})
|
||||
command)
|
||||
on-press-handler (if (:execute-immediately? command)
|
||||
#(dispatch [:execute-command-immediately command])
|
||||
(when (and (not answered?) status-initialized?)
|
||||
#(set-chat-command message-id command)))]
|
||||
[view st/command-request-view
|
||||
[touchable-highlight
|
||||
{:on-press on-press-handler}
|
||||
[view st/command-request-message-view
|
||||
(if (and markup
|
||||
(not (string? markup)))
|
||||
[view markup]
|
||||
[text {:style st/style-message-text
|
||||
:font :default}
|
||||
(or text-content markup content)])]]
|
||||
(when (:request-text command)
|
||||
[view st/command-request-text-view
|
||||
[text {:style st/style-sub-text
|
||||
:font :default}
|
||||
(:request-text command)]])
|
||||
[request-button message-id command on-press-handler]])))
|
||||
|
|
Loading…
Reference in New Issue