From eb446d7b4993ff371e1c14179d5b0b340ae9bd58 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 30 Jul 2019 21:20:30 +0200 Subject: [PATCH] Fix code quality issues --- .../session/room/create/CreateRoomTask.kt | 2 +- .../session/sync/UserAccountDataSyncHandler.kt | 2 +- .../user/accountdata/DirectChatsHelper.kt | 16 +++++++++++----- .../res/layout/fragment_create_direct_room.xml | 3 --- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/create/CreateRoomTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/create/CreateRoomTask.kt index f9cad783..7f793a25 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/create/CreateRoomTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/create/CreateRoomTask.kt @@ -82,7 +82,7 @@ internal class DefaultCreateRoomTask @Inject constructor(private val roomAPI: Ro this.isDirect = true } }.flatMap { - val directChats = directChatsHelper.getDirectChats() + val directChats = directChatsHelper.getLocalUserAccount() updateUserAccountDataTask.execute(UpdateUserAccountDataTask.DirectChatParams(directMessages = directChats)) }.flatMap { Try.just(roomId) 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 a303b5b8..73e2f266 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 @@ -79,7 +79,7 @@ internal class UserAccountDataSyncHandler @Inject constructor(private val monarc private fun synchronizeWithServerIfNeeded(realm: Realm, invites: Map?) { if (invites.isNullOrEmpty()) return - val directChats = directChatsHelper.getDirectChats() + val directChats = directChatsHelper.getLocalUserAccount() val directChatInvites = HashMap>().apply { directChats.forEach { (inviterId, roomIds) -> put(inviterId, ArrayList(roomIds)) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/DirectChatsHelper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/DirectChatsHelper.kt index 99212254..0f26f789 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/DirectChatsHelper.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/DirectChatsHelper.kt @@ -24,18 +24,24 @@ import io.realm.RealmConfiguration import timber.log.Timber import javax.inject.Inject -internal class DirectChatsHelper @Inject constructor(@SessionDatabase private val realmConfiguration: RealmConfiguration) { +internal class DirectChatsHelper @Inject constructor(@SessionDatabase + private val realmConfiguration: RealmConfiguration) { - fun getDirectChats(filterRoomId: String? = null): Map> { + /** + * @return a map of userId <-> list of roomId + */ + fun getLocalUserAccount(filterRoomId: String? = null): Map> { return Realm.getInstance(realmConfiguration).use { realm -> val currentDirectRooms = RoomSummaryEntity.getDirectRooms(realm) val directChatsMap = mutableMapOf>() for (directRoom in currentDirectRooms) { if (directRoom.roomId == filterRoomId) continue val directUserId = directRoom.directUserId ?: continue - directChatsMap.getOrPut(directUserId, { arrayListOf() }).apply { - add(directRoom.roomId) - } + directChatsMap + .getOrPut(directUserId, { arrayListOf() }) + .apply { + add(directRoom.roomId) + } } directChatsMap } diff --git a/vector/src/main/res/layout/fragment_create_direct_room.xml b/vector/src/main/res/layout/fragment_create_direct_room.xml index 427df615..41109b14 100644 --- a/vector/src/main/res/layout/fragment_create_direct_room.xml +++ b/vector/src/main/res/layout/fragment_create_direct_room.xml @@ -93,8 +93,6 @@ android:paddingTop="16dp" android:paddingBottom="16dp" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintLeft_toLeftOf="parent" - app:layout_constraintRight_toRightOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/chipGroupScrollView" /> @@ -113,7 +111,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="16dp" - android:layout_marginLeft="16dp" android:layout_marginTop="8dp" android:layout_marginBottom="8dp" android:minHeight="@dimen/layout_touch_size"