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

View File

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

View File

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

View File

@ -36,7 +36,7 @@ class ReadReceiptsItemFactory @Inject constructor(private val avatarRenderer: Av
}
val readReceiptsData = readReceipts
.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()