mirror of
https://github.com/status-im/status-react.git
synced 2025-01-23 09:19:59 +00:00
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
This commit is contained in:
parent
174e44c77d
commit
b22744f81e
43
src/legacy/status_im/mailserver/core.cljs
Normal file
43
src/legacy/status_im/mailserver/core.cljs
Normal file
@ -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))
|
@ -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)])))
|
||||
|
@ -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)
|
||||
|
@ -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})
|
@ -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}]])]]))
|
@ -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}}
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user