Fetch short preview during sending
This commit is contained in:
parent
d1fbde8a40
commit
0b8356a96e
|
@ -277,29 +277,36 @@
|
||||||
:proceed-event-creator (partial event-after-creator
|
:proceed-event-creator (partial event-after-creator
|
||||||
command-message)})))
|
command-message)})))
|
||||||
|
|
||||||
|
;; TODO (janherich) request-command-data functions and event need to be refactored, they are needlessly complicated
|
||||||
(defn proceed-command
|
(defn proceed-command
|
||||||
"Proceed with command processing by setting up and executing chain of events:
|
"Proceed with command processing by setting up and executing chain of events:
|
||||||
1. Params validation
|
1. Params validation
|
||||||
2. Preview fetching"
|
2. Short preview fetching
|
||||||
|
3. Preview fetching"
|
||||||
[{:keys [current-chat-id chats] :as db} {{:keys [bot]} :command :as content} message-id current-time]
|
[{:keys [current-chat-id chats] :as db} {{:keys [bot]} :command :as content} message-id current-time]
|
||||||
(let [params-template {:content content
|
(let [params-template {:content content
|
||||||
:chat-id current-chat-id
|
:chat-id current-chat-id
|
||||||
:group-id (when (get-in chats [current-chat-id :group-chat])
|
:group-id (when (get-in chats [current-chat-id :group-chat])
|
||||||
current-chat-id)
|
current-chat-id)
|
||||||
:jail-id (or bot current-chat-id)
|
:jail-id (or bot current-chat-id)
|
||||||
:message-id message-id
|
:message-id message-id
|
||||||
:current-time current-time}
|
:current-time current-time}
|
||||||
preview-params (merge params-template
|
preview-params (merge params-template
|
||||||
{:data-type :preview
|
{:data-type :preview
|
||||||
:event-after-creator (fn [command-message jail-response]
|
:event-after-creator (fn [command-message jail-response]
|
||||||
[::send-command
|
[::send-command
|
||||||
(assoc-in command-message [:command :preview] jail-response)])})
|
(assoc-in command-message [:command :preview] jail-response)])})
|
||||||
validation-params (merge params-template
|
short-preview-params (merge params-template
|
||||||
{:data-type :validator
|
{:data-type :short-preview
|
||||||
:event-after-creator (fn [_ jail-response]
|
:event-after-creator (fn [_ jail-response]
|
||||||
[::proceed-validation
|
[::request-command-data
|
||||||
jail-response
|
(assoc-in preview-params [:content :command :short-preview] jail-response)])})
|
||||||
[[::request-command-data preview-params]]])})]
|
validation-params (merge params-template
|
||||||
|
{:data-type :validator
|
||||||
|
:event-after-creator (fn [_ jail-response]
|
||||||
|
[::proceed-validation
|
||||||
|
jail-response
|
||||||
|
[[::request-command-data short-preview-params]]])})]
|
||||||
(request-command-data db validation-params)))
|
(request-command-data db validation-params)))
|
||||||
|
|
||||||
;;;; Handlers
|
;;;; Handlers
|
||||||
|
|
|
@ -17,41 +17,29 @@
|
||||||
[status-im.ui.components.chat-icon.screen :as chat-icon.screen]))
|
[status-im.ui.components.chat-icon.screen :as chat-icon.screen]))
|
||||||
|
|
||||||
(defn message-content-text [{:keys [content] :as message}]
|
(defn message-content-text [{:keys [content] :as message}]
|
||||||
(reagent/create-class
|
[react/view styles/last-message-container
|
||||||
{:display-name "message-content-text"
|
(cond
|
||||||
:component-will-mount
|
|
||||||
#(when (and (or (:command content)
|
|
||||||
(:content-command content))
|
|
||||||
(not (:short-preview content)))
|
|
||||||
(re-frame/dispatch [:request-command-message-data message
|
|
||||||
{:data-type :short-preview
|
|
||||||
:cache-data? true}]))
|
|
||||||
:reagent-render
|
|
||||||
(fn [{:keys [content] :as message}]
|
|
||||||
[react/view styles/last-message-container
|
|
||||||
(cond
|
|
||||||
|
|
||||||
(not message)
|
(not message)
|
||||||
[react/text {:style styles/last-message-text}
|
[react/text {:style styles/last-message-text}
|
||||||
(i18n/label :t/no-messages)]
|
(i18n/label :t/no-messages)]
|
||||||
|
|
||||||
(str/blank? content)
|
(str/blank? content)
|
||||||
[react/text {:style styles/last-message-text}
|
[react/text {:style styles/last-message-text}
|
||||||
""]
|
""]
|
||||||
|
|
||||||
(:content content)
|
(:content content)
|
||||||
[react/text {:style styles/last-message-text
|
[react/text {:style styles/last-message-text
|
||||||
:number-of-lines 1}
|
:number-of-lines 1}
|
||||||
(:content content)]
|
(:content content)]
|
||||||
|
|
||||||
(and (:command content)
|
(and (:command content) (-> content :short-preview :markup))
|
||||||
(-> content :short-preview :markup))
|
(commands-utils/generate-hiccup (-> content :short-preview :markup))
|
||||||
(commands-utils/generate-hiccup (-> content :short-preview :markup))
|
|
||||||
|
|
||||||
:else
|
:else
|
||||||
[react/text {:style styles/last-message-text
|
[react/text {:style styles/last-message-text
|
||||||
:number-of-lines 1}
|
:number-of-lines 1}
|
||||||
content])])}))
|
content])])
|
||||||
|
|
||||||
(defview message-status [{:keys [chat-id contacts]}
|
(defview message-status [{:keys [chat-id contacts]}
|
||||||
{:keys [message-id user-statuses outgoing] :as msg}]
|
{:keys [message-id user-statuses outgoing] :as msg}]
|
||||||
|
|
Loading…
Reference in New Issue