Skip to content
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
merged 5 commits into from
Sep 12, 2024

Conversation

jmartinesp
Copy link
Contributor

Changes

  • Add fn sdk_base::Room::is_state_partially_or_fully_synced(). I was planning to reuse Room::is_state_fully_synced(), but this apparently doesn't work with SSS.
  • Add fn Client::await_room_remote_echo(&RoomId), which will loop indefinitely until it finds a room with the provided room id, using ClientInner::sync_beat to delay the checks. This is the core of the changes, and an FFI fn has been created to access it.
  • SlidingSyncRoom is no longer needed in fn RoomListItem::default_room_timeline_builder(). It was mandatory, and used only to pre-fill the timeline with initial items. After discussing this behavior we decided we can make it non-mandatory so timelines can be created for rooms that haven't been synced yet, which was a source of pain in the clients.
  • Fix dumb typo in TimelineState.

Motivation

After using Client::create_room in the clients we found some cases where we were trying to create a timeline for the just created room while it still hadn't been synced and this resulted in an error and the full room not being returned to the clients. The new await_room_remote_echo fn will let us wait until the room has been synced, fixing this issue.

Also, there may be some cases where a room is in the local DB but it hasn't been synced yet. The behaviour change in default_room_timeline_builder should fix that.

  • Public API changes documented in changelogs (optional)

Signed-off-by:

@jmartinesp jmartinesp requested a review from a team as a code owner September 11, 2024 12:26
@jmartinesp jmartinesp requested review from andybalaam and removed request for a team September 11, 2024 12:26
Copy link

codecov bot commented Sep 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.32%. Comparing base (9e7ab63) to head (2693857).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3979      +/-   ##
==========================================
+ Coverage   84.27%   84.32%   +0.05%     
==========================================
  Files         266      266              
  Lines       28286    28296      +10     
==========================================
+ Hits        23838    23862      +24     
+ Misses       4448     4434      -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an extra test please, LGTM otherwise!

Comment on lines 2254 to 2255
return room;
} else {
warn!("Room wasn't partially synced, waiting for sync beat to try again");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no else after return please :)

Also I think the warn can just be a debug, it's not high priority enough that it should jump out to our eyes when looking at rageshakes IMO.

warn!("Room wasn't partially synced, waiting for sync beat to try again");
}
} else {
warn!("Room wasn't found, waiting for sync beat to try again");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto, debug here

warn!("Room wasn't found, waiting for sync beat to try again");
}
self.inner.sync_beat.listen().await;
debug!("New sync beat found");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this one we can remove, since the next loop iteration will immediately log something or return.

Comment on lines 2827 to 2830
let room =
tokio::time::timeout(Duration::from_secs(1), client.await_room_remote_echo(room_id))
.await
.unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do slightly better here, and not involve time at all:

let room = client.await_room_remote_echo(room_id).now_or_never().unwrap();

(now_or_never() requires a trait to be in scope)


// Perform the /sync request with a delay so it starts after the
// `await_room_remote_echo` call has happened
tokio::spawn({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, here and below for the tokio:: usage, please add use tokio:: statements at the top of this file, so it's shorter to read here

Comment on lines +1009 to +1010
/// **Note: this function will loop endlessly until either it finds the room
/// or an externally set timeout happens.**
Copy link
Member

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 :))

Copy link
Contributor Author

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.

.await
.map_err(Error::EventCache)?;
.map_err(Error::EventCache)?;
}
Copy link
Member

Choose a reason for hiding this comment

The 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.

@bnjbvr bnjbvr removed the request for review from andybalaam September 12, 2024 08:47
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test. A few comments still unaddressed, so requesting changes again.

@jmartinesp
Copy link
Contributor Author

My bad, I have addressed the rest in 606c6b9, I thought I had already uploaded it.

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

 This new fn is used to check when a room is at least partially synced, which seems to be the case with SSS.
This fn will loop until it finds an at least partially synced room with the given id. It uses the `ClientInner::sync_beat` listener to wait until the next check is needed.
…oom_timeline_builder`.

Having initial items shouldn't be mandatory to create a timeline, the timeline can also be empty.
@jmartinesp jmartinesp force-pushed the feat/allow-client-to-wait-for-a-room-remote-echo branch from 606c6b9 to 2693857 Compare September 12, 2024 10:53
@jmartinesp jmartinesp enabled auto-merge (rebase) September 12, 2024 10:53
@jmartinesp jmartinesp merged commit 5827bb7 into main Sep 12, 2024
40 checks passed
@jmartinesp jmartinesp deleted the feat/allow-client-to-wait-for-a-room-remote-echo branch September 12, 2024 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants