Type Alias dc_context_t

Source
pub type dc_context_t = Context;
Expand description

Struct representing the deltachat context.

Aliased Type§

struct dc_context_t { /* private fields */ }

Implementations

§

impl Context

pub async fn get_config(&self, key: Config) -> Result<Option<String>, Error>

Get a config key value if set, or a default value. Returns None if no value exists.

pub async fn get_config_parsed<T>( &self, key: Config, ) -> Result<Option<T>, Error>
where T: FromStr,

Returns Some(T) if a value for the given key exists (incl. default value) and was successfully parsed. Returns None if could not parse.

pub async fn get_config_int(&self, key: Config) -> Result<i32, Error>

Returns 32-bit signed integer configuration value for the given key.

pub async fn get_config_u32(&self, key: Config) -> Result<u32, Error>

Returns 32-bit unsigned integer configuration value for the given key.

pub async fn get_config_i64(&self, key: Config) -> Result<i64, Error>

Returns 64-bit signed integer configuration value for the given key.

pub async fn get_config_u64(&self, key: Config) -> Result<u64, Error>

Returns 64-bit unsigned integer configuration value for the given key.

pub async fn get_config_bool(&self, key: Config) -> Result<bool, Error>

Returns boolean configuration value for the given key.

pub async fn get_config_delete_server_after(&self) -> Result<Option<i64>, Error>

Gets configured “delete_server_after” value.

None means never delete the message, Some(0) means delete at once, Some(x) means delete after x seconds.

pub async fn get_configured_provider( &self, ) -> Result<Option<&'static Provider>, Error>

Gets the configured provider, as saved in the configured_provider value.

The provider is determined by get_provider_info() during configuration and then saved to the db in param.save_to_database(), together with all the other configured_* values.

pub async fn get_config_delete_device_after(&self) -> Result<Option<i64>, Error>

Gets configured “delete_device_after” value.

None means never delete the message, Some(x) means delete after x seconds.

pub async fn set_config( &self, key: Config, value: Option<&str>, ) -> Result<(), Error>

Set the given config key and make it effective. This may restart the IO scheduler. If None is passed as a value the value is cleared and set to the default if there is one.

pub async fn set_config_u32(&self, key: Config, value: u32) -> Result<(), Error>

Set the given config to an unsigned 32-bit integer value.

pub async fn set_config_bool( &self, key: Config, value: bool, ) -> Result<(), Error>

Set the given config to a boolean value.

pub async fn set_ui_config( &self, key: &str, value: Option<&str>, ) -> Result<(), Error>

Sets an ui-specific key-value pair. Keys must be prefixed by ui. and should be followed by the name of the system and maybe subsystem, eg. ui.desktop.linux.foo, ui.desktop.macos.bar, ui.ios.foobar.

pub async fn get_ui_config(&self, key: &str) -> Result<Option<String>, Error>

Gets an ui-specific value set by set_ui_config().

§

impl Context

pub async fn get_connectivity(&self) -> Connectivity

Get the current connectivity, i.e. whether the device is connected to the IMAP server. One of:

  • DC_CONNECTIVITY_NOT_CONNECTED (1000-1999): Show e.g. the string “Not connected” or a red dot
  • DC_CONNECTIVITY_CONNECTING (2000-2999): Show e.g. the string “Connecting…” or a yellow dot
  • DC_CONNECTIVITY_WORKING (3000-3999): Show e.g. the string “Updating…” or a spinning wheel
  • DC_CONNECTIVITY_CONNECTED (>=4000): Show e.g. the string “Connected” or a green dot

We don’t use exact values but ranges here so that we can split up states into multiple states in the future.

Meant as a rough overview that can be shown e.g. in the title of the main screen.

If the connectivity changes, a DC_EVENT_CONNECTIVITY_CHANGED will be emitted.

pub async fn get_connectivity_html(&self) -> Result<String, Error>

Get an overview of the current connectivity, and possibly more statistics. Meant to give the user more insight about the current status than the basic connectivity info returned by dc_get_connectivity(); show this e.g., if the user taps on said basic connectivity info.

If this page changes, a DC_EVENT_CONNECTIVITY_CHANGED will be emitted.

This comes as an HTML from the core so that we can easily improve it and the improvement instantly reaches all UIs.

pub async fn wait_for_all_work_done(&self)

Waits until background work is finished.

§

impl Context

pub async fn get_or_try_init_peer_channel( &self, ) -> Result<RwLockReadGuard<'_, Iroh>, Error>

Get or initialize the iroh peer channel.

§

impl Context

pub async fn get_primary_self_addr(&self) -> Result<String, Error>

Returns the primary self address. Returns an error if no self addr is configured.

§

impl Context

pub async fn get_status_update( &self, msg_id: MsgId, status_update_serial: StatusUpdateSerial, ) -> Result<String, Error>

Returns the update_item with status_update_serial from the webxdc with message id msg_id.

pub async fn send_webxdc_status_update( &self, instance_msg_id: MsgId, update_str: &str, ) -> Result<(), Error>

Sends a status update for an webxdc instance.

If the instance is a draft, the status update is sent once the instance is actually sent. Otherwise, the update is sent as soon as possible.

pub async fn send_webxdc_status_update_struct( &self, instance_msg_id: MsgId, status_update: StatusUpdateItem, ) -> Result<(), Error>

Sends a status update for an webxdc instance. Also see [Self::send_webxdc_status_update]

pub async fn get_webxdc_status_updates( &self, instance_msg_id: MsgId, last_known_serial: StatusUpdateSerial, ) -> Result<String, Error>

Returns status updates as an JSON-array, ready to be consumed by a webxdc.

Example: [{"serial":1, "max_serial":3, "payload":"any update data"}, {"serial":3, "max_serial":3, "payload":"another update data"}] Updates with serials larger than last_known_serial are returned. If no last serial is known, set last_known_serial to 0. If no updates are available, an empty JSON-array is returned.

§

impl Context

pub async fn is_configured(&self) -> Result<bool, Error>

Checks if the context is already configured.

pub async fn configure(&self) -> Result<(), Error>

Configures this account with the currently provided parameters.

Deprecated since 2025-02; use add_transport_from_qr() or add_or_update_transport() instead.

pub async fn add_or_update_transport( &self, param: &mut EnteredLoginParam, ) -> Result<(), Error>

Configures a new email account using the provided parameters and adds it as a transport.

If the email address is the same as an existing transport, then this existing account will be reconfigured instead of a new one being added.

This function stops and starts IO as needed.

Usually it will be enough to only set addr and imap.password, and all the other settings will be autoconfigured.

During configuration, ConfigureProgress events are emitted; they indicate a successful configuration as well as errors and may be used to create a progress bar. This function will return after configuration is finished.

If configuration is successful, the working server parameters will be saved and used for connecting to the server. The parameters entered by the user will be saved separately so that they can be prefilled when the user opens the server-configuration screen again.

See also:

  • [Self::is_configured()] to check whether there is at least one working transport.
  • [Self::add_transport_from_qr()] to add a transport from a server encoded in a QR code.
  • [Self::list_transports()] to get a list of all configured transports.
  • [Self::delete_transport()] to remove a transport.

pub async fn add_transport_from_qr(&self, qr: &str) -> Result<(), Error>

Adds a new email account as a transport using the server encoded in the QR code. See [Self::add_or_update_transport].

pub async fn list_transports(&self) -> Result<Vec<EnteredLoginParam>, Error>

Returns the list of all email accounts that are used as a transport in the current profile. Use [Self::add_or_update_transport()] to add or change a transport and [Self::delete_transport()] to delete a transport.

pub async fn delete_transport(&self, _addr: &str) -> Result<(), Error>

Removes the transport with the specified email address (i.e. [EnteredLoginParam::addr]).

§

impl Context

pub async fn new( dbfile: &Path, id: u32, events: Events, stock_strings: StockStrings, ) -> Result<Context, Error>

Creates new context and opens the database.

pub async fn new_closed( dbfile: &Path, id: u32, events: Events, stockstrings: StockStrings, push_subscriber: PushSubscriber, ) -> Result<Context, Error>

Creates new context without opening the database.

pub async fn open(&self, passphrase: String) -> Result<bool, Error>

Opens the database with the given passphrase.

Returns true if passphrase is correct, false is passphrase is not correct. Fails on other errors.

pub async fn change_passphrase(&self, passphrase: String) -> Result<(), Error>

Changes encrypted database passphrase.

pub async fn is_open(&self) -> bool

Returns true if database is open.

pub async fn start_io(&self)

Starts the IO scheduler.

pub async fn stop_io(&self)

Stops the IO scheduler.

pub async fn restart_io_if_running(&self)

Restarts the IO scheduler if it was running before when it is not running this is an no-op

pub async fn maybe_network(&self)

Indicate that the network likely has come back.

pub async fn is_chatmail(&self) -> Result<bool, Error>

Returns true if an account is on a chatmail server.

pub async fn background_fetch(&self) -> Result<(), Error>

Does a single round of fetching from IMAP and returns.

Can be used even if I/O is currently stopped. If I/O is currently stopped, starts a new IMAP connection and fetches from Inbox and DeltaChat folders.

pub fn get_dbfile(&self) -> &Path

Returns database file path.

pub fn get_blobdir(&self) -> &Path

Returns blob directory path.

pub fn emit_event(&self, event: EventType)

Emits a single event.

pub fn emit_msgs_changed_without_ids(&self)

Emits a generic MsgsChanged event (without chat or message id)

pub fn emit_msgs_changed(&self, chat_id: ChatId, msg_id: MsgId)

Emits a MsgsChanged event with specified chat and message ids

If IDs are unset, [Self::emit_msgs_changed_without_ids] or [Self::emit_msgs_changed_without_msg_id] should be used instead of this function.

pub fn emit_msgs_changed_without_msg_id(&self, chat_id: ChatId)

Emits a MsgsChanged event with specified chat and without message id.

pub fn emit_incoming_msg(&self, chat_id: ChatId, msg_id: MsgId)

Emits an IncomingMsg event with specified chat and message ids

pub async fn emit_location_changed( &self, contact_id: Option<ContactId>, ) -> Result<(), Error>

Emits an LocationChanged event and a WebxdcStatusUpdate in case there is a maps integration

pub fn get_event_emitter(&self) -> EventEmitter

Returns a receiver for emitted events.

Multiple emitters can be created, but note that in this case each emitted event will only be received by one of the emitters, not by all of them.

pub fn get_id(&self) -> u32

Get the ID of this context.

pub async fn stop_ongoing(&self)

Signal an ongoing process to stop.

pub async fn get_info(&self) -> Result<BTreeMap<&'static str, String>, Error>

Returns information about the context as key-value pairs.

pub async fn draft_self_report(&self) -> Result<ChatId, Error>

Drafts a message with statistics about the usage of Delta Chat. The user can inspect the message if they want, and then hit “Send”.

On the other end, a bot will receive the message and make it available to Delta Chat’s developers.

pub async fn get_fresh_msgs(&self) -> Result<Vec<MsgId>, Error>

Get a list of fresh, unmuted messages in unblocked chats.

The list starts with the most recent message and is typically used to show notifications. Moreover, the number of returned messages can be used for a badge counter on the app icon.

pub async fn get_next_msgs(&self) -> Result<Vec<MsgId>, Error>

Returns a list of messages with database ID higher than requested.

Blocked contacts and chats are excluded, but self-sent messages and contact requests are included in the results.

pub async fn wait_next_msgs(&self) -> Result<Vec<MsgId>, Error>

Returns a list of messages with database ID higher than last marked as seen.

This function is supposed to be used by bot to request messages that are not processed yet.

Waits for notification and returns a result. Note that the result may be empty if the message is deleted shortly after notification or notification is manually triggered to interrupt waiting. Notification may be manually triggered by calling [Self::stop_io].

pub async fn search_msgs( &self, chat_id: Option<ChatId>, query: &str, ) -> Result<Vec<MsgId>, Error>

Searches for messages containing the query string case-insensitively.

If chat_id is provided this searches only for messages in this chat, if chat_id is None this searches messages from all chats.

NB: Wrt the search in long messages which are shown truncated with the “Show Full Message…” button, we only look at the first several kilobytes. Let’s not fix this – one can send a dictionary in the message that matches any reasonable search request, but the user won’t see the match because they should tap on “Show Full Message…” for that. Probably such messages would only clutter search results.

pub async fn is_inbox(&self, folder_name: &str) -> Result<bool, Error>

Returns true if given folder name is the name of the inbox.

pub async fn is_sentbox(&self, folder_name: &str) -> Result<bool, Error>

Returns true if given folder name is the name of the “sent” folder.

pub async fn is_mvbox(&self, folder_name: &str) -> Result<bool, Error>

Returns true if given folder name is the name of the “DeltaChat” folder.

pub async fn is_trash(&self, folder_name: &str) -> Result<bool, Error>

Returns true if given folder name is the name of the trash folder.

§

impl Context

pub async fn push_state(&self) -> NotifyState

Returns push notification subscriber state.

§

impl Context

pub async fn send_sync_msg(&self) -> Result<Option<MsgId>, Error>

Sends out a self-sent message with items to be synchronized, if any.

Mustn’t be called from multiple tasks in parallel to avoid sending the same sync items twice because sync items are removed from the db only after successful sending. We guarantee this by calling send_sync_msg() only from the inbox loop.

§

impl Context

pub fn set_last_error(&self, error: &str)

Set last error string. Implemented as blocking as used from macros in different, not always async blocks.

pub fn get_last_error(&self) -> String

Get last error string.

§

impl Context

pub async fn set_stock_translation( &self, id: StockMessage, stockstring: String, ) -> Result<(), Error>

Set the stock string for the [StockMessage].

§

impl Context

pub async fn set_webxdc_integration(&self, file: &str) -> Result<(), Error>

Sets Webxdc file as integration. file is the .xdc to use as Webxdc integration.

pub async fn init_webxdc_integration( &self, integrate_for: Option<ChatId>, ) -> Result<Option<MsgId>, Error>

Returns Webxdc instance used for optional integrations. UI can open the Webxdc as usual. Returns None if there is no integration; the caller can add one using set_webxdc_integration then. integrate_for is the chat to get the integration for.

Trait Implementations

§

impl Clone for Context

§

fn clone(&self) -> Context

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Context

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Deref for Context

§

type Target = InnerContext

The resulting type after dereferencing.
§

fn deref(&self) -> &<Context as Deref>::Target

Dereferences the value.