Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alwx committed Oct 2, 2017
1 parent 204435a commit 3525ec0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
18 changes: 12 additions & 6 deletions src/status_im/chat/models/commands.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,15 @@
(update content :command #((keyword command) commands))))
content))

(defn parse-command-request [possible-requests {:keys [message-id content] :as message}]
(let [possible-requests (->> possible-requests
(map (fn [{:keys [request] :as message}]
[(:message-id request) message]))
(into {}))]
(assoc content :command (get possible-requests message-id))))
(defn find-command-for-request
[{:keys [message-id content] :as message} possible-requests possible-commands]
(let [requests (->> possible-requests
(map (fn [{:keys [request] :as message}]
[(:message-id request) message]))
(into {}))
commands (->> possible-commands
(map (fn [{:keys [name] :as message}]
[name message]))
(into {}))]
(assoc content :command (or (get requests message-id)
(get commands (get content :command))))))
4 changes: 2 additions & 2 deletions src/status_im/chat/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
:<- [:chats]
:<- [:get-current-chat-id]
:<- [:chat :input-text]
(fn [[chats chat-id text] [_ type]]
(->> (get-in chats [chat-id type])
(fn [[chats current-chat-id text] [_ type chat-id]]
(->> (get-in chats [(or chat-id current-chat-id) type])
(filter #(or (str/includes? (chat-utils/command-name %) (or text "")))))))

(reg-sub
Expand Down
39 changes: 20 additions & 19 deletions src/status_im/chat/views/message/request_message.cljs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns status-im.chat.views.message.request-message
(:require-macros [status-im.utils.views :refer [defview letsubs]])
(:require [re-frame.core :refer [subscribe dispatch]]
[reagent.core :as r]
[status-im.components.react :refer [view
Expand Down Expand Up @@ -61,7 +62,6 @@
#(reset! loop? false)
:reagent-render
(fn [message-id {command-icon :icon :as command} on-press-handler]
(log/debug "ALWX C" command)
(when command
[touchable-highlight
{:on-press on-press-handler
Expand All @@ -71,34 +71,35 @@
(when command-icon
[icon command-icon st/command-request-image])]]))})))

(defn message-content-command-request
(defview message-content-command-request
[{:keys [message-id chat-id]}]
(let [requests (subscribe [:chat-actions :possible-requests])
answered? (subscribe [:is-request-answered? message-id])
status-initialized? (subscribe [:get :status-module-initialized?])
markup (subscribe [:get-message-preview message-id])]
(letsubs [requests [:chat-actions :possible-requests]
commands [:chat-actions :possible-commands]
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/parse-command-request @requests message)
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)))]
{:keys [command content]} (commands/find-command-for-request message requests commands)
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/comand-request-view
[touchable-highlight
{:on-press on-press-handler}
[view st/command-request-message-view
(if (and @markup
(not (string? @markup)))
[view @markup]
(if (and markup
(not (string? markup)))
[view markup]
[text {:style st/style-message-text
:font :default}
(or text-content @markup content)])]]
(or text-content markup content)])]]
(when (:request-text command)
[view st/command-request-text-view
[text {:style st/style-sub-text
Expand Down

0 comments on commit 3525ec0

Please sign in to comment.