diff --git a/src/status_im/chat/models/loading.cljs b/src/status_im/chat/models/loading.cljs index 0338089738..1dad858cc7 100644 --- a/src/status_im/chat/models/loading.cljs +++ b/src/status_im/chat/models/loading.cljs @@ -29,14 +29,24 @@ new-chats) chats (merge old-chats chats)] {:db (assoc db :chats chats + :chats/all-chats-loading? false :chats/loading? false)})) (fx/defn initialize-chats "Initialize persisted chats on startup" [cofx] - (data-store.chats/fetch-chats-rpc cofx {:on-success - #(re-frame/dispatch - [:chats-list/load-success %])})) + (data-store.chats/fetch-some-chats-rpc cofx {:num 60 + :on-success + #(re-frame/dispatch + [:chats-list/load-success %])})) + +(fx/defn load-all-chats + "Initialize persisted chats on startup" + {:events [:load-all-chats]} + [{:keys [db]}] + (when-not (:chats/all-chats-loaded? db) + (fx/merge {:db (assoc db :chats/all-chats-loaded? true :chats/all-chats-loading? true)} + (data-store.chats/fetch-chats-rpc {:on-success #(re-frame/dispatch [:chats-list/load-success %])})))) (fx/defn handle-failed-loading-messages {:events [::failed-loading-messages]} diff --git a/src/status_im/data_store/chats.cljs b/src/status_im/data_store/chats.cljs index 51ecd7313b..0c468eae84 100644 --- a/src/status_im/data_store/chats.cljs +++ b/src/status_im/data_store/chats.cljs @@ -70,8 +70,14 @@ (update :last-message #(when % (messages/<-rpc %))) (dissoc :members))) -(fx/defn fetch-chats-rpc [cofx {:keys [on-success]}] +(fx/defn fetch-chats-rpc [_ {:keys [on-success]}] {::json-rpc/call [{:method (json-rpc/call-ext-method "chats") :params [] :on-success #(on-success (map <-rpc %)) :on-failure #(log/error "failed to fetch chats" 0 -1 %)}]}) + +(fx/defn fetch-some-chats-rpc [_ {:keys [on-success num]}] + {::json-rpc/call [{:method (json-rpc/call-ext-method "latestActiveNChats") + :params [num] + :on-success #(on-success (map <-rpc %)) + :on-failure #(log/error "failed to fetch chats" 0 -1 %)}]}) \ No newline at end of file diff --git a/src/status_im/ethereum/json_rpc.cljs b/src/status_im/ethereum/json_rpc.cljs index e35c144d11..024b9cb7cb 100644 --- a/src/status_im/ethereum/json_rpc.cljs +++ b/src/status_im/ethereum/json_rpc.cljs @@ -73,6 +73,7 @@ "wakuext_sendContactUpdate" {} "wakuext_sendContactUpdates" {} "wakuext_chats" {} + "wakuext_latestActiveNChats" {} "wakuext_activeChats" {} "wakuext_addSystemMessages" {} "wakuext_deleteMessagesFrom" {} diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 766f14ec64..956034b099 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -121,6 +121,8 @@ (reg-root-key-sub :group-chat/invitations :group-chat/invitations) (reg-root-key-sub :chats/mention-suggestions :chats/mention-suggestions) (reg-root-key-sub :chat/inputs-with-mentions :chat/inputs-with-mentions) +(reg-root-key-sub :chats/all-chats-loading? :chats/all-chats-loading?) + ;;browser (reg-root-key-sub :browsers :browser/browsers) (reg-root-key-sub :browser/options :browser/options) diff --git a/src/status_im/ui/screens/home/views.cljs b/src/status_im/ui/screens/home/views.cljs index 272f066870..637b756cbe 100644 --- a/src/status_im/ui/screens/home/views.cljs +++ b/src/status_im/ui/screens/home/views.cljs @@ -141,7 +141,8 @@ (views/defview communities-and-chats [] (views/letsubs [{:keys [items search-filter]} [:home-items] - hide-home-tooltip? [:hide-home-tooltip?]] + hide-home-tooltip? [:hide-home-tooltip?] + all-chats-loading? [:chats/all-chats-loading?]] (if (and (empty? items) (empty? search-filter) hide-home-tooltip? @@ -154,6 +155,7 @@ :keyboard-should-persist-taps :always :data items :render-fn render-fn + :on-end-reached #(re-frame/dispatch [:load-all-chats]) :header [:<> (when (or (seq items) @search-active? (seq search-filter)) [search-input-wrapper search-filter (empty? items)]) @@ -161,9 +163,12 @@ (when (and (empty? items) (or @search-active? (seq search-filter))) [start-suggestion search-filter])] - :footer (if (and (not hide-home-tooltip?) (not @search-active?)) - [home-tooltip-view] - [react/view {:height 68}])}]))) + :footer [:<> + (when all-chats-loading? + [react/activity-indicator]) + (if (and (not hide-home-tooltip?) (not @search-active?)) + [home-tooltip-view] + [react/view {:height 68}])]}]))) (views/defview chats-list [] (views/letsubs [loading? [:chats/loading?]] diff --git a/status-go-version.json b/status-go-version.json index 2c356e68c9..92d3e26bf1 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -2,7 +2,7 @@ "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh ' instead", "owner": "status-im", "repo": "status-go", - "version": "v0.83.14", - "commit-sha1": "c51f9b800c62867c821096e59220a564a96603c6", - "src-sha256": "0zgk6zgp84bz6c344iyxabr4cw8gnnm1ld2y7k07vzq3r37cxnhq" + "version": "v0.83.16", + "commit-sha1": "ab08042f214bb4473eb677949643b18e46824a15", + "src-sha256": "0cas8fmllqbkllicypwbjjpdjn7jp3asl4jzwrnr3y8c5y9mbxy0" }