Skip to content

Commit

Permalink
fix(settings): Show current mailserver in legacy settings (#21901)
Browse files Browse the repository at this point in the history
A regression removed more code than we wanted in
#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 #21375
  • Loading branch information
ilmotta authored Jan 17, 2025
1 parent 174e44c commit b22744f
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 155 deletions.
43 changes: 43 additions & 0 deletions src/legacy/status_im/mailserver/core.cljs
Original file line number Diff line number Diff line change
@@ -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))
8 changes: 0 additions & 8 deletions src/legacy/status_im/subs/mailservers.cljs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)])))
5 changes: 0 additions & 5 deletions src/legacy/status_im/subs/root.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions src/legacy/status_im/ui/screens/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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}}
Expand Down
7 changes: 4 additions & 3 deletions src/legacy/status_im/ui/screens/sync_settings/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/status_im/common/signals/events.cljs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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))

Expand Down
14 changes: 10 additions & 4 deletions src/status_im/contexts/profile/login/events.cljs
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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]}]
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions src/status_im/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b22744f

Please sign in to comment.