2023-10-16 13:47:20 +00:00
|
|
|
(ns status-im.subs.mailservers
|
2022-09-21 14:03:06 +00:00
|
|
|
(:require [re-frame.core :as re-frame]
|
2022-12-20 14:45:37 +00:00
|
|
|
[status-im.fleet.core :as fleet]
|
|
|
|
[status-im.mailserver.core :as mailserver]))
|
2022-09-21 14:03:06 +00:00
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:mailserver/current-name
|
|
|
|
:<- [:mailserver/current-id]
|
|
|
|
:<- [:fleets/current-fleet]
|
|
|
|
:<- [:mailserver/mailservers]
|
|
|
|
(fn [[current-mailserver-id current-fleet mailservers]]
|
|
|
|
(get-in mailservers [current-fleet current-mailserver-id :name])))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:mailserver/connecting?
|
|
|
|
:<- [:mailserver/state]
|
|
|
|
(fn [state]
|
|
|
|
(#{:connecting :added} state)))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:mailserver/connection-error?
|
|
|
|
:<- [:mailserver/state]
|
|
|
|
(fn [state]
|
|
|
|
(#{:error :disconnected} state)))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:chats/fetching-gap-in-progress?
|
|
|
|
:<- [:mailserver/fetching-gaps-in-progress]
|
|
|
|
(fn [gaps [_ ids _]]
|
|
|
|
(seq (select-keys gaps ids))))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:mailserver/fetching?
|
|
|
|
:<- [:mailserver/state]
|
|
|
|
:<- [:mailserver/pending-requests]
|
|
|
|
:<- [:mailserver/connecting?]
|
|
|
|
:<- [:mailserver/connection-error?]
|
|
|
|
:<- [:mailserver/request-error?]
|
|
|
|
(fn [[state pending-requests connecting? connection-error? request-error?]]
|
|
|
|
(and pending-requests
|
|
|
|
(= state :connected)
|
|
|
|
(pos-int? pending-requests)
|
|
|
|
(not (or connecting? connection-error? request-error?)))))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:mailserver/fleet-mailservers
|
|
|
|
:<- [:fleets/current-fleet]
|
|
|
|
:<- [:mailserver/mailservers]
|
|
|
|
(fn [[current-fleet mailservers]]
|
|
|
|
(current-fleet mailservers)))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:mailserver.edit/connected?
|
|
|
|
:<- [:mailserver.edit/mailserver]
|
|
|
|
:<- [:mailserver/current-id]
|
|
|
|
(fn [[mailserver current-mailserver-id]]
|
|
|
|
(= (get-in mailserver [:id :value])
|
|
|
|
current-mailserver-id)))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:mailserver/use-status-nodes?
|
|
|
|
(fn [db _]
|
|
|
|
(boolean (mailserver/fetch-use-mailservers? {:db db}))))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:mailserver.edit/validation-errors
|
|
|
|
:<- [:mailserver.edit/mailserver]
|
|
|
|
(fn [mailserver]
|
|
|
|
(set (keep
|
|
|
|
(fn [[k {:keys [error]}]]
|
|
|
|
(when error k))
|
|
|
|
mailserver))))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:mailserver/connected?
|
|
|
|
:<- [:mailserver/state]
|
|
|
|
:<- [:disconnected?]
|
|
|
|
(fn [[mail-state disconnected?]]
|
|
|
|
(let [mailserver-connected? (= :connected mail-state)]
|
|
|
|
(and mailserver-connected?
|
|
|
|
(not disconnected?)))))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:mailserver/preferred-id
|
2023-06-28 11:48:34 +00:00
|
|
|
:<- [:profile/profile]
|
2022-09-21 14:03:06 +00:00
|
|
|
(fn [multiaccount]
|
|
|
|
(get-in multiaccount
|
2023-06-28 11:48:34 +00:00
|
|
|
[:pinned-mailservers (fleet/current-fleet-sub multiaccount)])))
|