Merge pull request #7747 from vector-im/fix/mna/verification-request-priority

Verification request is not showing when verify session popup is displayed (PSG-1017)
This commit is contained in:
Maxime NATUREL 2022-12-12 09:44:25 +01:00 committed by GitHub
commit 361b0411c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 34 deletions

1
changelog.d/7743.bugfix Normal file
View file

@ -0,0 +1 @@
Verification request is not showing when verify session popup is displayed

View file

@ -72,10 +72,11 @@ class IncomingVerificationRequestHandler @Inject constructor(
val user = session.getUserOrDefault(tx.otherUserId).toMatrixItem() val user = session.getUserOrDefault(tx.otherUserId).toMatrixItem()
val name = user.getBestName() val name = user.getBestName()
val alert = VerificationVectorAlert( val alert = VerificationVectorAlert(
uid, uid = uid,
context.getString(R.string.sas_incoming_request_notif_title), title = context.getString(R.string.sas_incoming_request_notif_title),
context.getString(R.string.sas_incoming_request_notif_content, name), description = context.getString(R.string.sas_incoming_request_notif_content, name),
R.drawable.ic_shield_black, iconId = R.drawable.ic_shield_black,
priority = PopupAlertManager.INCOMING_VERIFICATION_REQUEST_PRIORITY,
shouldBeDisplayedIn = { activity -> shouldBeDisplayedIn = { activity ->
if (activity is VectorBaseActivity<*>) { if (activity is VectorBaseActivity<*>) {
// TODO a bit too ugly :/ // TODO a bit too ugly :/
@ -85,7 +86,7 @@ class IncomingVerificationRequestHandler @Inject constructor(
} }
} ?: true } ?: true
} else true } else true
} },
) )
.apply { .apply {
viewBinder = VerificationVectorAlert.ViewBinder(user, avatarRenderer.get()) viewBinder = VerificationVectorAlert.ViewBinder(user, avatarRenderer.get())
@ -127,12 +128,9 @@ class IncomingVerificationRequestHandler @Inject constructor(
// For incoming request we should prompt (if not in activity where this request apply) // For incoming request we should prompt (if not in activity where this request apply)
if (pr.isIncoming) { if (pr.isIncoming) {
// if it's a self verification for my devices, we can discard the review login alert // if it's a self verification for my devices, we can discard the review login alert
// if not this request will be underneath and not visible by the user... // if not, this request will be underneath and not visible by the user...
// it will re-appear later // it will re-appear later
if (pr.otherUserId == session?.myUserId) { cancelAnyVerifySessionAlerts(pr)
// XXX this is a bit hard coded :/
popupAlertManager.cancelAlert("review_login")
}
val user = session.getUserOrDefault(pr.otherUserId).toMatrixItem() val user = session.getUserOrDefault(pr.otherUserId).toMatrixItem()
val name = user.getBestName() val name = user.getBestName()
val description = if (name == pr.otherUserId) { val description = if (name == pr.otherUserId) {
@ -142,21 +140,23 @@ class IncomingVerificationRequestHandler @Inject constructor(
} }
val alert = VerificationVectorAlert( val alert = VerificationVectorAlert(
uniqueIdForVerificationRequest(pr), uid = uniqueIdForVerificationRequest(pr),
context.getString(R.string.sas_incoming_request_notif_title), title = context.getString(R.string.sas_incoming_request_notif_title),
description, description = description,
R.drawable.ic_shield_black, iconId = R.drawable.ic_shield_black,
priority = PopupAlertManager.INCOMING_VERIFICATION_REQUEST_PRIORITY,
shouldBeDisplayedIn = { activity -> shouldBeDisplayedIn = { activity ->
if (activity is RoomDetailActivity) { if (activity is RoomDetailActivity) {
activity.intent?.extras?.getParcelableCompat<TimelineArgs>(RoomDetailActivity.EXTRA_ROOM_DETAIL_ARGS)?.let { activity.intent?.extras?.getParcelableCompat<TimelineArgs>(RoomDetailActivity.EXTRA_ROOM_DETAIL_ARGS)?.let {
it.roomId != pr.roomId it.roomId != pr.roomId
} ?: true } ?: true
} else true } else true
} },
) )
.apply { .apply {
viewBinder = VerificationVectorAlert.ViewBinder(user, avatarRenderer.get()) viewBinder = VerificationVectorAlert.ViewBinder(user, avatarRenderer.get())
contentAction = Runnable { contentAction = Runnable {
cancelAnyVerifySessionAlerts(pr)
(weakCurrentActivity?.get() as? VectorBaseActivity<*>)?.let { (weakCurrentActivity?.get() as? VectorBaseActivity<*>)?.let {
val roomId = pr.roomId val roomId = pr.roomId
if (roomId.isNullOrBlank()) { if (roomId.isNullOrBlank()) {
@ -186,6 +186,13 @@ class IncomingVerificationRequestHandler @Inject constructor(
} }
} }
private fun cancelAnyVerifySessionAlerts(pr: PendingVerificationRequest) {
if (pr.otherUserId == session?.myUserId) {
popupAlertManager.cancelAlert(PopupAlertManager.REVIEW_LOGIN_UID)
popupAlertManager.cancelAlert(PopupAlertManager.VERIFY_SESSION_UID)
}
}
override fun verificationRequestUpdated(pr: PendingVerificationRequest) { override fun verificationRequestUpdated(pr: PendingVerificationRequest) {
// If an incoming request is readied (by another device?) we should discard the alert // If an incoming request is readied (by another device?) we should discard the alert
if (pr.isIncoming && (pr.isReady || pr.handledByOtherSession || pr.cancelConclusion != null)) { if (pr.isIncoming && (pr.isReady || pr.handledByOtherSession || pr.cancelConclusion != null)) {

View file

@ -437,9 +437,10 @@ class HomeActivity :
private fun handleAskPasswordToInitCrossSigning(events: HomeActivityViewEvents.AskPasswordToInitCrossSigning) { private fun handleAskPasswordToInitCrossSigning(events: HomeActivityViewEvents.AskPasswordToInitCrossSigning) {
// We need to ask // We need to ask
promptSecurityEvent( promptSecurityEvent(
events.userItem, uid = PopupAlertManager.UPGRADE_SECURITY_UID,
R.string.upgrade_security, userItem = events.userItem,
R.string.security_prompt_text titleRes = R.string.upgrade_security,
descRes = R.string.security_prompt_text,
) { ) {
it.navigator.upgradeSessionSecurity(it, true) it.navigator.upgradeSessionSecurity(it, true)
} }
@ -448,9 +449,10 @@ class HomeActivity :
private fun handleCrossSigningInvalidated(event: HomeActivityViewEvents.OnCrossSignedInvalidated) { private fun handleCrossSigningInvalidated(event: HomeActivityViewEvents.OnCrossSignedInvalidated) {
// We need to ask // We need to ask
promptSecurityEvent( promptSecurityEvent(
event.userItem, uid = PopupAlertManager.VERIFY_SESSION_UID,
R.string.crosssigning_verify_this_session, userItem = event.userItem,
R.string.confirm_your_identity titleRes = R.string.crosssigning_verify_this_session,
descRes = R.string.confirm_your_identity,
) { ) {
it.navigator.waitSessionVerification(it) it.navigator.waitSessionVerification(it)
} }
@ -459,9 +461,10 @@ class HomeActivity :
private fun handleOnNewSession(event: HomeActivityViewEvents.CurrentSessionNotVerified) { private fun handleOnNewSession(event: HomeActivityViewEvents.CurrentSessionNotVerified) {
// We need to ask // We need to ask
promptSecurityEvent( promptSecurityEvent(
event.userItem, uid = PopupAlertManager.VERIFY_SESSION_UID,
R.string.crosssigning_verify_this_session, userItem = event.userItem,
R.string.confirm_your_identity titleRes = R.string.crosssigning_verify_this_session,
descRes = R.string.confirm_your_identity,
) { ) {
if (event.waitForIncomingRequest) { if (event.waitForIncomingRequest) {
it.navigator.waitSessionVerification(it) it.navigator.waitSessionVerification(it)
@ -474,9 +477,10 @@ class HomeActivity :
private fun handleCantVerify(event: HomeActivityViewEvents.CurrentSessionCannotBeVerified) { private fun handleCantVerify(event: HomeActivityViewEvents.CurrentSessionCannotBeVerified) {
// We need to ask // We need to ask
promptSecurityEvent( promptSecurityEvent(
event.userItem, uid = PopupAlertManager.UPGRADE_SECURITY_UID,
R.string.crosssigning_cannot_verify_this_session, userItem = event.userItem,
R.string.crosssigning_cannot_verify_this_session_desc titleRes = R.string.crosssigning_cannot_verify_this_session,
descRes = R.string.crosssigning_cannot_verify_this_session_desc,
) { ) {
it.navigator.open4SSetup(it, SetupMode.PASSPHRASE_AND_NEEDED_SECRETS_RESET) it.navigator.open4SSetup(it, SetupMode.PASSPHRASE_AND_NEEDED_SECRETS_RESET)
} }
@ -485,7 +489,7 @@ class HomeActivity :
private fun handlePromptToEnablePush() { private fun handlePromptToEnablePush() {
popupAlertManager.postVectorAlert( popupAlertManager.postVectorAlert(
DefaultVectorAlert( DefaultVectorAlert(
uid = "enablePush", uid = PopupAlertManager.ENABLE_PUSH_UID,
title = getString(R.string.alert_push_are_disabled_title), title = getString(R.string.alert_push_are_disabled_title),
description = getString(R.string.alert_push_are_disabled_description), description = getString(R.string.alert_push_are_disabled_description),
iconId = R.drawable.ic_room_actions_notifications_mutes, iconId = R.drawable.ic_room_actions_notifications_mutes,
@ -518,10 +522,16 @@ class HomeActivity :
) )
} }
private fun promptSecurityEvent(userItem: MatrixItem.UserItem, titleRes: Int, descRes: Int, action: ((VectorBaseActivity<*>) -> Unit)) { private fun promptSecurityEvent(
uid: String,
userItem: MatrixItem.UserItem,
titleRes: Int,
descRes: Int,
action: ((VectorBaseActivity<*>) -> Unit),
) {
popupAlertManager.postVectorAlert( popupAlertManager.postVectorAlert(
VerificationVectorAlert( VerificationVectorAlert(
uid = "upgradeSecurity", uid = uid,
title = getString(titleRes), title = getString(titleRes),
description = getString(descRes), description = getString(descRes),
iconId = R.drawable.ic_shield_warning iconId = R.drawable.ic_shield_warning

View file

@ -156,7 +156,7 @@ class HomeDetailFragment :
unknownDeviceDetectorSharedViewModel.onEach { state -> unknownDeviceDetectorSharedViewModel.onEach { state ->
state.unknownSessions.invoke()?.let { unknownDevices -> state.unknownSessions.invoke()?.let { unknownDevices ->
if (unknownDevices.firstOrNull()?.currentSessionTrust == true) { if (unknownDevices.firstOrNull()?.currentSessionTrust == true) {
val uid = "review_login" val uid = PopupAlertManager.REVIEW_LOGIN_UID
alertManager.cancelAlert(uid) alertManager.cancelAlert(uid)
val olderUnverified = unknownDevices.filter { !it.isNew } val olderUnverified = unknownDevices.filter { !it.isNew }
val newest = unknownDevices.firstOrNull { it.isNew }?.deviceInfo val newest = unknownDevices.firstOrNull { it.isNew }?.deviceInfo

View file

@ -160,7 +160,7 @@ class NewHomeDetailFragment :
unknownDeviceDetectorSharedViewModel.onEach { state -> unknownDeviceDetectorSharedViewModel.onEach { state ->
state.unknownSessions.invoke()?.let { unknownDevices -> state.unknownSessions.invoke()?.let { unknownDevices ->
if (unknownDevices.firstOrNull()?.currentSessionTrust == true) { if (unknownDevices.firstOrNull()?.currentSessionTrust == true) {
val uid = "review_login" val uid = PopupAlertManager.REVIEW_LOGIN_UID
alertManager.cancelAlert(uid) alertManager.cancelAlert(uid)
val olderUnverified = unknownDevices.filter { !it.isNew } val olderUnverified = unknownDevices.filter { !it.isNew }
val newest = unknownDevices.firstOrNull { it.isNew }?.deviceInfo val newest = unknownDevices.firstOrNull { it.isNew }?.deviceInfo

View file

@ -50,6 +50,12 @@ class PopupAlertManager @Inject constructor(
companion object { companion object {
const val INCOMING_CALL_PRIORITY = Int.MAX_VALUE const val INCOMING_CALL_PRIORITY = Int.MAX_VALUE
const val INCOMING_VERIFICATION_REQUEST_PRIORITY = 1
const val DEFAULT_PRIORITY = 0
const val REVIEW_LOGIN_UID = "review_login"
const val UPGRADE_SECURITY_UID = "upgrade_security"
const val VERIFY_SESSION_UID = "verify_session"
const val ENABLE_PUSH_UID = "enable_push"
} }
private var weakCurrentActivity: WeakReference<Activity>? = null private var weakCurrentActivity: WeakReference<Activity>? = null
@ -145,7 +151,7 @@ class PopupAlertManager @Inject constructor(
private fun displayNextIfPossible() { private fun displayNextIfPossible() {
val currentActivity = weakCurrentActivity?.get() val currentActivity = weakCurrentActivity?.get()
if (Alerter.isShowing || currentActivity == null || currentActivity.isDestroyed) { if (currentActivity == null || currentActivity.isDestroyed) {
// will retry later // will retry later
return return
} }

View file

@ -98,7 +98,7 @@ open class DefaultVectorAlert(
override val dismissOnClick: Boolean = true override val dismissOnClick: Boolean = true
override val priority: Int = 0 override val priority: Int = PopupAlertManager.DEFAULT_PRIORITY
override val isLight: Boolean = false override val isLight: Boolean = false

View file

@ -30,6 +30,7 @@ class VerificationVectorAlert(
title: String, title: String,
override val description: String, override val description: String,
@DrawableRes override val iconId: Int?, @DrawableRes override val iconId: Int?,
override val priority: Int = PopupAlertManager.DEFAULT_PRIORITY,
/** /**
* Alert are displayed by default, but let this lambda return false to prevent displaying. * Alert are displayed by default, but let this lambda return false to prevent displaying.
*/ */