Skip to content

feat(users): migrate UsersDao, UsersRepository and UserManager to coroutines - #6644

Draft
mahibi wants to merge 3 commits into
masterfrom
migrateUserManagerToCoroutines
Draft

mahibi wants to merge 3 commits into
masterfrom
migrateUserManagerToCoroutines

Conversation

@mahibi

@mahibi mahibi commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Migrates user account handling (UserManager, UsersRepository, UsersDao) from RxJava to Kotlin coroutines, then updates every call site in the app to use the new suspend API.

Commit 1 — data layer (feat(users): migrate UsersDao, UsersRepository and UserManager to coroutines)

  • UsersDao: abstract class → interface, every DB method becomes suspend fun; getActiveUserObservable(): Observable → getActiveUserFlow(): Flow<UserEntity?>.
  • UsersRepository/UsersRepositoryImpl: mirrors the DAO — Single/Maybe → suspend fun, Observable → Flow.
  • UserManager: internals rewritten as suspend functions. Every existing public Rx-returning method is kept as a @deprecated, one-line rxSingle/rxMaybe wrapper around the new suspend function, so
    existing callers keep compiling.
  • Tests and the Compose-preview dummy DAO updated to match.

Commit 2 — call sites (feat(users): migrate UserManager call sites off RxJava wrappers)

  • Switches every call site (Activities, ViewModels, Compose, Workers, BroadcastReceivers, the OkHttp interceptor) off the deprecated wrappers and onto the suspend functions, using
    lifecycleScope/viewModelScope/rememberCoroutineScope() where a coroutine scope is available, and runBlocking where the call site must stay synchronous (onCreate/onResume, Worker.doWork()/init,
    BroadcastReceiver.onReceive) — a like-for-like swap, since .blockingGet() already blocked the same thread.
  • Fixes a few dormant bugs found along the way, where a returned Single/Maybe was never subscribed to, so the update silently never ran: ConversationsListActivity.handleEcoSystemIntent,
    SettingsActivity's client-cert and profile-refresh updates, PushRegistrationWorker.webPushUnregistrationWork.
  • Leaves the plain Java Worker classes and KeyManager on the deprecated Rx wrappers (Java can't call Kotlin suspend funs without manual Continuation handling), and leaves UserManager.currentUser call
    sites in DiagnosisElement, LocalLoginDataSource, and CurrentUserProviderOldImpl on Rx, since its "pick any user and mark it active" fallback isn't exposed as a suspend function and the documented
    replacement (CurrentUserProvider.getCurrentUser()) has different semantics.

Recommended follow-ups

  • Convert the remaining plain Worker subclasses (NotificationWorker, PushRegistrationWorker, ShareOperationWorker) to CoroutineWorker, matching ReadMarkerSyncWorker/ChatMessageCatchUpWorker, so their suspend calls stop needing runBlocking.
  • Use goAsync() + a coroutine scope in the four BroadcastReceivers for the same reason.
  • Decide on a path for the Java-only call sites (CapabilitiesWorker, DeleteConversationWorker, SignalingSettingsWorker, WebsocketConnectionsWorker, AccountRemovalWorker,
    AddParticipantsToConversationWorker, KeyManager) — either convert them to Kotlin or accept they'll stay on the deprecated Rx wrappers indefinitely.
  • If CurrentUserProvider.getCurrentUser() should eventually replace UserManager.currentUser everywhere, its fallback behavior (auto-picking and activating a user when none is marked active) needs to be
    decided on and ported over first.

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔖 Capability is checked or not needed
  • 🔙 Backport requests are created or not needed: /backport to stable-xx.x
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@mahibi mahibi self-assigned this Sep 4, 2026
@mahibi
mahibi force-pushed the migrateUserManagerToCoroutines branch from fb61129 to eed482b Compare September 8, 2026 15:39
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

APK file: https://github.com/nextcloud/talk-android/actions/runs/34246126796/artifacts/10064452703
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

@mahibi
mahibi force-pushed the migrateUserManagerToCoroutines branch from eed482b to 08cffb6 Compare September 10, 2026 10:35
@github-actions

Copy link
Copy Markdown
Contributor

APK file: https://github.com/nextcloud/talk-android/actions/runs/34466901916/artifacts/10150441248
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

@mahibi
mahibi force-pushed the migrateUserManagerToCoroutines branch from 08cffb6 to 7ffb02c Compare September 14, 2026 13:29
@github-actions

Copy link
Copy Markdown
Contributor

APK file: https://github.com/nextcloud/talk-android/actions/runs/34849556867/artifacts/10350730917
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

@mahibi
mahibi force-pushed the migrateUserManagerToCoroutines branch from 7ffb02c to c94d688 Compare September 17, 2026 15:56
@github-actions

Copy link
Copy Markdown
Contributor

APK file: https://github.com/nextcloud/talk-android/actions/runs/35243431480/artifacts/10506924023
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

@mahibi mahibi added this to the 25.1.0 milestone Sep 17, 2026
@mahibi
mahibi force-pushed the migrateUserManagerToCoroutines branch 2 times, most recently from 30d6126 to 4bb299b Compare September 18, 2026 15:42
…outines

Convert the user data layer (UsersDao, UsersRepository/Impl) from RxJava2
to suspend fun/Flow, mirroring the ConversationsDao pattern already used
elsewhere. UserManager gains suspend counterparts for every method
alongside its existing RxJava-typed API, which is now deprecated and
bridges to the suspend implementation via kotlinx-coroutines-rx2, so the
~50 existing call sites keep compiling unchanged. Follow-up PRs will
migrate those callers in batches and then remove the deprecated methods.

Assisted-by: Claude Code:claude-sonnet-5

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Switches call sites across the app to the suspend functions added on
UserManager/UsersRepository, using lifecycleScope/viewModelScope in
Activities and ViewModels, rememberCoroutineScope in Compose, and
runBlocking where the call site must stay synchronous (onCreate/onResume,
OkHttp interceptor, BroadcastReceivers, plain Worker classes). Also fixes
a few spots where a returned Single/Maybe was never subscribed to, so the
underlying update silently never ran (ConversationsListActivity's
handleEcoSystemIntent, SettingsActivity's client-cert and profile-refresh
updates, PushRegistrationWorker's webPushUnregistrationWork).

Java call sites (plain Worker classes and KeyManager) are left on the
deprecated Rx wrappers, since Java cannot call Kotlin suspend functions
without manual Continuation handling.

Assisted-by: Claude Code:claude-sonnet-5

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
scheduleDuplicateAccountsForDeletionSuspend() was the only method with
tests; currentUser, deleteUserSuspend, scheduleUserForDeletionWithIdSuspend,
setUserAsActiveSuspend, storeProfileSuspend and other suspend methods
introduced by the coroutines migration had none.

Assisted-by: Claude Code:claude-sonnet-5

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
@mahibi
mahibi force-pushed the migrateUserManagerToCoroutines branch from 4bb299b to 36275f5 Compare September 19, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant