Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
poljar committed Oct 18, 2023
1 parent 0981966 commit 2f41fe1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
4 changes: 2 additions & 2 deletions bindings/matrix-sdk-ffi/src/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ impl Encryption {
&self,
progress_listener: Option<Box<dyn BackupSteadyStateListener>>,
) {
let recovery = self.inner.recovery();
let wait_for_steady_state = recovery.wait_for_backup_steady_state();
let backups = self.inner.backups();
let wait_for_steady_state = backups.wait_for_steady_state();

let task = if let Some(listener) = progress_listener {
let mut progress_stream = wait_for_steady_state.subscribe_to_progress();
Expand Down
12 changes: 6 additions & 6 deletions crates/matrix-sdk/src/encryption/backups/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ use tracing::trace;
use super::{Backups, UploadState};

#[derive(Debug)]
pub struct WaitForSteadyState {
pub(super) backups: Backups,
pub struct WaitForSteadyState<'a> {
pub(super) backups: &'a Backups,
pub(super) progress: SharedObservable<UploadState>,
pub(super) timeout: Option<Duration>,
}

impl WaitForSteadyState {
impl<'a> WaitForSteadyState<'a> {
pub fn subscribe_to_progress(&self) -> impl Stream<Item = UploadState> {
self.progress.subscribe_reset()
}
Expand All @@ -40,12 +40,12 @@ impl WaitForSteadyState {
}
}

impl IntoFuture for WaitForSteadyState {
impl<'a> IntoFuture for WaitForSteadyState<'a> {
type Output = ();
#[cfg(target_arch = "wasm32")]
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output>>>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output + 'a>>>;
#[cfg(not(target_arch = "wasm32"))]
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>;

fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk/src/encryption/backups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ impl Backups {
Ok(())
}

pub fn wait_for_steady_state(&self) -> WaitForSteadyState {
pub fn wait_for_steady_state(&self) -> WaitForSteadyState<'_> {
WaitForSteadyState {
backups: self.clone(),
backups: self,
progress: self.client.inner.backups_state.upload_progress.clone(),
timeout: None,
}
Expand Down
7 changes: 0 additions & 7 deletions crates/matrix-sdk/src/encryption/recovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ mod futures;

pub use futures::{Enable, EnableProgress};

use super::backups::WaitForSteadyState;

#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
#[ruma_event(type = "m.org.matrix.custom.secret_storage_disabled", kind = GlobalAccountData)]
struct SecretStorageDisabledContent {
Expand Down Expand Up @@ -110,11 +108,6 @@ impl Recovery {
Ok(())
}

pub fn wait_for_backup_steady_state(&self) -> WaitForSteadyState {
let backups = self.client.encryption().backups();
backups.wait_for_steady_state()
}

/// Is this device the last device the user has.
pub async fn are_we_the_last_man_standing(&self) -> Result<bool> {
let olm_machine = self.client.olm_machine().await;
Expand Down
4 changes: 2 additions & 2 deletions examples/encryption-recovery/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ async fn logout(client: &Client) -> Result<()> {
}

async fn logout_no_recovery(client: &Client) -> Result<()> {
let recovery = client.encryption().recovery();
let backups = client.encryption().backups();

let wait = recovery.wait_for_backup_steady_state();
let wait = backups.wait_for_steady_state();

println!("Waiting for the room keys to upload.");

Expand Down

0 comments on commit 2f41fe1

Please sign in to comment.