fix: Make sure room.sync_up works under all conditions

This commit is contained in:
Flix
2022-11-02 15:42:06 +01:00
committed by Damir Jelić
parent a3a9858bf4
commit 1ab33a28c9
2 changed files with 14 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
use std::{borrow::Borrow, collections::BTreeMap, ops::Deref, sync::Arc, time::Duration};
use std::{borrow::Borrow, collections::BTreeMap, ops::Deref, sync::Arc};
use matrix_sdk_base::{
deserialized_responses::{MembersResponse, TimelineEvent},
@@ -420,17 +420,6 @@ impl Common {
self.request_members().await
}
/// Wait for the room to be fully synced.
///
/// This method makes sure the room that was returned when joining/leaving
/// rooms has been echoed back in the sync. Warning: This waits until a sync
/// happens and does not return if no sync is happening!
pub async fn sync_up(&self) {
while !self.is_synced() {
self.client.inner.sync_beat.listen().wait_timeout(Duration::from_secs(1));
}
}
/// Get active members for this room, includes invited, joined members.
///
/// *Note*: This method will fetch the members from the homeserver if the

View File

@@ -383,6 +383,19 @@ impl Joined {
Ok(())
}
/// Wait for the room to be fully synced.
///
/// This method makes sure the room that was returned when joining a room
/// has been echoed back in the sync.
/// Warning: This waits until a sync happens and does not return if no sync
/// is happening! It can also return early when the room is not a joined
/// room anymore!
pub async fn sync_up(&self) {
while !self.is_synced() && self.room_type() == RoomType::Joined {
self.client.inner.sync_beat.listen().wait_timeout(Duration::from_secs(1));
}
}
/// Send a room message to this room.
///
/// Returns the parsed response from the server.