Fix chat loading time

Signed-off-by: Volodymyr Kozieiev <vkjr.sp@gmail.com>
This commit is contained in:
Volodymyr Kozieiev 2018-10-02 09:40:11 +03:00
parent b6bb596a00
commit e89628ce3a
No known key found for this signature in database
GPG Key ID: 1F706640AAF07516
1 changed files with 16 additions and 5 deletions

View File

@ -157,15 +157,26 @@
[react/view {:style (message.style/delivery-status outgoing)} [react/view {:style (message.style/delivery-status outgoing)}
[message/message-delivery-status message]]])})))) [message/message-delivery-status message]]])}))))
(def load-step 5)
(defn load-more [all-messages-count messages-to-load]
(let [next-count (min all-messages-count (+ @messages-to-load load-step))]
(reset! messages-to-load next-count)))
(views/defview messages-view [{:keys [chat-id group-chat]}] (views/defview messages-view [{:keys [chat-id group-chat]}]
(views/letsubs [messages [:get-current-chat-messages-stream] (views/letsubs [messages [:get-current-chat-messages-stream]
current-public-key [:get-current-public-key]] current-public-key [:get-current-public-key]
(let [chat-id* (atom nil) messages-to-load (reagent/atom load-step)
scroll-ref (atom nil) chat-id* (reagent/atom nil)]
{:component-did-update #(load-more (count messages) messages-to-load)
:component-did-mount #(load-more (count messages) messages-to-load)}
(let [scroll-ref (atom nil)
scroll-timer (atom nil) scroll-timer (atom nil)
scroll-height (atom nil) scroll-height (atom nil)
_ (when (or (not @chat-id*) (not= @chat-id* chat-id)) _ (when (or (not @chat-id*) (not= @chat-id* chat-id))
(reset! chat-id* chat-id))] (do
(reset! messages-to-load load-step)
(reset! chat-id* chat-id)))]
[react/view {:style styles/messages-view} [react/view {:style styles/messages-view}
[react/scroll-view {:scrollEventThrottle 16 [react/scroll-view {:scrollEventThrottle 16
:headerHeight styles/messages-list-vertical-padding :headerHeight styles/messages-list-vertical-padding
@ -182,7 +193,7 @@
:ref #(reset! scroll-ref %)} :ref #(reset! scroll-ref %)}
[react/view [react/view
(doall (doall
(for [[index {:keys [from content message-id type value] :as message-obj}] (map-indexed vector messages)] (for [[index {:keys [from content message-id type value] :as message-obj}] (map-indexed vector (take @messages-to-load messages))]
^{:key message-obj} ^{:key message-obj}
[message (:text content) (= from current-public-key) [message (:text content) (= from current-public-key)
(assoc message-obj :group-chat group-chat (assoc message-obj :group-chat group-chat