pub struct Accounts {
dir: PathBuf,
config: Config,
accounts: BTreeMap<u32, Context>,
events: Events,
pub(crate) stockstrings: StockStrings,
push_subscriber: PushSubscriber,
}
Expand description
Account manager, that can handle multiple accounts in a single place.
Fields§
§dir: PathBuf
§config: Config
§accounts: BTreeMap<u32, Context>
Map from account ID to the account.
events: Events
Event channel to emit account manager errors.
stockstrings: StockStrings
Stock string translations shared by all created contexts.
This way changing a translation for one context automatically changes it for all other contexts.
push_subscriber: PushSubscriber
Push notification subscriber shared between accounts.
Implementations§
source§impl Accounts
impl Accounts
sourcepub async fn set_stock_translation(
&self,
id: StockMessage,
stockstring: String,
) -> Result<()>
pub async fn set_stock_translation( &self, id: StockMessage, stockstring: String, ) -> Result<()>
Set the stock string for the StockMessage.
source§impl Accounts
impl Accounts
sourcepub async fn new(dir: PathBuf, writable: bool) -> Result<Self>
pub async fn new(dir: PathBuf, writable: bool) -> Result<Self>
Loads or creates an accounts folder at the given dir
.
sourceasync fn open(dir: PathBuf, writable: bool) -> Result<Self>
async fn open(dir: PathBuf, writable: bool) -> Result<Self>
Opens an existing accounts structure. Will error if the folder doesn’t exist, no account exists and no config exists.
sourcepub fn get_account(&self, id: u32) -> Option<Context>
pub fn get_account(&self, id: u32) -> Option<Context>
Returns an account by its id
:
sourcepub fn get_selected_account(&self) -> Option<Context>
pub fn get_selected_account(&self) -> Option<Context>
Returns the currently selected account.
sourcepub fn get_selected_account_id(&self) -> Option<u32>
pub fn get_selected_account_id(&self) -> Option<u32>
Returns the currently selected account’s id or None if no account is selected.
sourcepub async fn select_account(&mut self, id: u32) -> Result<()>
pub async fn select_account(&mut self, id: u32) -> Result<()>
Selects the given account.
sourcepub async fn add_account(&mut self) -> Result<u32>
pub async fn add_account(&mut self) -> Result<u32>
Adds a new account and opens it.
Returns account ID.
sourcepub async fn add_closed_account(&mut self) -> Result<u32>
pub async fn add_closed_account(&mut self) -> Result<u32>
Adds a new closed account.
sourcepub async fn remove_account(&mut self, id: u32) -> Result<()>
pub async fn remove_account(&mut self, id: u32) -> Result<()>
Removes an account.
sourcepub async fn migrate_account(&mut self, dbfile: PathBuf) -> Result<u32>
pub async fn migrate_account(&mut self, dbfile: PathBuf) -> Result<u32>
Migrates an existing account into this structure.
Returns the ID of new account.
sourcepub async fn start_io(&mut self)
pub async fn start_io(&mut self)
Starts background tasks such as IMAP and SMTP loops for all accounts.
sourcepub async fn maybe_network(&self)
pub async fn maybe_network(&self)
Notifies all accounts that the network may have become available.
sourcepub async fn maybe_network_lost(&self)
pub async fn maybe_network_lost(&self)
Notifies all accounts that the network connection may have been lost.
sourceasync fn background_fetch_no_timeout(accounts: Vec<Context>, events: Events)
async fn background_fetch_no_timeout(accounts: Vec<Context>, events: Events)
Performs a background fetch for all accounts in parallel.
This is an auxiliary function and not part of public API. Use Accounts::background_fetch instead.
sourceasync fn background_fetch_with_timeout(
accounts: Vec<Context>,
events: Events,
timeout: Duration,
)
async fn background_fetch_with_timeout( accounts: Vec<Context>, events: Events, timeout: Duration, )
Auxiliary function for Accounts::background_fetch.
sourcepub fn background_fetch(&self, timeout: Duration) -> impl Future<Output = ()>
pub fn background_fetch(&self, timeout: Duration) -> impl Future<Output = ()>
Performs a background fetch for all accounts in parallel with a timeout.
The AccountsBackgroundFetchDone
event is emitted at the end,
process all events until you get this one and you can safely return to the background
without forgetting to create notifications caused by timing race conditions.
Returns a future that resolves when background fetch is done,
but does not capture &self
.
sourcepub fn emit_event(&self, event: EventType)
pub fn emit_event(&self, event: EventType)
Emits a single event.
sourcepub fn get_event_emitter(&self) -> EventEmitter
pub fn get_event_emitter(&self) -> EventEmitter
Returns event emitter.
sourcepub async fn set_push_device_token(&self, token: &str) -> Result<()>
pub async fn set_push_device_token(&self, token: &str) -> Result<()>
Sets notification token for Apple Push Notification service.