From c313ce78cb58d8f9a56550396873ead9ef46bb06 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 8 Aug 2019 17:49:50 +0200 Subject: [PATCH] Read receipts: sort descending by timestamp --- .../mapper/ReadReceiptsSummaryMapper.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/ReadReceiptsSummaryMapper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/ReadReceiptsSummaryMapper.kt index 3887f3ac..b7cdabfc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/ReadReceiptsSummaryMapper.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/ReadReceiptsSummaryMapper.kt @@ -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 @@ -25,15 +26,20 @@ import io.realm.Realm import io.realm.RealmConfiguration import javax.inject.Inject -internal class ReadReceiptsSummaryMapper @Inject constructor(@SessionDatabase private val realmConfiguration: RealmConfiguration){ +internal class ReadReceiptsSummaryMapper @Inject constructor(@SessionDatabase private val realmConfiguration: RealmConfiguration) { fun map(readReceiptsSummaryEntity: ReadReceiptsSummaryEntity): List { return Realm.getInstance(realmConfiguration).use { realm -> - readReceiptsSummaryEntity.readReceipts.mapNotNull { - val user = UserEntity.where(realm, it.userId).findFirst() - ?: return@mapNotNull null - ReadReceipt(user.asDomain(), it.originServerTs.toLong()) - } + 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 + } } }