diff --git a/src/status_im/chat/models/loading.cljs b/src/status_im/chat/models/loading.cljs index 9ee58cd7d5..1665eeaf13 100644 --- a/src/status_im/chat/models/loading.cljs +++ b/src/status_im/chat/models/loading.cljs @@ -67,43 +67,25 @@ statuses)) (fx/defn initialize-chats - "Initialize all persisted chats on startup" - [{:keys [db default-dapps all-stored-chats] :as cofx}] - (let [chats (reduce (fn [acc {:keys [chat-id] :as chat}] + "Initialize persisted chats on startup" + [{:keys [db default-dapps get-all-stored-chats] :as cofx} + {:keys [from to] :or {from 0 to nil}}] + (let [old-chats (:chats db) + chats (reduce (fn [acc {:keys [chat-id] :as chat}] (assoc acc chat-id (assoc chat :messages-initialized? false :referenced-messages {} :messages empty-message-map))) {} - all-stored-chats)] + (get-all-stored-chats from to)) + chats (merge old-chats chats)] (fx/merge cofx {:db (assoc db :chats chats :contacts/dapps default-dapps)} (commands/load-commands commands/register)))) -(fx/defn initialize-pending-messages - "Change status of own messages which are still in `sending` status to `not-sent` - (If signal from status-go has not been received)" - [{:keys [db] :as cofx}] - (let [me (accounts.db/current-public-key cofx) - pending-statuses (->> (vals (:chats db)) - (mapcat :message-statuses) - (mapcat (fn [[_ user-id->status]] - (filter (comp (partial = :sending) :status) - (get user-id->status me))))) - updated-statuses (map #(assoc % :status :not-sent) pending-statuses)] - {:data-store/tx [(user-statuses-store/save-statuses-tx updated-statuses)] - :db (reduce - (fn [acc {:keys [chat-id message-id status public-key]}] - (assoc-in acc - [:chats chat-id :message-status message-id - public-key :status] - status)) - db - updated-statuses)})) - (defn load-more-messages "Loads more messages for current chat" [{{:keys [current-chat-id] :as db} :db diff --git a/src/status_im/data_store/chats.cljs b/src/status_im/data_store/chats.cljs index 1cb169fb3d..392dcf06b8 100644 --- a/src/status_im/data_store/chats.cljs +++ b/src/status_im/data_store/chats.cljs @@ -60,11 +60,14 @@ (re-frame/reg-cofx :data-store/all-chats (fn [cofx _] - (assoc cofx :all-stored-chats (map normalize-chat - (-> @core/account-realm - (core/get-all :chat) - (core/sorted :timestamp :desc) - (core/all-clj :chat)))))) + (assoc cofx :get-all-stored-chats + (fn [from to] + (map normalize-chat + (-> @core/account-realm + (core/get-all :chat) + (core/sorted :timestamp :desc) + (core/page from to) + (core/all-clj :chat))))))) (defn save-chat-tx "Returns tx function for saving chat" diff --git a/src/status_im/data_store/realm/core.cljs b/src/status_im/data_store/realm/core.cljs index 6b3ca2e4bf..3fadff6d95 100644 --- a/src/status_im/data_store/realm/core.cljs +++ b/src/status_im/data_store/realm/core.cljs @@ -311,7 +311,7 @@ (.sorted results (clj->js fields))) (defn page [results from to] - (js/Array.prototype.slice.call results from to)) + (js/Array.prototype.slice.call results from (or to -1))) (defn filtered [results filter-query] (.filtered results filter-query)) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 937bd0a611..5730153959 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -94,15 +94,15 @@ (init/handle-init-store-error cofx encryption-key))) (handlers/register-handler-fx - :init-chats + :init-rest-of-chats [(re-frame/inject-cofx :web3/get-web3) (re-frame/inject-cofx :get-default-dapps) (re-frame/inject-cofx :data-store/all-chats)] - (fn [{:keys [db] :as cofx} [_ address]] + (fn [{:keys [db] :as cofx} [_]] + (log/debug "PERF" :init-rest-of-chats (.now js/Date)) (fx/merge cofx {:db (assoc db :chats/loading? false)} - (chat-loading/initialize-chats) - (chat-loading/initialize-pending-messages)))) + (chat-loading/initialize-chats {:from 10})))) (handlers/register-handler-fx :init.callback/account-change-success @@ -110,7 +110,9 @@ (re-frame/inject-cofx :data-store/get-all-contacts) (re-frame/inject-cofx :data-store/get-all-installations) (re-frame/inject-cofx :data-store/all-browsers) - (re-frame/inject-cofx :data-store/all-dapp-permissions)] + (re-frame/inject-cofx :data-store/all-dapp-permissions) + (re-frame/inject-cofx :get-default-dapps) + (re-frame/inject-cofx :data-store/all-chats)] (fn [{:keys [db] :as cofx} [_ address]] (let [{:node/keys [status on-ready]} db] (fx/merge @@ -118,7 +120,8 @@ (if (= status :started) (accounts.login/login) (node/initialize (get-in db [:accounts/login :address]))) - (init/initialize-account address))))) + (init/initialize-account address) + (chat-loading/initialize-chats {:to 10}))))) (handlers/register-handler-fx :init.callback/keychain-reset diff --git a/src/status_im/transport/core.cljs b/src/status_im/transport/core.cljs index 02ee85fd0c..f2c4e7b19b 100644 --- a/src/status_im/transport/core.cljs +++ b/src/status_im/transport/core.cljs @@ -18,7 +18,6 @@ - restoring existing symetric keys along with their unique filters - (optionally) initializing mailserver" [{:keys [db web3] :as cofx}] - (log/debug :init-whisper) (when-let [public-key (get-in db [:account/account :public-key])] (let [public-key-topics (keep (fn [[chat-id {:keys [topic sym-key]}]] (when (and (not sym-key) diff --git a/src/status_im/transport/filters.cljs b/src/status_im/transport/filters.cljs index 76c63007dc..964a9244a7 100644 --- a/src/status_im/transport/filters.cljs +++ b/src/status_im/transport/filters.cljs @@ -85,7 +85,6 @@ (handlers/register-handler-fx :shh.callback/filter-added (fn [{:keys [db] :as cofx} [_ topic chat-id filter]] - (log/debug "PERF" :shh.callback/filter-added) (fx/merge cofx {:db (assoc-in db [:transport/filters chat-id] filter)} (mailserver/reset-request-to) diff --git a/src/status_im/ui/screens/desktop/main/tabs/home/views.cljs b/src/status_im/ui/screens/desktop/main/tabs/home/views.cljs index 11e3b7eb19..c862122139 100644 --- a/src/status_im/ui/screens/desktop/main/tabs/home/views.cljs +++ b/src/status_im/ui/screens/desktop/main/tabs/home/views.cljs @@ -147,7 +147,7 @@ (fn [this] (let [[_ loading?] (.. this -props -argv)] (when loading? - (re-frame/dispatch [:init-chats]))))} + (re-frame/dispatch [:init-rest-of-chats]))))} [react/view {:style styles/chat-list-view} [react/view {:style styles/chat-list-header} [search-input search-filter] @@ -155,16 +155,11 @@ [react/touchable-highlight {:on-press #(re-frame/dispatch [:set-in [:desktop :popup] popup])} [react/view {:style styles/add-new} [icons/icon :icons/add {:style {:tint-color :white}}]]]]] - (if loading? - [react/view {:style {:flex 1 - :justify-content :center - :align-items :center}} - [components/activity-indicator {:animating true}]] - [react/scroll-view {:enableArrayScrollingOptimization true} - [react/view - (for [[index chat] (map-indexed vector filtered-home-items)] - ^{:key (first chat)} - [chat-list-item chat])]])])) + [react/scroll-view {:enableArrayScrollingOptimization true} + [react/view + (for [[index chat] (map-indexed vector filtered-home-items)] + ^{:key (first chat)} + [chat-list-item chat])]]])) (views/defview chat-list-view-wrapper [] (views/letsubs [loading? [:get :chats/loading?]] diff --git a/src/status_im/ui/screens/home/views.cljs b/src/status_im/ui/screens/home/views.cljs index 00f6d8a8f8..f51c29f6b1 100644 --- a/src/status_im/ui/screens/home/views.cljs +++ b/src/status_im/ui/screens/home/views.cljs @@ -99,17 +99,12 @@ (let [[_ loading?] (.. this -props -argv)] (when loading? (utils/set-timeout - #(re-frame/dispatch [:init-chats]) + #(re-frame/dispatch [:init-rest-of-chats]) 100))))} [react/view styles/container [toolbar show-welcome? (and network-initialized? (not rpc-network?)) sync-state latest-block-number] (cond show-welcome? [welcome view-id] - loading? - [react/view {:style {:flex 1 - :justify-content :center - :align-items :center}} - [components/activity-indicator {:animating true}]] :else [chats-list]) (when platform/android?