Prefer using state.otherUserId over nullable state.otherUserMxItem?.id

This commit is contained in:
Benoit Marty 2022-09-14 19:05:38 +02:00
parent 7982f4be00
commit 6d2a9ec9d5
7 changed files with 17 additions and 19 deletions

View file

@ -235,7 +235,7 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
showFragment(
VerificationEmojiCodeFragment::class,
VerificationArgs(
state.otherUserMxItem?.id ?: "",
state.otherUserId,
// If it was outgoing it.transaction id would be null, but the pending request
// would be updated (from localId to txId)
state.pendingRequest.invoke()?.transactionId ?: state.transactionId
@ -271,7 +271,7 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
VerificationQRWaitingFragment::class,
VerificationQRWaitingFragment.Args(
isMe = state.isMe,
otherUserName = state.otherUserMxItem?.getBestName() ?: ""
otherUserName = state.otherUserMxItem?.getBestName() ?: state.otherUserId
)
)
return@withState
@ -319,7 +319,7 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
showFragment(
VerificationChooseMethodFragment::class,
VerificationArgs(
otherUserId = state.otherUserMxItem?.id ?: "",
otherUserId = state.otherUserId,
verificationId = state.pendingRequest.invoke()?.transactionId
)
)
@ -328,7 +328,7 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
showFragment(
VerificationRequestFragment::class,
VerificationArgs(
otherUserId = state.otherUserMxItem?.id ?: "",
otherUserId = state.otherUserId,
verificationId = state.pendingRequest.invoke()?.transactionId,
verificationLocalId = state.roomId
)
@ -340,7 +340,7 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
showFragment(
VerificationChooseMethodFragment::class,
VerificationArgs(
otherUserId = state.otherUserMxItem?.id ?: "",
otherUserId = state.otherUserId,
verificationId = state.pendingRequest.invoke()?.transactionId
)
)

View file

@ -216,12 +216,12 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
private fun cancelAllPendingVerifications(state: VerificationBottomSheetViewState) {
session.cryptoService()
.verificationService().getExistingVerificationRequest(state.otherUserMxItem?.id ?: "", state.transactionId)?.let {
.verificationService().getExistingVerificationRequest(state.otherUserId, state.transactionId)?.let {
session.cryptoService().verificationService().cancelVerificationRequest(it)
}
session.cryptoService()
.verificationService()
.getExistingTransaction(state.otherUserMxItem?.id ?: "", state.transactionId ?: "")
.getExistingTransaction(state.otherUserId, state.transactionId ?: "")
?.cancel(CancelCode.User)
}
@ -249,7 +249,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
}
override fun handle(action: VerificationAction) = withState { state ->
val otherUserId = state.otherUserMxItem?.id ?: return@withState
val otherUserId = state.otherUserId
val roomId = state.roomId
?: session.roomService().getExistingDirectRoomWithUser(otherUserId)
@ -514,7 +514,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
override fun transactionUpdated(tx: VerificationTransaction) = withState { state ->
if (state.selfVerificationMode && state.transactionId == null) {
// is this an incoming with that user
if (tx.isIncoming && tx.otherUserId == state.otherUserMxItem?.id) {
if (tx.isIncoming && tx.otherUserId == state.otherUserId) {
// Also auto accept incoming if needed!
if (tx is IncomingSasVerificationTransaction) {
if (tx.uxState == IncomingSasVerificationTransaction.UxState.SHOW_ACCEPT) {
@ -564,7 +564,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
if (state.selfVerificationMode && state.pendingRequest.invoke() == null && state.transactionId == null) {
// is this an incoming with that user
if (pr.isIncoming && pr.otherUserId == state.otherUserMxItem?.id) {
if (pr.isIncoming && pr.otherUserId == state.otherUserId) {
if (!pr.isReady) {
// auto ready in this case, as we are waiting
// TODO, can I be here in DM mode? in this case should test if roomID is null?

View file

@ -60,8 +60,8 @@ class VerificationCancelController @Inject constructor(
}
}
} else {
val otherUserID = state.otherUserMxItem?.id ?: ""
val otherDisplayName = state.otherUserMxItem?.displayName ?: ""
val otherUserID = state.otherUserId
val otherDisplayName = state.otherUserMxItem?.displayName ?: state.otherUserId
bottomSheetVerificationNoticeItem {
id("notice")
notice(

View file

@ -78,7 +78,7 @@ class VerificationChooseMethodFragment :
override fun doVerifyBySas() = withState(sharedViewModel) { state ->
sharedViewModel.handle(
VerificationAction.StartSASVerification(
state.otherUserMxItem?.id ?: "",
state.otherUserId,
state.pendingRequest.invoke()?.transactionId ?: ""
)
)
@ -130,7 +130,7 @@ class VerificationChooseMethodFragment :
private fun onRemoteQrCodeScanned(remoteQrCode: String) = withState(sharedViewModel) { state ->
sharedViewModel.handle(
VerificationAction.RemoteQrCodeScanned(
state.otherUserMxItem?.id ?: "",
state.otherUserId,
state.pendingRequest.invoke()?.transactionId ?: "",
remoteQrCode
)

View file

@ -54,7 +54,7 @@ class VerificationQrScannedByOtherController @Inject constructor(
if (state.isMe) {
notice(host.stringProvider.getString(R.string.qr_code_scanned_self_verif_notice).toEpoxyCharSequence())
} else {
val name = state.otherUserMxItem?.getBestName() ?: ""
val name = state.otherUserMxItem?.getBestName() ?: state.otherUserId
notice(host.stringProvider.getString(R.string.qr_code_scanned_by_other_notice, name).toEpoxyCharSequence())
}
}

View file

@ -52,7 +52,7 @@ class VerificationRequestController @Inject constructor(
override fun buildModels() {
val state = viewState ?: return
val matrixItem = viewState?.otherUserMxItem ?: return
val matrixItem = state.otherUserMxItem ?: return
val host = this
if (state.selfVerificationMode) {

View file

@ -64,9 +64,7 @@ class VerificationRequestFragment :
}
override fun onClickOnVerificationStart(): Unit = withState(viewModel) { state ->
state.otherUserMxItem?.id?.let { otherUserId ->
viewModel.handle(VerificationAction.RequestVerificationByDM(otherUserId, state.roomId))
}
viewModel.handle(VerificationAction.RequestVerificationByDM(state.otherUserId, state.roomId))
}
override fun onClickRecoverFromPassphrase() {