-
Notifications
You must be signed in to change notification settings - Fork 170
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
Fix the logic of the room list banner state #3615
Changes from all commits
0b2ae98
1b8b176
e88d74a
434fbd4
230abd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,6 @@ | |
import io.element.android.libraries.matrix.api.encryption.RecoveryState | ||
import io.element.android.libraries.matrix.api.roomlist.RoomList | ||
import io.element.android.libraries.matrix.api.sync.SyncService | ||
import io.element.android.libraries.matrix.api.sync.SyncState | ||
import io.element.android.libraries.matrix.api.timeline.ReceiptType | ||
import io.element.android.libraries.preferences.api.store.SessionPreferencesStore | ||
import io.element.android.libraries.push.api.notifications.NotificationCleaner | ||
|
@@ -173,33 +172,48 @@ | |
} | ||
|
||
@Composable | ||
private fun securityBannerState( | ||
private fun rememberSecurityBannerState( | ||
securityBannerDismissed: Boolean, | ||
needsSlidingSyncMigration: Boolean, | ||
): State<SecurityBannerState> { | ||
val currentSecurityBannerDismissed by rememberUpdatedState(securityBannerDismissed) | ||
val currentNeedsSlidingSyncMigration by rememberUpdatedState(needsSlidingSyncMigration) | ||
val recoveryState by encryptionService.recoveryStateStateFlow.collectAsState() | ||
val syncState by syncService.syncState.collectAsState() | ||
return remember { | ||
derivedStateOf { | ||
when { | ||
currentSecurityBannerDismissed -> SecurityBannerState.None | ||
syncState == SyncState.Running -> { | ||
when (recoveryState) { | ||
RecoveryState.DISABLED -> SecurityBannerState.SetUpRecovery | ||
RecoveryState.INCOMPLETE -> SecurityBannerState.RecoveryKeyConfirmation | ||
RecoveryState.UNKNOWN, | ||
RecoveryState.WAITING_FOR_SYNC, | ||
RecoveryState.ENABLED -> SecurityBannerState.None | ||
} | ||
} | ||
needsSlidingSyncMigration -> SecurityBannerState.NeedsNativeSlidingSyncMigration | ||
else -> SecurityBannerState.None | ||
} | ||
calculateBannerState( | ||
securityBannerDismissed = currentSecurityBannerDismissed, | ||
needsSlidingSyncMigration = currentNeedsSlidingSyncMigration, | ||
recoveryState = recoveryState, | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun calculateBannerState( | ||
securityBannerDismissed: Boolean, | ||
needsSlidingSyncMigration: Boolean, | ||
recoveryState: RecoveryState, | ||
): SecurityBannerState { | ||
if (securityBannerDismissed) { | ||
return SecurityBannerState.None | ||
} | ||
|
||
when (recoveryState) { | ||
RecoveryState.DISABLED -> return SecurityBannerState.SetUpRecovery | ||
RecoveryState.INCOMPLETE -> return SecurityBannerState.RecoveryKeyConfirmation | ||
RecoveryState.UNKNOWN, | ||
RecoveryState.WAITING_FOR_SYNC, | ||
RecoveryState.ENABLED -> Unit | ||
} | ||
|
||
if (needsSlidingSyncMigration) { | ||
return SecurityBannerState.NeedsNativeSlidingSyncMigration | ||
Check warning on line 211 in features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListPresenter.kt Codecov / codecov/patchfeatures/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListPresenter.kt#L211
|
||
} | ||
|
||
return SecurityBannerState.None | ||
} | ||
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. |
||
|
||
@Composable | ||
private fun roomListContentState( | ||
securityBannerDismissed: Boolean, | ||
|
@@ -228,7 +242,7 @@ | |
showEmpty -> RoomListContentState.Empty | ||
showSkeleton -> RoomListContentState.Skeleton(count = 16) | ||
else -> { | ||
val securityBannerState by securityBannerState(securityBannerDismissed, needsSlidingSyncMigration) | ||
val securityBannerState by rememberSecurityBannerState(securityBannerDismissed, needsSlidingSyncMigration) | ||
RoomListContentState.Rooms( | ||
securityBannerState = securityBannerState, | ||
fullScreenIntentPermissionsState = fullScreenIntentPermissionsPresenter.present(), | ||
|
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.
Is it not because
needsSlidingSyncMigration
needs to be wrapped in a state likesecurityBannerDismissed
, withrememberUpdatedState
?