Skip to content

Commit

Permalink
add additional getSecretsFromInbox
Browse files Browse the repository at this point in the history
  • Loading branch information
BillCarsonFr committed Oct 5, 2023
1 parent 726baf0 commit 0f0645b
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use std::{collections::BTreeMap, ops::Deref, sync::Arc, time::Duration};

use futures_util::{pin_mut, StreamExt};
use js_sys::{Array, Function, Map, Promise, Set};
use matrix_sdk_common::ruma::{self, serde::Raw, DeviceKeyAlgorithm, OwnedTransactionId, UInt};
use matrix_sdk_common::ruma::{
self, events::secret::request::SecretName, serde::Raw, DeviceKeyAlgorithm, OwnedTransactionId,
UInt,
};
use matrix_sdk_crypto::{
backups::MegolmV1BackupKey,
store::{DeviceChanges, IdentityChanges},
Expand Down Expand Up @@ -1132,6 +1135,29 @@ impl OlmMachine {
});
}

/// Get all the secrets with the given secret_name we have currently
/// stored.
///
/// Usually you would just register a callback with
/// [`register_receive_secret_callback`], but if the clients is shutdown
/// before handling them, this method can be used to retrieve them.
///
/// Returns a `Promise` for a `Set` of `String` corresponding to the secret
/// values.
#[wasm_bindgen(js_name = "getSecretsFromInbox")]
pub async fn get_secrets_from_inbox(&self, secret_name: String) -> Result<Promise, JsError> {
let set = Set::new(&JsValue::UNDEFINED);
let me = self.inner.clone();

Ok(future_to_promise(async move {
let name = SecretName::from(secret_name);
for gossip in me.store().get_secrets_from_inbox(&name).await? {
set.add(&JsValue::from_str(&gossip.event.content.secret));
}
Ok(set)
}))
}

/// Shut down the `OlmMachine`.
///
/// The `OlmMachine` cannot be used after this method has been called.
Expand Down

0 comments on commit 0f0645b

Please sign in to comment.