Merge pull request #453 from vector-im/feature/fix_code_quality

Fix code quality issues
This commit is contained in:
ganfra 2019-07-30 21:54:38 +02:00 committed by GitHub
commit 9c390dcc0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 25 deletions

View File

@ -82,7 +82,7 @@ internal class DefaultCreateRoomTask @Inject constructor(private val roomAPI: Ro
this.isDirect = true this.isDirect = true
} }
}.flatMap { }.flatMap {
val directChats = directChatsHelper.getDirectChats() val directChats = directChatsHelper.getLocalUserAccount()
updateUserAccountDataTask.execute(UpdateUserAccountDataTask.DirectChatParams(directMessages = directChats)) updateUserAccountDataTask.execute(UpdateUserAccountDataTask.DirectChatParams(directMessages = directChats))
}.flatMap { }.flatMap {
Try.just(roomId) Try.just(roomId)

View File

@ -78,13 +78,7 @@ internal class UserAccountDataSyncHandler @Inject constructor(private val monarc
// If we get some direct chat invites, we synchronize the user account data including those. // If we get some direct chat invites, we synchronize the user account data including those.
private fun synchronizeWithServerIfNeeded(realm: Realm, invites: Map<String, InvitedRoomSync>?) { private fun synchronizeWithServerIfNeeded(realm: Realm, invites: Map<String, InvitedRoomSync>?) {
if (invites.isNullOrEmpty()) return if (invites.isNullOrEmpty()) return

val directChats = directChatsHelper.getLocalUserAccount()
val directChats = directChatsHelper.getDirectChats()
val directChatInvites = HashMap<String, MutableList<String>>().apply {
directChats.forEach { (inviterId, roomIds) ->
put(inviterId, ArrayList(roomIds))
}
}
var hasUpdate = false var hasUpdate = false
invites.forEach { (roomId, _) -> invites.forEach { (roomId, _) ->
val myUserStateEvent = RoomMembers(realm, roomId).getStateEvent(credentials.userId) val myUserStateEvent = RoomMembers(realm, roomId).getStateEvent(credentials.userId)
@ -92,19 +86,21 @@ internal class UserAccountDataSyncHandler @Inject constructor(private val monarc
val myUserRoomMember: RoomMember? = myUserStateEvent?.let { it.asDomain().content?.toModel() } val myUserRoomMember: RoomMember? = myUserStateEvent?.let { it.asDomain().content?.toModel() }
val isDirect = myUserRoomMember?.isDirect val isDirect = myUserRoomMember?.isDirect
if (inviterId != null && inviterId != credentials.userId && isDirect == true) { if (inviterId != null && inviterId != credentials.userId && isDirect == true) {
directChatInvites.getOrPut(inviterId, { arrayListOf() }).apply { directChats
if (contains(roomId)) { .getOrPut(inviterId, { arrayListOf() })
Timber.v("Direct chats already include room $roomId with user $inviterId") .apply {
} else { if (contains(roomId)) {
this.add(roomId) Timber.v("Direct chats already include room $roomId with user $inviterId")
hasUpdate = true } else {
} add(roomId)
} hasUpdate = true
}
}
} }
} }
if (hasUpdate) { if (hasUpdate) {
val updateUserAccountParams = UpdateUserAccountDataTask.DirectChatParams( val updateUserAccountParams = UpdateUserAccountDataTask.DirectChatParams(
directMessages = directChatInvites directMessages = directChats
) )
updateUserAccountDataTask.configureWith(updateUserAccountParams).executeBy(taskExecutor) updateUserAccountDataTask.configureWith(updateUserAccountParams).executeBy(taskExecutor)
} }

View File

@ -24,18 +24,24 @@ import io.realm.RealmConfiguration
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject 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<String, List<String>> { /**
* @return a map of userId <-> list of roomId
*/
fun getLocalUserAccount(filterRoomId: String? = null): MutableMap<String, MutableList<String>> {
return Realm.getInstance(realmConfiguration).use { realm -> return Realm.getInstance(realmConfiguration).use { realm ->
val currentDirectRooms = RoomSummaryEntity.getDirectRooms(realm) val currentDirectRooms = RoomSummaryEntity.getDirectRooms(realm)
val directChatsMap = mutableMapOf<String, MutableList<String>>() val directChatsMap = mutableMapOf<String, MutableList<String>>()
for (directRoom in currentDirectRooms) { for (directRoom in currentDirectRooms) {
if (directRoom.roomId == filterRoomId) continue if (directRoom.roomId == filterRoomId) continue
val directUserId = directRoom.directUserId ?: continue val directUserId = directRoom.directUserId ?: continue
directChatsMap.getOrPut(directUserId, { arrayListOf() }).apply { directChatsMap
add(directRoom.roomId) .getOrPut(directUserId, { arrayListOf() })
} .apply {
add(directRoom.roomId)
}
} }
directChatsMap directChatsMap
} }

View File

@ -93,8 +93,6 @@
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingBottom="16dp" android:paddingBottom="16dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chipGroupScrollView" /> app:layout_constraintTop_toBottomOf="@+id/chipGroupScrollView" />


@ -113,7 +111,6 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:minHeight="@dimen/layout_touch_size" android:minHeight="@dimen/layout_touch_size"