Room list : add quick ordering

This commit is contained in:
ganfra
2019-01-29 16:02:42 +01:00
parent 0e7596e0aa
commit 6df8809ee0
8 changed files with 109 additions and 13 deletions

View File

@ -16,6 +16,7 @@
package im.vector.matrix.android.api.session.room.model
import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.room.model.tag.RoomTag
/**
@ -28,6 +29,7 @@ data class RoomSummary(
val topic: String = "",
val avatarUrl: String = "",
val isDirect: Boolean,
val lastMessage: Event? = null,
val otherMemberIds: List<String> = emptyList(),
var notificationCount: Int = 0,
var highlightCount: Int = 0,

View File

@ -33,6 +33,7 @@ internal object RoomSummaryMapper {
topic = roomSummaryEntity.topic ?: "",
avatarUrl = roomSummaryEntity.avatarUrl ?: "",
isDirect = roomSummaryEntity.isDirect,
lastMessage = roomSummaryEntity.lastMessage?.asDomain(),
otherMemberIds = roomSummaryEntity.otherMemberIds.toList(),
highlightCount = roomSummaryEntity.highlightCount,
notificationCount = roomSummaryEntity.notificationCount,

View File

@ -50,9 +50,13 @@ internal fun EventEntity.Companion.where(realm: Realm,
}
internal fun EventEntity.Companion.latestEvent(realm: Realm,
roomId: String): EventEntity? {
val chunkEntity = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId)
return chunkEntity?.events?.where()?.sort(EventEntityFields.DISPLAY_INDEX)?.findFirst()
roomId: String,
excludedTypes: List<String> = emptyList()): EventEntity? {
val query = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId)?.events?.where()
return query
?.not()?.`in`(EventEntityFields.TYPE, excludedTypes.toTypedArray())
?.sort(EventEntityFields.DISPLAY_INDEX)
?.findFirst()
}

View File

@ -28,6 +28,7 @@ import im.vector.matrix.android.internal.database.model.EventEntity
import im.vector.matrix.android.internal.database.model.RoomEntity
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
import im.vector.matrix.android.internal.database.query.last
import im.vector.matrix.android.internal.database.query.latestEvent
import im.vector.matrix.android.internal.database.query.where
import im.vector.matrix.android.internal.session.room.members.RoomDisplayNameResolver
import im.vector.matrix.android.internal.session.room.members.RoomMembers
@ -57,7 +58,7 @@ internal class RoomSummaryUpdater(monarchy: Monarchy,
val roomSummary = RoomSummaryEntity.where(realm, roomId).findFirst()
?: realm.createObject(roomId)
val lastMessageEvent = EventEntity.where(realm, roomId, EventType.MESSAGE).last()
val lastEvent = EventEntity.latestEvent(realm, roomId)
val lastTopicEvent = EventEntity.where(realm, roomId, EventType.STATE_ROOM_TOPIC).last()?.asDomain()
val otherRoomMembers = RoomMembers(realm, roomId).getLoaded().filterKeys { it != credentials.userId }
@ -65,7 +66,7 @@ internal class RoomSummaryUpdater(monarchy: Monarchy,
roomSummary.displayName = roomDisplayNameResolver.resolve(context, roomId).toString()
roomSummary.avatarUrl = roomAvatarResolver.resolve(roomId)
roomSummary.topic = lastTopicEvent?.content.toModel<RoomTopicContent>()?.topic
roomSummary.lastMessage = lastMessageEvent
roomSummary.lastMessage = lastEvent
roomSummary.otherMemberIds.clear()
roomSummary.otherMemberIds.addAll(otherRoomMembers.keys)
}