From c7c6cf70e47c497030c76e0142634102ba882538 Mon Sep 17 00:00:00 2001 From: onurays Date: Wed, 6 May 2020 11:20:08 +0300 Subject: [PATCH] Code review fixes. --- .../session/user/DefaultUserService.kt | 8 ++++--- .../invite/InviteUsersToRoomActivity.kt | 21 +++++++------------ .../userdirectory/KnownUsersFragment.kt | 4 +--- .../userdirectory/KnownUsersFragmentArgs.kt | 2 +- .../userdirectory/UserDirectoryViewEvents.kt | 2 +- .../userdirectory/UserDirectoryViewState.kt | 11 ++-------- 6 files changed, 18 insertions(+), 30 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/DefaultUserService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/DefaultUserService.kt index 3a5d524347..7cd2f1b743 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/DefaultUserService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/DefaultUserService.kt @@ -104,9 +104,11 @@ internal class DefaultUserService @Inject constructor(private val monarchy: Mona .contains(UserEntityFields.USER_ID, filter) .endGroup() } - excludedUserIds?.let { - query.not().`in`(UserEntityFields.USER_ID, it.toTypedArray()) - } + excludedUserIds + ?.takeIf { it.isNotEmpty() } + ?.let { + query.not().`in`(UserEntityFields.USER_ID, it.toTypedArray()) + } query.sort(UserEntityFields.DISPLAY_NAME) } return monarchy.findAllPagedWithChanges(realmDataSourceFactory, livePagedListBuilder) diff --git a/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomActivity.kt b/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomActivity.kt index f687fe75cf..08d2653ca9 100644 --- a/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomActivity.kt @@ -26,7 +26,6 @@ import com.airbnb.mvrx.MvRx import com.airbnb.mvrx.viewModel import com.airbnb.mvrx.withState import im.vector.matrix.android.api.failure.Failure -import im.vector.matrix.android.api.session.room.failure.CreateRoomFailure import im.vector.riotx.R import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.error.ErrorFormatter @@ -114,20 +113,16 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() { private fun renderInviteFailure(error: Throwable) { hideWaitingView() - if (error is CreateRoomFailure.CreatedWithTimeout) { - finish() + val message = if (error is Failure.ServerError && error.httpCode == HttpURLConnection.HTTP_INTERNAL_ERROR /*500*/) { + // This error happen if the invited userId does not exist. + getString(R.string.invite_users_to_room_failure) } else { - val message = if (error is Failure.ServerError && error.httpCode == HttpURLConnection.HTTP_INTERNAL_ERROR /*500*/) { - // This error happen if the invited userId does not exist. - getString(R.string.invite_users_to_room_failure) - } else { - errorFormatter.toHumanReadable(error) - } - AlertDialog.Builder(this) - .setMessage(message) - .setPositiveButton(R.string.ok, null) - .show() + errorFormatter.toHumanReadable(error) } + AlertDialog.Builder(this) + .setMessage(message) + .setPositiveButton(R.string.ok, null) + .show() } private fun renderInvitationSuccess() = withState(viewModel) { diff --git a/vector/src/main/java/im/vector/riotx/features/userdirectory/KnownUsersFragment.kt b/vector/src/main/java/im/vector/riotx/features/userdirectory/KnownUsersFragment.kt index c9f97e69fe..78482e0b54 100644 --- a/vector/src/main/java/im/vector/riotx/features/userdirectory/KnownUsersFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/userdirectory/KnownUsersFragment.kt @@ -48,9 +48,7 @@ class KnownUsersFragment @Inject constructor( override fun getLayoutResId() = R.layout.fragment_known_users - override fun getMenuRes() = withState(viewModel) { - return@withState it.menuResId ?: -1 - } + override fun getMenuRes() = args.menuResId private val viewModel: UserDirectoryViewModel by activityViewModel() private lateinit var sharedActionViewModel: UserDirectorySharedActionViewModel diff --git a/vector/src/main/java/im/vector/riotx/features/userdirectory/KnownUsersFragmentArgs.kt b/vector/src/main/java/im/vector/riotx/features/userdirectory/KnownUsersFragmentArgs.kt index 34f1eb826b..9e87633608 100644 --- a/vector/src/main/java/im/vector/riotx/features/userdirectory/KnownUsersFragmentArgs.kt +++ b/vector/src/main/java/im/vector/riotx/features/userdirectory/KnownUsersFragmentArgs.kt @@ -22,6 +22,6 @@ import kotlinx.android.parcel.Parcelize @Parcelize data class KnownUsersFragmentArgs( val title: String, - val menuResId: Int? = null, + val menuResId: Int, val excludedUserIds: Set? = null ) : Parcelable diff --git a/vector/src/main/java/im/vector/riotx/features/userdirectory/UserDirectoryViewEvents.kt b/vector/src/main/java/im/vector/riotx/features/userdirectory/UserDirectoryViewEvents.kt index 8673e55622..435fce8b16 100644 --- a/vector/src/main/java/im/vector/riotx/features/userdirectory/UserDirectoryViewEvents.kt +++ b/vector/src/main/java/im/vector/riotx/features/userdirectory/UserDirectoryViewEvents.kt @@ -19,6 +19,6 @@ package im.vector.riotx.features.userdirectory import im.vector.riotx.core.platform.VectorViewEvents /** - * Transient events for create direct room screen + * Transient events for invite users to room screen */ sealed class UserDirectoryViewEvents : VectorViewEvents diff --git a/vector/src/main/java/im/vector/riotx/features/userdirectory/UserDirectoryViewState.kt b/vector/src/main/java/im/vector/riotx/features/userdirectory/UserDirectoryViewState.kt index 76abad5a00..52f92a9994 100644 --- a/vector/src/main/java/im/vector/riotx/features/userdirectory/UserDirectoryViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/userdirectory/UserDirectoryViewState.kt @@ -30,15 +30,8 @@ data class UserDirectoryViewState( val selectedUsers: Set = emptySet(), val createAndInviteState: Async = Uninitialized, val directorySearchTerm: String = "", - val filterKnownUsersValue: Option = Option.empty(), - val title: String, - val menuResId: Int? + val filterKnownUsersValue: Option = Option.empty() ) : MvRxState { - constructor(args: KnownUsersFragmentArgs) : this(title = args.title, menuResId = args.menuResId, excludedUserIds = args.excludedUserIds) - - enum class DisplayMode { - KNOWN_USERS, - DIRECTORY_USERS - } + constructor(args: KnownUsersFragmentArgs) : this(excludedUserIds = args.excludedUserIds) }