mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 13:40:55 -04:00
feat(sdk): Add public set_account_data[_raw] to Account
This commit is contained in:
committed by
Jonas Platte
parent
f8502720c3
commit
f1a03ececd
@@ -24,18 +24,23 @@ use ruma::{
|
||||
add_3pid, change_password, deactivate, delete_3pid, get_3pids,
|
||||
request_3pid_management_token_via_email, request_3pid_management_token_via_msisdn,
|
||||
},
|
||||
config::set_global_account_data,
|
||||
profile::{
|
||||
get_avatar_url, get_display_name, get_profile, set_avatar_url, set_display_name,
|
||||
},
|
||||
uiaa::AuthData,
|
||||
},
|
||||
assign,
|
||||
events::room::MediaSource,
|
||||
events::{
|
||||
room::MediaSource, AnyGlobalAccountDataEventContent, GlobalAccountDataEventContent,
|
||||
GlobalAccountDataEventType,
|
||||
},
|
||||
serde::Raw,
|
||||
thirdparty::Medium,
|
||||
ClientSecret, MxcUri, OwnedMxcUri, SessionId, UInt,
|
||||
};
|
||||
|
||||
use crate::{config::RequestConfig, Client, Error, Result};
|
||||
use crate::{config::RequestConfig, Client, Error, HttpError, Result};
|
||||
|
||||
/// A high-level API to manage the client owner's account.
|
||||
///
|
||||
@@ -623,4 +628,34 @@ impl Account {
|
||||
});
|
||||
Ok(self.client.send(request, None).await?)
|
||||
}
|
||||
|
||||
/// Set the given account data event.
|
||||
pub async fn set_account_data<T>(
|
||||
&self,
|
||||
content: T,
|
||||
) -> Result<set_global_account_data::v3::Response>
|
||||
where
|
||||
T: GlobalAccountDataEventContent,
|
||||
{
|
||||
let own_user =
|
||||
self.client.user_id().ok_or_else(|| Error::from(HttpError::AuthenticationRequired))?;
|
||||
|
||||
let request = set_global_account_data::v3::Request::new(own_user, &content)?;
|
||||
|
||||
Ok(self.client.send(request, None).await?)
|
||||
}
|
||||
|
||||
/// Set the given raw account data event.
|
||||
pub async fn set_account_data_raw(
|
||||
&self,
|
||||
event_type: GlobalAccountDataEventType,
|
||||
content: Raw<AnyGlobalAccountDataEventContent>,
|
||||
) -> Result<set_global_account_data::v3::Response> {
|
||||
let own_user =
|
||||
self.client.user_id().ok_or_else(|| Error::from(HttpError::AuthenticationRequired))?;
|
||||
|
||||
let request = set_global_account_data::v3::Request::new_raw(event_type, own_user, content);
|
||||
|
||||
Ok(self.client.send(request, None).await?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,7 @@ use matrix_sdk_base::crypto::{
|
||||
pub use matrix_sdk_base::crypto::{LocalTrust, MediaEncryptionInfo, RoomKeyImportResult};
|
||||
use matrix_sdk_common::instant::Duration;
|
||||
#[cfg(feature = "e2e-encryption")]
|
||||
use ruma::{
|
||||
api::client::config::set_global_account_data, events::GlobalAccountDataEventContent,
|
||||
OwnedDeviceId,
|
||||
};
|
||||
use ruma::OwnedDeviceId;
|
||||
use ruma::{
|
||||
api::client::{
|
||||
backup::add_backup_keys::v3::Response as KeysBackupResponse,
|
||||
@@ -61,7 +58,7 @@ use crate::{
|
||||
identities::{Device, UserDevices},
|
||||
verification::{SasVerification, Verification, VerificationRequest},
|
||||
},
|
||||
error::{HttpError, HttpResult, RoomKeyImportError},
|
||||
error::{HttpResult, RoomKeyImportError},
|
||||
room, Client, Error, Result,
|
||||
};
|
||||
|
||||
@@ -214,22 +211,6 @@ impl Client {
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "e2e-encryption")]
|
||||
async fn send_account_data<T>(
|
||||
&self,
|
||||
content: T,
|
||||
) -> Result<set_global_account_data::v3::Response>
|
||||
where
|
||||
T: GlobalAccountDataEventContent,
|
||||
{
|
||||
let own_user =
|
||||
self.user_id().ok_or_else(|| Error::from(HttpError::AuthenticationRequired))?;
|
||||
|
||||
let request = set_global_account_data::v3::Request::new(own_user, &content)?;
|
||||
|
||||
Ok(self.send(request, None).await?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "e2e-encryption")]
|
||||
pub(crate) async fn create_dm_room(
|
||||
&self,
|
||||
@@ -268,7 +249,7 @@ impl Client {
|
||||
// TODO We should probably save the fact that we need to send this out
|
||||
// because otherwise we might end up in a state where we have a DM that
|
||||
// isn't marked as one.
|
||||
self.send_account_data(content).await?;
|
||||
self.account().set_account_data(content).await?;
|
||||
|
||||
// If the room is already in our store, fetch it, otherwise wait for a
|
||||
// sync to be done which should put the room into our store.
|
||||
|
||||
Reference in New Issue
Block a user