[#13357] 'Unknown Not a contact' screen with endless spinner when starting new 1-1 or public chat / opening it via push notification (#13379)

This commit is contained in:
flexsurfer 2022-05-30 13:37:13 +02:00 committed by GitHub
parent e4cba0f663
commit a4b169efa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 149 additions and 130 deletions

View File

@ -204,14 +204,11 @@
(fx/defn close-chat
{:events [:close-chat]}
[{:keys [db] :as cofx}]
(let [chat-id (:current-chat-id db)
navigate-after-home-to-chat (:navigate-after-home-to-chat db)]
(when-let [chat-id (:current-chat-id 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/merge cofx
{:db (dissoc db :current-chat-id)}
(offload-messages chat-id))))
(fx/defn force-close-chat
[{:keys [db] :as cofx} chat-id]
@ -249,20 +246,17 @@
"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]
(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/merge cofx
{:dispatch [:navigate-to :chat]}
(navigation/change-tab :chat)
(navigation/pop-to-root-tab :chat-stack)
(close-chat)
(force-close-chat chat-id)
(fn [{:keys [db]}]
{:db (assoc db :current-chat-id chat-id)})
(preload-chat-data chat-id)
#(when (group-chat? cofx chat-id)
(loading/load-chat % chat-id))))
(fx/defn navigate-to-chat-nav2
"Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data"
@ -319,29 +313,28 @@
(fx/defn handle-public-chat-created
{:events [::public-chat-created]}
[{:keys [db]} chat-id _ response]
[{: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]
(fx/defn create-public-chat-go [_ chat-id]
{::json-rpc/call [{:method "wakuext_createPublicChat"
:params [{:id chat-id}]
:on-success #(re-frame/dispatch [::public-chat-created chat-id opts %])
:on-success #(re-frame/dispatch [::public-chat-created chat-id %])
:on-error #(log/error "failed to create public chat" chat-id %)}]})
(fx/defn start-public-chat
"Starts a new public chat"
{:events [:chat.ui/start-public-chat]}
[cofx topic {:keys [profile-public-key] :as opts}]
(if (or (new-public-chat.db/valid-topic? topic) profile-public-key)
[cofx topic]
(if (new-public-chat.db/valid-topic? topic)
(if (active-chat? cofx topic)
(navigate-to-chat cofx topic)
(create-public-chat-go
cofx
topic
opts))
topic))
{:utils/show-popup {:title (i18n/label :t/cant-open-public-chat)
:content (i18n/label :t/invalid-public-chat-topic)}}))
@ -500,4 +493,4 @@
(update-in [:chats chat-id :unviewed-messages-count]
#(max (- % count) 0))
(update-in [:chats chat-id :unviewed-mentions-count]
#(max (- % countWithMentions) 0)))})
#(max (- % countWithMentions) 0)))})

View File

@ -11,9 +11,8 @@
:interceptors [(re-frame/inject-cofx :random-id-generator)]}
[cofx {:keys [public-key ens-name]}]
(fx/merge cofx
{:dispatch-later [{:ms 1000 :dispatch [:chat.ui/start-chat public-key ens-name]}]}
(notification-center/accept-all-activity-center-notifications-from-chat public-key)
(navigation/pop-to-root-tab :chat-stack)))
(chat/start-chat public-key ens-name)
(notification-center/accept-all-activity-center-notifications-from-chat public-key)))
(fx/defn contact-code-submitted
{:events [:contact.ui/contact-code-submitted]

View File

@ -59,7 +59,7 @@
[status-im.wallet.core :as wallet]
status-im.wallet.custom-tokens.core
[status-im.navigation.core :as navigation.core]
[status-im.multiaccounts.login.core :as login.core]
[status-im.navigation.state :as navigation.state]
[status-im.signing.core :as signing]
status-im.wallet-connect.core
status-im.wallet-connect-legacy.core
@ -123,7 +123,7 @@
current-tab (get db :current-tab :chat)
view-id (:view-id db)
screen-params (get-in db [:navigation/screen-params view-id])
root-id @navigation.core/root-id
root-id @navigation.state/root-id
dispatch-later (cond-> []
(= view-id :chat)
(conj {:ms 1000

View File

@ -15,9 +15,7 @@
{:events [:navigate-chat-updated]}
[cofx chat-id]
(when (get-in cofx [:db :chats chat-id])
(fx/merge cofx
{:dispatch-later [{:ms 1000 :dispatch [:chat.ui/navigate-to-chat chat-id]}]}
(navigation/pop-to-root-tab :chat-stack))))
(models.chat/navigate-to-chat cofx chat-id)))
(fx/defn handle-chat-removed
{:events [:chat-removed]}

View File

@ -14,19 +14,13 @@
[status-im.utils.fx :as fx]
[status-im.utils.platform :as platform]
[taoensso.timbre :as log]
[status-im.multiaccounts.login.core :as login-core]))
[status-im.multiaccounts.login.core :as login-core]
[status-im.navigation.state :as state]))
(def debug? ^boolean js/goog.DEBUG)
(def splash-screen (-> rn .-NativeModules .-SplashScreen))
(defonce root-comp-id (atom nil))
(defonce root-id (atom nil))
(defonce pushed-screen-id (atom nil))
(defonce curr-modal (atom nil))
(defonce modals (atom []))
(defonce dissmissing (atom false))
(defonce set-navigation-default-options
(.setDefaultOptions Navigation (clj->js {:layout {:orientation "portrait"}})))
@ -43,19 +37,19 @@
(defn dismiss-all-modals []
(log/debug "dissmiss-all-modals")
(when @curr-modal
(reset! curr-modal false)
(reset! dissmissing true)
(doseq [modal @modals]
(when @state/curr-modal
(reset! state/curr-modal false)
(reset! state/dissmissing true)
(doseq [modal @state/modals]
(.dismissModal Navigation (name modal)))
(reset! modals [])))
(reset! state/modals [])))
;; PUSH SCREEN
(defn navigate [comp]
(log/debug "NAVIGATE" comp)
(let [{:keys [options]} (get views/screens comp)]
(.push Navigation
(name @root-comp-id)
(name @state/root-comp-id)
(clj->js {:component {:id comp
:name comp
:options (merge options
@ -80,11 +74,11 @@
(defn open-modal [comp]
(log/debug "open-modal" comp)
(let [{:keys [options]} (get views/screens comp)]
(if @dissmissing
(reset! dissmissing comp)
(if @state/dissmissing
(reset! state/dissmissing comp)
(do
(reset! curr-modal true)
(swap! modals conj comp)
(reset! state/curr-modal true)
(swap! state/modals conj comp)
(.showModal Navigation
(clj->js {:stack {:children
[{:component
@ -100,8 +94,8 @@
;; DISSMISS MODAL
(defn dissmissModal []
(log/debug "dissmissModal")
(reset! dissmissing true)
(.dismissModal Navigation (name (last @modals))))
(reset! state/dissmissing true)
(.dismissModal Navigation (name (last @state/modals))))
(defonce register-nav-button-reg
(.registerNavigationButtonPressedListener
@ -110,7 +104,7 @@
(let [id (.-buttonId evn)]
(if (= "dismiss-modal" id)
(do
(when-let [event (get-in views/screens [(last @modals) :on-dissmiss])]
(when-let [event (get-in views/screens [(last @state/modals) :on-dissmiss])]
(re-frame/dispatch event))
(dissmissModal))
(when-let [handler (get-in views/screens [(keyword id) :right-handler])]
@ -128,17 +122,17 @@
(.registerModalDismissedListener
(.events Navigation)
(fn [_]
(if (> (count @modals) 1)
(let [new-modals (butlast @modals)]
(reset! modals (vec new-modals))
(if (> (count @state/modals) 1)
(let [new-modals (butlast @state/modals)]
(reset! state/modals (vec new-modals))
(set-view-id (last new-modals)))
(do
(reset! modals [])
(reset! curr-modal false)
(set-view-id @pushed-screen-id)))
(reset! state/modals [])
(reset! state/curr-modal false)
(set-view-id @state/pushed-screen-id)))
(let [comp @dissmissing]
(reset! dissmissing false)
(let [comp @state/dissmissing]
(reset! state/dissmissing false)
(when (keyword? comp)
(open-modal comp))))))
@ -154,8 +148,8 @@
(not= view-id :popover)
(not= view-id :visibility-status-popover))
(set-view-id view-id)
(when-not @curr-modal
(reset! pushed-screen-id view-id))))))))
(when-not @state/curr-modal
(reset! state/pushed-screen-id view-id))))))))
;; SCREEN DID DISAPPEAR
(defonce screen-disappear-reg
@ -176,16 +170,16 @@
:init-root-fx
(fn [new-root-id]
(log/debug :init-root-fx new-root-id)
(reset! root-comp-id new-root-id)
(reset! root-id @root-comp-id)
(reset! state/root-comp-id new-root-id)
(reset! state/root-id @state/root-comp-id)
(.setRoot Navigation (clj->js (get (roots/roots) new-root-id)))))
(re-frame/reg-fx
:init-root-with-component-fx
(fn [[new-root-id new-root-comp-id]]
(log/debug :init-root-with-component-fx new-root-id new-root-comp-id)
(reset! root-comp-id new-root-comp-id)
(reset! root-id @root-comp-id)
(reset! state/root-comp-id new-root-comp-id)
(reset! state/root-id @state/root-comp-id)
(.setRoot Navigation (clj->js (get (roots/roots) new-root-id)))))
(fx/defn set-multiaccount-root
@ -201,13 +195,14 @@
(defonce rset-app-launched
(.registerAppLaunchedListener (.events Navigation)
(fn []
(reset! curr-modal false)
(reset! dissmissing false)
(if (or (= @root-id :multiaccounts) (= @root-id :multiaccounts-keycard))
(reset! state/curr-modal false)
(reset! state/dissmissing false)
(if (or (= @state/root-id :multiaccounts)
(= @state/root-id :multiaccounts-keycard))
(re-frame/dispatch-sync [::set-multiaccount-root])
(when @root-id
(reset! root-comp-id @root-id)
(.setRoot Navigation (clj->js (get (roots/roots) @root-id)))
(when @state/root-id
(reset! state/root-comp-id @state/root-id)
(.setRoot Navigation (clj->js (get (roots/roots) @state/root-id)))
(re-frame/dispatch [::login-core/check-last-chat])))
(.hide ^js splash-screen))))
@ -248,7 +243,7 @@
:change-tab-fx
(fn [tab]
(log/debug :change-tab-fx)
(reset! root-comp-id (get tab-root-ids (get tab-key-idx tab)))
(reset! state/root-comp-id (get tab-root-ids (get tab-key-idx tab)))
(.mergeOptions Navigation "tabs-stack" (clj->js {:bottomTabs {:currentTabIndex (get tab-key-idx tab)}}))
;;when we change tab we want to dismiss all modals
(dismiss-all-modals)))
@ -289,9 +284,9 @@
comp (get tab-root-ids selected-tab-index)
tab-key (get (clojure.set/map-invert tab-key-idx) selected-tab-index)]
(re-frame/dispatch [:set :current-tab tab-key])
(when (and platform/android? (= @root-comp-id comp))
(when (and platform/android? (= @state/root-comp-id comp))
(.popToRoot Navigation (name comp)))
(reset! root-comp-id comp)))))
(reset! state/root-comp-id comp)))))
;; OVERLAY (Popover and bottom sheets)
(defn dissmiss-overlay [comp]
@ -405,15 +400,15 @@
:navigate-back-fx
(fn []
(log/debug :navigate-back-fx)
(if @curr-modal
(if @state/curr-modal
(dissmissModal)
(.pop Navigation (name @root-comp-id)))))
(.pop Navigation (name @state/root-comp-id)))))
(re-frame/reg-fx
:navigate-replace-fx
(fn [view-id]
(log/debug :navigate-replace-fx view-id)
(.pop Navigation (name @root-comp-id))
(.pop Navigation (name @state/root-comp-id))
(navigate view-id)))
(def community-screens '(:community-management

View File

@ -0,0 +1,8 @@
(ns status-im.navigation.state)
(defonce root-comp-id (atom nil))
(defonce root-id (atom nil))
(defonce pushed-screen-id (atom nil))
(defonce curr-modal (atom nil))
(defonce modals (atom []))
(defonce dissmissing (atom false))

View File

@ -50,7 +50,7 @@
(fx/defn handle-public-chat [cofx {:keys [topic]}]
(when (seq topic)
(chat/start-public-chat cofx topic {})))
(chat/start-public-chat cofx topic)))
(fx/defn handle-group-chat [cofx params]
(group-chats/create-from-link cofx params))

View File

@ -6,7 +6,7 @@
[status-im.utils.platform :as platform]
[status-im.utils.utils :as utils]
["react" :as reactjs]
["react-native" :as react-native :refer (Keyboard)]
["react-native" :as react-native :refer (Keyboard BackHandler)]
["react-native-image-crop-picker" :default image-picker]
["react-native-safe-area-context" :as safe-area-context
:refer (SafeAreaProvider SafeAreaInsetsContext)]
@ -270,3 +270,9 @@
(def safe-area-provider (reagent/adapt-react-class SafeAreaProvider))
(def safe-area-consumer (reagent/adapt-react-class (.-Consumer ^js SafeAreaInsetsContext)))
(defn hw-back-add-listener [callback]
(.addEventListener BackHandler "hardwareBackPress" callback))
(defn hw-back-remove-listener [callback]
(.removeEventListener BackHandler "hardwareBackPress" callback))

View File

@ -12,7 +12,7 @@
(:require-macros [status-im.utils.views :as views]))
(defn- start-chat [topic]
(re-frame/dispatch [:chat.ui/start-public-chat topic {:navigation-reset? true}])
(re-frame/dispatch [:chat.ui/start-public-chat topic])
(re-frame/dispatch [:set :public-group-topic nil]))
(defn- hash-icon []

View File

@ -86,10 +86,7 @@
:accessibility-label :open-chat
:title (str "#" topic)
:subtitle (i18n/label :t/open-chat)
:on-press #(do
(re-frame/dispatch [:navigate-change-tab :chat])
(re-frame/dispatch [:pop-to-root-tab :chat-stack])
(hide-sheet-and-dispatch [:chat.ui/start-public-chat topic {:navigation-reset? true}]))
:on-press #(hide-sheet-and-dispatch [:chat.ui/start-public-chat topic])
:chevron true}]
[components/separator]])
(if connected?

View File

@ -159,7 +159,7 @@
:text-decoration-line :underline}
:on-press
#(re-frame/dispatch
[:chat.ui/start-public-chat literal {:navigation-reset? true}])}
[:chat.ui/start-public-chat literal])}
"#"
literal])

View File

@ -1,5 +1,6 @@
(ns status-im.ui.screens.chat.views
(:require [re-frame.core :as re-frame]
re-frame.db
[reagent.core :as reagent]
[status-im.i18n.i18n :as i18n]
[status-im.ui.components.chat-icon.screen :as chat-icon.screen]
@ -32,7 +33,9 @@
[status-im.constants :as constants]
[status-im.utils.platform :as platform]
[status-im.utils.utils :as utils]
[status-im.ui.screens.chat.sheets :as sheets]))
[status-im.ui.screens.chat.sheets :as sheets]
[status-im.utils.debounce :as debounce]
[status-im.navigation.state :as navigation.state]))
(defn invitation-requests [chat-id admins]
(let [current-pk @(re-frame/subscribe [:multiaccount/public-key])
@ -332,20 +335,41 @@
:inverted (when platform/ios? true)
:style (when platform/android? {:scaleY -1})})]))
(defn topbar-button []
(re-frame/dispatch [:bottom-sheet/show-sheet
{:content (fn []
[sheets/current-chat-actions])
:height 256}]))
(defn topbar []
(defn topbar-content []
(let [window-width @(re-frame/subscribe [:dimensions/window-width])
{:keys [group-chat chat-id] :as chat-info} @(re-frame/subscribe [:chats/current-chat])]
[react/touchable-highlight {:on-press #(when-not group-chat (re-frame/dispatch [:chat.ui/show-profile chat-id]))
:style {:flex 1 :width (- window-width 120)}}
[react/touchable-highlight {:on-press #(when-not group-chat
(debounce/dispatch-and-chill [:chat.ui/show-profile chat-id] 1000))
:style {:flex 1 :width (- window-width 120)}}
[toolbar-content/toolbar-content-view-inner chat-info]]))
(defn chat []
(defn navigate-back-handler []
(when (and (not @navigation.state/curr-modal) (= (get @re-frame.db/app-db :view-id) :chat))
(react/hw-back-remove-listener navigate-back-handler)
(re-frame/dispatch [:close-chat])
(re-frame/dispatch [:navigate-back])))
(defn topbar []
;;we don't use topbar component, because we want chat view as simple (fast) as possible
[react/view {:height 56}
[react/touchable-highlight {:on-press-in navigate-back-handler
:accessibility-label :back-button
:style {:height 56 :width 40 :align-items :center :justify-content :center
:padding-left 16}}
[icons/icon :main-icons/arrow-left {:color colors/black}]]
[react/view {:flex 1 :left 52 :right 52 :top 0 :bottom 0 :position :absolute}
[topbar-content]]
[react/touchable-highlight {:on-press-in #(re-frame/dispatch [:bottom-sheet/show-sheet
{:content (fn []
[sheets/current-chat-actions])
:height 256}])
:accessibility-label :chat-menu-button
:style {:right 0 :top 0 :bottom 0 :position :absolute
:height 56 :width 40 :align-items :center :justify-content :center
:padding-right 16}}
[icons/icon :main-icons/more {:color colors/black}]]])
(defn chat-render []
(let [bottom-space (reagent/atom 0)
panel-space (reagent/atom 52)
active-panel (reagent/atom nil)
@ -363,6 +387,7 @@
@(re-frame/subscribe [:chats/current-chat-chat-view])
max-bottom-space (max @bottom-space @panel-space)]
[:<>
[topbar]
[connectivity/loading-indicator]
(when chat-id
(if group-chat
@ -398,3 +423,11 @@
:set-active-panel set-active-panel
:text-input-ref text-input-ref}]]
[bottom-sheet @active-panel]])]))))
(defn chat []
(reagent/create-class
{:component-did-mount (fn []
(react/hw-back-remove-listener navigate-back-handler)
(react/hw-back-add-listener navigate-back-handler))
:component-will-unmount (fn [] (react/hw-back-remove-listener navigate-back-handler))
:reagent-render chat-render}))

View File

@ -31,8 +31,7 @@
:accessibility-label :request-a-feature-button
:on-press
#(re-frame/dispatch [:chat.ui/start-public-chat
"support"
{:navigation-reset? false}])
"support"])
:chevron true}])
(defn help-center []

View File

@ -22,7 +22,6 @@
[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]
["react-native-navigation" :refer (Navigation)]
[status-im.ui.components.invite.views :as invite]
[status-im.utils.config :as config])
(:require-macros [status-im.utils.views :as views]))
@ -180,19 +179,13 @@
: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)
: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]])}))
[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]])

View File

@ -123,8 +123,7 @@
;[quo2.foundations.colors :as quo2.colors]))
(def components
[{:name :chat-toolbar
:component chat/topbar}])
[])
(defn right-button-options [id icon]
{:id id
@ -222,10 +221,9 @@
;Chat
{:name :chat
: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
:hardwareBackButton {:dismissModalOnPress false
:popStackOnPress false}
:topBar {:visible false}}
:component chat/chat}
;Pinned messages

View File

@ -76,7 +76,7 @@
(fx/defn handle-public-chat [cofx {:keys [topic]}]
(log/info "universal-links: handling public chat" topic)
(when (seq topic)
(chat/start-public-chat cofx topic {})))
(chat/start-public-chat cofx topic)))
(fx/defn handle-view-profile
[{:keys [db] :as cofx} {:keys [public-key ens-name]}]

View File

@ -15,7 +15,7 @@ from views.base_element import Button, BaseElement, EditBox, Text, CheckBox
class BackButton(Button):
def __init__(self, driver):
super().__init__(driver, accessibility_id="Navigate Up")
super().__init__(driver, accessibility_id="back-button")
def click(self, times_to_click: int = 1):
for _ in range(times_to_click):