Struct matrix_sdk_base::BaseClient
source · [−]pub struct BaseClient { /* private fields */ }
Expand description
A no IO Client implementation.
This Client is a state machine that receives responses and events and accordingly updates its state.
Implementations
sourceimpl BaseClient
impl BaseClient
sourcepub fn with_store_config(config: StoreConfig) -> Self
pub fn with_store_config(config: StoreConfig) -> Self
Create a new client.
Arguments
config
- An optional session if the user already has one from a previous login call.
sourcepub fn session(&self) -> &Arc<RwLock<Option<Session>>>
pub fn session(&self) -> &Arc<RwLock<Option<Session>>>
The current client session containing our user id, device id and access token.
sourcepub async fn receive_login_response(&self, response: &Response) -> Result<()>
pub async fn receive_login_response(&self, response: &Response) -> Result<()>
Receive a login response and update the session of the client.
Arguments
response
- A successful login response that contains our access token and device id.
sourcepub async fn restore_login(&self, session: Session) -> Result<()>
pub async fn restore_login(&self, session: Session) -> Result<()>
Restore a previously logged in session.
Arguments
session
- An session that the user already has from a previous login call.
sourcepub async fn sync_token(&self) -> Option<String>
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.
sourcepub async fn receive_sync_response(
&self,
response: Response
) -> Result<SyncResponse>
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.
sourcepub async fn receive_messages(
&self,
room_id: &RoomId,
timeline: TimelineSlice
) -> Result<()>
Available on crate feature experimental-timeline
only.
pub async fn receive_messages(
&self,
room_id: &RoomId,
timeline: TimelineSlice
) -> Result<()>
experimental-timeline
only.Receive a timeline slice obtained from a messages request.
You should pass only slices requested from the store to this function.
timeline
- TheTimelineSlice
sourcepub async fn receive_members(
&self,
room_id: &RoomId,
response: &Response
) -> Result<MembersResponse>
pub async fn receive_members(
&self,
room_id: &RoomId,
response: &Response
) -> Result<MembersResponse>
Receive a get member events response and convert it to a deserialized
MembersResponse
Arguments
-
room_id
- The room id this response belongs to. -
response
- The raw response that was received from the server.
sourcepub async fn receive_filter_upload(
&self,
filter_name: &str,
response: &Response
) -> Result<()>
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.
sourcepub async fn get_filter(&self, filter_name: &str) -> StoreResult<Option<String>>
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.
sourcepub async fn outgoing_requests(
&self
) -> Result<Vec<OutgoingRequest>, CryptoStoreError>
Available on crate feature e2e-encryption
only.
pub async fn outgoing_requests(
&self
) -> Result<Vec<OutgoingRequest>, CryptoStoreError>
e2e-encryption
only.Get the outgoing requests that need to be sent out.
This returns a list of OutGoingRequest
, those requests need to be sent
out to the server and the responses need to be passed back to the state
machine using mark_request_as_sent
.
sourcepub async fn mark_request_as_sent<'a>(
&self,
request_id: &TransactionId,
response: impl Into<IncomingResponse<'a>>
) -> Result<()>
Available on crate feature e2e-encryption
only.
pub async fn mark_request_as_sent<'a>(
&self,
request_id: &TransactionId,
response: impl Into<IncomingResponse<'a>>
) -> Result<()>
e2e-encryption
only.Mark the request with the given request id as sent.
Arguments
-
request_id
- The unique id of the request that was sent out. This is needed to couple the response with the now sent out request. -
response
- The response that was received from the server after the outgoing request was sent out.
sourcepub async fn get_missing_sessions(
&self,
users: impl Iterator<Item = &UserId>
) -> Result<Option<(OwnedTransactionId, KeysClaimRequest)>>
Available on crate feature e2e-encryption
only.
pub async fn get_missing_sessions(
&self,
users: impl Iterator<Item = &UserId>
) -> Result<Option<(OwnedTransactionId, KeysClaimRequest)>>
e2e-encryption
only.Get a tuple of device and one-time keys that need to be uploaded.
Returns an empty error if no keys need to be uploaded.
Available on crate feature e2e-encryption
only.
e2e-encryption
only.Get a to-device request that will share a group session for a room.
sourcepub async fn encrypt(
&self,
room_id: &RoomId,
content: impl MessageLikeEventContent
) -> Result<RoomEncryptedEventContent>
Available on crate feature e2e-encryption
only.
pub async fn encrypt(
&self,
room_id: &RoomId,
content: impl MessageLikeEventContent
) -> Result<RoomEncryptedEventContent>
e2e-encryption
only.Encrypt a message event content.
sourcepub async fn invalidate_group_session(
&self,
room_id: &RoomId
) -> Result<bool, CryptoStoreError>
Available on crate feature e2e-encryption
only.
pub async fn invalidate_group_session(
&self,
room_id: &RoomId
) -> Result<bool, CryptoStoreError>
e2e-encryption
only.Invalidate the currently active outbound group session for the given room.
Returns true if a session was invalidated, false if there was no session to invalidate.
sourcepub async fn get_device(
&self,
user_id: &UserId,
device_id: &DeviceId
) -> Result<Option<Device>, CryptoStoreError>
Available on crate feature e2e-encryption
only.
pub async fn get_device(
&self,
user_id: &UserId,
device_id: &DeviceId
) -> Result<Option<Device>, CryptoStoreError>
e2e-encryption
only.Get a specific device of a user.
Arguments
-
user_id
- The unique id of the user that the device belongs to. -
device_id
- The unique id of the device.
Returns a Device
if one is found and the crypto store didn’t throw an
error.
This will always return None if the client hasn’t been logged in.
Example
let device = client.get_device(&alice, device_id!("DEVICEID")).await;
println!("{:?}", device);
sourcepub async fn get_session(&self) -> Option<Session>
pub async fn get_session(&self) -> Option<Session>
Get the user login session.
If the client is currently logged in, this will return a
matrix_sdk::Session
object which can later be given to
restore_login
.
Returns a session object if the client is logged in. Otherwise returns
None
.
sourcepub async fn get_user_devices(
&self,
user_id: &UserId
) -> Result<UserDevices, CryptoStoreError>
Available on crate feature e2e-encryption
only.
pub async fn get_user_devices(
&self,
user_id: &UserId
) -> Result<UserDevices, CryptoStoreError>
e2e-encryption
only.Get a map holding all the devices of an user.
This will always return an empty map if the client hasn’t been logged in.
Arguments
user_id
- The unique id of the user that the devices belong to.
Panics
Panics if the client hasn’t been logged in and the crypto layer thus hasn’t been initialized.
Example
let devices = client.get_user_devices(alice).await.unwrap();
for device in devices.devices() {
println!("{:?}", device);
}
sourcepub async fn olm_machine(&self) -> Option<OlmMachine>
Available on crate feature e2e-encryption
only.
pub async fn olm_machine(&self) -> Option<OlmMachine>
e2e-encryption
only.Get the olm machine.
sourcepub async fn get_push_rules(&self, changes: &StateChanges) -> Result<Ruleset>
pub async fn get_push_rules(&self, changes: &StateChanges) -> Result<Ruleset>
Get the push rules.
Gets the push rules from changes
if they have been updated, otherwise
get them from the store. As a fallback, uses
Ruleset::server_default
if the user is logged in.
sourcepub async fn get_push_room_context(
&self,
room: &Room,
room_info: &RoomInfo,
changes: &StateChanges
) -> Result<Option<PushConditionRoomCtx>>
pub async fn get_push_room_context(
&self,
room: &Room,
room_info: &RoomInfo,
changes: &StateChanges
) -> Result<Option<PushConditionRoomCtx>>
Get the push context for the given room.
Tries to get the data from changes
or the up to date room_info
.
Loads the data from the store otherwise.
Returns None
if some data couldn’t be found. This should only happen
in brand new rooms, while we process its state.
sourcepub async fn update_push_room_context(
&self,
push_rules: &mut PushConditionRoomCtx,
user_id: &UserId,
room_info: &RoomInfo,
changes: &StateChanges
)
pub async fn update_push_room_context(
&self,
push_rules: &mut PushConditionRoomCtx,
user_id: &UserId,
room_info: &RoomInfo,
changes: &StateChanges
)
Update the push context for the given room.
Updates the context data from changes
or room_info
.
Trait Implementations
sourceimpl Clone for BaseClient
impl Clone for BaseClient
sourcefn clone(&self) -> BaseClient
fn clone(&self) -> BaseClient
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for BaseClient
Available on non-tarpaulin_include
only.
impl Debug for BaseClient
tarpaulin_include
only.Auto Trait Implementations
impl !RefUnwindSafe for BaseClient
impl Send for BaseClient
impl Sync for BaseClient
impl Unpin for BaseClient
impl !UnwindSafe for BaseClient
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more