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 name = user.getBestName()
val alert = VerificationVectorAlert(
uid,
context.getString(R.string.sas_incoming_request_notif_title),
context.getString(R.string.sas_incoming_request_notif_content, name),
R.drawable.ic_shield_black,
uid = uid,
title = context.getString(R.string.sas_incoming_request_notif_title),
description = context.getString(R.string.sas_incoming_request_notif_content, name),
iconId = R.drawable.ic_shield_black,
priority = PopupAlertManager.INCOMING_VERIFICATION_REQUEST_PRIORITY,
shouldBeDisplayedIn = { activity ->
if (activity is VectorBaseActivity<*>) {
// TODO a bit too ugly :/
@ -85,7 +86,7 @@ class IncomingVerificationRequestHandler @Inject constructor(
}
} ?: true
} else true
}
},
)
.apply {
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)
if (pr.isIncoming) {
// 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
if (pr.otherUserId == session?.myUserId) {
// XXX this is a bit hard coded :/
popupAlertManager.cancelAlert("review_login")
}
cancelAnyVerifySessionAlerts(pr)
val user = session.getUserOrDefault(pr.otherUserId).toMatrixItem()
val name = user.getBestName()
val description = if (name == pr.otherUserId) {
@ -142,21 +140,23 @@ class IncomingVerificationRequestHandler @Inject constructor(
}
val alert = VerificationVectorAlert(
uniqueIdForVerificationRequest(pr),
context.getString(R.string.sas_incoming_request_notif_title),
description,
R.drawable.ic_shield_black,
uid = uniqueIdForVerificationRequest(pr),
title = context.getString(R.string.sas_incoming_request_notif_title),
description = description,
iconId = R.drawable.ic_shield_black,
priority = PopupAlertManager.INCOMING_VERIFICATION_REQUEST_PRIORITY,
shouldBeDisplayedIn = { activity ->
if (activity is RoomDetailActivity) {
activity.intent?.extras?.getParcelableCompat<TimelineArgs>(RoomDetailActivity.EXTRA_ROOM_DETAIL_ARGS)?.let {
it.roomId != pr.roomId
} ?: true
} else true
}
},
)
.apply {
viewBinder = VerificationVectorAlert.ViewBinder(user, avatarRenderer.get())
contentAction = Runnable {
cancelAnyVerifySessionAlerts(pr)
(weakCurrentActivity?.get() as? VectorBaseActivity<*>)?.let {
val roomId = pr.roomId
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) {
// If an incoming request is readied (by another device?) we should discard the alert
if (pr.isIncoming && (pr.isReady || pr.handledByOtherSession || pr.cancelConclusion != null)) {

View File

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

View File

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

View File

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

View File

@ -50,6 +50,12 @@ class PopupAlertManager @Inject constructor(
companion object {
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
@ -145,7 +151,7 @@ class PopupAlertManager @Inject constructor(
private fun displayNextIfPossible() {
val currentActivity = weakCurrentActivity?.get()
if (Alerter.isShowing || currentActivity == null || currentActivity.isDestroyed) {
if (currentActivity == null || currentActivity.isDestroyed) {
// will retry later
return
}

View File

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

View File

@ -30,6 +30,7 @@ class VerificationVectorAlert(
title: String,
override val description: String,
@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.
*/