mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-12 10:00:50 -04:00
Don't use block_on in no_run doctests
… and clean up formatting around the affected ones.
This commit is contained in:
committed by
Jonas Platte
parent
63257e6226
commit
f12e827a67
@@ -75,19 +75,19 @@ pub enum KeyExportError {
|
||||
///
|
||||
/// * `passphrase` - The passphrase that was used to encrypt the exported keys.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use std::io::Cursor;
|
||||
/// # use matrix_sdk_crypto::{OlmMachine, decrypt_room_key_export};
|
||||
/// # use ruma::{device_id, user_id};
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID")).await;
|
||||
/// # let export = Cursor::new("".to_owned());
|
||||
/// let exported_keys = decrypt_room_key_export(export, "1234").unwrap();
|
||||
/// machine.import_room_keys(exported_keys, false, |_, _| {}).await.unwrap();
|
||||
/// # });
|
||||
/// # };
|
||||
/// ```
|
||||
pub fn decrypt_room_key_export(
|
||||
mut input: impl Read,
|
||||
@@ -133,18 +133,18 @@ pub fn decrypt_room_key_export(
|
||||
/// This method will panic if it can't get enough randomness from the OS to
|
||||
/// encrypt the exported keys securely.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk_crypto::{OlmMachine, encrypt_room_key_export};
|
||||
/// # use ruma::{device_id, user_id, room_id};
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID")).await;
|
||||
/// let room_id = room_id!("!test:localhost");
|
||||
/// let exported_keys = machine.export_room_keys(|s| s.room_id() == room_id).await.unwrap();
|
||||
/// let encrypted_export = encrypt_room_key_export(&exported_keys, "1234", 1);
|
||||
/// # });
|
||||
/// # };
|
||||
/// ```
|
||||
pub fn encrypt_room_key_export(
|
||||
keys: &[ExportedRoomKey],
|
||||
|
||||
@@ -1509,19 +1509,19 @@ impl OlmMachine {
|
||||
/// were imported and the total number of sessions that were found in the
|
||||
/// key export.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use std::io::Cursor;
|
||||
/// # use matrix_sdk_crypto::{OlmMachine, decrypt_room_key_export};
|
||||
/// # use ruma::{device_id, user_id};
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID")).await;
|
||||
/// # let export = Cursor::new("".to_owned());
|
||||
/// let exported_keys = decrypt_room_key_export(export, "1234").unwrap();
|
||||
/// machine.import_room_keys(exported_keys, false, |_, _| {}).await.unwrap();
|
||||
/// # });
|
||||
/// # };
|
||||
/// ```
|
||||
pub async fn import_room_keys(
|
||||
&self,
|
||||
@@ -1610,19 +1610,18 @@ impl OlmMachine {
|
||||
/// This method will panic if it can't get enough randomness from the OS to
|
||||
/// encrypt the exported keys securely.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk_crypto::{OlmMachine, encrypt_room_key_export};
|
||||
/// # use ruma::{device_id, user_id, room_id};
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID")).await;
|
||||
/// let room_id = room_id!("!test:localhost");
|
||||
/// let exported_keys = machine.export_room_keys(|s| s.room_id() == room_id).await.unwrap();
|
||||
/// let encrypted_export = encrypt_room_key_export(&exported_keys, "1234", 1);
|
||||
/// # });
|
||||
/// # };
|
||||
/// ```
|
||||
pub async fn export_room_keys(
|
||||
&self,
|
||||
|
||||
@@ -687,15 +687,15 @@ impl Sas {
|
||||
/// │ Done │
|
||||
/// └───────┘
|
||||
/// ```
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// use futures::stream::{Stream, StreamExt};
|
||||
/// use matrix_sdk_crypto::{Sas, SasState};
|
||||
///
|
||||
/// # futures::executor::block_on(async {
|
||||
/// # async {
|
||||
/// # let sas: Sas = unimplemented!();
|
||||
///
|
||||
/// let mut stream = sas.changes();
|
||||
///
|
||||
/// while let Some(state) = stream.next().await {
|
||||
@@ -731,7 +731,7 @@ impl Sas {
|
||||
/// | SasState::Confirmed => (),
|
||||
/// }
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub fn changes(&self) -> impl Stream<Item = SasState> {
|
||||
self.inner.subscribe().map(|s| (&s).into())
|
||||
|
||||
@@ -67,11 +67,11 @@ impl Account {
|
||||
/// Get the display name of the account.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// let user = "example";
|
||||
/// let client = Client::new(homeserver).await?;
|
||||
@@ -80,7 +80,7 @@ impl Account {
|
||||
/// if let Some(name) = client.account().get_display_name().await? {
|
||||
/// println!("Logged in as user '{user}' with display name '{name}'");
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn get_display_name(&self) -> Result<Option<String>> {
|
||||
let user_id = self.client.user_id().ok_or(Error::AuthenticationRequired)?;
|
||||
@@ -93,18 +93,18 @@ impl Account {
|
||||
/// Set the display name of the account.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// let user = "example";
|
||||
/// let client = Client::new(homeserver).await?;
|
||||
/// client.login_username(user, "password").send().await?;
|
||||
///
|
||||
/// client.account().set_display_name(Some("Alice")).await?;
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn set_display_name(&self, name: Option<&str>) -> Result<()> {
|
||||
let user_id = self.client.user_id().ok_or(Error::AuthenticationRequired)?;
|
||||
@@ -117,11 +117,11 @@ impl Account {
|
||||
/// Get the MXC URI of the account's avatar, if set.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let user = "example";
|
||||
/// let client = Client::new(homeserver).await?;
|
||||
@@ -130,7 +130,7 @@ impl Account {
|
||||
/// if let Some(url) = client.account().get_avatar_url().await? {
|
||||
/// println!("Your avatar's mxc url is {url}");
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn get_avatar_url(&self) -> Result<Option<OwnedMxcUri>> {
|
||||
let user_id = self.client.user_id().ok_or(Error::AuthenticationRequired)?;
|
||||
@@ -188,13 +188,13 @@ impl Account {
|
||||
/// * `format` - The desired format of the avatar.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use matrix_sdk::ruma::room_id;
|
||||
/// # use matrix_sdk::media::MediaFormat;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let user = "example";
|
||||
/// let client = Client::new(homeserver).await?;
|
||||
@@ -204,7 +204,7 @@ impl Account {
|
||||
/// {
|
||||
/// std::fs::write("avatar.png", avatar);
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn get_avatar(&self, format: MediaFormat) -> Result<Option<Vec<u8>>> {
|
||||
if let Some(url) = self.get_avatar_url().await? {
|
||||
@@ -227,18 +227,18 @@ impl Account {
|
||||
/// Returns the MXC URI of the uploaded avatar.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use std::fs;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// let image = fs::read("/home/example/selfie.jpg")?;
|
||||
///
|
||||
/// client.account().upload_avatar(&mime::IMAGE_JPEG, image).await?;
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [`Media::upload()`]: crate::Media::upload
|
||||
@@ -253,11 +253,11 @@ impl Account {
|
||||
/// Allows to get both the display name and avatar URL in a single call.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// let profile = client.account().get_profile().await?;
|
||||
@@ -265,7 +265,7 @@ impl Account {
|
||||
/// "You are '{:?}' with avatar '{:?}'",
|
||||
/// profile.displayname, profile.avatar_url
|
||||
/// );
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn get_profile(&self) -> Result<get_profile::v3::Response> {
|
||||
let user_id = self.client.user_id().ok_or(Error::AuthenticationRequired)?;
|
||||
@@ -293,6 +293,7 @@ impl Account {
|
||||
/// the strength requirements in the error's message.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use matrix_sdk::ruma::{
|
||||
@@ -302,16 +303,15 @@ impl Account {
|
||||
/// # },
|
||||
/// # assign,
|
||||
/// # };
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// client.account().change_password(
|
||||
/// "myverysecretpassword",
|
||||
/// Some(AuthData::Dummy(Dummy::new())),
|
||||
/// ).await?;
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
/// [uiaa]: https://spec.matrix.org/v1.2/client-server-api/#user-interactive-authentication-api
|
||||
/// [`UiaaResponse`]: ruma::api::client::uiaa::UiaaResponse
|
||||
@@ -341,6 +341,7 @@ impl Account {
|
||||
/// made but this time with some `auth_data` provided.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use matrix_sdk::ruma::{
|
||||
@@ -350,17 +351,15 @@ impl Account {
|
||||
/// # },
|
||||
/// # assign,
|
||||
/// # };
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// # let account = client.account();
|
||||
/// let response = account.deactivate(None, None).await;
|
||||
///
|
||||
/// // Proceed with UIAA.
|
||||
///
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
/// [3pid]: https://spec.matrix.org/v1.2/appendices/#3pid-types
|
||||
/// [uiaa]: https://spec.matrix.org/v1.2/client-server-api/#user-interactive-authentication-api
|
||||
@@ -384,11 +383,11 @@ impl Account {
|
||||
/// during sensitive operations.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// let threepids = client.account().get_3pids().await?.threepids;
|
||||
@@ -399,7 +398,7 @@ impl Account {
|
||||
/// threepid.address, threepid.medium
|
||||
/// );
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
/// [3pid]: https://spec.matrix.org/v1.2/appendices/#3pid-types
|
||||
pub async fn get_3pids(&self) -> Result<get_3pids::v3::Response> {
|
||||
@@ -439,12 +438,12 @@ impl Account {
|
||||
/// [`ErrorKind::ThreepidDenied`] error if it is denied.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use matrix_sdk::ruma::{ClientSecret, uint};
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// # let account = client.account();
|
||||
@@ -460,8 +459,7 @@ impl Account {
|
||||
/// account.add_3pid(&secret, &token_response.sid, None).await;
|
||||
///
|
||||
/// // Proceed with UIAA.
|
||||
///
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
/// [3pid]: https://spec.matrix.org/v1.2/appendices/#3pid-types
|
||||
/// [`ErrorKind::ThreepidInUse`]: ruma::api::client::error::ErrorKind::ThreepidInUse
|
||||
@@ -515,12 +513,12 @@ impl Account {
|
||||
/// [`ErrorKind::ThreepidDenied`] error if it is denied.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use matrix_sdk::ruma::{ClientSecret, uint};
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// # let account = client.account();
|
||||
@@ -536,8 +534,7 @@ impl Account {
|
||||
/// account.add_3pid(&secret, &token_response.sid, None).await;
|
||||
///
|
||||
/// // Proceed with UIAA.
|
||||
///
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
/// [3pid]: https://spec.matrix.org/v1.2/appendices/#3pid-types
|
||||
/// [`ErrorKind::ThreepidInUse`]: ruma::api::client::error::ErrorKind::ThreepidInUse
|
||||
@@ -624,28 +621,27 @@ impl Account {
|
||||
/// to an identity server in the first place.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use matrix_sdk::ruma::thirdparty::Medium;
|
||||
/// # use matrix_sdk::ruma::api::client::account::ThirdPartyIdRemovalStatus;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// # let account = client.account();
|
||||
/// match account
|
||||
/// .delete_3pid("paul@matrix.org", Medium::Email, None)
|
||||
/// .await?
|
||||
/// .id_server_unbind_result
|
||||
/// {
|
||||
/// ThirdPartyIdRemovalStatus::Success => {
|
||||
/// println!("3PID unbound from the Identity Server");
|
||||
/// }
|
||||
/// _ => println!("Could not unbind 3PID from the Identity Server"),
|
||||
/// .delete_3pid("paul@matrix.org", Medium::Email, None)
|
||||
/// .await?
|
||||
/// .id_server_unbind_result
|
||||
/// {
|
||||
/// ThirdPartyIdRemovalStatus::Success => {
|
||||
/// println!("3PID unbound from the Identity Server");
|
||||
/// }
|
||||
///
|
||||
/// # anyhow::Ok(()) });
|
||||
/// _ => println!("Could not unbind 3PID from the Identity Server"),
|
||||
/// }
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
/// [3pid]: https://spec.matrix.org/v1.2/appendices/#3pid-types
|
||||
/// [`ThirdPartyIdRemovalStatus::Success`]: ruma::api::client::account::ThirdPartyIdRemovalStatus::Success
|
||||
|
||||
@@ -301,8 +301,8 @@ impl Default for AttachmentConfig {
|
||||
/// use mime;
|
||||
/// # use matrix_sdk::{Client, ruma::room_id };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// #
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = Client::new(homeserver).await?;
|
||||
/// # let room_id = room_id!("!test:localhost");
|
||||
@@ -327,7 +327,7 @@ impl Default for AttachmentConfig {
|
||||
/// )
|
||||
/// .await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
#[cfg(feature = "image-proc")]
|
||||
pub fn generate_image_thumbnail<R: BufRead + Seek>(
|
||||
|
||||
@@ -199,14 +199,10 @@ impl ClientBuilder {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # futures::executor::block_on(async {
|
||||
/// ```no_run
|
||||
/// use matrix_sdk::Client;
|
||||
///
|
||||
/// let client_config = Client::builder().proxy("http://localhost:8080");
|
||||
///
|
||||
/// # anyhow::Ok(())
|
||||
/// # });
|
||||
/// ```
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn proxy(mut self, proxy: impl AsRef<str>) -> Self {
|
||||
|
||||
@@ -240,11 +240,11 @@ impl Client {
|
||||
/// homeserver.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// let client = Client::new(homeserver).await?;
|
||||
///
|
||||
@@ -253,8 +253,7 @@ impl Client {
|
||||
/// if capabilities.change_password.enabled {
|
||||
/// // Change password
|
||||
/// }
|
||||
///
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn get_capabilities(&self) -> HttpResult<Capabilities> {
|
||||
let res = self.send(get_capabilities::v3::Request::new(), None).await?;
|
||||
@@ -428,12 +427,10 @@ impl Client {
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # fn persist_session(_: Option<matrix_sdk::Session>) {};
|
||||
/// # async {
|
||||
/// use futures_util::StreamExt;
|
||||
/// use matrix_sdk::Client;
|
||||
/// # use matrix_sdk::Session;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # fn persist_session(_: Option<Session>) {};
|
||||
///
|
||||
/// let homeserver = "http://example.com";
|
||||
/// let client = Client::builder()
|
||||
@@ -460,8 +457,7 @@ impl Client {
|
||||
/// });
|
||||
///
|
||||
/// tokio::spawn(future);
|
||||
///
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [refreshing access tokens]: https://spec.matrix.org/v1.3/client-server-api/#refreshing-access-tokens
|
||||
@@ -480,13 +476,11 @@ impl Client {
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// use futures::StreamExt;
|
||||
/// use futures_util::StreamExt;
|
||||
/// use matrix_sdk::Client;
|
||||
/// # use matrix_sdk::Session;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # fn persist_session(_: &Session) {};
|
||||
///
|
||||
/// # async {
|
||||
/// let homeserver = "http://example.com";
|
||||
/// let client = Client::builder()
|
||||
/// .homeserver_url(homeserver)
|
||||
@@ -517,8 +511,7 @@ impl Client {
|
||||
/// persist_session(&session);
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [refreshing access tokens]: https://spec.matrix.org/v1.3/client-server-api/#refreshing-access-tokens
|
||||
@@ -615,7 +608,7 @@ impl Client {
|
||||
/// # .build()
|
||||
/// # .await
|
||||
/// # .unwrap();
|
||||
///
|
||||
/// #
|
||||
/// client.add_event_handler(
|
||||
/// |ev: SyncRoomMessageEvent, room: Room, client: Client| async move {
|
||||
/// // Common usage: Room event plus room and client.
|
||||
@@ -1071,11 +1064,12 @@ impl Client {
|
||||
/// * `data` - The additional data which should be attached to the login
|
||||
/// request.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// use matrix_sdk::Client;
|
||||
///
|
||||
/// let client = Client::new(homeserver).await?;
|
||||
@@ -1095,7 +1089,7 @@ impl Client {
|
||||
/// "Logged in as {user}, got device_id {} and access_token {}",
|
||||
/// response.device_id, response.access_token,
|
||||
/// );
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub fn login_custom(
|
||||
&self,
|
||||
@@ -1129,12 +1123,11 @@ impl Client {
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use matrix_sdk::ruma::{assign, DeviceId};
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # let homeserver = Url::parse("https://example.com").unwrap();
|
||||
/// # let redirect_url = "http://localhost:1234";
|
||||
/// # let login_token = "token";
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// let client = Client::new(homeserver).await.unwrap();
|
||||
/// let sso_url = client.get_sso_login_url(redirect_url, None);
|
||||
///
|
||||
@@ -1151,7 +1144,7 @@ impl Client {
|
||||
/// "Logged in as {}, got device_id {} and access_token {}",
|
||||
/// response.user_id, response.device_id, response.access_token,
|
||||
/// );
|
||||
/// # })
|
||||
/// # };
|
||||
/// ```
|
||||
///
|
||||
/// [`get_sso_login_url`]: #method.get_sso_login_url
|
||||
@@ -1192,10 +1185,9 @@ impl Client {
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # let homeserver = Url::parse("https://example.com").unwrap();
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// let client = Client::new(homeserver).await.unwrap();
|
||||
///
|
||||
/// let response = client
|
||||
@@ -1211,7 +1203,7 @@ impl Client {
|
||||
/// "Logged in as {}, got device_id {} and access_token {}",
|
||||
/// response.user_id, response.device_id, response.access_token
|
||||
/// );
|
||||
/// # })
|
||||
/// # };
|
||||
/// ```
|
||||
///
|
||||
/// [`get_sso_login_url`]: #method.get_sso_login_url
|
||||
@@ -1267,8 +1259,7 @@ impl Client {
|
||||
/// Client, Session,
|
||||
/// };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
///
|
||||
/// let homeserver = Url::parse("http://example.com")?;
|
||||
/// let client = Client::new(homeserver).await?;
|
||||
@@ -1281,7 +1272,7 @@ impl Client {
|
||||
/// };
|
||||
///
|
||||
/// client.restore_session(session).await?;
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// The `Session` object can also be created from the response the
|
||||
@@ -1290,8 +1281,7 @@ impl Client {
|
||||
/// ```no_run
|
||||
/// use matrix_sdk::{Client, Session};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
///
|
||||
/// let homeserver = Url::parse("http://example.com")?;
|
||||
/// let client = Client::new(homeserver).await?;
|
||||
@@ -1301,7 +1291,7 @@ impl Client {
|
||||
///
|
||||
/// // Persist the `Session` so it can later be used to restore the login.
|
||||
/// client.restore_session(session).await?;
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [`login`]: #method.login
|
||||
@@ -1357,8 +1347,7 @@ impl Client {
|
||||
/// ```no_run
|
||||
/// use matrix_sdk::{Client, Error, Session};
|
||||
/// use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # fn get_credentials() -> (&'static str, &'static str) { ("", "") };
|
||||
/// # fn persist_session(_: Option<Session>) {};
|
||||
///
|
||||
@@ -1395,8 +1384,7 @@ impl Client {
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
///
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [refreshing access tokens]: https://spec.matrix.org/v1.3/client-server-api/#refreshing-access-tokens
|
||||
@@ -1479,10 +1467,9 @@ impl Client {
|
||||
/// # },
|
||||
/// # DeviceId,
|
||||
/// # };
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
///
|
||||
/// let mut request = RegistrationRequest::new();
|
||||
/// request.username = Some("user".to_owned());
|
||||
@@ -1493,7 +1480,7 @@ impl Client {
|
||||
///
|
||||
/// let client = Client::new(homeserver).await.unwrap();
|
||||
/// client.register(request).await;
|
||||
/// # })
|
||||
/// # };
|
||||
/// ```
|
||||
#[instrument(skip_all)]
|
||||
pub async fn register(
|
||||
@@ -1537,9 +1524,8 @@ impl Client {
|
||||
/// # sync::sync_events::v3::Filter,
|
||||
/// # }
|
||||
/// # };
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # let client = Client::new(homeserver).await.unwrap();
|
||||
/// let mut filter = FilterDefinition::default();
|
||||
@@ -1557,7 +1543,7 @@ impl Client {
|
||||
/// .filter(Filter::FilterId(filter_id));
|
||||
///
|
||||
/// let response = client.sync_once(sync_settings).await.unwrap();
|
||||
/// # });
|
||||
/// # };
|
||||
#[instrument(skip(self, definition))]
|
||||
pub async fn get_or_upload_filter(
|
||||
&self,
|
||||
@@ -1638,13 +1624,11 @@ impl Client {
|
||||
/// # let limit = Some(10);
|
||||
/// # let since = Some("since token");
|
||||
/// # let server = Some("servername.com".try_into().unwrap());
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
///
|
||||
/// # async {
|
||||
/// let mut client = Client::new(homeserver).await.unwrap();
|
||||
///
|
||||
/// client.public_rooms(limit, since, server).await;
|
||||
/// # });
|
||||
/// # };
|
||||
/// ```
|
||||
#[cfg_attr(not(target_arch = "wasm32"), deny(clippy::future_not_send))]
|
||||
pub async fn public_rooms(
|
||||
@@ -1676,23 +1660,23 @@ impl Client {
|
||||
/// one user is invited, the room will be automatically added to the direct
|
||||
/// rooms in the account data.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// use matrix_sdk::Client;
|
||||
///
|
||||
/// # use matrix_sdk::ruma::api::client::room::{
|
||||
/// # create_room::v3::Request as CreateRoomRequest,
|
||||
/// # Visibility,
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
///
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// #
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// let request = CreateRoomRequest::new();
|
||||
/// let client = Client::new(homeserver).await.unwrap();
|
||||
/// assert!(client.create_room(request).await.is_ok());
|
||||
/// # });
|
||||
/// # };
|
||||
/// ```
|
||||
pub async fn create_room(&self, request: create_room::v3::Request) -> Result<room::Joined> {
|
||||
let invite = request.invite.clone();
|
||||
@@ -1737,13 +1721,12 @@ impl Client {
|
||||
/// * `room_search` - The easiest way to create this request is using the
|
||||
/// `get_public_rooms_filtered::Request` itself.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use url::Url;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// use matrix_sdk::ruma::{
|
||||
/// api::client::directory::get_public_rooms_filtered, directory::Filter,
|
||||
@@ -1758,9 +1741,9 @@ impl Client {
|
||||
/// let response = client.public_rooms_filtered(request).await?;
|
||||
///
|
||||
/// for room in response.chunk {
|
||||
/// println!("Found room {:?}", room);
|
||||
/// println!("Found room {room:?}");
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn public_rooms_filtered(
|
||||
&self,
|
||||
@@ -1788,9 +1771,8 @@ impl Client {
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::{Client, config::SyncSettings};
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = Client::new(homeserver).await?;
|
||||
/// use matrix_sdk::ruma::{api::client::profile, user_id};
|
||||
@@ -1806,7 +1788,7 @@ impl Client {
|
||||
///
|
||||
/// // Check the corresponding Response struct to find out what types are
|
||||
/// // returned
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn send<Request>(
|
||||
&self,
|
||||
@@ -1962,9 +1944,8 @@ impl Client {
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::{Client, config::SyncSettings};
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = Client::new(homeserver).await?;
|
||||
/// let response = client.devices().await?;
|
||||
@@ -1976,7 +1957,7 @@ impl Client {
|
||||
/// device.display_name.as_deref().unwrap_or("")
|
||||
/// );
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn devices(&self) -> HttpResult<get_devices::v3::Response> {
|
||||
let request = get_devices::v3::Request::new();
|
||||
@@ -2002,11 +1983,10 @@ impl Client {
|
||||
/// # ruma::{api::client::uiaa, device_id},
|
||||
/// # Client, Error, config::SyncSettings,
|
||||
/// # };
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use serde_json::json;
|
||||
/// # use url::Url;
|
||||
/// # use std::collections::BTreeMap;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = Client::new(homeserver).await?;
|
||||
/// let devices = &[device_id!("DEVICEID").to_owned()];
|
||||
@@ -2024,7 +2004,7 @@ impl Client {
|
||||
/// .await?;
|
||||
/// }
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
pub async fn delete_devices(
|
||||
&self,
|
||||
devices: &[OwnedDeviceId],
|
||||
@@ -2106,12 +2086,11 @@ impl Client {
|
||||
/// * [`set_presence`] - To tell the server to set the presence and to
|
||||
/// which state.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let username = "";
|
||||
/// # let password = "";
|
||||
@@ -2135,7 +2114,7 @@ impl Client {
|
||||
/// // Now keep on syncing forever. `sync()` will use the stored sync token
|
||||
/// // from our `sync_once()` call automatically.
|
||||
/// client.sync(SyncSettings::default()).await;
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [`sync`]: #method.sync
|
||||
@@ -2220,12 +2199,11 @@ impl Client {
|
||||
/// up to the user of the API to check the error and decide whether the sync
|
||||
/// should continue or not.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let username = "";
|
||||
/// # let password = "";
|
||||
@@ -2246,7 +2224,7 @@ impl Client {
|
||||
/// // Now keep on syncing forever. `sync()` will use the latest sync token
|
||||
/// // automatically.
|
||||
/// client.sync(SyncSettings::default()).await?;
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [argument docs]: #method.sync_once
|
||||
@@ -2285,8 +2263,7 @@ impl Client {
|
||||
/// # use std::time::Duration;
|
||||
/// # use matrix_sdk::{Client, config::SyncSettings, LoopCtrl};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080").unwrap();
|
||||
/// # let mut client = Client::new(homeserver).await.unwrap();
|
||||
///
|
||||
@@ -2310,7 +2287,7 @@ impl Client {
|
||||
/// LoopCtrl::Continue
|
||||
/// })
|
||||
/// .await;
|
||||
/// })
|
||||
/// };
|
||||
/// ```
|
||||
#[instrument(skip_all)]
|
||||
pub async fn sync_with_callback<C>(
|
||||
@@ -2365,11 +2342,10 @@ impl Client {
|
||||
/// # use std::time::Duration;
|
||||
/// # use matrix_sdk::{Client, config::SyncSettings, LoopCtrl};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080").unwrap();
|
||||
/// # let mut client = Client::new(homeserver).await.unwrap();
|
||||
///
|
||||
/// #
|
||||
/// use tokio::sync::mpsc::channel;
|
||||
///
|
||||
/// let (tx, rx) = channel(100);
|
||||
@@ -2391,7 +2367,7 @@ impl Client {
|
||||
/// Ok(LoopCtrl::Continue)
|
||||
/// })
|
||||
/// .await;
|
||||
/// })
|
||||
/// };
|
||||
/// ```
|
||||
#[instrument(skip(self, callback))]
|
||||
pub async fn sync_with_result_callback<C>(
|
||||
@@ -2441,8 +2417,7 @@ impl Client {
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let username = "";
|
||||
/// # let password = "";
|
||||
@@ -2465,7 +2440,7 @@ impl Client {
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
#[allow(unknown_lints, clippy::let_with_type_underscore)] // triggered by instrument macro
|
||||
#[instrument(skip(self))]
|
||||
|
||||
@@ -78,13 +78,12 @@ impl Device {
|
||||
/// this. `m.qr_code.show.v1` is only available if the `qrcode` feature is
|
||||
/// enabled, which it is by default.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::{Client, ruma::{device_id, user_id}};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
@@ -94,7 +93,7 @@ impl Device {
|
||||
/// if let Some(device) = device {
|
||||
/// let verification = device.request_verification().await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [`request_verification_with_methods()`]:
|
||||
@@ -131,8 +130,7 @@ impl Device {
|
||||
/// # }
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
@@ -147,7 +145,7 @@ impl Device {
|
||||
/// let verification =
|
||||
/// device.request_verification_with_methods(methods).await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn request_verification_with_methods(
|
||||
&self,
|
||||
@@ -174,8 +172,7 @@ impl Device {
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::{Client, ruma::{device_id, user_id}};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
@@ -185,7 +182,7 @@ impl Device {
|
||||
/// if let Some(device) = device {
|
||||
/// let verification = device.start_verification().await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [`request_verification()`]: #method.request_verification
|
||||
@@ -238,8 +235,7 @@ impl Device {
|
||||
/// # }
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
@@ -249,7 +245,7 @@ impl Device {
|
||||
/// if let Some(device) = device {
|
||||
/// device.verify().await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn verify(&self) -> Result<(), ManualVerifyError> {
|
||||
let request = self.inner.verify().await?;
|
||||
@@ -353,8 +349,7 @@ impl Device {
|
||||
/// # }
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
@@ -376,7 +371,7 @@ impl Device {
|
||||
/// );
|
||||
/// }
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [`UserIdentity::verify()`]:
|
||||
@@ -469,8 +464,7 @@ impl Device {
|
||||
/// # }
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
@@ -492,7 +486,7 @@ impl Device {
|
||||
/// );
|
||||
/// }
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [`UserIdentity::verify()`]:
|
||||
|
||||
@@ -37,10 +37,9 @@
|
||||
//! ```no_run
|
||||
//! # use matrix_sdk::{Client, ruma::{device_id, user_id}};
|
||||
//! # use url::Url;
|
||||
//! # use futures::executor::block_on;
|
||||
//! # let alice = user_id!("@alice:example.org");
|
||||
//! # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
//! # block_on(async {
|
||||
//! # async {
|
||||
//! # let client = Client::new(homeserver).await.unwrap();
|
||||
//! let device =
|
||||
//! client.encryption().get_device(alice, device_id!("DEVICEID")).await?;
|
||||
@@ -55,7 +54,7 @@
|
||||
//! // Let's just mark it as verified.
|
||||
//! device.verify().await?;
|
||||
//! }
|
||||
//! # anyhow::Ok(()) });
|
||||
//! # anyhow::Ok(()) };
|
||||
//! ```
|
||||
//!
|
||||
//! Verifying a user identity works largely the same:
|
||||
@@ -63,10 +62,9 @@
|
||||
//! ```no_run
|
||||
//! # use matrix_sdk::{Client, ruma::user_id};
|
||||
//! # use url::Url;
|
||||
//! # use futures::executor::block_on;
|
||||
//! # let alice = user_id!("@alice:example.org");
|
||||
//! # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
//! # block_on(async {
|
||||
//! # async {
|
||||
//! # let client = Client::new(homeserver).await.unwrap();
|
||||
//! let user = client.encryption().get_user_identity(alice).await?;
|
||||
//!
|
||||
@@ -80,7 +78,7 @@
|
||||
//! // Let's just mark it as verified.
|
||||
//! user.verify().await?;
|
||||
//! }
|
||||
//! # anyhow::Ok(()) });
|
||||
//! # anyhow::Ok(()) };
|
||||
//! ```
|
||||
//!
|
||||
//! [cross signing keys]: https://spec.matrix.org/unstable/client-server-api/#cross-signing
|
||||
|
||||
@@ -97,7 +97,7 @@ impl UserIdentity {
|
||||
/// # use url::Url;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # futures::executor::block_on(async {
|
||||
/// # async {
|
||||
/// # let client = Client::new(homeserver).await.unwrap();
|
||||
/// let user = client.encryption().get_user_identity(alice).await?;
|
||||
///
|
||||
@@ -105,7 +105,7 @@ impl UserIdentity {
|
||||
/// println!("This user identity belongs to {}", user.user_id().as_str());
|
||||
/// }
|
||||
///
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub fn user_id(&self) -> &UserId {
|
||||
match &self.inner {
|
||||
@@ -148,7 +148,7 @@ impl UserIdentity {
|
||||
/// # use url::Url;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # futures::executor::block_on(async {
|
||||
/// # async {
|
||||
/// # let client = Client::new(homeserver).await.unwrap();
|
||||
/// let user = client.encryption().get_user_identity(alice).await?;
|
||||
///
|
||||
@@ -156,7 +156,7 @@ impl UserIdentity {
|
||||
/// let verification = user.request_verification().await?;
|
||||
/// }
|
||||
///
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [`request_verification_with_methods()`]:
|
||||
@@ -203,10 +203,9 @@ impl UserIdentity {
|
||||
/// # }
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let client = Client::new(homeserver).await.unwrap();
|
||||
/// let user = client.encryption().get_user_identity(alice).await?;
|
||||
///
|
||||
@@ -218,7 +217,7 @@ impl UserIdentity {
|
||||
/// let verification =
|
||||
/// user.request_verification_with_methods(methods).await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [`request_verification()`]: #method.request_verification
|
||||
@@ -282,17 +281,16 @@ impl UserIdentity {
|
||||
/// # }
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let client = Client::new(homeserver).await.unwrap();
|
||||
/// let user = client.encryption().get_user_identity(alice).await?;
|
||||
///
|
||||
/// if let Some(user) = user {
|
||||
/// user.verify().await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
/// [`Encryption::cross_signing_status()`]: crate::encryption::Encryption::cross_signing_status
|
||||
pub async fn verify(&self) -> Result<(), ManualVerifyError> {
|
||||
@@ -325,10 +323,9 @@ impl UserIdentity {
|
||||
/// # }
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let client = Client::new(homeserver).await.unwrap();
|
||||
/// let user = client.encryption().get_user_identity(alice).await?;
|
||||
///
|
||||
@@ -339,7 +336,7 @@ impl UserIdentity {
|
||||
/// println!("User {} is not verified", user.user_id().as_str());
|
||||
/// }
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub fn is_verified(&self) -> bool {
|
||||
match &self.inner {
|
||||
@@ -364,10 +361,9 @@ impl UserIdentity {
|
||||
/// # }
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let client = Client::new(homeserver).await.unwrap();
|
||||
/// let user = client.encryption().get_user_identity(alice).await?;
|
||||
///
|
||||
@@ -391,7 +387,7 @@ impl UserIdentity {
|
||||
/// );
|
||||
/// }
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub fn master_key(&self) -> &MasterPubkey {
|
||||
match &self.inner {
|
||||
|
||||
@@ -105,12 +105,13 @@ impl Client {
|
||||
/// encrypting and uploading a provided reader.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `content_type` - The content type of the file.
|
||||
/// * `reader` - The reader that should be encrypted and uploaded.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use url::Url;
|
||||
/// # use matrix_sdk::ruma::{room_id, OwnedRoomId};
|
||||
@@ -122,16 +123,16 @@ impl Client {
|
||||
/// struct CustomEventContent {
|
||||
/// encrypted_file: matrix_sdk::ruma::events::room::EncryptedFile,
|
||||
/// }
|
||||
/// # block_on(async {
|
||||
///
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// # let room = client.get_joined_room(&room_id!("!test:example.com")).unwrap();
|
||||
///
|
||||
/// let mut reader = std::io::Cursor::new(b"Hello, world!");
|
||||
/// let encrypted_file = client.prepare_encrypted_file(&mime::TEXT_PLAIN, &mut reader).await?;
|
||||
///
|
||||
/// room.send(CustomEventContent { encrypted_file }, None).await?;
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn prepare_encrypted_file<'a, R: Read + ?Sized + 'a>(
|
||||
&self,
|
||||
@@ -519,8 +520,7 @@ impl Encryption {
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::{Client, ruma::{device_id, user_id}};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
@@ -533,7 +533,7 @@ impl Encryption {
|
||||
/// let verification = device.request_verification().await?;
|
||||
/// }
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn get_device(
|
||||
&self,
|
||||
@@ -559,17 +559,16 @@ impl Encryption {
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::{Client, ruma::user_id};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// let devices = client.encryption().get_user_devices(alice).await?;
|
||||
///
|
||||
/// for device in devices.devices() {
|
||||
/// println!("{:?}", device);
|
||||
/// println!("{device:?}");
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn get_user_devices(&self, user_id: &UserId) -> Result<UserDevices, Error> {
|
||||
let devices = self
|
||||
@@ -598,8 +597,7 @@ impl Encryption {
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::{Client, ruma::user_id};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
@@ -610,7 +608,7 @@ impl Encryption {
|
||||
///
|
||||
/// let verification = user.request_verification().await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn get_user_identity(
|
||||
&self,
|
||||
@@ -641,14 +639,14 @@ impl Encryption {
|
||||
/// interactive auth and the same request needs to be made but this time
|
||||
/// with some `auth_data` provided.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use std::collections::BTreeMap;
|
||||
/// # use matrix_sdk::{ruma::api::client::uiaa, Client};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use serde_json::json;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// if let Err(e) = client.encryption().bootstrap_cross_signing(None).await {
|
||||
@@ -668,7 +666,7 @@ impl Encryption {
|
||||
/// panic!("Error durign cross signing bootstrap {:#?}", e);
|
||||
/// }
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
pub async fn bootstrap_cross_signing(&self, auth_data: Option<AuthData>) -> Result<()> {
|
||||
let olm = self.client.olm_machine().ok_or(Error::AuthenticationRequired)?;
|
||||
|
||||
@@ -718,9 +716,8 @@ impl Encryption {
|
||||
/// # Client, config::SyncSettings,
|
||||
/// # ruma::room_id,
|
||||
/// # };
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = Client::new(homeserver).await?;
|
||||
/// let path = PathBuf::from("/home/example/e2e-keys.txt");
|
||||
@@ -738,7 +735,7 @@ impl Encryption {
|
||||
/// .encryption()
|
||||
/// .export_room_keys(path, "secret-passphrase", |s| s.room_id() == room_id)
|
||||
/// .await?;
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub async fn export_room_keys(
|
||||
@@ -787,9 +784,8 @@ impl Encryption {
|
||||
/// # Client, config::SyncSettings,
|
||||
/// # ruma::room_id,
|
||||
/// # };
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = Client::new(homeserver).await?;
|
||||
/// let path = PathBuf::from("/home/example/e2e-keys.txt");
|
||||
@@ -800,7 +796,7 @@ impl Encryption {
|
||||
/// "Imported {} room keys out of {}",
|
||||
/// result.imported_count, result.total_count
|
||||
/// );
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub async fn import_room_keys(
|
||||
|
||||
@@ -43,7 +43,6 @@ impl SasVerification {
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # use ruma::user_id;
|
||||
/// use matrix_sdk::{
|
||||
@@ -53,7 +52,7 @@ impl SasVerification {
|
||||
///
|
||||
/// # let flow_id = "someID";
|
||||
/// # let user_id = user_id!("@alice:example");
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// let sas = client
|
||||
@@ -69,7 +68,7 @@ impl SasVerification {
|
||||
///
|
||||
/// sas.accept_with_settings(only_decimal).await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn accept_with_settings(&self, settings: AcceptSettings) -> Result<()> {
|
||||
if let Some(request) = self.inner.accept_with_settings(settings) {
|
||||
@@ -114,11 +113,10 @@ impl SasVerification {
|
||||
|
||||
/// Get the emoji version of the short auth string.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # use ruma::user_id;
|
||||
/// use matrix_sdk::{
|
||||
@@ -128,7 +126,7 @@ impl SasVerification {
|
||||
///
|
||||
/// # let flow_id = "someID";
|
||||
/// # let user_id = user_id!("@alice:example");
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// let sas_verification = client
|
||||
@@ -152,7 +150,7 @@ impl SasVerification {
|
||||
///
|
||||
/// println!("Do the emojis match?\n{emoji_string}\n{description}");
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub fn emoji(&self) -> Option<[Emoji; 7]> {
|
||||
self.inner.emoji()
|
||||
@@ -269,10 +267,9 @@ impl SasVerification {
|
||||
/// use futures::stream::{Stream, StreamExt};
|
||||
/// use matrix_sdk::encryption::verification::{SasState, SasVerification};
|
||||
///
|
||||
/// # futures::executor::block_on(async {
|
||||
/// # async {
|
||||
/// # let sas: SasVerification = unimplemented!();
|
||||
/// # let user_confirmed = false;
|
||||
///
|
||||
/// let mut stream = sas.changes();
|
||||
///
|
||||
/// while let Some(state) = stream.next().await {
|
||||
@@ -313,7 +310,7 @@ impl SasVerification {
|
||||
/// | SasState::Confirmed => (),
|
||||
/// }
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub fn changes(&self) -> impl Stream<Item = SasState> {
|
||||
self.inner.changes()
|
||||
|
||||
@@ -89,15 +89,14 @@ impl Media {
|
||||
/// * `reader` - A `Reader` that will be used to fetch the raw bytes of the
|
||||
/// media.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use std::fs;
|
||||
/// # use matrix_sdk::{Client, ruma::room_id};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use mime;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = Client::new(homeserver).await?;
|
||||
/// let image = fs::read("/home/example/my-cat.jpg")?;
|
||||
@@ -105,7 +104,7 @@ impl Media {
|
||||
/// let response = client.media().upload(&mime::IMAGE_JPEG, image).await?;
|
||||
///
|
||||
/// println!("Cat URI: {}", response.content_uri);
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn upload(
|
||||
&self,
|
||||
|
||||
@@ -148,14 +148,14 @@ impl Common {
|
||||
/// * `format` - The desired format of the avatar.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::Client;
|
||||
/// # use matrix_sdk::ruma::room_id;
|
||||
/// # use matrix_sdk::media::MediaFormat;
|
||||
/// # use url::Url;
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let user = "example";
|
||||
/// let client = Client::new(homeserver).await.unwrap();
|
||||
/// client.login_username(user, "password").send().await.unwrap();
|
||||
@@ -164,7 +164,7 @@ impl Common {
|
||||
/// if let Some(avatar) = room.avatar(MediaFormat::File).await.unwrap() {
|
||||
/// std::fs::write("avatar.png", avatar);
|
||||
/// }
|
||||
/// # })
|
||||
/// # };
|
||||
/// ```
|
||||
pub async fn avatar(&self, format: MediaFormat) -> Result<Option<Vec<u8>>> {
|
||||
let Some(url) = self.avatar_url() else { return Ok(None) };
|
||||
@@ -180,7 +180,8 @@ impl Common {
|
||||
/// decryption fails for an individual message, that message is returned
|
||||
/// undecrypted.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// use matrix_sdk::{room::MessagesOptions, Client};
|
||||
/// # use matrix_sdk::ruma::{
|
||||
@@ -190,15 +191,14 @@ impl Common {
|
||||
/// # use url::Url;
|
||||
///
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// let options =
|
||||
/// MessagesOptions::backward().from("t47429-4392820_219380_26003_2265");
|
||||
///
|
||||
/// let mut client = Client::new(homeserver).await.unwrap();
|
||||
/// let room = client.get_joined_room(room_id!("!roomid:example.com")).unwrap();
|
||||
/// assert!(room.messages(options).await.is_ok());
|
||||
/// # });
|
||||
/// # };
|
||||
/// ```
|
||||
#[instrument(skip_all, fields(room_id = ?self.inner.room_id(), ?options))]
|
||||
pub async fn messages(&self, options: MessagesOptions) -> Result<Messages> {
|
||||
@@ -709,7 +709,7 @@ impl Common {
|
||||
/// ```no_run
|
||||
/// # use std::str::FromStr;
|
||||
/// # use ruma::events::tag::{TagInfo, TagName, UserTagName};
|
||||
/// # futures::executor::block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = url::Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = matrix_sdk::Client::new(homeserver).await?;
|
||||
/// # let room_id = matrix_sdk::ruma::room_id!("!test:localhost");
|
||||
@@ -722,7 +722,7 @@ impl Common {
|
||||
///
|
||||
/// room.set_tag(TagName::User(user_tag), tag_info).await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn set_tag(
|
||||
&self,
|
||||
|
||||
@@ -174,29 +174,27 @@ impl Joined {
|
||||
///
|
||||
/// * `typing` - Whether the user is typing or has stopped typing.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// use matrix_sdk::ruma::api::client::typing::create_typing_event::v3::Typing;
|
||||
///
|
||||
/// # use matrix_sdk::{
|
||||
/// # Client, config::SyncSettings,
|
||||
/// # ruma::room_id,
|
||||
/// # };
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
///
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// # let room_id = room_id!("!test:localhost");
|
||||
/// let room_id = room_id!("!SVkFJHzfwvuaIEawgC:localhost");
|
||||
///
|
||||
/// if let Some(room) = client.get_joined_room(&room_id) {
|
||||
/// room.typing_notice(true).await?
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn typing_notice(&self, typing: bool) -> Result<()> {
|
||||
// Only send a request to the homeserver if the old timeout has elapsed
|
||||
@@ -317,16 +315,16 @@ impl Joined {
|
||||
/// will wait for a sync to be received, this might time out if no
|
||||
/// sync loop is running or if the server is slow.
|
||||
///
|
||||
/// # Examples
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::{
|
||||
/// # Client, config::SyncSettings,
|
||||
/// # ruma::room_id,
|
||||
/// # };
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # block_on(async {
|
||||
/// #
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
/// # let room_id = room_id!("!test:localhost");
|
||||
@@ -335,7 +333,7 @@ impl Joined {
|
||||
/// if let Some(room) = client.get_joined_room(&room_id) {
|
||||
/// room.enable_encryption().await?
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
#[instrument(skip_all)]
|
||||
pub async fn enable_encryption(&self) -> Result<()> {
|
||||
@@ -479,7 +477,6 @@ impl Joined {
|
||||
/// # use std::sync::{Arc, RwLock};
|
||||
/// # use matrix_sdk::{Client, config::SyncSettings};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::ruma::room_id;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// use matrix_sdk::ruma::{
|
||||
@@ -489,11 +486,11 @@ impl Joined {
|
||||
/// },
|
||||
/// uint, MilliSecondsSinceUnixEpoch, TransactionId,
|
||||
/// };
|
||||
/// # block_on(async {
|
||||
///
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = Client::new(homeserver).await?;
|
||||
/// # let room_id = room_id!("!test:localhost");
|
||||
///
|
||||
/// let content = RoomMessageEventContent::text_plain("Hello world");
|
||||
/// let txn_id = TransactionId::new();
|
||||
///
|
||||
@@ -523,7 +520,7 @@ impl Joined {
|
||||
/// if let Some(room) = client.get_joined_room(&room_id) {
|
||||
/// room.send(content, Some(&txn_id)).await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [`SyncMessageLikeEvent`]: ruma::events::SyncMessageLikeEvent
|
||||
@@ -571,13 +568,13 @@ impl Joined {
|
||||
/// events sent by our own device and/or to implement local echo.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use std::sync::{Arc, RwLock};
|
||||
/// # use matrix_sdk::{Client, config::SyncSettings};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use matrix_sdk::ruma::room_id;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = Client::new(homeserver).await?;
|
||||
/// # let room_id = room_id!("!test:localhost");
|
||||
@@ -590,7 +587,7 @@ impl Joined {
|
||||
/// if let Some(room) = client.get_joined_room(&room_id) {
|
||||
/// room.send_raw(content, "m.room.message", None).await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [`SyncMessageLikeEvent`]: ruma::events::SyncMessageLikeEvent
|
||||
@@ -692,8 +689,7 @@ impl Joined {
|
||||
/// # use matrix_sdk::{Client, ruma::room_id, attachment::AttachmentConfig};
|
||||
/// # use url::Url;
|
||||
/// # use mime;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = Client::new(homeserver).await?;
|
||||
/// # let room_id = room_id!("!test:localhost");
|
||||
@@ -707,7 +703,7 @@ impl Joined {
|
||||
/// AttachmentConfig::new(),
|
||||
/// ).await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
/// [`upload()`]: crate::Media::upload
|
||||
@@ -1054,7 +1050,7 @@ impl Joined {
|
||||
/// ```no_run
|
||||
/// use serde_json::json;
|
||||
///
|
||||
/// # futures::executor::block_on(async {
|
||||
/// # async {
|
||||
/// # let homeserver = url::Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = matrix_sdk::Client::new(homeserver).await?;
|
||||
/// # let room_id = matrix_sdk::ruma::room_id!("!test:localhost");
|
||||
@@ -1067,7 +1063,7 @@ impl Joined {
|
||||
/// if let Some(room) = client.get_joined_room(&room_id) {
|
||||
/// room.send_state_event_raw(content, "m.room.member", "").await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
#[instrument(skip_all)]
|
||||
pub async fn send_state_event_raw(
|
||||
@@ -1107,18 +1103,19 @@ impl Joined {
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # futures::executor::block_on(async {
|
||||
/// use matrix_sdk::ruma::event_id;
|
||||
///
|
||||
/// # async {
|
||||
/// # let homeserver = url::Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = matrix_sdk::Client::new(homeserver).await?;
|
||||
/// # let room_id = matrix_sdk::ruma::room_id!("!test:localhost");
|
||||
/// use matrix_sdk::ruma::event_id;
|
||||
///
|
||||
/// #
|
||||
/// if let Some(room) = client.get_joined_room(&room_id) {
|
||||
/// let event_id = event_id!("$xxxxxx:example.org");
|
||||
/// let reason = Some("Indecent material");
|
||||
/// room.redact(&event_id, reason, None).await?;
|
||||
/// }
|
||||
/// # anyhow::Ok(()) });
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
#[instrument(skip_all)]
|
||||
pub async fn redact(
|
||||
|
||||
@@ -40,14 +40,13 @@ impl RoomMember {
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use futures::executor::block_on;
|
||||
/// use matrix_sdk::{
|
||||
/// media::MediaFormat, room::RoomMember, ruma::room_id, Client,
|
||||
/// RoomMemberships,
|
||||
/// };
|
||||
/// # use url::Url;
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # block_on(async {
|
||||
/// # async {
|
||||
/// # let user = "example";
|
||||
/// let client = Client::new(homeserver).await.unwrap();
|
||||
/// client.login_username(user, "password").send().await.unwrap();
|
||||
@@ -58,7 +57,7 @@ impl RoomMember {
|
||||
/// if let Some(avatar) = member.avatar(MediaFormat::File).await.unwrap() {
|
||||
/// std::fs::write("avatar.png", avatar);
|
||||
/// }
|
||||
/// # })
|
||||
/// # };
|
||||
/// ```
|
||||
pub async fn avatar(&self, format: MediaFormat) -> Result<Option<Vec<u8>>> {
|
||||
let Some(url) = self.avatar_url() else { return Ok(None) };
|
||||
|
||||
@@ -35,10 +35,9 @@ typically runs on a separate domain, it can be configured on the
|
||||
[`SlidingSyncBuilder`]:
|
||||
|
||||
```rust,no_run
|
||||
# use futures::executor::block_on;
|
||||
# use matrix_sdk::Client;
|
||||
# use url::Url;
|
||||
# block_on(async {
|
||||
# async {
|
||||
# let homeserver = Url::parse("http://example.com")?;
|
||||
# let client = Client::new(homeserver).await?;
|
||||
let sliding_sync_builder = client
|
||||
@@ -47,7 +46,7 @@ let sliding_sync_builder = client
|
||||
.homeserver(Url::parse("http://sliding-sync.example.org")?);
|
||||
|
||||
# anyhow::Ok(())
|
||||
# });
|
||||
# };
|
||||
```
|
||||
|
||||
After the general configuration, one typically wants to add a list via the
|
||||
@@ -262,7 +261,6 @@ sure to look at both for all subscribed objects.
|
||||
In full, this typically looks like this:
|
||||
|
||||
```rust,no_run
|
||||
# use futures::executor::block_on;
|
||||
# use futures::{pin_mut, StreamExt};
|
||||
# use matrix_sdk::{
|
||||
# sliding_sync::{SlidingSyncMode, SlidingSyncListBuilder},
|
||||
@@ -273,7 +271,7 @@ In full, this typically looks like this:
|
||||
# };
|
||||
# use tracing::{debug, error, info, warn};
|
||||
# use url::Url;
|
||||
# block_on(async {
|
||||
# async {
|
||||
# let homeserver = Url::parse("http://example.com")?;
|
||||
# let client = Client::new(homeserver).await?;
|
||||
let sliding_sync = client
|
||||
@@ -304,7 +302,7 @@ loop {
|
||||
}
|
||||
|
||||
# anyhow::Ok(())
|
||||
# });
|
||||
# };
|
||||
```
|
||||
|
||||
### Quick refreshing
|
||||
@@ -409,13 +407,12 @@ start up and retrieve only the data needed to actually run.
|
||||
# Full example
|
||||
|
||||
```rust,no_run
|
||||
# use futures::executor::block_on;
|
||||
use matrix_sdk::{Client, sliding_sync::{SlidingSyncList, SlidingSyncMode}};
|
||||
use ruma::{assign, {api::client::sync::sync_events::v4, events::StateEventType}};
|
||||
use tracing::{warn, error, info, debug};
|
||||
use futures::{StreamExt, pin_mut};
|
||||
use url::Url;
|
||||
# block_on(async {
|
||||
# async {
|
||||
# let homeserver = Url::parse("http://example.com")?;
|
||||
# let client = Client::new(homeserver).await?;
|
||||
let full_sync_list_name = "full-sync".to_owned();
|
||||
@@ -500,7 +497,7 @@ loop {
|
||||
}
|
||||
|
||||
# anyhow::Ok(())
|
||||
# });
|
||||
# };
|
||||
```
|
||||
|
||||
[MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/3575
|
||||
|
||||
Reference in New Issue
Block a user