Read receipts: use RoomMember instead of User and avoid creating realm instance each time

This commit is contained in:
ganfra 2022-02-22 12:45:54 +01:00
parent fcca75ee23
commit d27acfa64f
5 changed files with 12 additions and 16 deletions

View File

@ -16,9 +16,7 @@
package org.matrix.android.sdk.api.session.room.model package org.matrix.android.sdk.api.session.room.model
import org.matrix.android.sdk.api.session.user.model.User
data class ReadReceipt( data class ReadReceipt(
val user: User, val roomMember: RoomMemberSummary,
val originServerTs: Long val originServerTs: Long
) )

View File

@ -19,7 +19,7 @@ package org.matrix.android.sdk.internal.database.mapper
import org.matrix.android.sdk.api.session.room.model.ReadReceipt import org.matrix.android.sdk.api.session.room.model.ReadReceipt
import org.matrix.android.sdk.internal.database.RealmSessionProvider import org.matrix.android.sdk.internal.database.RealmSessionProvider
import org.matrix.android.sdk.internal.database.model.ReadReceiptsSummaryEntity import org.matrix.android.sdk.internal.database.model.ReadReceiptsSummaryEntity
import org.matrix.android.sdk.internal.database.model.UserEntity import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntity
import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.database.query.where
import javax.inject.Inject import javax.inject.Inject
@ -29,14 +29,12 @@ internal class ReadReceiptsSummaryMapper @Inject constructor(private val realmSe
if (readReceiptsSummaryEntity == null) { if (readReceiptsSummaryEntity == null) {
return emptyList() return emptyList()
} }
return realmSessionProvider.withRealm { realm -> val readReceipts = readReceiptsSummaryEntity.readReceipts
val readReceipts = readReceiptsSummaryEntity.readReceipts return readReceipts
readReceipts .mapNotNull {
.mapNotNull { val roomMember = RoomMemberSummaryEntity.where(readReceiptsSummaryEntity.realm, roomId = it.roomId, userId = it.userId).findFirst()
val user = UserEntity.where(realm, it.userId).findFirst() ?: return@mapNotNull null
?: return@mapNotNull null ReadReceipt(roomMember.asDomain(), it.originServerTs.toLong())
ReadReceipt(user.asDomain(), it.originServerTs.toLong()) }
}
}
} }
} }

View File

@ -48,7 +48,7 @@ internal class TimelineEventMapper @Inject constructor(private val readReceiptsS
), ),
readReceipts = readReceipts readReceipts = readReceipts
?.distinctBy { ?.distinctBy {
it.user it.roomMember
}?.sortedByDescending { }?.sortedByDescending {
it.originServerTs it.originServerTs
}.orEmpty() }.orEmpty()

View File

@ -516,7 +516,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
val event = itr.previous() val event = itr.previous()
timelineEventsGroups.addOrIgnore(event) timelineEventsGroups.addOrIgnore(event)
val currentReadReceipts = ArrayList(event.readReceipts).filter { val currentReadReceipts = ArrayList(event.readReceipts).filter {
it.user.userId != session.myUserId it.roomMember.userId != session.myUserId
} }
if (timelineEventVisibilityHelper.shouldShowEvent( if (timelineEventVisibilityHelper.shouldShowEvent(
timelineEvent = event, timelineEvent = event,

View File

@ -36,7 +36,7 @@ class ReadReceiptsItemFactory @Inject constructor(private val avatarRenderer: Av
} }
val readReceiptsData = readReceipts val readReceiptsData = readReceipts
.map { .map {
ReadReceiptData(it.user.userId, it.user.avatarUrl, it.user.displayName, it.originServerTs) ReadReceiptData(it.roomMember.userId, it.roomMember.avatarUrl, it.roomMember.displayName, it.originServerTs)
} }
.toList() .toList()