[#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
{: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) (chat.state/reset-visible-item)
(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 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]
(let [home-view? (= (get db :view-id) :home)]
(fx/merge cofx (fx/merge cofx
(close-chat (:current-chat-id db)) (close-chat)
(force-close-chat chat-id)
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:db (assoc db :current-chat-id chat-id :ignore-close-chat true)}) {:db (assoc db :current-chat-id chat-id :navigate-after-home-to-chat (not home-view?))})
(preload-chat-data chat-id) (preload-chat-data chat-id)
#(when (group-chat? cofx chat-id) #(when (group-chat? cofx chat-id)
(loading/load-chat % chat-id)) (loading/load-chat % chat-id))
#(when-not dont-reset? #(when-not home-view?
(navigation/change-tab % :chat)) (navigation/change-tab % :chat))
#(when-not dont-reset? #(when-not home-view?
(navigation/pop-to-root-tab % :chat-stack)) (navigation/pop-to-root-tab % :chat-stack))
(navigation/navigate-to-cofx :chat nil))) (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,10 +354,6 @@
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
{: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 [] (fn []
(let [{:keys [chat-id show-input? group-chat admins invitation-admin] :as chat} (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 ;;we want to react only on these fields, do not use full chat map here
@ -399,4 +394,4 @@
:active-panel @active-panel :active-panel @active-panel
:set-active-panel set-active-panel :set-active-panel set-active-panel
:text-input-ref text-input-ref}]] :text-input-ref text-input-ref}]]
[bottom-sheet @active-panel]])]))}))) [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,6 +200,12 @@
:accessibility-label :notifications-unread-badge}]])])) :accessibility-label :notifications-unread-badge}]])]))
(defn home [] (defn home []
(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} [react/keyboard-avoiding-view {:style {:flex 1}
:ignore-offset true} :ignore-offset true}
[topbar/topbar {:title (i18n/label :t/chat) [topbar/topbar {:title (i18n/label :t/chat)
@ -208,4 +215,4 @@
[notifications-button]]}] [notifications-button]]}]
[chats-list] [chats-list]
[plus-button] [plus-button]
[tabbar/tabs-counts-subscriptions]]) [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)