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
|
package io.element.android.features.messages.impl.crypto.identity
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
|
@ -35,7 +36,39 @@ fun IdentityChangeStateView(
|
||||||
val identityChangeViolation = state.roomMemberIdentityStateChanges.firstOrNull {
|
val identityChangeViolation = state.roomMemberIdentityStateChanges.firstOrNull {
|
||||||
it.identityState.isAViolation()
|
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(
|
ComposerAlertMolecule(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
avatar = identityChangeViolation.identityRoomMember.avatarData,
|
avatar = identityChangeViolation.identityRoomMember.avatarData,
|
||||||
|
|
@ -46,21 +79,7 @@ fun IdentityChangeStateView(
|
||||||
CommonStrings.crypto_identity_change_pin_violation_new_user_id,
|
CommonStrings.crypto_identity_change_pin_violation_new_user_id,
|
||||||
identityChangeViolation.identityRoomMember.userId,
|
identityChangeViolation.identityRoomMember.userId,
|
||||||
)
|
)
|
||||||
val fullText = if (identityChangeViolation.identityState == IdentityState.PinViolation) {
|
val fullText = stringResource(textId, displayName, userIdStr, learnMoreStr)
|
||||||
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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
append(fullText)
|
append(fullText)
|
||||||
val userIdStartIndex = fullText.indexOf(userIdStr)
|
val userIdStartIndex = fullText.indexOf(userIdStr)
|
||||||
addStyle(
|
addStyle(
|
||||||
|
|
@ -91,22 +110,11 @@ fun IdentityChangeStateView(
|
||||||
end = learnMoreStartIndex + learnMoreStr.length,
|
end = learnMoreStartIndex + learnMoreStr.length,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
submitText = if (identityChangeViolation.identityState == IdentityState.VerificationViolation) {
|
submitText = stringResource(submitTextId),
|
||||||
stringResource(CommonStrings.crypto_identity_change_withdraw_verification_action)
|
onSubmitClick = onSubmitClick,
|
||||||
} else {
|
isCritical = isCritical,
|
||||||
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,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@PreviewsDayNight
|
@PreviewsDayNight
|
||||||
@Composable
|
@Composable
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue