revert unnecessary :chats/last-message-content subscription

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
bitsikka 2019-09-03 13:30:58 +05:45 committed by Andrey Shovkoplyas
parent ba8e49b649
commit df66b73054
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
2 changed files with 47 additions and 54 deletions

View File

@ -715,16 +715,6 @@
(fn [{:keys [unviewed-messages-count]}] (fn [{:keys [unviewed-messages-count]}]
unviewed-messages-count)) unviewed-messages-count))
(re-frame/reg-sub
:chats/last-message-content
(fn [[_ chat-id]]
(re-frame/subscribe [:chats/chat chat-id]))
(fn [{:keys [last-message-content last-message-content-type timestamp last-message-timestamp]}]
{:content last-message-content
:content-type last-message-content-type
:last-message-timestamp last-message-timestamp
:timestamp timestamp}))
(re-frame/reg-sub (re-frame/reg-sub
:chats/photo-path :chats/photo-path
:<- [:contacts/contacts] :<- [:contacts/contacts]

View File

@ -24,46 +24,43 @@
(when-let [command (commands-receiving/lookup-command-by-ref message id->command)] (when-let [command (commands-receiving/lookup-command-by-ref message id->command)]
(commands/generate-short-preview command (commands/add-chat-contacts contacts message))))) (commands/generate-short-preview command (commands/add-chat-contacts contacts message)))))
(defview message-content-text [chat-id] (defn message-content-text [{:keys [content content-type] :as message}]
(letsubs [{:keys [content content-type] :as message} [:chats/last-message-content chat-id]] [react/view styles/last-message-container
[react/view styles/last-message-container (cond
(cond
(not (and content content-type)) (not (and content content-type))
[react/text {:style styles/last-message-text [react/text {:style styles/last-message-text
:accessibility-label :no-messages-text} :accessibility-label :no-messages-text}
(i18n/label :t/no-messages)] (i18n/label :t/no-messages)]
(= constants/content-type-command content-type) (= constants/content-type-command content-type)
[command-short-preview message] [command-short-preview message]
(= constants/content-type-sticker content-type) (= constants/content-type-sticker content-type)
[react/image {:style {:margin 1 :width 20 :height 20} [react/image {:style {:margin 1 :width 20 :height 20}
:source {:uri (contenthash/url (:hash content))}}] :source {:uri (contenthash/url (:hash content))}}]
(string/blank? (:text content)) (string/blank? (:text content))
[react/text {:style styles/last-message-text} [react/text {:style styles/last-message-text}
""] ""]
(:text content) (:text content)
[react/text {:style styles/last-message-text [react/text {:style styles/last-message-text
:number-of-lines 1 :number-of-lines 1
:accessibility-label :chat-message-text} :accessibility-label :chat-message-text}
(:text content)] (:text content)]
:else :else
[react/text {:style styles/last-message-text [react/text {:style styles/last-message-text
:number-of-lines 1 :number-of-lines 1
:accessibility-label :chat-message-text} :accessibility-label :chat-message-text}
content])])) content])])
(defview message-timestamp [chat-id] (defn message-timestamp [timestamp]
(letsubs [{:keys [last-message-timestamp timestamp]} [:chats/last-message-content chat-id]] (when timestamp
(let [ts (if (pos? last-message-timestamp) last-message-timestamp timestamp)] [react/text {:style styles/datetime-text
(when ts :accessibility-label :last-message-time-text}
[react/text {:style styles/datetime-text (string/upper-case (time/to-short-str timestamp))]))
:accessibility-label :last-message-time-text}
(string/upper-case (time/to-short-str ts))]))))
(defview unviewed-indicator [chat-id] (defview unviewed-indicator [chat-id]
(letsubs [unviewed-messages-count [:chats/unviewed-messages-count chat-id]] (letsubs [unviewed-messages-count [:chats/unviewed-messages-count chat-id]]
@ -76,15 +73,18 @@
(let [{:keys (let [{:keys
[chat-id chat-name name [chat-id chat-name name
color online group-chat color online group-chat
public? public-key public? public-key contact
contact]} home-item last-message-timestamp
private-group? (and group-chat (not public?)) timestamp
public-group? (and group-chat public?) last-message-content
truncated-chat-name (utils/truncate-str chat-name 30) last-message-content-type]} home-item
chat-actions (cond private-group? (and group-chat (not public?))
(and group-chat public?) :public-chat-actions public-group? (and group-chat public?)
(and group-chat (not public?)) :group-chat-actions truncated-chat-name (utils/truncate-str chat-name 30)
:else :private-chat-actions)] chat-actions (cond
(and group-chat public?) :public-chat-actions
(and group-chat (not public?)) :group-chat-actions
:else :private-chat-actions)]
[list-item/list-item [list-item/list-item
{:icon [chat-icon.screen/chat-icon-view-chat-list {:icon [chat-icon.screen/chat-icon-view-chat-list
contact group-chat truncated-chat-name color online false] contact group-chat truncated-chat-name color online false]
@ -94,11 +94,14 @@
:else nil) :else nil)
:title truncated-chat-name :title truncated-chat-name
:title-accessibility-label :chat-name-text :title-accessibility-label :chat-name-text
:title-row-accessory [message-timestamp chat-id] :title-row-accessory [message-timestamp (if (pos? last-message-timestamp)
last-message-timestamp
timestamp)]
:subtitle :subtitle
(let [{:keys [tribute-status tribute-label]} (:tribute-to-talk contact)] (let [{:keys [tribute-status tribute-label]} (:tribute-to-talk contact)]
(if (not (#{:require :pending} tribute-status)) (if (not (#{:require :pending} tribute-status))
[message-content-text chat-id] [message-content-text {:content last-message-content
:content-type last-message-content-type}]
tribute-label)) tribute-label))
:subtitle-row-accessory [unviewed-indicator chat-id] :subtitle-row-accessory [unviewed-indicator chat-id]
:on-press #(do :on-press #(do