Read receipts: sort descending by timestamp

This commit is contained in:
ganfra 2019-08-08 17:49:50 +02:00
parent 39f58d048b
commit c313ce78cb

View File

@ -17,6 +17,7 @@
package im.vector.matrix.android.internal.database.mapper

import im.vector.matrix.android.api.session.room.model.ReadReceipt
import im.vector.matrix.android.internal.database.model.ReadReceiptEntityFields
import im.vector.matrix.android.internal.database.model.ReadReceiptsSummaryEntity
import im.vector.matrix.android.internal.database.model.UserEntity
import im.vector.matrix.android.internal.database.query.where
@ -29,11 +30,16 @@ internal class ReadReceiptsSummaryMapper @Inject constructor(@SessionDatabase pr

fun map(readReceiptsSummaryEntity: ReadReceiptsSummaryEntity): List<ReadReceipt> {
return Realm.getInstance(realmConfiguration).use { realm ->
readReceiptsSummaryEntity.readReceipts.mapNotNull {
val readReceipts = readReceiptsSummaryEntity.readReceipts
readReceipts
.mapNotNull {
val user = UserEntity.where(realm, it.userId).findFirst()
?: return@mapNotNull null
ReadReceipt(user.asDomain(), it.originServerTs.toLong())
}
.sortedByDescending {
it.originServerTs
}
}
}