preload chats

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2021-08-16 13:06:29 +02:00
parent f940f8dfc8
commit 25a6495d37
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
6 changed files with 35 additions and 11 deletions

View File

@ -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]}

View File

@ -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 %)}]})

View File

@ -73,6 +73,7 @@
"wakuext_sendContactUpdate" {}
"wakuext_sendContactUpdates" {}
"wakuext_chats" {}
"wakuext_latestActiveNChats" {}
"wakuext_activeChats" {}
"wakuext_addSystemMessages" {}
"wakuext_deleteMessagesFrom" {}

View File

@ -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)

View File

@ -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?]]

View File

@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' 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"
}