[#11895] No last message when opening chat but it was visible on chat-preview

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2021-11-29 09:32:02 +01:00
parent 53d7d719f0
commit b587a8f85e
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
9 changed files with 107 additions and 111 deletions

View File

@ -37,7 +37,7 @@
(fx/defn join-public-chat (fx/defn join-public-chat
[cofx chat-name] [cofx chat-name]
(chat/start-public-chat cofx chat-name {:navigation-reset? true})) (chat/start-public-chat cofx chat-name))
(fx/defn accept-pack (fx/defn accept-pack
{:events [::accept-pack]} {:events [::accept-pack]}

View File

@ -199,15 +199,23 @@
(fx/defn close-chat (fx/defn close-chat
{:events [:close-chat]} {:events [:close-chat]}
[{:keys [db] :as cofx} target-chat-id] [{:keys [db] :as cofx}]
(let [chat-id (:current-chat-id db)] (let [chat-id (:current-chat-id db)
(if (:ignore-close-chat db) navigate-after-home-to-chat (:navigate-after-home-to-chat db)]
{:db (dissoc db :ignore-close-chat)} (chat.state/reset-visible-item)
(when (= target-chat-id chat-id) (if navigate-after-home-to-chat
(chat.state/reset-visible-item) {:db (dissoc db :navigate-after-home-to-chat)}
(fx/merge cofx (fx/merge cofx
{:db (dissoc db :current-chat-id)} {:db (dissoc db :current-chat-id)}
(offload-messages 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 (fx/defn remove-chat
"Removes chat completely from app, producing all necessary effects for that" "Removes chat completely from app, producing all necessary effects for that"
@ -234,19 +242,21 @@
(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"
{:events [:chat.ui/navigate-to-chat]} {:events [:chat.ui/navigate-to-chat]}
[{db :db :as cofx} chat-id dont-reset?] [{db :db :as cofx} chat-id]
(fx/merge cofx (let [home-view? (= (get db :view-id) :home)]
(close-chat (:current-chat-id db)) (fx/merge cofx
(fn [{:keys [db]}] (close-chat)
{:db (assoc db :current-chat-id chat-id :ignore-close-chat true)}) (force-close-chat chat-id)
(preload-chat-data chat-id) (fn [{:keys [db]}]
#(when (group-chat? cofx chat-id) {:db (assoc db :current-chat-id chat-id :navigate-after-home-to-chat (not home-view?))})
(loading/load-chat % chat-id)) (preload-chat-data chat-id)
#(when-not dont-reset? #(when (group-chat? cofx chat-id)
(navigation/change-tab % :chat)) (loading/load-chat % chat-id))
#(when-not dont-reset? #(when-not home-view?
(navigation/pop-to-root-tab % :chat-stack)) (navigation/change-tab % :chat))
(navigation/navigate-to-cofx :chat nil))) #(when-not home-view?
(navigation/pop-to-root-tab % :chat-stack))
(navigation/navigate-to-cofx :chat nil))))
(fx/defn handle-clear-history-response (fx/defn handle-clear-history-response
{:events [::history-cleared]} {:events [::history-cleared]}
@ -294,14 +304,11 @@
(fx/defn handle-public-chat-created (fx/defn handle-public-chat-created
{:events [::public-chat-created]} {:events [::public-chat-created]}
[{:keys [db]} chat-id {:keys [dont-navigate?]} response] [{:keys [db]} chat-id _ response]
(let [chat (chats-store/<-rpc (first (:chats response))) {:db (-> db
db-with-chat {:db (-> db (assoc-in [:chats chat-id] (chats-store/<-rpc (first (:chats response))))
(assoc-in [:chats chat-id] chat) (update :chats-home-list conj chat-id))
(update :chats-home-list conj chat-id))}] :dispatch [:chat.ui/navigate-to-chat chat-id]})
(if dont-navigate?
db-with-chat
(assoc db-with-chat :dispatch [:chat.ui/navigate-to-chat chat-id]))))
(fx/defn create-public-chat-go [_ chat-id opts] (fx/defn create-public-chat-go [_ chat-id opts]
{::json-rpc/call [{:method "wakuext_createPublicChat" {::json-rpc/call [{:method "wakuext_createPublicChat"
@ -312,11 +319,10 @@
(fx/defn start-public-chat (fx/defn start-public-chat
"Starts a new public chat" "Starts a new public chat"
{:events [:chat.ui/start-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 (or (new-public-chat.db/valid-topic? topic) profile-public-key)
(if (active-chat? cofx topic) (if (active-chat? cofx topic)
(when-not dont-navigate? (navigate-to-chat cofx topic)
(navigate-to-chat cofx topic false))
(create-public-chat-go (create-public-chat-go
cofx cofx
topic topic

View File

@ -61,7 +61,7 @@
[cofx {:keys [chat-id invitation-admin chat-name]}] [cofx {:keys [chat-id invitation-admin chat-name]}]
(if (get-in cofx [:db :chats chat-id]) (if (get-in cofx [:db :chats chat-id])
{:dispatch-n [[:accept-all-activity-center-notifications-from-chat 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") {::json-rpc/call [{:method (json-rpc/call-ext-method "createGroupChatFromInvitation")
:params [chat-name chat-id invitation-admin] :params [chat-name chat-id invitation-admin]
:js-response true :js-response true

View File

@ -1197,19 +1197,6 @@
(hydrate-messages messages)))))) (hydrate-messages messages))))))
;;we want to keep data unchanged so react doesn't change component when we leave screen ;;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)) (def memo-profile-messages-stream (atom nil))
(re-frame/reg-sub (re-frame/reg-sub

View File

@ -295,7 +295,7 @@
(defn messages-view [{:keys [chat bottom-space pan-responder space-keeper show-input?]}] (defn messages-view [{:keys [chat bottom-space pan-responder space-keeper show-input?]}]
(let [{:keys [group-chat chat-id public? community-id admins]} chat (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 ;;do not use anonymous functions for handlers
[list/flat-list [list/flat-list
(merge (merge
@ -343,8 +343,7 @@
[toolbar-content/toolbar-content-view-inner chat-info]])) [toolbar-content/toolbar-content-view-inner chat-info]]))
(defn chat [] (defn chat []
(let [curr-chat-id (:chat-id @(re-frame/subscribe [:chats/current-chat-chat-view])) (let [bottom-space (reagent/atom 0)
bottom-space (reagent/atom 0)
panel-space (reagent/atom 52) panel-space (reagent/atom 52)
active-panel (reagent/atom nil) active-panel (reagent/atom nil)
position-y (animated/value 0) position-y (animated/value 0)
@ -355,48 +354,44 @@
space-keeper (get-space-keeper-ios bottom-space panel-space active-panel text-input-ref) space-keeper (get-space-keeper-ios bottom-space panel-space active-panel text-input-ref)
set-active-panel (get-set-active-panel active-panel) set-active-panel (get-set-active-panel active-panel)
on-close #(set-active-panel nil)] on-close #(set-active-panel nil)]
(reagent/create-class (fn []
{:component-will-unmount #(re-frame/dispatch-sync [:close-chat curr-chat-id]) (let [{:keys [chat-id show-input? group-chat admins invitation-admin] :as chat}
:component-did-mount (fn [] (js/setTimeout #(re-frame/dispatch [:set :ignore-close-chat false]) 500)) ;;we want to react only on these fields, do not use full chat map here
:reagent-render @(re-frame/subscribe [:chats/current-chat-chat-view])
(fn [] max-bottom-space (max @bottom-space @panel-space)]
(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 [connectivity/loading-indicator]
@(re-frame/subscribe [:chats/current-chat-chat-view]) (when chat-id
max-bottom-space (max @bottom-space @panel-space)] (if group-chat
[:<> [invitation-requests chat-id admins]
[connectivity/loading-indicator] [add-contact-bar chat-id]))
(when chat-id ;;MESSAGES LIST
(if group-chat [messages-view {:chat chat
[invitation-requests chat-id admins] :bottom-space max-bottom-space
[add-contact-bar chat-id])) :pan-responder pan-responder
;;MESSAGES LIST :space-keeper space-keeper
[messages-view {:chat chat :show-input? show-input?}]
:bottom-space max-bottom-space (when (and group-chat invitation-admin)
:pan-responder pan-responder [accessory/view {:y position-y
:space-keeper space-keeper :on-update-inset on-update}
:show-input? show-input?}] [invitation-bar chat-id]])
(when (and group-chat invitation-admin) [components/autocomplete-mentions text-input-ref max-bottom-space]
[accessory/view {:y position-y (when show-input?
:on-update-inset on-update} ;; NOTE: this only accepts two children
[invitation-bar chat-id]]) [accessory/view {:y position-y
[components/autocomplete-mentions text-input-ref max-bottom-space] :pan-state pan-state
(when show-input? :has-panel (boolean @active-panel)
;; NOTE: this only accepts two children :on-close on-close
[accessory/view {:y position-y :on-update-inset on-update}
:pan-state pan-state [react/view
:has-panel (boolean @active-panel) [edit/edit-message-auto-focus-wrapper text-input-ref]
:on-close on-close [reply/reply-message-auto-focus-wrapper text-input-ref]
:on-update-inset on-update} ;; We set the key so we can force a re-render as
[react/view ;; it does not rely on ratom but just atoms
[edit/edit-message-auto-focus-wrapper text-input-ref] ^{:key (str @components/chat-input-key "chat-input")}
[reply/reply-message-auto-focus-wrapper text-input-ref] [components/chat-toolbar
;; We set the key so we can force a re-render as {:chat-id chat-id
;; it does not rely on ratom but just atoms :active-panel @active-panel
^{:key (str @components/chat-input-key "chat-input")} :set-active-panel set-active-panel
[components/chat-toolbar :text-input-ref text-input-ref}]]
{:chat-id chat-id [bottom-sheet @active-panel]])]))))
:active-panel @active-panel
:set-active-panel set-active-panel
:text-input-ref text-input-ref}]]
[bottom-sheet @active-panel]])]))})))

View File

@ -154,14 +154,14 @@
:color :secondary} :color :secondary}
text]]) 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 [inner-item/home-list-item
;; We want communities to behave as public chats when it comes to ;; We want communities to behave as public chats when it comes to
;; unread indicator ;; unread indicator
(assoc home-item :public? true) (assoc home-item :public? true)
{:on-press (fn [] {:on-press (fn []
(re-frame/dispatch [:dismiss-keyboard]) (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 [:search/home-filter-changed nil])
(re-frame/dispatch [:accept-all-activity-center-notifications-from-chat chat-id])) (re-frame/dispatch [:accept-all-activity-center-notifications-from-chat chat-id]))
:on-long-press #(re-frame/dispatch [:bottom-sheet/show-sheet :on-long-press #(re-frame/dispatch [:bottom-sheet/show-sheet

View File

@ -24,7 +24,8 @@
[status-im.ui.components.topbar :as topbar] [status-im.ui.components.topbar :as topbar]
[status-im.ui.components.plus-button :as components.plus-button] [status-im.ui.components.plus-button :as components.plus-button]
[status-im.ui.screens.chat.sheets :as sheets] [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])) (:require-macros [status-im.utils.views :as views]))
(defn home-tooltip-view [] (defn home-tooltip-view []
@ -199,13 +200,19 @@
:accessibility-label :notifications-unread-badge}]])])) :accessibility-label :notifications-unread-badge}]])]))
(defn home [] (defn home []
[react/keyboard-avoiding-view {:style {:flex 1} (reagent/create-class
:ignore-offset true} {:component-did-mount #(set! (.-navigationEventListener %) (.bindComponent (.events Navigation) % "home"))
[topbar/topbar {:title (i18n/label :t/chat) :componentWillAppear #(do (re-frame/dispatch-sync [:set :view-id :home])
:navigation :none (re-frame/dispatch [:close-chat]))
:right-component [react/view {:flex-direction :row :margin-right 16} :reagent-render
[connectivity/connectivity-button] (fn []
[notifications-button]]}] [react/keyboard-avoiding-view {:style {:flex 1}
[chats-list] :ignore-offset true}
[plus-button] [topbar/topbar {:title (i18n/label :t/chat)
[tabbar/tabs-counts-subscriptions]]) :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]])}))

View File

@ -219,7 +219,8 @@
;Chat ;Chat
{:name :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} :alignment :fill}
:rightButtons (right-button-options :chat :more)}} :rightButtons (right-button-options :chat :more)}}
:right-handler chat/topbar-button :right-handler chat/topbar-button

View File

@ -72,7 +72,7 @@
(fx/defn handle-community-chat [cofx {:keys [chat-id]}] (fx/defn handle-community-chat [cofx {:keys [chat-id]}]
(log/info "universal-links: handling community chat" chat-id) (log/info "universal-links: handling community chat" chat-id)
{:dispatch-n [[:accept-all-activity-center-notifications-from-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]}] (fx/defn handle-public-chat [cofx {:keys [topic]}]
(log/info "universal-links: handling public chat" topic) (log/info "universal-links: handling public chat" topic)