Fetch short preview during sending

This commit is contained in:
janherich 2018-02-13 17:11:55 +01:00
parent d1fbde8a40
commit 0b8356a96e
No known key found for this signature in database
GPG Key ID: C23B473AFBE94D13
2 changed files with 47 additions and 52 deletions

View File

@ -277,10 +277,12 @@
:proceed-event-creator (partial event-after-creator
command-message)})))
;; TODO (janherich) request-command-data functions and event need to be refactored, they are needlessly complicated
(defn proceed-command
"Proceed with command processing by setting up and executing chain of events:
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]
(let [params-template {:content content
:chat-id current-chat-id
@ -294,12 +296,17 @@
:event-after-creator (fn [command-message jail-response]
[::send-command
(assoc-in command-message [:command :preview] jail-response)])})
short-preview-params (merge params-template
{:data-type :short-preview
:event-after-creator (fn [_ jail-response]
[::request-command-data
(assoc-in preview-params [:content :command :short-preview] jail-response)])})
validation-params (merge params-template
{:data-type :validator
:event-after-creator (fn [_ jail-response]
[::proceed-validation
jail-response
[[::request-command-data preview-params]]])})]
[[::request-command-data short-preview-params]]])})]
(request-command-data db validation-params)))
;;;; Handlers

View File

@ -17,17 +17,6 @@
[status-im.ui.components.chat-icon.screen :as chat-icon.screen]))
(defn message-content-text [{:keys [content] :as message}]
(reagent/create-class
{:display-name "message-content-text"
: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
@ -44,14 +33,13 @@
:number-of-lines 1}
(:content content)]
(and (:command content)
(-> content :short-preview :markup))
(and (:command content) (-> content :short-preview :markup))
(commands-utils/generate-hiccup (-> content :short-preview :markup))
:else
[react/text {:style styles/last-message-text
:number-of-lines 1}
content])])}))
content])])
(defview message-status [{:keys [chat-id contacts]}
{:keys [message-id user-statuses outgoing] :as msg}]