feat(bindings): Add account data interaction to sdk-ffi

Co-authored-by: Doug <douglase@element.io>
This commit is contained in:
Jonas Platte
2022-08-31 13:42:05 +02:00
committed by Jonas Platte
parent bb04a1e041
commit 96384d9447
2 changed files with 29 additions and 0 deletions

View File

@@ -62,6 +62,12 @@ interface Client {
[Throws=ClientError]
string device_id();
[Throws=ClientError]
string? account_data(string event_type);
[Throws=ClientError]
void set_account_data(string event_type, string content);
sequence<Room> rooms();
[Throws=ClientError]

View File

@@ -12,6 +12,7 @@ use matrix_sdk::{
sync::sync_events::v3::Filter,
},
events::room::MediaSource,
serde::Raw,
TransactionId,
},
Client as MatrixClient, LoopCtrl, Session,
@@ -223,6 +224,28 @@ impl Client {
Ok(device_id.to_string())
}
/// Get the content of the event of the given type out of the account data
/// store.
///
/// It will be returned as a JSON string.
pub fn account_data(&self, event_type: String) -> anyhow::Result<Option<String>> {
RUNTIME.block_on(async move {
let event = self.client.account().account_data_raw(event_type.into()).await?;
Ok(event.map(|e| e.json().get().to_owned()))
})
}
/// Set the given account data content for the given event type.
///
/// It should be supplied as a JSON string.
pub fn set_account_data(&self, event_type: String, content: String) -> anyhow::Result<()> {
RUNTIME.block_on(async move {
let raw_content = Raw::from_json_string(content)?;
self.client.account().set_account_data_raw(event_type.into(), raw_content).await?;
Ok(())
})
}
pub fn get_media_content(&self, media_source: Arc<MediaSource>) -> anyhow::Result<Vec<u8>> {
let l = self.client.clone();
let source = (*media_source).clone();