From b587a8f85e652c896da9353bd8bc7363c5beb224 Mon Sep 17 00:00:00 2001 From: andrey Date: Mon, 29 Nov 2021 09:32:02 +0100 Subject: [PATCH] [#11895] No last message when opening chat but it was visible on chat-preview Signed-off-by: andrey --- src/status_im/acquisition/chat.cljs | 2 +- src/status_im/chat/models.cljs | 72 ++++++++------- src/status_im/group_chats/core.cljs | 2 +- src/status_im/subs.cljs | 13 --- src/status_im/ui/screens/chat/views.cljs | 91 +++++++++---------- .../ui/screens/communities/community.cljs | 4 +- src/status_im/ui/screens/home/views.cljs | 29 +++--- src/status_im/ui/screens/screens.cljs | 3 +- src/status_im/utils/universal_links/core.cljs | 2 +- 9 files changed, 107 insertions(+), 111 deletions(-) diff --git a/src/status_im/acquisition/chat.cljs b/src/status_im/acquisition/chat.cljs index b44dafca8c..c8223d1dc8 100644 --- a/src/status_im/acquisition/chat.cljs +++ b/src/status_im/acquisition/chat.cljs @@ -37,7 +37,7 @@ (fx/defn join-public-chat [cofx chat-name] - (chat/start-public-chat cofx chat-name {:navigation-reset? true})) + (chat/start-public-chat cofx chat-name)) (fx/defn accept-pack {:events [::accept-pack]} diff --git a/src/status_im/chat/models.cljs b/src/status_im/chat/models.cljs index edbda05a84..1764bcd746 100644 --- a/src/status_im/chat/models.cljs +++ b/src/status_im/chat/models.cljs @@ -199,15 +199,23 @@ (fx/defn close-chat {:events [:close-chat]} - [{:keys [db] :as cofx} target-chat-id] - (let [chat-id (:current-chat-id db)] - (if (:ignore-close-chat db) - {:db (dissoc db :ignore-close-chat)} - (when (= target-chat-id chat-id) - (chat.state/reset-visible-item) - (fx/merge cofx - {:db (dissoc db :current-chat-id)} - (offload-messages chat-id)))))) + [{:keys [db] :as cofx}] + (let [chat-id (:current-chat-id db) + navigate-after-home-to-chat (:navigate-after-home-to-chat db)] + (chat.state/reset-visible-item) + (if navigate-after-home-to-chat + {:db (dissoc db :navigate-after-home-to-chat)} + (fx/merge cofx + {:db (dissoc db :current-chat-id)} + (offload-messages chat-id))))) + +(fx/defn force-close-chat + [{:keys [db] :as cofx} chat-id] + (do + (chat.state/reset-visible-item) + (fx/merge cofx + {:db (dissoc db :current-chat-id)} + (offload-messages chat-id)))) (fx/defn remove-chat "Removes chat completely from app, producing all necessary effects for that" @@ -234,19 +242,21 @@ (fx/defn navigate-to-chat "Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data" {:events [:chat.ui/navigate-to-chat]} - [{db :db :as cofx} chat-id dont-reset?] - (fx/merge cofx - (close-chat (:current-chat-id db)) - (fn [{:keys [db]}] - {:db (assoc db :current-chat-id chat-id :ignore-close-chat true)}) - (preload-chat-data chat-id) - #(when (group-chat? cofx chat-id) - (loading/load-chat % chat-id)) - #(when-not dont-reset? - (navigation/change-tab % :chat)) - #(when-not dont-reset? - (navigation/pop-to-root-tab % :chat-stack)) - (navigation/navigate-to-cofx :chat nil))) + [{db :db :as cofx} chat-id] + (let [home-view? (= (get db :view-id) :home)] + (fx/merge cofx + (close-chat) + (force-close-chat chat-id) + (fn [{:keys [db]}] + {:db (assoc db :current-chat-id chat-id :navigate-after-home-to-chat (not home-view?))}) + (preload-chat-data chat-id) + #(when (group-chat? cofx chat-id) + (loading/load-chat % chat-id)) + #(when-not home-view? + (navigation/change-tab % :chat)) + #(when-not home-view? + (navigation/pop-to-root-tab % :chat-stack)) + (navigation/navigate-to-cofx :chat nil)))) (fx/defn handle-clear-history-response {:events [::history-cleared]} @@ -294,14 +304,11 @@ (fx/defn handle-public-chat-created {:events [::public-chat-created]} - [{:keys [db]} chat-id {:keys [dont-navigate?]} response] - (let [chat (chats-store/<-rpc (first (:chats response))) - db-with-chat {:db (-> db - (assoc-in [:chats chat-id] chat) - (update :chats-home-list conj chat-id))}] - (if dont-navigate? - db-with-chat - (assoc db-with-chat :dispatch [:chat.ui/navigate-to-chat chat-id])))) + [{:keys [db]} chat-id _ response] + {:db (-> db + (assoc-in [:chats chat-id] (chats-store/<-rpc (first (:chats response)))) + (update :chats-home-list conj chat-id)) + :dispatch [:chat.ui/navigate-to-chat chat-id]}) (fx/defn create-public-chat-go [_ chat-id opts] {::json-rpc/call [{:method "wakuext_createPublicChat" @@ -312,11 +319,10 @@ (fx/defn start-public-chat "Starts a new public chat" {:events [:chat.ui/start-public-chat]} - [cofx topic {:keys [dont-navigate? profile-public-key] :as opts}] + [cofx topic {:keys [profile-public-key] :as opts}] (if (or (new-public-chat.db/valid-topic? topic) profile-public-key) (if (active-chat? cofx topic) - (when-not dont-navigate? - (navigate-to-chat cofx topic false)) + (navigate-to-chat cofx topic) (create-public-chat-go cofx topic diff --git a/src/status_im/group_chats/core.cljs b/src/status_im/group_chats/core.cljs index 46e701e71a..cca77b3f16 100644 --- a/src/status_im/group_chats/core.cljs +++ b/src/status_im/group_chats/core.cljs @@ -61,7 +61,7 @@ [cofx {:keys [chat-id invitation-admin chat-name]}] (if (get-in cofx [:db :chats chat-id]) {:dispatch-n [[:accept-all-activity-center-notifications-from-chat chat-id] - [:chat.ui/navigate-to-chat chat-id false]]} + [:chat.ui/navigate-to-chat chat-id]]} {::json-rpc/call [{:method (json-rpc/call-ext-method "createGroupChatFromInvitation") :params [chat-name chat-id invitation-admin] :js-response true diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 8f6d6fdc4d..1b543fee0e 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -1197,19 +1197,6 @@ (hydrate-messages messages)))))) ;;we want to keep data unchanged so react doesn't change component when we leave screen -(def memo-chat-messages-stream (atom nil)) - -(re-frame/reg-sub - :chats/chat-messages-stream - (fn [[_ chat-id] _] - [(re-frame/subscribe [:chats/raw-chat-messages-stream chat-id]) - (re-frame/subscribe [:chats/chat-no-messages? chat-id]) - (re-frame/subscribe [:view-id])]) - (fn [[messages empty view-id]] - (when (or (= view-id :chat) empty) - (reset! memo-chat-messages-stream messages)) - @memo-chat-messages-stream)) - (def memo-profile-messages-stream (atom nil)) (re-frame/reg-sub diff --git a/src/status_im/ui/screens/chat/views.cljs b/src/status_im/ui/screens/chat/views.cljs index 2bc8a2c87f..f247a48f3b 100644 --- a/src/status_im/ui/screens/chat/views.cljs +++ b/src/status_im/ui/screens/chat/views.cljs @@ -295,7 +295,7 @@ (defn messages-view [{:keys [chat bottom-space pan-responder space-keeper show-input?]}] (let [{:keys [group-chat chat-id public? community-id admins]} chat - messages @(re-frame/subscribe [:chats/chat-messages-stream chat-id])] + messages @(re-frame/subscribe [:chats/raw-chat-messages-stream chat-id])] ;;do not use anonymous functions for handlers [list/flat-list (merge @@ -343,8 +343,7 @@ [toolbar-content/toolbar-content-view-inner chat-info]])) (defn chat [] - (let [curr-chat-id (:chat-id @(re-frame/subscribe [:chats/current-chat-chat-view])) - bottom-space (reagent/atom 0) + (let [bottom-space (reagent/atom 0) panel-space (reagent/atom 52) active-panel (reagent/atom nil) position-y (animated/value 0) @@ -355,48 +354,44 @@ space-keeper (get-space-keeper-ios bottom-space panel-space active-panel text-input-ref) set-active-panel (get-set-active-panel active-panel) on-close #(set-active-panel nil)] - (reagent/create-class - {:component-will-unmount #(re-frame/dispatch-sync [:close-chat curr-chat-id]) - :component-did-mount (fn [] (js/setTimeout #(re-frame/dispatch [:set :ignore-close-chat false]) 500)) - :reagent-render - (fn [] - (let [{:keys [chat-id show-input? group-chat admins invitation-admin] :as chat} - ;;we want to react only on these fields, do not use full chat map here - @(re-frame/subscribe [:chats/current-chat-chat-view]) - max-bottom-space (max @bottom-space @panel-space)] - [:<> - [connectivity/loading-indicator] - (when chat-id - (if group-chat - [invitation-requests chat-id admins] - [add-contact-bar chat-id])) - ;;MESSAGES LIST - [messages-view {:chat chat - :bottom-space max-bottom-space - :pan-responder pan-responder - :space-keeper space-keeper - :show-input? show-input?}] - (when (and group-chat invitation-admin) - [accessory/view {:y position-y - :on-update-inset on-update} - [invitation-bar chat-id]]) - [components/autocomplete-mentions text-input-ref max-bottom-space] - (when show-input? - ;; NOTE: this only accepts two children - [accessory/view {:y position-y - :pan-state pan-state - :has-panel (boolean @active-panel) - :on-close on-close - :on-update-inset on-update} - [react/view - [edit/edit-message-auto-focus-wrapper text-input-ref] - [reply/reply-message-auto-focus-wrapper text-input-ref] - ;; We set the key so we can force a re-render as - ;; it does not rely on ratom but just atoms - ^{:key (str @components/chat-input-key "chat-input")} - [components/chat-toolbar - {:chat-id chat-id - :active-panel @active-panel - :set-active-panel set-active-panel - :text-input-ref text-input-ref}]] - [bottom-sheet @active-panel]])]))}))) + (fn [] + (let [{:keys [chat-id show-input? group-chat admins invitation-admin] :as chat} + ;;we want to react only on these fields, do not use full chat map here + @(re-frame/subscribe [:chats/current-chat-chat-view]) + max-bottom-space (max @bottom-space @panel-space)] + [:<> + [connectivity/loading-indicator] + (when chat-id + (if group-chat + [invitation-requests chat-id admins] + [add-contact-bar chat-id])) + ;;MESSAGES LIST + [messages-view {:chat chat + :bottom-space max-bottom-space + :pan-responder pan-responder + :space-keeper space-keeper + :show-input? show-input?}] + (when (and group-chat invitation-admin) + [accessory/view {:y position-y + :on-update-inset on-update} + [invitation-bar chat-id]]) + [components/autocomplete-mentions text-input-ref max-bottom-space] + (when show-input? + ;; NOTE: this only accepts two children + [accessory/view {:y position-y + :pan-state pan-state + :has-panel (boolean @active-panel) + :on-close on-close + :on-update-inset on-update} + [react/view + [edit/edit-message-auto-focus-wrapper text-input-ref] + [reply/reply-message-auto-focus-wrapper text-input-ref] + ;; We set the key so we can force a re-render as + ;; it does not rely on ratom but just atoms + ^{:key (str @components/chat-input-key "chat-input")} + [components/chat-toolbar + {:chat-id chat-id + :active-panel @active-panel + :set-active-panel set-active-panel + :text-input-ref text-input-ref}]] + [bottom-sheet @active-panel]])])))) diff --git a/src/status_im/ui/screens/communities/community.cljs b/src/status_im/ui/screens/communities/community.cljs index f5cccf20ed..53a317c6dd 100644 --- a/src/status_im/ui/screens/communities/community.cljs +++ b/src/status_im/ui/screens/communities/community.cljs @@ -154,14 +154,14 @@ :color :secondary} text]]) -(defn community-chat-item [{:keys [chat-id] :as home-item} _ _ {:keys [from-chat]}] +(defn community-chat-item [{:keys [chat-id] :as home-item} _ _ _] [inner-item/home-list-item ;; We want communities to behave as public chats when it comes to ;; unread indicator (assoc home-item :public? true) {:on-press (fn [] (re-frame/dispatch [:dismiss-keyboard]) - (re-frame/dispatch [:chat.ui/navigate-to-chat chat-id (not from-chat)]) + (re-frame/dispatch [:chat.ui/navigate-to-chat chat-id]) (re-frame/dispatch [:search/home-filter-changed nil]) (re-frame/dispatch [:accept-all-activity-center-notifications-from-chat chat-id])) :on-long-press #(re-frame/dispatch [:bottom-sheet/show-sheet diff --git a/src/status_im/ui/screens/home/views.cljs b/src/status_im/ui/screens/home/views.cljs index dd16b41ce8..3edb2d33fd 100644 --- a/src/status_im/ui/screens/home/views.cljs +++ b/src/status_im/ui/screens/home/views.cljs @@ -24,7 +24,8 @@ [status-im.ui.components.topbar :as topbar] [status-im.ui.components.plus-button :as components.plus-button] [status-im.ui.screens.chat.sheets :as sheets] - [status-im.ui.components.tabbar.core :as tabbar]) + [status-im.ui.components.tabbar.core :as tabbar] + ["react-native-navigation" :refer (Navigation)]) (:require-macros [status-im.utils.views :as views])) (defn home-tooltip-view [] @@ -199,13 +200,19 @@ :accessibility-label :notifications-unread-badge}]])])) (defn home [] - [react/keyboard-avoiding-view {:style {:flex 1} - :ignore-offset true} - [topbar/topbar {:title (i18n/label :t/chat) - :navigation :none - :right-component [react/view {:flex-direction :row :margin-right 16} - [connectivity/connectivity-button] - [notifications-button]]}] - [chats-list] - [plus-button] - [tabbar/tabs-counts-subscriptions]]) + (reagent/create-class + {:component-did-mount #(set! (.-navigationEventListener %) (.bindComponent (.events Navigation) % "home")) + :componentWillAppear #(do (re-frame/dispatch-sync [:set :view-id :home]) + (re-frame/dispatch [:close-chat])) + :reagent-render + (fn [] + [react/keyboard-avoiding-view {:style {:flex 1} + :ignore-offset true} + [topbar/topbar {:title (i18n/label :t/chat) + :navigation :none + :right-component [react/view {:flex-direction :row :margin-right 16} + [connectivity/connectivity-button] + [notifications-button]]}] + [chats-list] + [plus-button] + [tabbar/tabs-counts-subscriptions]])})) diff --git a/src/status_im/ui/screens/screens.cljs b/src/status_im/ui/screens/screens.cljs index b4b3bbfd93..562e2a1f39 100644 --- a/src/status_im/ui/screens/screens.cljs +++ b/src/status_im/ui/screens/screens.cljs @@ -219,7 +219,8 @@ ;Chat {:name :chat - :options {:topBar {:title {:component {:name :chat-toolbar :id :chat-toolbar} + :options {:popGesture false + :topBar {:title {:component {:name :chat-toolbar :id :chat-toolbar} :alignment :fill} :rightButtons (right-button-options :chat :more)}} :right-handler chat/topbar-button diff --git a/src/status_im/utils/universal_links/core.cljs b/src/status_im/utils/universal_links/core.cljs index da8688d051..b8e7b59170 100644 --- a/src/status_im/utils/universal_links/core.cljs +++ b/src/status_im/utils/universal_links/core.cljs @@ -72,7 +72,7 @@ (fx/defn handle-community-chat [cofx {:keys [chat-id]}] (log/info "universal-links: handling community chat" chat-id) {:dispatch-n [[:accept-all-activity-center-notifications-from-chat chat-id] - [:chat.ui/navigate-to-chat chat-id true]]}) + [:chat.ui/navigate-to-chat chat-id]]}) (fx/defn handle-public-chat [cofx {:keys [topic]}] (log/info "universal-links: handling public chat" topic)