diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index 87dc476731..bed514f2f9 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -56,26 +56,22 @@ [view st/track-mark] [text {:style st/track-duration-text} "03:39"]]]) -(defn message-content-command [content preview] - (let [commands-atom (subscribe [:get-commands-and-responses])] - (fn [content preview] - (let [commands @commands-atom - {:keys [command content]} - (parse-command-msg-content commands content)] - [view st/content-command-view - [view st/command-container - [view (st/command-view command) - [text {:style st/command-name} - (str "!" (:name command))]]] - ;; todo doesn't reflect design - (when-let [icon (:icon command)] - [view st/command-image-view - [image {:source {:uri icon} - :style st/command-image}]]) - (if preview - preview - [text {:style st/command-text} - content])])))) +(defview message-content-command [content preview] + [commands [:get-commands-and-responses]] + (let [{:keys [command content]} (parse-command-msg-content commands content) + {:keys [name icon type]} command] + [view st/content-command-view + [view st/command-container + [view (st/command-view command) + [text {:style st/command-name} + (str (if (= :command type) "!" "") name)]]] + (when icon + [view st/command-image-view + [image {:source {:uri icon} + :style st/command-image}]]) + (if preview + preview + [text {:style st/command-text} content])])) (defn set-chat-command [msg-id command] (dispatch [:set-response-chat-command msg-id (keyword (:name command))])) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index 417175bc8a..2291ade0fc 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -61,11 +61,16 @@ (get-hash-by-file file))] (assoc db ::valid-hash valid?))) +(defn mark-as [as coll] + (->> coll + (map (fn [[k v]] [k (assoc v :type as)])) + (into {}))) + (defn add-commands [db [id _ {:keys [commands responses]}]] (-> db - (update-in [:chats id :commands] merge commands) - (update-in [:chats id :responses] merge responses))) + (update-in [:chats id :commands] merge (mark-as :command commands)) + (update-in [:chats id :responses] merge (mark-as :response responses)))) (defn save-commands-js! [_ [id file]]