From 63a59dbc0c61c8154c6e3d3ab0c1e8c5c259ec1c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 19 Apr 2021 14:11:24 +0200 Subject: [PATCH] Defensive code against invalid userId --- .../login2/created/AccountCreatedViewModel.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/login2/created/AccountCreatedViewModel.kt b/vector/src/main/java/im/vector/app/features/login2/created/AccountCreatedViewModel.kt index d1684a9867..1acec968b6 100644 --- a/vector/src/main/java/im/vector/app/features/login2/created/AccountCreatedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/login2/created/AccountCreatedViewModel.kt @@ -25,10 +25,13 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import im.vector.app.core.platform.VectorViewModel import kotlinx.coroutines.launch +import org.matrix.android.sdk.api.MatrixPatterns import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.toMatrixItem import org.matrix.android.sdk.rx.rx import org.matrix.android.sdk.rx.unwrap +import timber.log.Timber class AccountCreatedViewModel @AssistedInject constructor( @Assisted initialState: AccountCreatedViewState, @@ -62,7 +65,14 @@ class AccountCreatedViewModel @AssistedInject constructor( session.rx() .liveUser(session.myUserId) .unwrap() - .map { it.toMatrixItem() } + .map { + if (MatrixPatterns.isUserId(it.userId)) { + it.toMatrixItem() + } else { + Timber.w("liveUser() has returned an invalid user: $it") + MatrixItem.UserItem(session.myUserId, null, null) + } + } .execute { copy(currentUser = it) }