Code quality: equalTo

This commit is contained in:
Benoit Marty 2019-07-09 15:33:31 +02:00
parent 0919b9460d
commit d08778c674
8 changed files with 28 additions and 12 deletions

View File

@ -34,7 +34,10 @@ import io.realm.Sort
// By default if a chunk is empty we consider it unlinked
internal fun ChunkEntity.isUnlinked(): Boolean {
assertIsManaged()
return timelineEvents.where().equalTo(TimelineEventEntityFields.ROOT.IS_UNLINKED, false).findAll().isEmpty()
return timelineEvents.where()
.equalTo(TimelineEventEntityFields.ROOT.IS_UNLINKED, false)
.findAll()
.isEmpty()
}
internal fun ChunkEntity.deleteOnCascade() {

View File

@ -26,11 +26,13 @@ import io.realm.Sort
import io.realm.kotlin.where
internal fun EventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery<EventEntity> {
return realm.where<EventEntity>().equalTo(EventEntityFields.EVENT_ID, eventId)
return realm.where<EventEntity>()
.equalTo(EventEntityFields.EVENT_ID, eventId)
}
internal fun EventEntity.Companion.where(realm: Realm, eventIds: List<String>): RealmQuery<EventEntity> {
return realm.where<EventEntity>().`in`(EventEntityFields.EVENT_ID, eventIds.toTypedArray())
return realm.where<EventEntity>()
.`in`(EventEntityFields.EVENT_ID, eventIds.toTypedArray())
}
internal fun EventEntity.Companion.where(realm: Realm,
@ -86,7 +88,9 @@ internal fun RealmQuery<EventEntity>.prev(since: Int? = null, strict: Boolean =
}
internal fun RealmList<EventEntity>.find(eventId: String): EventEntity? {
return this.where().equalTo(EventEntityFields.EVENT_ID, eventId).findFirst()
return this.where()
.equalTo(EventEntityFields.EVENT_ID, eventId)
.findFirst()
}
internal fun RealmList<EventEntity>.fastContains(eventId: String): Boolean {

View File

@ -24,7 +24,8 @@ import io.realm.RealmQuery
import io.realm.kotlin.where
internal fun GroupEntity.Companion.where(realm: Realm, roomId: String): RealmQuery<GroupEntity> {
return realm.where<GroupEntity>().equalTo(GroupEntityFields.GROUP_ID, roomId)
return realm.where<GroupEntity>()
.equalTo(GroupEntityFields.GROUP_ID, roomId)
}
internal fun GroupEntity.Companion.where(realm: Realm, membership: Membership? = null): RealmQuery<GroupEntity> {

View File

@ -25,7 +25,8 @@ import io.realm.RealmQuery
import io.realm.kotlin.where
internal fun RoomEntity.Companion.where(realm: Realm, roomId: String): RealmQuery<RoomEntity> {
return realm.where<RoomEntity>().equalTo(RoomEntityFields.ROOM_ID, roomId)
return realm.where<RoomEntity>()
.equalTo(RoomEntityFields.ROOM_ID, roomId)
}
internal fun RoomEntity.Companion.where(realm: Realm, membership: Membership? = null): RealmQuery<RoomEntity> {

View File

@ -29,11 +29,13 @@ import io.realm.Sort
import io.realm.kotlin.where
internal fun TimelineEventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery<TimelineEventEntity> {
return realm.where<TimelineEventEntity>().equalTo(TimelineEventEntityFields.EVENT_ID, eventId)
return realm.where<TimelineEventEntity>()
.equalTo(TimelineEventEntityFields.EVENT_ID, eventId)
}
internal fun TimelineEventEntity.Companion.where(realm: Realm, eventIds: List<String>): RealmQuery<TimelineEventEntity> {
return realm.where<TimelineEventEntity>().`in`(TimelineEventEntityFields.EVENT_ID, eventIds.toTypedArray())
return realm.where<TimelineEventEntity>()
.`in`(TimelineEventEntityFields.EVENT_ID, eventIds.toTypedArray())
}
internal fun TimelineEventEntity.Companion.where(realm: Realm,
@ -111,5 +113,7 @@ internal fun RealmQuery<TimelineEventEntity>.prev(since: Int? = null, strict: Bo
internal fun RealmList<TimelineEventEntity>.find(eventId: String): TimelineEventEntity? {
return this.where().equalTo(TimelineEventEntityFields.ROOT.EVENT_ID, eventId).findFirst()
return this.where()
.equalTo(TimelineEventEntityFields.ROOT.EVENT_ID, eventId)
.findFirst()
}

View File

@ -351,7 +351,9 @@ internal class DefaultTimeline(
val initialDisplayIndex = if (isLive) {
liveEvents.firstOrNull()?.root?.displayIndex
} else {
val initialEvent = liveEvents.where().equalTo(TimelineEventEntityFields.EVENT_ID, initialEventId).findFirst()
val initialEvent = liveEvents.where()
.equalTo(TimelineEventEntityFields.EVENT_ID, initialEventId)
.findFirst()
shouldFetchInitialEvent = initialEvent == null
initialEvent?.root?.displayIndex
} ?: DISPLAY_INDEX_UNKNOWN

View File

@ -40,7 +40,9 @@ internal class UserAccountDataSyncHandler @Inject constructor(private val monarc
val newDirectRoomIds = directMessages.content.values.flatten()
monarchy.runTransactionSync { realm ->
val oldDirectRooms = RoomSummaryEntity.where(realm).equalTo(RoomSummaryEntityFields.IS_DIRECT, true).findAll()
val oldDirectRooms = RoomSummaryEntity.where(realm)
.equalTo(RoomSummaryEntityFields.IS_DIRECT, true)
.findAll()
oldDirectRooms.forEach { it.isDirect = false }
newDirectRoomIds.forEach { roomId ->

View File

@ -121,7 +121,6 @@ ButterKnife\.findById\(
### Bad formatting of Realm query chain. Insert new line
\)\.equalTo
\)\.findAll
# Use StandardCharsets.UTF_8.name()
# DISABLED (min API to low)