Struct BaseClient

Source
pub struct BaseClient {
    pub room_key_recipient_strategy: CollectStrategy,
    pub decryption_trust_requirement: TrustRequirement,
    pub handle_verification_events: bool,
    /* private fields */
}
Expand description

A no (network) IO client implementation.

This client is a state machine that receives responses and events and accordingly updates its state. It is not designed to be used directly, but rather through matrix_sdk::Client.

use matrix_sdk_base::{store::StoreConfig, BaseClient};

let client = BaseClient::new(StoreConfig::new(
    "cross-process-holder-name".to_owned(),
));

Fields§

§room_key_recipient_strategy: CollectStrategy
Available on crate feature e2e-encryption only.

The strategy to use for picking recipient devices, when sending an encrypted message.

§decryption_trust_requirement: TrustRequirement
Available on crate feature e2e-encryption only.

The trust requirement to use for decrypting events.

§handle_verification_events: bool
Available on crate feature e2e-encryption only.

If the client should handle verification events received when syncing.

Implementations§

Source§

impl BaseClient

Source

pub fn new(config: StoreConfig) -> Self

Create a new client.

§Arguments
  • config - the configuration for the stores (state store, event cache store and crypto store).
Source

pub async fn clone_with_in_memory_state_store( &self, cross_process_store_locks_holder_name: &str, handle_verification_events: bool, ) -> Result<Self>

Available on crate feature e2e-encryption only.

Clones the current base client to use the same crypto store but a different, in-memory store config, and resets transient state.

Source

pub fn session_meta(&self) -> Option<&SessionMeta>

Get the session meta information.

If the client is currently logged in, this will return a SessionMeta object which contains the user ID and device ID. Otherwise it returns None.

Source

pub fn rooms(&self) -> Vec<Room>

Get all the rooms this client knows about.

Source

pub fn rooms_filtered(&self, filter: RoomStateFilter) -> Vec<Room>

Get all the rooms this client knows about, filtered by room state.

Source

pub fn rooms_stream( &self, ) -> (Vector<Room>, impl Stream<Item = Vec<VectorDiff<Room>>>)

Get a stream of all the rooms changes, in addition to the existing rooms.

Source

pub fn get_or_create_room( &self, room_id: &RoomId, room_state: RoomState, ) -> Room

Lookup the Room for the given RoomId, or create one, if it didn’t exist yet in the store

Source

pub fn state_store(&self) -> &DynStateStore

Get a reference to the state store.

Source

pub fn event_cache_store(&self) -> &EventCacheStoreLock

Get a reference to the event cache store.

Source

pub fn is_active(&self) -> bool

Check whether the client has been activated.

See BaseClient::activate to know what it means.

Source

pub async fn activate( &self, session_meta: SessionMeta, room_load_settings: RoomLoadSettings, custom_account: Option<Account>, ) -> Result<()>

Activate the client.

A client is considered active when:

  1. It has a SessionMeta (user ID, device ID and access token),
  2. Has loaded cached data from storage,
  3. If encryption is enabled, it also initialized or restored its OlmMachine.
§Arguments
  • session_meta - The meta of a session that the user already has from a previous login call.

  • custom_account - A custom matrix_sdk_crypto::vodozemac::olm::Account to be used for the identity and one-time keys of this BaseClient. If no account is provided, a new default one or one from the store will be used. If an account is provided and one already exists in the store for this UserId/DeviceId combination, an error will be raised. This is useful if one wishes to create identity keys before knowing the user/device IDs, e.g., to use the identity key as the device ID.

  • room_load_settings — Specify how many rooms must be restored; use ::default() if you don’t know which value to pick.

§Panics

This method panics if it is called twice.

Source

pub async fn regenerate_olm( &self, custom_account: Option<Account>, ) -> Result<()>

Available on crate feature e2e-encryption only.

Recreate an OlmMachine from scratch.

In particular, this will clear all its caches.

Source

pub async fn sync_token(&self) -> Option<String>

Get the current, if any, sync token of the client. This will be None if the client didn’t sync at least once.

Source

pub async fn room_knocked(&self, room_id: &RoomId) -> Result<Room>

User has knocked on a room.

Update the internal and cached state accordingly. Return the final Room.

Source

pub async fn room_joined(&self, room_id: &RoomId) -> Result<Room>

User has joined a room.

Update the internal and cached state accordingly. Return the final Room.

Source

pub async fn room_left(&self, room_id: &RoomId) -> Result<()>

User has left a room.

Update the internal and cached state accordingly.

Source

pub fn sync_lock(&self) -> &Mutex<()>

Get access to the store’s sync lock.

Source

pub async fn receive_sync_response( &self, response: Response, ) -> Result<SyncResponse>

Receive a response from a sync call.

§Arguments
  • response - The response that we received after a successful sync.
Source

pub async fn receive_sync_response_with_requested_required_states( &self, response: Response, requested_required_states: &RequestedRequiredStates, ) -> Result<SyncResponse>

Receive a response from a sync call, with the requested required state events.

§Arguments
  • response - The response that we received after a successful sync.
  • requested_required_states - The requested required state events.
Source

pub async fn receive_all_members( &self, room_id: &RoomId, request: &Request, response: &Response, ) -> Result<()>

Receive a get member events response and convert it to a deserialized MembersResponse

This client-server request must be made without filters to make sure all members are received. Otherwise, an error is returned.

§Arguments
  • room_id - The room id this response belongs to.

  • response - The raw response that was received from the server.

Source

pub async fn receive_filter_upload( &self, filter_name: &str, response: &Response, ) -> Result<()>

Receive a successful filter upload response, the filter id will be stored under the given name in the store.

The filter id can later be retrieved with the get_filter method.

§Arguments
  • filter_name - The name that should be used to persist the filter id in the store.

  • response - The successful filter upload response containing the filter id.

Source

pub async fn get_filter(&self, filter_name: &str) -> StoreResult<Option<String>>

Get the filter id of a previously uploaded filter.

Note: A filter will first need to be uploaded and persisted using receive_filter_upload.

§Arguments
  • filter_name - The name of the filter that was previously used to persist the filter.
Source

pub async fn share_room_key( &self, room_id: &RoomId, ) -> Result<Vec<Arc<ToDeviceRequest>>>

Available on crate feature e2e-encryption only.

Get a to-device request that will share a room key with users in a room.

Source

pub fn get_room(&self, room_id: &RoomId) -> Option<Room>

Get the room with the given room id.

§Arguments
  • room_id - The id of the room that should be fetched.
Source

pub async fn forget_room(&self, room_id: &RoomId) -> Result<()>

Forget the room with the given room ID.

The room will be dropped from the room list and the store.

§Arguments
  • room_id - The id of the room that should be forgotten.
Source

pub async fn olm_machine(&self) -> RwLockReadGuard<'_, Option<OlmMachine>>

Available on crate feature e2e-encryption only.

Get the olm machine.

Source

pub fn subscribe_to_ignore_user_list_changes(&self) -> Subscriber<Vec<String>>

Returns a subscriber that publishes an event every time the ignore user list changes

Source

pub fn room_info_notable_update_receiver( &self, ) -> Receiver<RoomInfoNotableUpdate>

Returns a new receiver that gets future room info notable updates.

Learn more by reading the RoomInfoNotableUpdate type.

Source§

impl BaseClient

Source

pub async fn process_sliding_sync_e2ee( &self, to_device: Option<&ToDevice>, e2ee: &E2EE, ) -> Result<Option<Vec<Raw<AnyToDeviceEvent>>>>

Available on crate feature e2e-encryption only.

Processes the E2EE-related events from the Sliding Sync response.

In addition to writes to the crypto store, this may also write into the state store, in particular it may write latest-events to the state store.

Returns whether any change happened.

Source

pub async fn process_sliding_sync<PEP: PreviousEventsProvider>( &self, response: &Response, previous_events_provider: &PEP, requested_required_states: &RequestedRequiredStates, ) -> Result<SyncResponse>

Process a response from a sliding sync call.

§Arguments
  • response - The response that we received after a successful sliding sync.
  • previous_events_provider - Timeline events prior to the current sync.

Trait Implementations§

Source§

impl Clone for BaseClient

Source§

fn clone(&self) -> BaseClient

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
Source§

impl Debug for BaseClient

Available on non-tarpaulin_include only.
Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

Source§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
Source§

fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<>
Source§

fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> AsyncTraitDeps for T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> SendOutsideWasm for T
where T: Send,

Source§

impl<T> SyncOutsideWasm for T
where T: Sync,