From d08778c6747a96d2a42b9c7ed5991e4f9818540e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 9 Jul 2019 15:33:31 +0200 Subject: [PATCH] Code quality: equalTo --- .../internal/database/helper/ChunkEntityHelper.kt | 5 ++++- .../internal/database/query/EventEntityQueries.kt | 10 +++++++--- .../internal/database/query/GroupEntityQueries.kt | 3 ++- .../internal/database/query/RoomEntityQueries.kt | 3 ++- .../database/query/TimelineEventEntityQueries.kt | 10 +++++++--- .../internal/session/room/timeline/DefaultTimeline.kt | 4 +++- .../session/sync/UserAccountDataSyncHandler.kt | 4 +++- tools/check/forbidden_strings_in_code.txt | 1 - 8 files changed, 28 insertions(+), 12 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/helper/ChunkEntityHelper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/helper/ChunkEntityHelper.kt index b779ec0824..8e877f89ce 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/helper/ChunkEntityHelper.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/helper/ChunkEntityHelper.kt @@ -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() { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt index 4327b6ee8d..6610edb884 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt @@ -26,11 +26,13 @@ import io.realm.Sort import io.realm.kotlin.where internal fun EventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery { - return realm.where().equalTo(EventEntityFields.EVENT_ID, eventId) + return realm.where() + .equalTo(EventEntityFields.EVENT_ID, eventId) } internal fun EventEntity.Companion.where(realm: Realm, eventIds: List): RealmQuery { - return realm.where().`in`(EventEntityFields.EVENT_ID, eventIds.toTypedArray()) + return realm.where() + .`in`(EventEntityFields.EVENT_ID, eventIds.toTypedArray()) } internal fun EventEntity.Companion.where(realm: Realm, @@ -86,7 +88,9 @@ internal fun RealmQuery.prev(since: Int? = null, strict: Boolean = } internal fun RealmList.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.fastContains(eventId: String): Boolean { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/GroupEntityQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/GroupEntityQueries.kt index 3d27a56b3f..33c9d868e1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/GroupEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/GroupEntityQueries.kt @@ -24,7 +24,8 @@ import io.realm.RealmQuery import io.realm.kotlin.where internal fun GroupEntity.Companion.where(realm: Realm, roomId: String): RealmQuery { - return realm.where().equalTo(GroupEntityFields.GROUP_ID, roomId) + return realm.where() + .equalTo(GroupEntityFields.GROUP_ID, roomId) } internal fun GroupEntity.Companion.where(realm: Realm, membership: Membership? = null): RealmQuery { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/RoomEntityQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/RoomEntityQueries.kt index 031cb93ea1..81818e53fe 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/RoomEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/RoomEntityQueries.kt @@ -25,7 +25,8 @@ import io.realm.RealmQuery import io.realm.kotlin.where internal fun RoomEntity.Companion.where(realm: Realm, roomId: String): RealmQuery { - return realm.where().equalTo(RoomEntityFields.ROOM_ID, roomId) + return realm.where() + .equalTo(RoomEntityFields.ROOM_ID, roomId) } internal fun RoomEntity.Companion.where(realm: Realm, membership: Membership? = null): RealmQuery { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/TimelineEventEntityQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/TimelineEventEntityQueries.kt index 5942118d84..3669ada720 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/TimelineEventEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/TimelineEventEntityQueries.kt @@ -29,11 +29,13 @@ import io.realm.Sort import io.realm.kotlin.where internal fun TimelineEventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery { - return realm.where().equalTo(TimelineEventEntityFields.EVENT_ID, eventId) + return realm.where() + .equalTo(TimelineEventEntityFields.EVENT_ID, eventId) } internal fun TimelineEventEntity.Companion.where(realm: Realm, eventIds: List): RealmQuery { - return realm.where().`in`(TimelineEventEntityFields.EVENT_ID, eventIds.toTypedArray()) + return realm.where() + .`in`(TimelineEventEntityFields.EVENT_ID, eventIds.toTypedArray()) } internal fun TimelineEventEntity.Companion.where(realm: Realm, @@ -111,5 +113,7 @@ internal fun RealmQuery.prev(since: Int? = null, strict: Bo internal fun RealmList.find(eventId: String): TimelineEventEntity? { - return this.where().equalTo(TimelineEventEntityFields.ROOT.EVENT_ID, eventId).findFirst() + return this.where() + .equalTo(TimelineEventEntityFields.ROOT.EVENT_ID, eventId) + .findFirst() } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/DefaultTimeline.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/DefaultTimeline.kt index 3b652d0b70..3925adf190 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/DefaultTimeline.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/DefaultTimeline.kt @@ -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 diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt index 52f66fa419..9c8760493e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt @@ -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 -> diff --git a/tools/check/forbidden_strings_in_code.txt b/tools/check/forbidden_strings_in_code.txt index 13328c3b22..1bc9dd61e4 100644 --- a/tools/check/forbidden_strings_in_code.txt +++ b/tools/check/forbidden_strings_in_code.txt @@ -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)