state.otherUserMxItem
cannot be null anymore.
Ensure the User is retrieved from the network, or fallback to a default User object.
This commit is contained in:
parent
6d2a9ec9d5
commit
92d7391232
@ -152,29 +152,25 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun invalidate() = withState(viewModel) { state ->
|
override fun invalidate() = withState(viewModel) { state ->
|
||||||
state.otherUserMxItem?.let { matrixItem ->
|
avatarRenderer.render(state.otherUserMxItem, views.otherUserAvatarImageView)
|
||||||
if (state.isMe) {
|
if (state.isMe) {
|
||||||
avatarRenderer.render(matrixItem, views.otherUserAvatarImageView)
|
if (state.sasTransactionState == VerificationTxState.Verified ||
|
||||||
if (state.sasTransactionState == VerificationTxState.Verified ||
|
state.qrTransactionState == VerificationTxState.Verified ||
|
||||||
state.qrTransactionState == VerificationTxState.Verified ||
|
state.verifiedFromPrivateKeys) {
|
||||||
state.verifiedFromPrivateKeys) {
|
views.otherUserShield.render(RoomEncryptionTrustLevel.Trusted)
|
||||||
views.otherUserShield.render(RoomEncryptionTrustLevel.Trusted)
|
|
||||||
} else {
|
|
||||||
views.otherUserShield.render(RoomEncryptionTrustLevel.Warning)
|
|
||||||
}
|
|
||||||
views.otherUserNameText.text = getString(
|
|
||||||
if (state.selfVerificationMode) R.string.crosssigning_verify_this_session else R.string.crosssigning_verify_session
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
avatarRenderer.render(matrixItem, views.otherUserAvatarImageView)
|
views.otherUserShield.render(RoomEncryptionTrustLevel.Warning)
|
||||||
|
}
|
||||||
if (state.sasTransactionState == VerificationTxState.Verified || state.qrTransactionState == VerificationTxState.Verified) {
|
views.otherUserNameText.text = getString(
|
||||||
views.otherUserNameText.text = getString(R.string.verification_verified_user, matrixItem.getBestName())
|
if (state.selfVerificationMode) R.string.crosssigning_verify_this_session else R.string.crosssigning_verify_session
|
||||||
views.otherUserShield.render(RoomEncryptionTrustLevel.Trusted)
|
)
|
||||||
} else {
|
} else {
|
||||||
views.otherUserNameText.text = getString(R.string.verification_verify_user, matrixItem.getBestName())
|
if (state.sasTransactionState == VerificationTxState.Verified || state.qrTransactionState == VerificationTxState.Verified) {
|
||||||
views.otherUserShield.render(null)
|
views.otherUserNameText.text = getString(R.string.verification_verified_user, state.otherUserMxItem.getBestName())
|
||||||
}
|
views.otherUserShield.render(RoomEncryptionTrustLevel.Trusted)
|
||||||
|
} else {
|
||||||
|
views.otherUserNameText.text = getString(R.string.verification_verify_user, state.otherUserMxItem.getBestName())
|
||||||
|
views.otherUserShield.render(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +267,7 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
|
|||||||
VerificationQRWaitingFragment::class,
|
VerificationQRWaitingFragment::class,
|
||||||
VerificationQRWaitingFragment.Args(
|
VerificationQRWaitingFragment.Args(
|
||||||
isMe = state.isMe,
|
isMe = state.isMe,
|
||||||
otherUserName = state.otherUserMxItem?.getBestName() ?: state.otherUserId
|
otherUserName = state.otherUserMxItem.getBestName()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return@withState
|
return@withState
|
||||||
|
@ -37,6 +37,7 @@ import kotlinx.coroutines.launch
|
|||||||
import org.matrix.android.sdk.api.Matrix
|
import org.matrix.android.sdk.api.Matrix
|
||||||
import org.matrix.android.sdk.api.MatrixCallback
|
import org.matrix.android.sdk.api.MatrixCallback
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.api.raw.RawService
|
import org.matrix.android.sdk.api.raw.RawService
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.KEYBACKUP_SECRET_SSSS_NAME
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.KEYBACKUP_SECRET_SSSS_NAME
|
||||||
@ -70,7 +71,7 @@ data class VerificationBottomSheetViewState(
|
|||||||
val roomId: String?,
|
val roomId: String?,
|
||||||
// true when we display the loading and we wait for the other (incoming request)
|
// true when we display the loading and we wait for the other (incoming request)
|
||||||
val selfVerificationMode: Boolean,
|
val selfVerificationMode: Boolean,
|
||||||
val otherUserMxItem: MatrixItem? = null,
|
val otherUserMxItem: MatrixItem,
|
||||||
val pendingRequest: Async<PendingVerificationRequest> = Uninitialized,
|
val pendingRequest: Async<PendingVerificationRequest> = Uninitialized,
|
||||||
val pendingLocalId: String? = null,
|
val pendingLocalId: String? = null,
|
||||||
val sasTransactionState: VerificationTxState? = null,
|
val sasTransactionState: VerificationTxState? = null,
|
||||||
@ -92,7 +93,8 @@ data class VerificationBottomSheetViewState(
|
|||||||
otherUserId = args.otherUserId,
|
otherUserId = args.otherUserId,
|
||||||
verificationId = args.verificationId,
|
verificationId = args.verificationId,
|
||||||
roomId = args.roomId,
|
roomId = args.roomId,
|
||||||
selfVerificationMode = args.selfVerificationMode
|
selfVerificationMode = args.selfVerificationMode,
|
||||||
|
otherUserMxItem = MatrixItem.UserItem(args.otherUserId),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +128,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val userItem = session.getUser(initialState.otherUserId)
|
fetchOtherUserProfile(initialState.otherUserId)
|
||||||
|
|
||||||
var autoReady = false
|
var autoReady = false
|
||||||
val pr = if (initialState.selfVerificationMode) {
|
val pr = if (initialState.selfVerificationMode) {
|
||||||
@ -160,7 +162,6 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
|
|||||||
|
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
otherUserMxItem = userItem?.toMatrixItem(),
|
|
||||||
sasTransactionState = sasTx?.state,
|
sasTransactionState = sasTx?.state,
|
||||||
qrTransactionState = qrTx?.state,
|
qrTransactionState = qrTx?.state,
|
||||||
transactionId = pr?.transactionId ?: initialState.verificationId,
|
transactionId = pr?.transactionId ?: initialState.verificationId,
|
||||||
@ -183,6 +184,28 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun fetchOtherUserProfile(otherUserId: String) {
|
||||||
|
session.getUser(otherUserId)?.toMatrixItem()?.let {
|
||||||
|
setState {
|
||||||
|
copy(
|
||||||
|
otherUserMxItem = it
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Always fetch the latest User data
|
||||||
|
viewModelScope.launch {
|
||||||
|
tryOrNull { session.userService().resolveUser(otherUserId) }
|
||||||
|
?.toMatrixItem()
|
||||||
|
?.let {
|
||||||
|
setState {
|
||||||
|
copy(
|
||||||
|
otherUserMxItem = it
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
session.cryptoService().verificationService().removeListener(this)
|
session.cryptoService().verificationService().removeListener(this)
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
|
@ -26,6 +26,7 @@ import im.vector.app.core.utils.colorizeMatchingText
|
|||||||
import im.vector.app.features.crypto.verification.VerificationBottomSheetViewState
|
import im.vector.app.features.crypto.verification.VerificationBottomSheetViewState
|
||||||
import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem
|
import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem
|
||||||
import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
|
import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
|
||||||
|
import im.vector.app.features.displayname.getBestName
|
||||||
import im.vector.lib.core.utils.epoxy.charsequence.EpoxyCharSequence
|
import im.vector.lib.core.utils.epoxy.charsequence.EpoxyCharSequence
|
||||||
import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
|
import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -61,7 +62,7 @@ class VerificationCancelController @Inject constructor(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val otherUserID = state.otherUserId
|
val otherUserID = state.otherUserId
|
||||||
val otherDisplayName = state.otherUserMxItem?.displayName ?: state.otherUserId
|
val otherDisplayName = state.otherUserMxItem.getBestName()
|
||||||
bottomSheetVerificationNoticeItem {
|
bottomSheetVerificationNoticeItem {
|
||||||
id("notice")
|
id("notice")
|
||||||
notice(
|
notice(
|
||||||
|
@ -54,7 +54,7 @@ class VerificationQrScannedByOtherController @Inject constructor(
|
|||||||
if (state.isMe) {
|
if (state.isMe) {
|
||||||
notice(host.stringProvider.getString(R.string.qr_code_scanned_self_verif_notice).toEpoxyCharSequence())
|
notice(host.stringProvider.getString(R.string.qr_code_scanned_self_verif_notice).toEpoxyCharSequence())
|
||||||
} else {
|
} else {
|
||||||
val name = state.otherUserMxItem?.getBestName() ?: state.otherUserId
|
val name = state.otherUserMxItem.getBestName()
|
||||||
notice(host.stringProvider.getString(R.string.qr_code_scanned_by_other_notice, name).toEpoxyCharSequence())
|
notice(host.stringProvider.getString(R.string.qr_code_scanned_by_other_notice, name).toEpoxyCharSequence())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,6 @@ class VerificationRequestController @Inject constructor(
|
|||||||
|
|
||||||
override fun buildModels() {
|
override fun buildModels() {
|
||||||
val state = viewState ?: return
|
val state = viewState ?: return
|
||||||
val matrixItem = state.otherUserMxItem ?: return
|
|
||||||
val host = this
|
val host = this
|
||||||
|
|
||||||
if (state.selfVerificationMode) {
|
if (state.selfVerificationMode) {
|
||||||
@ -107,11 +106,9 @@ class VerificationRequestController @Inject constructor(
|
|||||||
if (state.isMe) {
|
if (state.isMe) {
|
||||||
stringProvider.getString(R.string.verify_new_session_notice)
|
stringProvider.getString(R.string.verify_new_session_notice)
|
||||||
} else {
|
} else {
|
||||||
matrixItem.let {
|
stringProvider.getString(R.string.verification_request_notice, state.otherUserId)
|
||||||
stringProvider.getString(R.string.verification_request_notice, it.id)
|
.toSpannable()
|
||||||
.toSpannable()
|
.colorizeMatchingText(state.otherUserId, colorProvider.getColorFromAttribute(R.attr.vctr_notice_text_color))
|
||||||
.colorizeMatchingText(it.id, colorProvider.getColorFromAttribute(R.attr.vctr_notice_text_color))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bottomSheetVerificationNoticeItem {
|
bottomSheetVerificationNoticeItem {
|
||||||
@ -138,7 +135,7 @@ class VerificationRequestController @Inject constructor(
|
|||||||
is Loading -> {
|
is Loading -> {
|
||||||
bottomSheetVerificationWaitingItem {
|
bottomSheetVerificationWaitingItem {
|
||||||
id("waiting")
|
id("waiting")
|
||||||
title(host.stringProvider.getString(R.string.verification_request_waiting_for, matrixItem.getBestName()))
|
title(host.stringProvider.getString(R.string.verification_request_waiting_for, state.otherUserMxItem.getBestName()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is Success -> {
|
is Success -> {
|
||||||
@ -151,7 +148,7 @@ class VerificationRequestController @Inject constructor(
|
|||||||
} else {
|
} else {
|
||||||
bottomSheetVerificationWaitingItem {
|
bottomSheetVerificationWaitingItem {
|
||||||
id("waiting")
|
id("waiting")
|
||||||
title(host.stringProvider.getString(R.string.verification_request_waiting_for, matrixItem.getBestName()))
|
title(host.stringProvider.getString(R.string.verification_request_waiting_for, state.otherUserMxItem.getBestName()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user