mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Prefer usage of any
or none
rather indexOfFirst
wherever it is possible
This commit is contained in:
parent
5efe1f4bd8
commit
fc7beb7e5f
@ -246,8 +246,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
||||
val bobRoomSummariesLive = bob.getRoomSummariesLive(roomSummaryQueryParams { })
|
||||
val newRoomObserver = object : Observer<List<RoomSummary>> {
|
||||
override fun onChanged(t: List<RoomSummary>?) {
|
||||
val indexOfFirst = t?.indexOfFirst { it.roomId == roomId } ?: -1
|
||||
if (indexOfFirst != -1) {
|
||||
if (t?.any { it.roomId == roomId }.orFalse()) {
|
||||
bobRoomSummariesLive.removeObserver(this)
|
||||
latch.countDown()
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ class RoomPreviewViewModel @AssistedInject constructor(@Assisted private val ini
|
||||
.getThreePids()
|
||||
.filterIsInstance<ThreePid.Email>()
|
||||
|
||||
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) {
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user