Cleanup code.
This commit is contained in:
parent
a807141a91
commit
c7e8582778
1 changed files with 76 additions and 68 deletions
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
package io.element.android.features.messages.impl.crypto.identity
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
|
|
@ -35,7 +36,39 @@ fun IdentityChangeStateView(
|
|||
val identityChangeViolation = state.roomMemberIdentityStateChanges.firstOrNull {
|
||||
it.identityState.isAViolation()
|
||||
}
|
||||
if (identityChangeViolation != null) {
|
||||
when (identityChangeViolation?.identityState) {
|
||||
IdentityState.PinViolation -> ViolationAlert(
|
||||
identityChangeViolation = identityChangeViolation,
|
||||
onLinkClick = onLinkClick,
|
||||
textId = CommonStrings.crypto_identity_change_pin_violation_new,
|
||||
isCritical = false,
|
||||
submitTextId = CommonStrings.action_ok,
|
||||
onSubmitClick = { state.eventSink(IdentityChangeEvent.PinIdentity(identityChangeViolation.identityRoomMember.userId)) },
|
||||
modifier = modifier,
|
||||
)
|
||||
IdentityState.VerificationViolation -> ViolationAlert(
|
||||
identityChangeViolation = identityChangeViolation,
|
||||
onLinkClick = onLinkClick,
|
||||
textId = CommonStrings.crypto_identity_change_verification_violation_new,
|
||||
isCritical = true,
|
||||
submitTextId = CommonStrings.crypto_identity_change_withdraw_verification_action,
|
||||
onSubmitClick = { state.eventSink(IdentityChangeEvent.WithdrawVerification(identityChangeViolation.identityRoomMember.userId)) },
|
||||
modifier = modifier,
|
||||
)
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ViolationAlert(
|
||||
identityChangeViolation: RoomMemberIdentityStateChange,
|
||||
onLinkClick: (String, Boolean) -> Unit,
|
||||
@StringRes textId: Int,
|
||||
isCritical: Boolean,
|
||||
@StringRes submitTextId: Int,
|
||||
onSubmitClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
ComposerAlertMolecule(
|
||||
modifier = modifier,
|
||||
avatar = identityChangeViolation.identityRoomMember.avatarData,
|
||||
|
|
@ -46,21 +79,7 @@ fun IdentityChangeStateView(
|
|||
CommonStrings.crypto_identity_change_pin_violation_new_user_id,
|
||||
identityChangeViolation.identityRoomMember.userId,
|
||||
)
|
||||
val fullText = if (identityChangeViolation.identityState == IdentityState.PinViolation) {
|
||||
stringResource(
|
||||
id = CommonStrings.crypto_identity_change_pin_violation_new,
|
||||
displayName,
|
||||
userIdStr,
|
||||
learnMoreStr,
|
||||
)
|
||||
} else {
|
||||
stringResource(
|
||||
id = CommonStrings.crypto_identity_change_verification_violation_new,
|
||||
displayName,
|
||||
userIdStr,
|
||||
learnMoreStr,
|
||||
)
|
||||
}
|
||||
val fullText = stringResource(textId, displayName, userIdStr, learnMoreStr)
|
||||
append(fullText)
|
||||
val userIdStartIndex = fullText.indexOf(userIdStr)
|
||||
addStyle(
|
||||
|
|
@ -91,21 +110,10 @@ fun IdentityChangeStateView(
|
|||
end = learnMoreStartIndex + learnMoreStr.length,
|
||||
)
|
||||
},
|
||||
submitText = if (identityChangeViolation.identityState == IdentityState.VerificationViolation) {
|
||||
stringResource(CommonStrings.crypto_identity_change_withdraw_verification_action)
|
||||
} else {
|
||||
stringResource(CommonStrings.action_ok)
|
||||
},
|
||||
onSubmitClick = {
|
||||
if (identityChangeViolation.identityState == IdentityState.VerificationViolation) {
|
||||
state.eventSink(IdentityChangeEvent.WithdrawVerification(identityChangeViolation.identityRoomMember.userId))
|
||||
} else {
|
||||
state.eventSink(IdentityChangeEvent.PinIdentity(identityChangeViolation.identityRoomMember.userId))
|
||||
}
|
||||
},
|
||||
isCritical = identityChangeViolation.identityState == IdentityState.VerificationViolation,
|
||||
submitText = stringResource(submitTextId),
|
||||
onSubmitClick = onSubmitClick,
|
||||
isCritical = isCritical,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@PreviewsDayNight
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue