[#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
[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]}

View File

@ -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)
[{: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))))))
(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?]
[{db :db :as cofx} chat-id]
(let [home-view? (= (get db :view-id) :home)]
(fx/merge cofx
(close-chat (:current-chat-id db))
(close-chat)
(force-close-chat chat-id)
(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)
#(when (group-chat? cofx chat-id)
(loading/load-chat % chat-id))
#(when-not dont-reset?
#(when-not home-view?
(navigation/change-tab % :chat))
#(when-not dont-reset?
#(when-not home-view?
(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
{: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

View File

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

View File

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

View File

@ -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,10 +354,6 @@
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
@ -399,4 +394,4 @@
:active-panel @active-panel
:set-active-panel set-active-panel
:text-input-ref text-input-ref}]]
[bottom-sheet @active-panel]])]))})))
[bottom-sheet @active-panel]])]))))

View File

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

View File

@ -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,6 +200,12 @@
:accessibility-label :notifications-unread-badge}]])]))
(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}
:ignore-offset true}
[topbar/topbar {:title (i18n/label :t/chat)
@ -208,4 +215,4 @@
[notifications-button]]}]
[chats-list]
[plus-button]
[tabbar/tabs-counts-subscriptions]])
[tabbar/tabs-counts-subscriptions]])}))

View File

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

View File

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