RoomSummaryDataSource: not sure what to do when update index is > size
This commit is contained in:
parent
986fae43c2
commit
bb88919bb3
1 changed files with 18 additions and 6 deletions
|
|
@ -33,7 +33,6 @@ internal class RustRoomSummaryDataSource(
|
||||||
|
|
||||||
init {
|
init {
|
||||||
slidingSyncView.roomListDiff()
|
slidingSyncView.roomListDiff()
|
||||||
.buffer(50)
|
|
||||||
.onEach { diff ->
|
.onEach { diff ->
|
||||||
updateRoomSummaries {
|
updateRoomSummaries {
|
||||||
applyDiff(diff)
|
applyDiff(diff)
|
||||||
|
|
@ -77,16 +76,20 @@ internal class RustRoomSummaryDataSource(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun MutableList<RoomSummary>.applyDiff(diff: SlidingSyncViewRoomsListDiff) {
|
private fun MutableList<RoomSummary>.applyDiff(diff: SlidingSyncViewRoomsListDiff) {
|
||||||
Timber.v("ApplyDiff: $diff")
|
|
||||||
if (diff.isInvalidation()) {
|
fun MutableList<RoomSummary>.fillUntil(untilIndex: Int) {
|
||||||
return
|
repeat((size-1 until untilIndex).count()) {
|
||||||
|
add(buildEmptyRoomSummary())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Timber.v("ApplyDiff: $diff for list with size: $size")
|
||||||
when (diff) {
|
when (diff) {
|
||||||
is SlidingSyncViewRoomsListDiff.Push -> {
|
is SlidingSyncViewRoomsListDiff.Push -> {
|
||||||
val roomSummary = buildSummaryForRoomListEntry(diff.value)
|
val roomSummary = buildSummaryForRoomListEntry(diff.value)
|
||||||
add(roomSummary)
|
add(roomSummary)
|
||||||
}
|
}
|
||||||
is SlidingSyncViewRoomsListDiff.UpdateAt -> {
|
is SlidingSyncViewRoomsListDiff.UpdateAt -> {
|
||||||
|
fillUntil(diff.index.toInt())
|
||||||
val roomSummary = buildSummaryForRoomListEntry(diff.value)
|
val roomSummary = buildSummaryForRoomListEntry(diff.value)
|
||||||
set(diff.index.toInt(), roomSummary)
|
set(diff.index.toInt(), roomSummary)
|
||||||
}
|
}
|
||||||
|
|
@ -109,17 +112,26 @@ internal class RustRoomSummaryDataSource(
|
||||||
|
|
||||||
private fun buildSummaryForRoomListEntry(entry: RoomListEntry): RoomSummary {
|
private fun buildSummaryForRoomListEntry(entry: RoomListEntry): RoomSummary {
|
||||||
return when (entry) {
|
return when (entry) {
|
||||||
RoomListEntry.Empty -> RoomSummary.Empty(UUID.randomUUID().toString())
|
RoomListEntry.Empty -> buildEmptyRoomSummary()
|
||||||
is RoomListEntry.Invalidated -> buildRoomSummaryForIdentifier(entry.roomId)
|
is RoomListEntry.Invalidated -> buildRoomSummaryForIdentifier(entry.roomId)
|
||||||
is RoomListEntry.Filled -> buildRoomSummaryForIdentifier(entry.roomId)
|
is RoomListEntry.Filled -> buildRoomSummaryForIdentifier(entry.roomId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildEmptyRoomSummary(): RoomSummary {
|
||||||
|
return RoomSummary.Empty(UUID.randomUUID().toString())
|
||||||
|
}
|
||||||
|
|
||||||
private fun buildRoomSummaryForIdentifier(identifier: String): RoomSummary {
|
private fun buildRoomSummaryForIdentifier(identifier: String): RoomSummary {
|
||||||
val room = slidingSync.getRoom(identifier) ?: return RoomSummary.Empty(identifier)
|
val room = slidingSync.getRoom(identifier) ?: return RoomSummary.Empty(identifier)
|
||||||
val latestRoomMessage = room.latestRoomMessage()?.let {
|
val latestRoomMessage = room.latestRoomMessage()?.let {
|
||||||
roomMessageFactory.create(it)
|
roomMessageFactory.create(it)
|
||||||
}
|
}
|
||||||
|
val computedLastMessage = when {
|
||||||
|
latestRoomMessage == null -> null
|
||||||
|
room.isDm() == true -> latestRoomMessage.body
|
||||||
|
else -> "${latestRoomMessage.sender.value}: ${latestRoomMessage.body}"
|
||||||
|
}
|
||||||
return RoomSummary.Filled(
|
return RoomSummary.Filled(
|
||||||
details = RoomSummaryDetails(
|
details = RoomSummaryDetails(
|
||||||
roomId = RoomId(identifier),
|
roomId = RoomId(identifier),
|
||||||
|
|
@ -127,7 +139,7 @@ internal class RustRoomSummaryDataSource(
|
||||||
isDirect = room.isDm() ?: false,
|
isDirect = room.isDm() ?: false,
|
||||||
avatarURLString = room.fullRoom()?.avatarUrl(),
|
avatarURLString = room.fullRoom()?.avatarUrl(),
|
||||||
unreadNotificationCount = room.unreadNotifications().notificationCount().toInt(),
|
unreadNotificationCount = room.unreadNotifications().notificationCount().toInt(),
|
||||||
lastMessage = latestRoomMessage?.body,
|
lastMessage = computedLastMessage,
|
||||||
lastMessageTimestamp = latestRoomMessage?.originServerTs
|
lastMessageTimestamp = latestRoomMessage?.originServerTs
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue