Properly sort rooms according to events previewed in summary

Change-Id: Id17385a4d17869b0356aa7242407581e2193845e
This commit is contained in:
SpiritCroc 2021-05-01 10:39:10 +02:00
parent 3ee98f3c94
commit 2605c6ac9b
4 changed files with 12 additions and 8 deletions

View File

@ -100,13 +100,13 @@ data class RoomSummary constructor(
fun scLatestPreviewableEvent(preferenceProvider: RoomSummaryPreferenceProvider?): TimelineEvent? {
if (preferenceProvider == null) {
// Fallback to default
return latestPreviewableEvent
return latestPreviewableOriginalContentEvent
}
return when(preferenceProvider.getUnreadKind(isDirect)) {
UNREAD_KIND_ORIGINAL_CONTENT -> latestPreviewableOriginalContentEvent
UNREAD_KIND_CONTENT -> latestPreviewableContentEvent
// UNREAD_KIND_DEFAULT
else -> latestPreviewableEvent
else -> latestPreviewableOriginalContentEvent
}
}

View File

@ -207,7 +207,7 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
obj.setBoolean(RoomSummaryEntityFields.IS_LOW_PRIORITY, isLowPriority)
// XXX migrate last message origin server ts
obj.getObject(RoomSummaryEntityFields.LATEST_PREVIEWABLE_EVENT.`$`)
obj.getObject(RoomSummaryEntityFields.LATEST_PREVIEWABLE_ORIGINAL_CONTENT_EVENT.`$`)
?.getObject(TimelineEventEntityFields.ROOT.`$`)
?.getLong(EventEntityFields.ORIGIN_SERVER_TS)?.let {
obj.setLong(RoomSummaryEntityFields.LAST_ACTIVITY_TIME, it)

View File

@ -100,7 +100,7 @@ internal class RoomSummaryUpdater @Inject constructor(
val latestPreviewableContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEvent(realm, roomId)
val latestPreviewableOriginalContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEventScOriginalContent(realm, roomId)
val lastActivityFromEvent = latestPreviewableEvent?.root?.originServerTs
val lastActivityFromEvent = latestPreviewableOriginalContentEvent?.root?.originServerTs
if (lastActivityFromEvent != null) {
roomSummaryEntity.lastActivityTime = lastActivityFromEvent
}
@ -140,9 +140,9 @@ internal class RoomSummaryUpdater @Inject constructor(
}
roomSummaryEntity.updateHasFailedSending()
val root = latestPreviewableEvent?.root
val root = latestPreviewableOriginalContentEvent?.root
if (root?.type == EventType.ENCRYPTED && root.decryptionResultJson == null) {
Timber.v("Should decrypt ${latestPreviewableEvent.eventId}")
Timber.v("Should decrypt ${latestPreviewableOriginalContentEvent.eventId}")
// mmm i want to decrypt now or is it ok to do it async?
tryOrNull {
eventDecryptor.decryptEvent(root.asDomain(), "")
@ -174,5 +174,7 @@ internal class RoomSummaryUpdater @Inject constructor(
val roomSummaryEntity = RoomSummaryEntity.getOrCreate(realm, roomId)
roomSummaryEntity.updateHasFailedSending()
roomSummaryEntity.latestPreviewableEvent = RoomSummaryEventsHelper.getLatestPreviewableEvent(realm, roomId)
roomSummaryEntity.latestPreviewableContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEvent(realm, roomId)
roomSummaryEntity.latestPreviewableOriginalContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEventScOriginalContent(realm, roomId)
}
}

View File

@ -175,6 +175,8 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri
currentLastForwardChunk?.deleteOnCascade(deleteStateEvents = false, canDeleteRoot = false)
RoomSummaryEntity.where(realm, roomId).findFirst()?.apply {
latestPreviewableEvent = RoomSummaryEventsHelper.getLatestPreviewableEvent(realm, roomId)
latestPreviewableContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEvent(realm, roomId)
latestPreviewableOriginalContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEventScOriginalContent(realm, roomId)
}
}
} else {
@ -238,10 +240,10 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri
it.deleteOnCascade(deleteStateEvents = false, canDeleteRoot = false)
}
val roomSummaryEntity = RoomSummaryEntity.getOrCreate(realm, roomId)
val shouldUpdateSummary = roomSummaryEntity.latestPreviewableEvent == null
val shouldUpdateSummary = roomSummaryEntity.latestPreviewableOriginalContentEvent == null
|| (chunksToDelete.isNotEmpty() && currentChunk.isLastForward && direction == PaginationDirection.FORWARDS)
if (shouldUpdateSummary) {
roomSummaryEntity.latestPreviewableEvent = RoomSummaryEventsHelper.getLatestPreviewableEvent(realm, roomId)
roomSummaryEntity.latestPreviewableOriginalContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEventScOriginalContent(realm, roomId)
}
if (currentChunk.isValid) {
RoomEntity.where(realm, roomId).findFirst()?.addIfNecessary(currentChunk)