mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Read receipts: use RoomMember instead of User and avoid creating realm instance each time
This commit is contained in:
parent
fcca75ee23
commit
d27acfa64f
@ -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
|
||||||
)
|
)
|
||||||
|
@ -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())
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
|
@ -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,
|
||||||
|
@ -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()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user