Fix threads sort order, newest first

This commit is contained in:
ariskotsomitopoulos 2021-12-14 15:44:38 +02:00
parent d56281dca7
commit 5ceed4096e
2 changed files with 5 additions and 2 deletions

View File

@ -103,7 +103,7 @@ internal fun TimelineEventEntity.Companion.findAllThreadsForRoomId(realm: Realm,
TimelineEventEntity
.whereRoomId(realm, roomId = roomId)
.equalTo(TimelineEventEntityFields.ROOT.IS_ROOT_THREAD, true)
.sort(TimelineEventEntityFields.DISPLAY_INDEX, Sort.DESCENDING)
.sort("${TimelineEventEntityFields.ROOT.THREAD_SUMMARY_LATEST_MESSAGE}.${TimelineEventEntityFields.DISPLAY_INDEX}", Sort.DESCENDING)
/**
* Find the number of all the local notifications for the specified room
@ -188,7 +188,9 @@ internal fun updateNotificationsNew(roomId: String, realm: Realm, currentUserId:
val readReceiptChunkPosition = readReceiptChunkTimelineEvents.indexOfFirst { it.eventId == readReceipt }
if (readReceiptChunkPosition != -1 && readReceiptChunkPosition != readReceiptChunkTimelineEvents.lastIndex) {
if(readReceiptChunkPosition == -1) return
if (readReceiptChunkPosition < readReceiptChunkTimelineEvents.lastIndex) {
// If the read receipt is found inside the chunk
val threadEventsAfterReadReceipt = readReceiptChunkTimelineEvents

View File

@ -167,6 +167,7 @@ internal class DefaultTimeline(
timelineEvents = rootThreadEventId?.let {
TimelineEventEntity
.whereRoomId(realm, roomId = roomId)
.equalTo(TimelineEventEntityFields.CHUNK.IS_LAST_FORWARD, true)
.equalTo(TimelineEventEntityFields.ROOT.ROOT_THREAD_EVENT_ID, it)
.or()
.equalTo(TimelineEventEntityFields.ROOT.EVENT_ID, it)