From e89628ce3ad96a1be1c9640fb9eea85531cd9b8f Mon Sep 17 00:00:00 2001 From: Volodymyr Kozieiev Date: Tue, 2 Oct 2018 09:40:11 +0300 Subject: [PATCH] Fix chat loading time Signed-off-by: Volodymyr Kozieiev --- .../ui/screens/desktop/main/chat/views.cljs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/status_im/ui/screens/desktop/main/chat/views.cljs b/src/status_im/ui/screens/desktop/main/chat/views.cljs index f39f3812a9..6b9fe73d64 100644 --- a/src/status_im/ui/screens/desktop/main/chat/views.cljs +++ b/src/status_im/ui/screens/desktop/main/chat/views.cljs @@ -157,15 +157,26 @@ [react/view {:style (message.style/delivery-status outgoing)} [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/letsubs [messages [:get-current-chat-messages-stream] - current-public-key [:get-current-public-key]] - (let [chat-id* (atom nil) - scroll-ref (atom nil) + current-public-key [:get-current-public-key] + messages-to-load (reagent/atom load-step) + 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-height (atom nil) _ (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/scroll-view {:scrollEventThrottle 16 :headerHeight styles/messages-list-vertical-padding @@ -182,7 +193,7 @@ :ref #(reset! scroll-ref %)} [react/view (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} [message (:text content) (= from current-public-key) (assoc message-obj :group-chat group-chat