From b22744f81edba84dedd5a9f91d0a731d1a21cf11 Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Fri, 17 Jan 2025 14:26:20 -0300 Subject: [PATCH] fix(settings): Show current mailserver in legacy settings (#21901) A regression removed more code than we wanted in https://github.com/status-im/status-mobile/pull/20730 and the result was broken functionality in the Legacy settings. We now show the current mailserver correctly. The data is kept in sync via signals, just as the original code. Fixes https://github.com/status-im/status-mobile/issues/21375 --- src/legacy/status_im/mailserver/core.cljs | 43 +++++++++ src/legacy/status_im/subs/mailservers.cljs | 8 -- src/legacy/status_im/subs/root.cljs | 5 -- .../offline_messaging_settings/styles.cljs | 41 --------- .../offline_messaging_settings/views.cljs | 88 ------------------- src/legacy/status_im/ui/screens/screens.cljs | 4 - .../ui/screens/sync_settings/views.cljs | 7 +- src/status_im/common/signals/events.cljs | 7 ++ .../contexts/profile/login/events.cljs | 14 ++- src/status_im/db.cljs | 2 - 10 files changed, 64 insertions(+), 155 deletions(-) create mode 100644 src/legacy/status_im/mailserver/core.cljs delete mode 100644 src/legacy/status_im/ui/screens/offline_messaging_settings/styles.cljs delete mode 100644 src/legacy/status_im/ui/screens/offline_messaging_settings/views.cljs diff --git a/src/legacy/status_im/mailserver/core.cljs b/src/legacy/status_im/mailserver/core.cljs new file mode 100644 index 00000000000..969772fbbcf --- /dev/null +++ b/src/legacy/status_im/mailserver/core.cljs @@ -0,0 +1,43 @@ +(ns ^{:doc "Mailserver events and API"} legacy.status-im.mailserver.core + (:require + [legacy.status-im.multiaccounts.update.core :as multiaccounts.update] + [taoensso.timbre :as log] + [utils.re-frame :as rf])) + +(rf/defn handle-mailserver-changed + [{:keys [db]} ms] + (when (seq ms) + {:db (assoc db :mailserver/current-id (keyword ms))})) + +(rf/defn handle-mailserver-available + [{:keys [db]} ms] + {:db (assoc db :mailserver/current-id (keyword ms))}) + +(rf/defn toggle-use-mailservers + [_ value] + {:json-rpc/call + [{:method "wakuext_toggleUseMailservers" + :params [value] + :on-success #(log/info "successfully toggled use-mailservers" value) + :on-error #(log/error "failed to toggle use-mailserver" value %)}]}) + +(rf/defn update-use-mailservers + {:events [:mailserver.ui/use-history-switch-pressed]} + [cofx use-mailservers?] + (rf/merge cofx + (multiaccounts.update/optimistic :use-mailservers? use-mailservers?) + (toggle-use-mailservers use-mailservers?))) + +(defn add-mailservers + [db mailservers] + (reduce (fn [db {:keys [fleet id name] :as mailserver}] + (let [updated-mailserver + (-> mailserver + (update :id keyword) + (assoc :name (if (seq name) name id)) + (dissoc :fleet))] + (assoc-in db + [:mailserver/mailservers (keyword fleet) (keyword id)] + updated-mailserver))) + db + mailservers)) diff --git a/src/legacy/status_im/subs/mailservers.cljs b/src/legacy/status_im/subs/mailservers.cljs index d9254159f83..9119e025717 100644 --- a/src/legacy/status_im/subs/mailservers.cljs +++ b/src/legacy/status_im/subs/mailservers.cljs @@ -1,6 +1,5 @@ (ns legacy.status-im.subs.mailservers (:require - [legacy.status-im.fleet.core :as fleet] [re-frame.core :as re-frame])) (re-frame/reg-sub @@ -17,10 +16,3 @@ :<- [:mailserver/mailservers] (fn [[current-fleet mailservers]] (current-fleet mailservers))) - -(re-frame/reg-sub - :mailserver/preferred-id - :<- [:profile/profile] - (fn [multiaccount] - (get-in multiaccount - [:pinned-mailservers (fleet/current-fleet-sub multiaccount)]))) diff --git a/src/legacy/status_im/subs/root.cljs b/src/legacy/status_im/subs/root.cljs index bb088bfc898..beba3e2aff8 100644 --- a/src/legacy/status_im/subs/root.cljs +++ b/src/legacy/status_im/subs/root.cljs @@ -38,11 +38,6 @@ ;;mailserver (reg-root-key-sub :mailserver/current-id :mailserver/current-id) (reg-root-key-sub :mailserver/mailservers :mailserver/mailservers) -(reg-root-key-sub :mailserver.edit/mailserver :mailserver.edit/mailserver) -(reg-root-key-sub :mailserver/state :mailserver/state) -(reg-root-key-sub :mailserver/pending-requests :mailserver/pending-requests) -(reg-root-key-sub :mailserver/request-error? :mailserver/request-error) -(reg-root-key-sub :mailserver/fetching-gaps-in-progress :mailserver/fetching-gaps-in-progress) ;;contacts (reg-root-key-sub :contacts/contacts-raw :contacts/contacts) diff --git a/src/legacy/status_im/ui/screens/offline_messaging_settings/styles.cljs b/src/legacy/status_im/ui/screens/offline_messaging_settings/styles.cljs deleted file mode 100644 index 5a1fa5e449a..00000000000 --- a/src/legacy/status_im/ui/screens/offline_messaging_settings/styles.cljs +++ /dev/null @@ -1,41 +0,0 @@ -(ns legacy.status-im.ui.screens.offline-messaging-settings.styles - (:require - [legacy.status-im.ui.components.colors :as colors] - [legacy.status-im.utils.styles :as styles])) - -(def wrapper - {:flex 1}) - -(styles/defn mailserver-item - [] - {:flex-direction :row - :align-items :center - :justify-content :space-between - :padding-horizontal 16 - :ios {:height 64} - :android {:height 56}}) - -(def mailserver-item-name-text - {:typography :title}) - -(def switch-container - {:height 52}) - -(def automatic-selection-container - {:border-top-width 1 - :border-top-color colors/gray-lighter - :margin-top 16}) - -(def explanation-text - {:color colors/gray}) - -(def use-history-explanation-text-container - {:margin-right 16 - :margin-left 16 - :margin-top 8 - :margin-bottom 16}) - -(def history-nodes-label - {:color colors/gray - :padding-horizontal 16 - :margin-top 48}) diff --git a/src/legacy/status_im/ui/screens/offline_messaging_settings/views.cljs b/src/legacy/status_im/ui/screens/offline_messaging_settings/views.cljs deleted file mode 100644 index 8fe80a54a34..00000000000 --- a/src/legacy/status_im/ui/screens/offline_messaging_settings/views.cljs +++ /dev/null @@ -1,88 +0,0 @@ -(ns legacy.status-im.ui.screens.offline-messaging-settings.views - (:require-macros [legacy.status-im.utils.views :as views]) - (:require - [legacy.status-im.ui.components.colors :as colors] - [legacy.status-im.ui.components.core :as quo] - [legacy.status-im.ui.components.icons.icons :as icons] - [legacy.status-im.ui.components.list.views :as list] - [legacy.status-im.ui.components.react :as react] - [legacy.status-im.ui.components.topbar :as topbar] - [legacy.status-im.ui.screens.offline-messaging-settings.styles :as styles] - [legacy.status-im.ui.screens.profile.components.views :as profile.components] - [re-frame.core :as re-frame] - [utils.i18n :as i18n])) - -(defn pinned-state - [pinned?] - [react/view {:style styles/automatic-selection-container} - [react/view {:style styles/switch-container} - [profile.components/settings-switch-item - {:label-kw :t/mailserver-automatic - :value (not pinned?) - :action-fn #(if pinned? - (re-frame/dispatch [:mailserver.ui/unpin-pressed]) - (re-frame/dispatch [:mailserver.ui/pin-pressed]))}]] - [react/view {:style {:padding-horizontal 16}} - [react/text {:style styles/explanation-text} - (i18n/label :t/mailserver-automatic-switch-explanation)]]]) - -(defn render-row - [{:keys [name id custom]} _ _ {:keys [current-mailserver-id preferred-mailserver-id]}] - (let [pinned? preferred-mailserver-id - connected? (= id current-mailserver-id) - visible? (or pinned? ; show everything when auto selection is turned off - (and (not pinned?) ; auto selection turned on - (= current-mailserver-id id)))] ; show only the selected server - - (when visible? - [react/touchable-highlight - {:on-press (when pinned? - #(if custom - (re-frame/dispatch [:mailserver.ui/custom-mailserver-selected id]) - (re-frame/dispatch [:mailserver.ui/default-mailserver-selected id]))) - :accessibility-label :mailserver-item} - [react/view (styles/mailserver-item) - [react/text {:style styles/mailserver-item-name-text} - name] - - (if pinned? - [quo/radio {:value connected?}] - [icons/icon :check {:color colors/blue}])]]))) - -(views/defview offline-messaging-settings - [] - (views/letsubs [current-mailserver-id [:mailserver/current-id] - preferred-mailserver-id [:mailserver/preferred-id] - mailservers [:mailserver/fleet-mailservers] - {:keys [use-mailservers?]} [:profile/profile]] - [react/view {:style styles/wrapper} - [topbar/topbar - {:title (i18n/label :t/history-nodes) - :right-accessories - [{:icon :main-icons/add-circle - :on-press #(re-frame/dispatch [:mailserver.ui/add-pressed])}]}] - - [react/scroll-view - [react/view {:style styles/switch-container} - [profile.components/settings-switch-item - {:label-kw :t/offline-messaging-use-history-nodes - :value use-mailservers? - :action-fn #(re-frame/dispatch [:mailserver.ui/use-history-switch-pressed - (not use-mailservers?)])}]] - [react/view {:style styles/use-history-explanation-text-container} - [react/text {:style styles/explanation-text} - (i18n/label :t/offline-messaging-use-history-explanation)]] - - (when use-mailservers? - [:<> - [pinned-state preferred-mailserver-id] - - [react/text {:style styles/history-nodes-label} - (i18n/label :t/history-nodes)] - [list/flat-list - {:data (vals mailservers) - :default-separator? false - :key-fn :name - :render-data {:current-mailserver-id current-mailserver-id - :preferred-mailserver-id preferred-mailserver-id} - :render-fn render-row}]])]])) diff --git a/src/legacy/status_im/ui/screens/screens.cljs b/src/legacy/status_im/ui/screens/screens.cljs index f2ee4efeddf..c4b3d991ae4 100644 --- a/src/legacy/status_im/ui/screens/screens.cljs +++ b/src/legacy/status_im/ui/screens/screens.cljs @@ -12,7 +12,6 @@ [legacy.status-im.ui.screens.help-center.views :as help-center] [legacy.status-im.ui.screens.log-level-settings.views :as log-level-settings] [legacy.status-im.ui.screens.notifications-settings.views :as notifications-settings] - [legacy.status-im.ui.screens.offline-messaging-settings.views :as offline-messaging-settings] [legacy.status-im.ui.screens.pairing.views :as pairing] [legacy.status-im.ui.screens.peers-stats :as peers-stats] [legacy.status-im.ui.screens.profile.seed.views :as profile.seed] @@ -113,9 +112,6 @@ :options {:topBar (topbar-options (i18n/label :t/devices)) :insets {:top? true}} :component pairing/installations} - {:name :offline-messaging-settings - :options {:insets {:top? true}} - :component offline-messaging-settings/offline-messaging-settings} {:name :rpc-usage-info :options {:topBar (topbar-options :t/rpc-usage-info) :insets {:top? true}} diff --git a/src/legacy/status_im/ui/screens/sync_settings/views.cljs b/src/legacy/status_im/ui/screens/sync_settings/views.cljs index d8d1d7e7c54..d76802700fe 100644 --- a/src/legacy/status_im/ui/screens/sync_settings/views.cljs +++ b/src/legacy/status_im/ui/screens/sync_settings/views.cljs @@ -7,6 +7,7 @@ [legacy.status-im.ui.components.react :as react] [quo.core :as quo] [re-frame.core :as re-frame] + [react-native.clipboard :as clipboard] [status-im.constants :as constants] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -67,10 +68,10 @@ {:size :small :accessibility-label :offline-messages-settings-button :title (i18n/label :t/history-nodes) - :on-press #(re-frame/dispatch [:navigate-to :offline-messaging-settings]) + :on-press (fn [] + (clipboard/set-string current-mailserver-name)) :accessory :text - :accessory-text (when use-mailservers? current-mailserver-name) - :chevron true}] + :accessory-text (when use-mailservers? current-mailserver-name)}] ;; TODO(Ferossgp): Devider componemt [react/view {:height 1 diff --git a/src/status_im/common/signals/events.cljs b/src/status_im/common/signals/events.cljs index 68f12dbf102..9a6d8eb4144 100644 --- a/src/status_im/common/signals/events.cljs +++ b/src/status_im/common/signals/events.cljs @@ -1,6 +1,7 @@ (ns status-im.common.signals.events (:require [legacy.status-im.chat.models.message :as models.message] + [legacy.status-im.mailserver.core :as mailserver] [legacy.status-im.visibility-status-updates.core :as visibility-status-updates] [oops.core :as oops] [status-im.common.pairing.events :as pairing] @@ -63,6 +64,12 @@ "messages.new" (messages.transport/sanitize-messages-and-process-response cofx event-js true) + "mailserver.changed" + (mailserver/handle-mailserver-changed cofx (oops/oget event-js :id)) + + "mailserver.available" + (mailserver/handle-mailserver-available cofx (oops/oget event-js :id)) + "discovery.summary" (summary cofx (transforms/js->clj event-js)) diff --git a/src/status_im/contexts/profile/login/events.cljs b/src/status_im/contexts/profile/login/events.cljs index 8d7e21968d2..ef380f9fe25 100644 --- a/src/status_im/contexts/profile/login/events.cljs +++ b/src/status_im/contexts/profile/login/events.cljs @@ -1,7 +1,9 @@ (ns status-im.contexts.profile.login.events (:require [legacy.status-im.data-store.settings :as data-store.settings] + [legacy.status-im.mailserver.core :as mailserver] [native-module.core :as native-module] + [oops.core :as oops] [status-im.common.keychain.events :as keychain] [status-im.config :as config] [status-im.constants :as constants] @@ -10,7 +12,8 @@ [taoensso.timbre :as log] [utils.i18n :as i18n] [utils.re-frame :as rf] - [utils.security.core :as security])) + [utils.security.core :as security] + [utils.transforms :as transforms])) (rf/reg-event-fx :profile.login/login (fn [{:keys [db]}] @@ -132,9 +135,12 @@ :on-error #(log/error "node-info: failed error" %)}]]]}))) (rf/reg-event-fx :profile.login/messenger-started - (fn [{:keys [db]} [_]] - (let [new-account? (get db :onboarding/new-account?)] - {:db (assoc db :messenger/started? true) + (fn [{:keys [db]} [response-js]] + (let [mailservers (transforms/js->clj (oops/oget response-js :mailservers)) + new-account? (get db :onboarding/new-account?)] + {:db (-> db + (assoc :messenger/started? true) + (mailserver/add-mailservers mailservers)) :fx [[:fetch-chats-preview {:chat-preview-type constants/chat-preview-type-non-community :on-success (fn [result] diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index dac4a899ce6..14f8db86909 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -26,8 +26,6 @@ :peers-summary [] :transport/message-envelopes {} :mailserver/mailservers (fleet/default-mailservers {}) - :mailserver/topics {} - :mailserver/pending-requests 0 :chat/cooldowns 0 :chat/inputs {} :chat/cooldown-enabled? false