Skip to content

Add ActiveRoomHolder to manage the active room for a session #4758

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

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

jmartinesp
Copy link
Member

@jmartinesp jmartinesp commented May 21, 2025

Content

What the title says

Motivation and context

This allows us to reuse these rooms for several actions that would otherwise create a new instance of the room, which, if the room is already available, would cause delays of several seconds since the live timeline can take a while to restore if it contains many events.

Tests

These actions should be noticeably faster:

  • Starting or joining a call.
  • Sharing media from outside the app.
  • Syncing when a notification is received.
  • Replying to a notification.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

This allows us to reuse these rooms for several actions that would otherwise create a new instance of the room, which, if the room is already available, would cause delays of several seconds since the live timeline can take a while to restore if it contains many events.
@jmartinesp jmartinesp requested a review from a team as a code owner May 21, 2025 12:16
@jmartinesp jmartinesp requested review from bmarty and removed request for a team May 21, 2025 12:16
@jmartinesp jmartinesp added the PR-Misc For other changes label May 21, 2025
Copy link
Contributor

github-actions bot commented May 21, 2025

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/hMexZx

Copy link

codecov bot commented May 21, 2025

Codecov Report

Attention: Patch coverage is 66.03774% with 18 lines in your changes missing coverage. Please review.

Project coverage is 80.32%. Comparing base (8e87bf2) to head (ec2e448).
Report is 18 commits behind head on develop.

Files with missing lines Patch % Lines
...ment/android/features/share/impl/SharePresenter.kt 50.00% 1 Missing and 4 partials ⚠️
.../libraries/push/impl/push/SyncOnNotifiableEvent.kt 68.75% 1 Missing and 4 partials ⚠️
...droid/features/call/impl/ui/CallScreenPresenter.kt 40.00% 0 Missing and 3 partials ⚠️
...roid/services/appnavstate/api/ActiveRoomsHolder.kt 75.00% 0 Missing and 3 partials ⚠️
...ifications/NotificationBroadcastReceiverHandler.kt 50.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4758      +/-   ##
===========================================
- Coverage    80.32%   80.32%   -0.01%     
===========================================
  Files         2127     2128       +1     
  Lines        56319    56351      +32     
  Branches      7055     7068      +13     
===========================================
+ Hits         45241    45266      +25     
+ Misses        8661     8659       -2     
- Partials      2417     2426       +9     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Some remarks

class ActiveRoomHolder @Inject constructor() {
private val rooms = ConcurrentHashMap<SessionId, JoinedRoom>()

fun addRoom(room: JoinedRoom) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe change to setRoom? Or store a Stack of rooms to fix the issue with permalink?

@@ -95,6 +98,7 @@ class JoinedRoomLoadedFlowNode @AssistedInject constructor(
},
onDestroy = {
Timber.v("OnDestroy")
activeRoomHolder.removeRoom(inputs.room.sessionId)
Copy link
Member

Choose a reason for hiding this comment

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

This does not work well with permalink. If a room A opens a room B, when going back to room A, the holder will be empty.

@jmartinesp jmartinesp force-pushed the misc/add-active-room-holder branch from 86da4f7 to f7549de Compare May 22, 2025 14:07
Copy link
Member

@bmarty bmarty 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 update. A few more comments.

@@ -95,6 +98,7 @@ class JoinedRoomLoadedFlowNode @AssistedInject constructor(
},
onDestroy = {
Timber.v("OnDestroy")
activeRoomHolder.removeRoom(inputs.room.sessionId)
Copy link
Member

Choose a reason for hiding this comment

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

I still believe that this would be useful to provide the roomId to the removeRoom api, to double check that we are removing the correct room, and not the last added one.

Also one question, what will happen if there is an active call in the room, but the user closes the timeline? I guess the only issue is that there will be no cache, so not a real problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

I still believe that this would be useful to provide the roomId to the removeRoom api, to double check that we are removing the correct room, and not the last added one.

Makes sense.

Also one question, what will happen if there is an active call in the room, but the user closes the timeline? I guess the only issue is that there will be no cache, so not a real problem.

I'd say nothing really. A call needs the sync to work and an active timeline to start the call, but if it's already running there should be no issues, at least with the current features.

) : ClearCacheUseCase {
override suspend fun invoke() = withContext(coroutineDispatchers.io) {
// Active rooms should be disposed of before clearing the cache
activeRoomHolder.removeRoom(matrixClient.sessionId)?.destroy()
Copy link
Member

Choose a reason for hiding this comment

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

Now that activeRoomHolder stores a list of rooms, I think this code needs to be updated to destroy all the rooms.

* This works as a FILO (First In Last Out) stack, meaning that the last room added for a session will be the first one to be removed.
*/
@SingleIn(AppScope::class)
class ActiveRoomHolder @Inject constructor() {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rename to ActiveRoomsHolder?

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Misc For other changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants