Load messages on will-focus
Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
parent
19fdced2bc
commit
55a955d8dd
|
@ -233,11 +233,30 @@
|
||||||
(when platform/desktop?
|
(when platform/desktop?
|
||||||
(update-dock-badge-label))))))
|
(update-dock-badge-label))))))
|
||||||
|
|
||||||
|
(fx/defn offload-all-messages
|
||||||
|
{:events [::offload-all-messages]}
|
||||||
|
[{:keys [db] :as cofx}]
|
||||||
|
(when-let [current-chat-id (:current-chat-id db)]
|
||||||
|
{:db
|
||||||
|
(-> db
|
||||||
|
(dissoc :loaded-chat-id)
|
||||||
|
(update-in [:chats current-chat-id]
|
||||||
|
assoc
|
||||||
|
:all-loaded? false
|
||||||
|
:cursor nil
|
||||||
|
:messages-initialized? false
|
||||||
|
:messages {}
|
||||||
|
:message-list nil))}))
|
||||||
|
|
||||||
(fx/defn preload-chat-data
|
(fx/defn preload-chat-data
|
||||||
"Takes chat-id and coeffects map, returns effects necessary when navigating to chat"
|
"Takes chat-id and coeffects map, returns effects necessary when navigating to chat"
|
||||||
[{:keys [db] :as cofx} chat-id]
|
[{:keys [db] :as cofx} chat-id]
|
||||||
|
(let [old-current-chat-id (:current-chat-id db)]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (assoc db :current-chat-id chat-id)}
|
(when-not (= old-current-chat-id chat-id)
|
||||||
|
(offload-all-messages))
|
||||||
|
(fn [{:keys [db]}]
|
||||||
|
{:db (assoc db :current-chat-id chat-id)})
|
||||||
;; Group chat don't need this to load as all the loading of topics
|
;; Group chat don't need this to load as all the loading of topics
|
||||||
;; happens on membership changes
|
;; happens on membership changes
|
||||||
(when-not (group-chat? cofx chat-id)
|
(when-not (group-chat? cofx chat-id)
|
||||||
|
@ -245,7 +264,7 @@
|
||||||
(when platform/desktop?
|
(when platform/desktop?
|
||||||
(mark-messages-seen chat-id))
|
(mark-messages-seen chat-id))
|
||||||
(when (and (one-to-one-chat? cofx chat-id) (not (contact.db/contact-exists? db chat-id)))
|
(when (and (one-to-one-chat? cofx chat-id) (not (contact.db/contact-exists? db chat-id)))
|
||||||
(contact.core/create-contact chat-id))))
|
(contact.core/create-contact chat-id)))))
|
||||||
|
|
||||||
(fx/defn navigate-to-chat
|
(fx/defn navigate-to-chat
|
||||||
"Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data"
|
"Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data"
|
||||||
|
|
|
@ -38,21 +38,6 @@
|
||||||
:chats/loading? false)}
|
:chats/loading? false)}
|
||||||
(filters/load-filters))))
|
(filters/load-filters))))
|
||||||
|
|
||||||
(fx/defn offload-all-messages
|
|
||||||
{:events [::offload-all-messages]}
|
|
||||||
[{:keys [db] :as cofx}]
|
|
||||||
(when-let [current-chat-id (:current-chat-id db)]
|
|
||||||
{:db
|
|
||||||
(-> db
|
|
||||||
(dissoc :loaded-chat-id)
|
|
||||||
(update-in [:chats current-chat-id]
|
|
||||||
assoc
|
|
||||||
:all-loaded? false
|
|
||||||
:cursor nil
|
|
||||||
:messages-initialized? false
|
|
||||||
:messages {}
|
|
||||||
:message-list nil))}))
|
|
||||||
|
|
||||||
(fx/defn handle-chat-visibility-changed
|
(fx/defn handle-chat-visibility-changed
|
||||||
{:events [:chat.ui/message-visibility-changed]}
|
{:events [:chat.ui/message-visibility-changed]}
|
||||||
[{:keys [db] :as cofx} event]
|
[{:keys [db] :as cofx} event]
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
status-im.utils.universal-links.events
|
status-im.utils.universal-links.events
|
||||||
status-im.ui.screens.profile.events
|
status-im.ui.screens.profile.events
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
|
[status-im.chat.models.loading :as chat.loading]
|
||||||
[status-im.chat.models :as chat]
|
[status-im.chat.models :as chat]
|
||||||
[status-im.hardwallet.core :as hardwallet]
|
[status-im.hardwallet.core :as hardwallet]
|
||||||
[status-im.mailserver.core :as mailserver]
|
[status-im.mailserver.core :as mailserver]
|
||||||
|
@ -203,5 +204,9 @@
|
||||||
:keycard-login-pin (hardwallet/enter-pin-screen-did-load %)
|
:keycard-login-pin (hardwallet/enter-pin-screen-did-load %)
|
||||||
:add-new-account-pin (hardwallet/enter-pin-screen-did-load %)
|
:add-new-account-pin (hardwallet/enter-pin-screen-did-load %)
|
||||||
:hardwallet-authentication-method (hardwallet/authentication-method-screen-did-load %)
|
:hardwallet-authentication-method (hardwallet/authentication-method-screen-did-load %)
|
||||||
|
;; We need this as if you click on universal-links you transition
|
||||||
|
;; from chat to chat, and therefore we won't be loading new
|
||||||
|
;; messages
|
||||||
|
:chat (chat.loading/load-messages %)
|
||||||
:multiaccounts (hardwallet/multiaccounts-screen-did-load %)
|
:multiaccounts (hardwallet/multiaccounts-screen-did-load %)
|
||||||
nil))))
|
nil))))
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
[status-im.ui.screens.group.views :as group]
|
[status-im.ui.screens.group.views :as group]
|
||||||
[status-im.ui.screens.profile.group-chat.views :as profile.group-chat]
|
[status-im.ui.screens.profile.group-chat.views :as profile.group-chat]
|
||||||
[status-im.chat.models.loading :as chat.loading]
|
[status-im.chat.models.loading :as chat.loading]
|
||||||
|
[status-im.chat.models :as chat.models]
|
||||||
[status-im.ui.screens.group.events :as group.events]
|
[status-im.ui.screens.group.events :as group.events]
|
||||||
[status-im.ui.components.tabbar.styles :as tabbar.styles]
|
[status-im.ui.components.tabbar.styles :as tabbar.styles]
|
||||||
[status-im.ui.screens.stickers.views :as stickers]))
|
[status-im.ui.screens.stickers.views :as stickers]))
|
||||||
|
@ -16,7 +17,7 @@
|
||||||
[stack {:initial-route-name :home
|
[stack {:initial-route-name :home
|
||||||
:header-mode :none}
|
:header-mode :none}
|
||||||
[{:name :home
|
[{:name :home
|
||||||
:on-focus [::chat.loading/offload-all-messages]
|
:on-focus [::chat.models/offload-all-messages]
|
||||||
:style {:padding-bottom tabbar.styles/tabs-diff}
|
:style {:padding-bottom tabbar.styles/tabs-diff}
|
||||||
:component home/home}
|
:component home/home}
|
||||||
{:name :chat
|
{:name :chat
|
||||||
|
|
Loading…
Reference in New Issue