Extract function and add more logs.
This commit is contained in:
committed by
Benoit Marty
parent
209d4f8fe0
commit
cb8bd077da
@@ -55,27 +55,7 @@ class LoggedInPresenter @Inject constructor(
|
||||
|
||||
LaunchedEffect(isVerified) {
|
||||
if (isVerified) {
|
||||
Timber.d("Ensure pusher is registered")
|
||||
val currentPushProvider = pushService.getCurrentPushProvider()
|
||||
val result = if (currentPushProvider == null) {
|
||||
Timber.d("Register with the first available push provider")
|
||||
val pushProvider = pushService.getAvailablePushProviders().firstOrNull() ?: return@LaunchedEffect
|
||||
val distributor = pushProvider.getDistributors().firstOrNull() ?: return@LaunchedEffect
|
||||
pushService.registerWith(matrixClient, pushProvider, distributor)
|
||||
} else {
|
||||
val currentPushDistributor = currentPushProvider.getCurrentDistributor(matrixClient)
|
||||
if (currentPushDistributor == null) {
|
||||
Timber.d("Register with the first available distributor")
|
||||
val distributor = currentPushProvider.getDistributors().firstOrNull() ?: return@LaunchedEffect
|
||||
pushService.registerWith(matrixClient, currentPushProvider, distributor)
|
||||
} else {
|
||||
Timber.d("Re-register with the current distributor")
|
||||
pushService.registerWith(matrixClient, currentPushProvider, currentPushDistributor)
|
||||
}
|
||||
}
|
||||
result.onFailure {
|
||||
Timber.e(it, "Failed to register pusher")
|
||||
}
|
||||
ensurePusherIsRegistered()
|
||||
} else {
|
||||
Timber.w("Session is not verified, not registering pusher")
|
||||
}
|
||||
@@ -99,6 +79,33 @@ class LoggedInPresenter @Inject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun ensurePusherIsRegistered() {
|
||||
Timber.d("Ensure pusher is registered")
|
||||
val currentPushProvider = pushService.getCurrentPushProvider()
|
||||
val result = if (currentPushProvider == null) {
|
||||
Timber.d("Register with the first available push provider")
|
||||
val pushProvider = pushService.getAvailablePushProviders().firstOrNull()
|
||||
?: return Unit.also { Timber.w("No push provider available") }
|
||||
val distributor = pushProvider.getDistributors().firstOrNull()
|
||||
?: return Unit.also { Timber.w("No distributor available") }
|
||||
pushService.registerWith(matrixClient, pushProvider, distributor)
|
||||
} else {
|
||||
val currentPushDistributor = currentPushProvider.getCurrentDistributor(matrixClient)
|
||||
if (currentPushDistributor == null) {
|
||||
Timber.d("Register with the first available distributor")
|
||||
val distributor = currentPushProvider.getDistributors().firstOrNull()
|
||||
?: return Unit.also { Timber.w("No distributor available") }
|
||||
pushService.registerWith(matrixClient, currentPushProvider, distributor)
|
||||
} else {
|
||||
Timber.d("Re-register with the current distributor")
|
||||
pushService.registerWith(matrixClient, currentPushProvider, currentPushDistributor)
|
||||
}
|
||||
}
|
||||
result.onFailure {
|
||||
Timber.e(it, "Failed to register pusher")
|
||||
}
|
||||
}
|
||||
|
||||
private fun reportCryptoStatusToAnalytics(verificationState: SessionVerifiedStatus, recoveryState: RecoveryState) {
|
||||
// Update first the user property, to store the current status for that posthog user
|
||||
val userVerificationState = verificationState.toAnalyticsUserPropertyValue()
|
||||
|
||||
Reference in New Issue
Block a user