Raise priority of incoming verification request alert + cancel existing verification alerts

This commit is contained in:
Maxime NATUREL 2022-12-08 14:00:35 +01:00
parent b49045ff15
commit df55c84167
7 changed files with 50 additions and 31 deletions

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())
@ -130,8 +131,8 @@ class IncomingVerificationRequestHandler @Inject constructor(
// 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")
popupAlertManager.cancelAlert(PopupAlertManager.REVIEW_LOGIN_UID)
popupAlertManager.cancelAlert(PopupAlertManager.VERIFY_SESSION_UID)
}
val user = session.getUserOrDefault(pr.otherUserId).toMatrixItem()
val name = user.getBestName()
@ -142,17 +143,18 @@ 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())

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.
*/