-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add fn to await a synced room from Client
#3979
Merged
jmartinesp
merged 5 commits into
main
from
feat/allow-client-to-wait-for-a-room-remote-echo
Sep 12, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
60bf0f3
sdk-base: add `Room::is_state_partially_or_fully_synced()`
jmartinesp 958678c
sdk: add `Client::await_room_remote_echo(&room_id)`
jmartinesp cce3279
ffi: add FFI fn for `Client::await_room_remote_echo(&room_id)`
jmartinesp 014e302
sdk-ui: make `SlidingSyncRoom` not needed in `RoomListItem::default_r…
jmartinesp 2693857
sdk-ui: fix typo in `TimelineState::replace_with_remove_events`
jmartinesp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ use std::{ops::Deref, sync::Arc}; | |
use async_once_cell::OnceCell as AsyncOnceCell; | ||
use matrix_sdk::SlidingSync; | ||
use ruma::RoomId; | ||
use tracing::info; | ||
|
||
use super::Error; | ||
use crate::{ | ||
|
@@ -150,27 +151,32 @@ impl Room { | |
} | ||
|
||
/// Create a new [`TimelineBuilder`] with the default configuration. | ||
/// | ||
/// If the room was synced before some initial events will be added to the | ||
/// [`TimelineBuilder`]. | ||
bnjbvr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub async fn default_room_timeline_builder(&self) -> Result<TimelineBuilder, Error> { | ||
// TODO we can remove this once the event cache handles his own cache. | ||
|
||
let sliding_sync_room = | ||
let sliding_sync_room = self.inner.sliding_sync.get_room(self.inner.room.room_id()).await; | ||
bnjbvr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if let Some(sliding_sync_room) = sliding_sync_room { | ||
bnjbvr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.inner | ||
.sliding_sync | ||
.get_room(self.inner.room.room_id()) | ||
.room | ||
.client() | ||
.event_cache() | ||
.add_initial_events( | ||
self.inner.room.room_id(), | ||
sliding_sync_room.timeline_queue().iter().cloned().collect(), | ||
sliding_sync_room.prev_batch(), | ||
) | ||
.await | ||
.ok_or_else(|| Error::RoomNotFound(self.inner.room.room_id().to_owned()))?; | ||
|
||
self.inner | ||
.room | ||
.client() | ||
.event_cache() | ||
.add_initial_events( | ||
self.inner.room.room_id(), | ||
sliding_sync_room.timeline_queue().iter().cloned().collect(), | ||
sliding_sync_room.prev_batch(), | ||
) | ||
.await | ||
.map_err(Error::EventCache)?; | ||
.map_err(Error::EventCache)?; | ||
} else { | ||
info!( | ||
"No cached sliding sync room found for `{}`, the timeline will be empty.", | ||
self.room_id() | ||
); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some info! statement in the else case, to indicate that we didn't have a timeline cache for this room? That will help debunk issues when people are in offline mode. |
||
|
||
Ok(Timeline::builder(&self.inner.room).track_read_marker_and_receipts()) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd do a slightly different API at the FFI level: add an
Option<Duration>
as a parameter, and add a timeout here, so the consumer doesn't have to. Does it make sense? (You get to decide if it's a good idea, based on your usage of the API in the app :))There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked @stefanceriu and we decided to have the client implement the timeout.