mirror of
https://github.com/status-im/status-mobile.git
synced 2025-01-14 02:35:54 +00:00
Add unpinning of mailservers
Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
parent
6fe3f0500a
commit
b26b6ee5e0
@ -1 +1 @@
|
|||||||
0.23.0-beta.5
|
0.23.0-beta.7
|
||||||
|
@ -393,6 +393,16 @@
|
|||||||
(fn [cofx _]
|
(fn [cofx _]
|
||||||
(mailserver/connect-to-mailserver cofx)))
|
(mailserver/connect-to-mailserver cofx)))
|
||||||
|
|
||||||
|
(handlers/register-handler-fx
|
||||||
|
:mailserver.ui/unpin-pressed
|
||||||
|
(fn [cofx _]
|
||||||
|
(mailserver/unpin cofx)))
|
||||||
|
|
||||||
|
(handlers/register-handler-fx
|
||||||
|
:mailserver.ui/pin-pressed
|
||||||
|
(fn [cofx _]
|
||||||
|
(mailserver/pin cofx)))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:mailserver.ui/request-error-pressed
|
:mailserver.ui/request-error-pressed
|
||||||
(fn [cofx _]
|
(fn [cofx _]
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
(def seven-days (* 7 one-day))
|
(def seven-days (* 7 one-day))
|
||||||
(def maximum-number-of-attempts 2)
|
(def maximum-number-of-attempts 2)
|
||||||
(def request-timeout 30)
|
(def request-timeout 30)
|
||||||
(def min-limit 200)
|
(def min-limit 100)
|
||||||
(def max-limit 2000)
|
(def max-limit 2000)
|
||||||
(def backoff-interval-ms 3000)
|
(def backoff-interval-ms 3000)
|
||||||
(def default-limit max-limit)
|
(def default-limit max-limit)
|
||||||
@ -46,6 +46,7 @@
|
|||||||
"Time after which mailserver connection is considered to have failed"
|
"Time after which mailserver connection is considered to have failed"
|
||||||
10000)
|
10000)
|
||||||
(def limit (atom default-limit))
|
(def limit (atom default-limit))
|
||||||
|
(def success-counter (atom 0))
|
||||||
|
|
||||||
(defn connected? [{:keys [db]} id]
|
(defn connected? [{:keys [db]} id]
|
||||||
(= (:mailserver/current-id db) id))
|
(= (:mailserver/current-id db) id))
|
||||||
@ -143,17 +144,30 @@
|
|||||||
(fn [enodes]
|
(fn [enodes]
|
||||||
(update-mailservers! enodes)))
|
(update-mailservers! enodes)))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
|
||||||
:mailserver/set-limit
|
|
||||||
(fn [n]
|
|
||||||
(reset! limit n)))
|
|
||||||
|
|
||||||
(defn decrease-limit []
|
(defn decrease-limit []
|
||||||
(max min-limit (/ @limit 2)))
|
(max min-limit (/ @limit 2)))
|
||||||
|
|
||||||
(defn increase-limit []
|
(defn increase-limit []
|
||||||
(min max-limit (* @limit 2)))
|
(min max-limit (* @limit 2)))
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
:mailserver/set-limit
|
||||||
|
(fn [n]
|
||||||
|
(reset! limit n)))
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
:mailserver/increase-limit
|
||||||
|
(fn []
|
||||||
|
(if (>= @success-counter 2)
|
||||||
|
(reset! limit (increase-limit))
|
||||||
|
(swap! success-counter inc))))
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
:mailserver/decrease-limit
|
||||||
|
(fn []
|
||||||
|
(reset! limit (decrease-limit))
|
||||||
|
(reset! success-counter 0)))
|
||||||
|
|
||||||
(defn mark-trusted-peer! [web3 enode]
|
(defn mark-trusted-peer! [web3 enode]
|
||||||
(.markTrustedPeer (transport.utils/shh web3)
|
(.markTrustedPeer (transport.utils/shh web3)
|
||||||
enode
|
enode
|
||||||
@ -262,7 +276,7 @@
|
|||||||
(log/debug "Adjusting mailserver request" "from:" from "adjusted-from:" adjusted-from)
|
(log/debug "Adjusting mailserver request" "from:" from "adjusted-from:" adjusted-from)
|
||||||
adjusted-from))
|
adjusted-from))
|
||||||
|
|
||||||
(fx/defn handle-request-success [{:keys [db]} request-id]
|
(fx/defn handle-request-success [{:keys [db]} {:keys [request-id]}]
|
||||||
(when (:mailserver/current-request db)
|
(when (:mailserver/current-request db)
|
||||||
{:db (assoc-in db [:mailserver/current-request :request-id] request-id)}))
|
{:db (assoc-in db [:mailserver/current-request :request-id] request-id)}))
|
||||||
|
|
||||||
@ -527,7 +541,7 @@
|
|||||||
(if (empty? error)
|
(if (empty? error)
|
||||||
(fx/merge
|
(fx/merge
|
||||||
cofx
|
cofx
|
||||||
{:mailserver/set-limit (increase-limit)}
|
{:mailserver/increase-limit []}
|
||||||
(update-mailserver-topics {:request-id (:requestID event)
|
(update-mailserver-topics {:request-id (:requestID event)
|
||||||
:cursor (:cursor event)}))
|
:cursor (:cursor event)}))
|
||||||
|
|
||||||
@ -603,11 +617,11 @@
|
|||||||
web3 (:web3 db)]
|
web3 (:web3 db)]
|
||||||
(log/info "mailserver: message request " request-id "expired for mailserver topic" topics "from" from "to" to "cursor" cursor "limit" (decrease-limit))
|
(log/info "mailserver: message request " request-id "expired for mailserver topic" topics "from" from "to" to "cursor" cursor "limit" (decrease-limit))
|
||||||
{:db (update-in db [:mailserver/current-request :attempts] inc)
|
{:db (update-in db [:mailserver/current-request :attempts] inc)
|
||||||
:mailserver/set-limit (decrease-limit)
|
:mailserver/decrease-limit []
|
||||||
:mailserver/request-messages {:web3 web3
|
:mailserver/request-messages {:web3 web3
|
||||||
:mailserver mailserver
|
:mailserver mailserver
|
||||||
:request (assoc request :limit (decrease-limit))}})
|
:request (assoc request :limit (decrease-limit))}})
|
||||||
{:mailserver/set-limit (decrease-limit)})))))
|
{:mailserver/decrease-limit []})))))
|
||||||
|
|
||||||
(fx/defn initialize-mailserver
|
(fx/defn initialize-mailserver
|
||||||
[cofx custom-mailservers]
|
[cofx custom-mailservers]
|
||||||
@ -733,10 +747,31 @@
|
|||||||
(fx/defn save-settings
|
(fx/defn save-settings
|
||||||
[{:keys [db] :as cofx} current-fleet mailserver-id]
|
[{:keys [db] :as cofx} current-fleet mailserver-id]
|
||||||
(let [{:keys [address]} (fetch-current cofx)
|
(let [{:keys [address]} (fetch-current cofx)
|
||||||
settings (get-in db [:account/account :settings])]
|
settings (get-in db [:account/account :settings])
|
||||||
|
;; Check if previous mailserver was pinned
|
||||||
|
pinned? (get-in settings [:mailserver current-fleet])]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (assoc db :mailserver/current-id mailserver-id)
|
{:db (assoc db :mailserver/current-id mailserver-id)
|
||||||
:mailserver/remove-peer address}
|
:mailserver/remove-peer address}
|
||||||
(connect-to-mailserver)
|
(connect-to-mailserver)
|
||||||
|
(when pinned?
|
||||||
|
(accounts.update/update-settings (assoc-in settings [:mailserver current-fleet] mailserver-id)
|
||||||
|
{})))))
|
||||||
|
|
||||||
|
(fx/defn unpin
|
||||||
|
[{:keys [db] :as cofx}]
|
||||||
|
(let [current-fleet (fleet/current-fleet db)
|
||||||
|
settings (get-in db [:account/account :settings])]
|
||||||
|
(fx/merge cofx
|
||||||
|
(accounts.update/update-settings (update settings :mailserver dissoc current-fleet)
|
||||||
|
{})
|
||||||
|
(change-mailserver))))
|
||||||
|
|
||||||
|
(fx/defn pin
|
||||||
|
[{:keys [db] :as cofx}]
|
||||||
|
(let [current-fleet (fleet/current-fleet db)
|
||||||
|
mailserver-id (:mailserver/current-id db)
|
||||||
|
settings (get-in db [:account/account :settings])]
|
||||||
|
(fx/merge cofx
|
||||||
(accounts.update/update-settings (assoc-in settings [:mailserver current-fleet] mailserver-id)
|
(accounts.update/update-settings (assoc-in settings [:mailserver current-fleet] mailserver-id)
|
||||||
{}))))
|
{}))))
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
(ns status-im.mailserver.subs
|
(ns status-im.mailserver.subs
|
||||||
(:require [re-frame.core :as re-frame]))
|
(:require
|
||||||
|
[status-im.mailserver.core :as mailserver]
|
||||||
|
[re-frame.core :as re-frame]))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:mailserver/state
|
:mailserver/state
|
||||||
@ -46,6 +48,11 @@
|
|||||||
(fn [db]
|
(fn [db]
|
||||||
(:mailserver/current-id db)))
|
(:mailserver/current-id db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
:mailserver/preferred-id
|
||||||
|
(fn [db]
|
||||||
|
(mailserver/preferred-mailserver-id {:db db})))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:mailserver/mailservers
|
:mailserver/mailservers
|
||||||
(fn [db]
|
(fn [db]
|
||||||
|
@ -160,11 +160,14 @@
|
|||||||
{:keys [settings]} [:account/account]
|
{:keys [settings]} [:account/account]
|
||||||
mailservers [:mailserver/fleet-mailservers]
|
mailservers [:mailserver/fleet-mailservers]
|
||||||
mailserver-state [:mailserver/state]
|
mailserver-state [:mailserver/state]
|
||||||
|
preferred-mailserver-id [:mailserver/preferred-id]
|
||||||
node-status [:node-status]
|
node-status [:node-status]
|
||||||
peers-count [:peers-count]
|
peers-count [:peers-count]
|
||||||
connection-stats [:connection-stats]
|
connection-stats [:connection-stats]
|
||||||
disconnected [:disconnected?]]
|
disconnected [:disconnected?]]
|
||||||
(let [render-fn (offline-messaging.views/render-row current-mailserver-id)
|
(let [render-fn (offline-messaging.views/render-row
|
||||||
|
current-mailserver-id
|
||||||
|
preferred-mailserver-id)
|
||||||
pfs? (:pfs? settings)
|
pfs? (:pfs? settings)
|
||||||
connection-message (connection-status peers-count node-status mailserver-state disconnected)]
|
connection-message (connection-status peers-count node-status mailserver-state disconnected)]
|
||||||
[react/scroll-view
|
[react/scroll-view
|
||||||
@ -182,6 +185,7 @@
|
|||||||
|
|
||||||
[react/view {:style styles/title-separator}]
|
[react/view {:style styles/title-separator}]
|
||||||
[react/text {:style styles/adv-settings-subtitle} (i18n/label :offline-messaging)]
|
[react/text {:style styles/adv-settings-subtitle} (i18n/label :offline-messaging)]
|
||||||
|
[offline-messaging.views/pinned-state preferred-mailserver-id]
|
||||||
[react/view
|
[react/view
|
||||||
(for [mailserver (vals mailservers)]
|
(for [mailserver (vals mailservers)]
|
||||||
^{:key (:id mailserver)}
|
^{:key (:id mailserver)}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
(ns status-im.ui.screens.offline-messaging-settings.styles
|
(ns status-im.ui.screens.offline-messaging-settings.styles
|
||||||
(:require [status-im.ui.components.colors :as colors]
|
(:require [status-im.ui.components.colors :as colors]
|
||||||
[status-im.utils.platform :as platform])
|
[status-im.utils.platform :as platform])
|
||||||
(:require-macros [status-im.utils.styles :refer [defstyle]]))
|
(:require-macros [status-im.utils.styles :refer [defnstyle
|
||||||
|
defstyle]]))
|
||||||
|
|
||||||
(def wrapper
|
(def wrapper
|
||||||
{:flex 1
|
{:flex 1
|
||||||
@ -10,10 +11,13 @@
|
|||||||
(def mailserver-item-inner
|
(def mailserver-item-inner
|
||||||
{:padding-horizontal 16})
|
{:padding-horizontal 16})
|
||||||
|
|
||||||
(defstyle mailserver-item
|
(defnstyle mailserver-item [pinned?]
|
||||||
{:flex-direction :row
|
{:flex-direction :row
|
||||||
:background-color :white
|
:background-color :white
|
||||||
:align-items :center
|
:align-items :center
|
||||||
|
:opacity (if pinned?
|
||||||
|
1
|
||||||
|
0.4)
|
||||||
:padding-horizontal 16
|
:padding-horizontal 16
|
||||||
:ios {:height 64}
|
:ios {:height 64}
|
||||||
:android {:height 56}})
|
:android {:height 56}})
|
||||||
@ -46,3 +50,14 @@
|
|||||||
|
|
||||||
(defn mailserver-icon [connected?]
|
(defn mailserver-icon [connected?]
|
||||||
(hash-map (if platform/desktop? :tint-color :color) (if connected? :white :gray)))
|
(hash-map (if platform/desktop? :tint-color :color) (if connected? :white :gray)))
|
||||||
|
|
||||||
|
(def mailserver-pinned
|
||||||
|
{:padding-horizontal 16
|
||||||
|
:flex-direction :row
|
||||||
|
:padding-vertical 5})
|
||||||
|
|
||||||
|
(def mailserver-pinned-text
|
||||||
|
{:color colors/black})
|
||||||
|
|
||||||
|
(def mailserver-pinned-text-container
|
||||||
|
{:margin-top 15})
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
[status-im.utils.config :as config]
|
[status-im.utils.config :as config]
|
||||||
|
[status-im.ui.components.checkbox.view :as checkbox.views]
|
||||||
[status-im.ui.components.icons.vector-icons :as vector-icons]
|
[status-im.ui.components.icons.vector-icons :as vector-icons]
|
||||||
[status-im.ui.components.list.views :as list]
|
[status-im.ui.components.list.views :as list]
|
||||||
[status-im.ui.components.react :as react]
|
[status-im.ui.components.react :as react]
|
||||||
@ -20,15 +21,29 @@
|
|||||||
(if platform/desktop? {:style (styles/mailserver-icon connected?)}
|
(if platform/desktop? {:style (styles/mailserver-icon connected?)}
|
||||||
(styles/mailserver-icon connected?))]])
|
(styles/mailserver-icon connected?))]])
|
||||||
|
|
||||||
(defn render-row [current-mailserver-id]
|
(defn pinned-state [pinned?]
|
||||||
|
[react/touchable-highlight {:on-press (if pinned?
|
||||||
|
#(re-frame/dispatch [:mailserver.ui/unpin-pressed])
|
||||||
|
#(re-frame/dispatch [:mailserver.ui/pin-pressed]))}
|
||||||
|
[react/view {:style styles/mailserver-pinned}
|
||||||
|
[checkbox.views/checkbox
|
||||||
|
{:checked? (not pinned?)
|
||||||
|
:on-value-change (if pinned?
|
||||||
|
#(re-frame/dispatch [:mailserver.ui/unpin-pressed])
|
||||||
|
#(re-frame/dispatch [:mailserver.ui/pin-pressed]))}]
|
||||||
|
[react/view {:style styles/mailserver-pinned-text-container}
|
||||||
|
[react/text {:style styles/mailserver-pinned-text}
|
||||||
|
(i18n/label :t/mailserver-automatic)]]]])
|
||||||
|
|
||||||
|
(defn render-row [current-mailserver-id pinned?]
|
||||||
(fn [{:keys [name id user-defined]}]
|
(fn [{:keys [name id user-defined]}]
|
||||||
(let [connected? (= id current-mailserver-id)]
|
(let [connected? (= id current-mailserver-id)]
|
||||||
[react/touchable-highlight
|
[react/touchable-highlight
|
||||||
{:on-press #(if user-defined
|
{:on-press (when pinned? #(if user-defined
|
||||||
(re-frame/dispatch [:mailserver.ui/user-defined-mailserver-selected id])
|
(re-frame/dispatch [:mailserver.ui/user-defined-mailserver-selected id])
|
||||||
(re-frame/dispatch [:mailserver.ui/default-mailserver-selected id]))
|
(re-frame/dispatch [:mailserver.ui/default-mailserver-selected id])))
|
||||||
:accessibility-label :mailserver-item}
|
:accessibility-label :mailserver-item}
|
||||||
[react/view styles/mailserver-item
|
[react/view (styles/mailserver-item pinned?)
|
||||||
[mailserver-icon connected?]
|
[mailserver-icon connected?]
|
||||||
[react/view styles/mailserver-item-inner
|
[react/view styles/mailserver-item-inner
|
||||||
[react/text {:style styles/mailserver-item-name-text}
|
[react/text {:style styles/mailserver-item-name-text}
|
||||||
@ -36,6 +51,7 @@
|
|||||||
|
|
||||||
(views/defview offline-messaging-settings []
|
(views/defview offline-messaging-settings []
|
||||||
(views/letsubs [current-mailserver-id [:mailserver/current-id]
|
(views/letsubs [current-mailserver-id [:mailserver/current-id]
|
||||||
|
preferred-mailserver-id [:mailserver/preferred-id]
|
||||||
mailservers [:mailserver/fleet-mailservers]]
|
mailservers [:mailserver/fleet-mailservers]]
|
||||||
[react/view {:flex 1}
|
[react/view {:flex 1}
|
||||||
[status-bar/status-bar]
|
[status-bar/status-bar]
|
||||||
@ -45,7 +61,9 @@
|
|||||||
[toolbar/actions
|
[toolbar/actions
|
||||||
[(toolbar.actions/add false #(re-frame/dispatch [:mailserver.ui/add-pressed]))]]]
|
[(toolbar.actions/add false #(re-frame/dispatch [:mailserver.ui/add-pressed]))]]]
|
||||||
[react/view styles/wrapper
|
[react/view styles/wrapper
|
||||||
|
[pinned-state preferred-mailserver-id]
|
||||||
[list/flat-list {:data (vals mailservers)
|
[list/flat-list {:data (vals mailservers)
|
||||||
:default-separator? false
|
:default-separator? false
|
||||||
:key-fn :name
|
:key-fn :name
|
||||||
:render-fn (render-row current-mailserver-id)}]]]))
|
:render-fn (render-row current-mailserver-id
|
||||||
|
preferred-mailserver-id)}]]]))
|
||||||
|
@ -354,7 +354,7 @@
|
|||||||
(testing "it did not reach the maximum number of attempts"
|
(testing "it did not reach the maximum number of attempts"
|
||||||
(testing "it reached the maximum number of attempts"
|
(testing "it reached the maximum number of attempts"
|
||||||
(testing "it decrease the limit")
|
(testing "it decrease the limit")
|
||||||
(is (= {:mailserver/set-limit 1000} (mailserver/resend-request {:db {:mailserver/current-request
|
(is (= {:mailserver/decrease-limit []} (mailserver/resend-request {:db {:mailserver/current-request
|
||||||
{}}}
|
{}}}
|
||||||
{})))))))
|
{})))))))
|
||||||
|
|
||||||
@ -398,6 +398,30 @@
|
|||||||
(is (= (into #{} (keys (peers-summary-change-result true false false)))
|
(is (= (into #{} (keys (peers-summary-change-result true false false)))
|
||||||
#{}))))
|
#{}))))
|
||||||
|
|
||||||
|
(deftest unpin-test
|
||||||
|
(testing "it removes the preference"
|
||||||
|
(let [db {:mailserver/current-id "mailserverid"
|
||||||
|
:mailserver/mailservers
|
||||||
|
{:eth.beta {"mailserverid" {:address "mailserver-address"
|
||||||
|
:password "mailserver-password"}}}
|
||||||
|
:account/account
|
||||||
|
{:settings {:fleet :eth.beta
|
||||||
|
:mailserver {:eth.beta "mailserverid"}}}}]
|
||||||
|
(is (not (get-in (mailserver/unpin {:db db})
|
||||||
|
[:db :account/account :settings :mailserver :eth.beta]))))))
|
||||||
|
|
||||||
|
(deftest pin-test
|
||||||
|
(testing "it removes the preference"
|
||||||
|
(let [db {:mailserver/current-id "mailserverid"
|
||||||
|
:mailserver/mailservers
|
||||||
|
{:eth.beta {"mailserverid" {:address "mailserver-address"
|
||||||
|
:password "mailserver-password"}}}
|
||||||
|
:account/account
|
||||||
|
{:settings {:fleet :eth.beta
|
||||||
|
:mailserver {}}}}]
|
||||||
|
(is (= "mailserverid" (get-in (mailserver/pin {:db db})
|
||||||
|
[:db :account/account :settings :mailserver :eth.beta]))))))
|
||||||
|
|
||||||
(deftest connect-to-mailserver
|
(deftest connect-to-mailserver
|
||||||
(let [db {:mailserver/current-id "mailserverid"
|
(let [db {:mailserver/current-id "mailserverid"
|
||||||
:mailserver/mailservers
|
:mailserver/mailservers
|
||||||
|
@ -263,6 +263,7 @@
|
|||||||
"update-status": "Update your status...",
|
"update-status": "Update your status...",
|
||||||
"errors": "Errors",
|
"errors": "Errors",
|
||||||
"mailserver-connection-error": "Could not connect to mailserver",
|
"mailserver-connection-error": "Could not connect to mailserver",
|
||||||
|
"mailserver-automatic": "Automatic selection",
|
||||||
"currency-display-name-kzt": "Kazakhstan Tenge",
|
"currency-display-name-kzt": "Kazakhstan Tenge",
|
||||||
"no-recent-chats": "Your Home screen will house your recent chats and DApp history. Tap the plus (+) button to get started.",
|
"no-recent-chats": "Your Home screen will house your recent chats and DApp history. Tap the plus (+) button to get started.",
|
||||||
"install": "Install",
|
"install": "Install",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user