diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt index ccea6f53b9..71796192a8 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt @@ -246,8 +246,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) { val bobRoomSummariesLive = bob.getRoomSummariesLive(roomSummaryQueryParams { }) val newRoomObserver = object : Observer> { override fun onChanged(t: List?) { - val indexOfFirst = t?.indexOfFirst { it.roomId == roomId } ?: -1 - if (indexOfFirst != -1) { + if (t?.any { it.roomId == roomId }.orFalse()) { bobRoomSummariesLive.removeObserver(this) latch.countDown() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/CancelSendTracker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/CancelSendTracker.kt index 5f6ebc68c2..fe180536c8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/CancelSendTracker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/CancelSendTracker.kt @@ -44,10 +44,10 @@ internal class CancelSendTracker @Inject constructor() { } fun isCancelRequestedFor(eventId: String?, roomId: String?): Boolean { - val index = synchronized(cancellingRequests) { - cancellingRequests.indexOfFirst { it.localId == eventId && it.roomId == roomId } + val found = synchronized(cancellingRequests) { + cancellingRequests.any { it.localId == eventId && it.roomId == roomId } } - return index != -1 + return found } fun markCancelled(eventId: String, roomId: String) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt index f3ff38e237..70562de998 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt @@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.room.summary import io.realm.Realm import io.realm.kotlin.createObject +import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toModel @@ -236,7 +237,7 @@ internal class RoomSummaryUpdater @Inject constructor( .findFirst() ?.let { childSum -> lookupMap.entries.firstOrNull { it.key.roomId == lookedUp.roomId }?.let { entry -> - if (entry.value.indexOfFirst { it.roomId == childSum.roomId } == -1) { + if (entry.value.none { it.roomId == childSum.roomId }) { // add looked up as a parent entry.value.add(childSum) } @@ -299,7 +300,7 @@ internal class RoomSummaryUpdater @Inject constructor( .process(RoomSummaryEntityFields.MEMBERSHIP_STR, Membership.activeMemberships()) .findFirst() ?.let { parentSum -> - if (lookupMap[parentSum]?.indexOfFirst { it.roomId == lookedUp.roomId } == -1) { + if (lookupMap[parentSum]?.none { it.roomId == lookedUp.roomId }.orFalse()) { // add lookedup as a parent lookupMap[parentSum]?.add(lookedUp) } diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewViewModel.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewViewModel.kt index 7b012f4fac..bdb0a96e9e 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewViewModel.kt @@ -46,7 +46,7 @@ import timber.log.Timber class RoomPreviewViewModel @AssistedInject constructor(@Assisted private val initialState: RoomPreviewViewState, private val session: Session) : - VectorViewModel(initialState) { + VectorViewModel(initialState) { @AssistedFactory interface Factory : MavericksAssistedViewModelFactory { @@ -71,7 +71,7 @@ class RoomPreviewViewModel @AssistedInject constructor(@Assisted private val ini .getThreePids() .filterIsInstance() - val status = if (threePids.indexOfFirst { it.email == initialState.fromEmailInvite.email } != -1) { + val status = if (threePids.any { it.email == initialState.fromEmailInvite.email }) { try { session.identityService().getShareStatus(threePids) } catch (failure: Throwable) { diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/advanced/RoomJoinRuleChooseRestrictedViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/advanced/RoomJoinRuleChooseRestrictedViewModel.kt index 4bd7568ccd..7328b1f9f0 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/advanced/RoomJoinRuleChooseRestrictedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/advanced/RoomJoinRuleChooseRestrictedViewModel.kt @@ -308,7 +308,7 @@ class RoomJoinRuleChooseRestrictedViewModel @AssistedInject constructor( private fun handleToggleSelection(action: RoomJoinRuleChooseRestrictedActions.ToggleSelection) = withState { state -> val selection = state.updatedAllowList.toMutableList() - if (selection.indexOfFirst { action.matrixItem.id == it.id } != -1) { + if (selection.any { action.matrixItem.id == it.id }) { selection.removeAll { it.id == action.matrixItem.id } } else { selection.add(action.matrixItem) diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt index 3d628fbaa4..5ffc2a0fae 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt @@ -29,6 +29,7 @@ import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.list.UnreadCounterBadgeView import im.vector.app.group import im.vector.app.space +import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.group.model.GroupSummary import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomSummary @@ -140,7 +141,7 @@ class SpaceSummaryController @Inject constructor( val isSelected = selected is RoomGroupingMethod.BySpace && groupSummary.roomId == selected.space()?.roomId // does it have children? val subSpaces = groupSummary.spaceChildren?.filter { childInfo -> - summaries?.indexOfFirst { it.roomId == childInfo.childRoomId } != -1 + summaries?.any { it.roomId == childInfo.childRoomId }.orFalse() }?.sortedWith(subSpaceComparator) val hasChildren = (subSpaces?.size ?: 0) > 0 val expanded = expandedStates[groupSummary.roomId] == true @@ -191,7 +192,7 @@ class SpaceSummaryController @Inject constructor( val childSummary = summaries?.firstOrNull { it.roomId == info.childRoomId } ?: return // does it have children? val subSpaces = childSummary.spaceChildren?.filter { childInfo -> - summaries.indexOfFirst { it.roomId == childInfo.childRoomId } != -1 + summaries.any { it.roomId == childInfo.childRoomId } }?.sortedWith(subSpaceComparator) val expanded = expandedStates[childSummary.roomId] == true val isSelected = selected is RoomGroupingMethod.BySpace && childSummary.roomId == selected.space()?.roomId