Fix filtering of Event at the beginning of DM.
This commit is contained in:
parent
9d6c9456a5
commit
f87422a022
7 changed files with 150 additions and 43 deletions
|
|
@ -28,6 +28,7 @@ class MatrixRoomInfoMapper {
|
|||
fun map(rustRoomInfo: RustRoomInfo): MatrixRoomInfo = rustRoomInfo.let {
|
||||
return MatrixRoomInfo(
|
||||
id = RoomId(it.id),
|
||||
creator = it.creator?.let(::UserId),
|
||||
name = it.displayName,
|
||||
rawName = it.rawName,
|
||||
topic = it.topic,
|
||||
|
|
|
|||
|
|
@ -207,15 +207,17 @@ class RustTimeline(
|
|||
_timelineItems,
|
||||
backPaginationStatus.map { it.hasMoreToLoad }.distinctUntilChanged(),
|
||||
forwardPaginationStatus.map { it.hasMoreToLoad }.distinctUntilChanged(),
|
||||
matrixRoom.roomInfoFlow.map { it.creator },
|
||||
isInit,
|
||||
) { timelineItems, hasMoreToLoadBackward, hasMoreToLoadForward, isInit ->
|
||||
) { timelineItems, hasMoreToLoadBackward, hasMoreToLoadForward, roomCreator, isInit ->
|
||||
withContext(dispatcher) {
|
||||
timelineItems
|
||||
.process { items ->
|
||||
roomBeginningPostProcessor.process(
|
||||
items = items,
|
||||
isDm = matrixRoom.isDm,
|
||||
hasMoreToLoadBackwards = hasMoreToLoadBackward
|
||||
roomCreator = roomCreator,
|
||||
hasMoreToLoadBackwards = hasMoreToLoadBackward,
|
||||
)
|
||||
}
|
||||
.process(predicate = isInit) { items ->
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ package io.element.android.libraries.matrix.impl.timeline.postprocessor
|
|||
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import io.element.android.libraries.matrix.api.core.UniqueId
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
import io.element.android.libraries.matrix.api.timeline.MatrixTimelineItem
|
||||
import io.element.android.libraries.matrix.api.timeline.Timeline
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.MembershipChange
|
||||
|
|
@ -25,12 +26,14 @@ class RoomBeginningPostProcessor(private val mode: Timeline.Mode) {
|
|||
fun process(
|
||||
items: List<MatrixTimelineItem>,
|
||||
isDm: Boolean,
|
||||
hasMoreToLoadBackwards: Boolean
|
||||
roomCreator: UserId?,
|
||||
hasMoreToLoadBackwards: Boolean,
|
||||
): List<MatrixTimelineItem> {
|
||||
return when {
|
||||
items.isEmpty() -> items
|
||||
mode == Timeline.Mode.PINNED_EVENTS -> items
|
||||
isDm -> processForDM(items, roomCreator)
|
||||
hasMoreToLoadBackwards -> items
|
||||
isDm -> processForDM(items)
|
||||
else -> processForRoom(items)
|
||||
}
|
||||
}
|
||||
|
|
@ -40,15 +43,18 @@ class RoomBeginningPostProcessor(private val mode: Timeline.Mode) {
|
|||
return listOf(roomBeginningItem) + items
|
||||
}
|
||||
|
||||
private fun processForDM(items: List<MatrixTimelineItem>): List<MatrixTimelineItem> {
|
||||
// Find room creation event. This is usually index 0
|
||||
private fun processForDM(items: List<MatrixTimelineItem>, roomCreator: UserId?): List<MatrixTimelineItem> {
|
||||
// Find room creation event.
|
||||
// This is usually the first MatrixTimelineItem.Event (so index 1, index 0 is a date)
|
||||
val roomCreationEventIndex = items.indexOfFirst {
|
||||
val stateEventContent = (it as? MatrixTimelineItem.Event)?.event?.content as? StateContent
|
||||
stateEventContent?.content is OtherState.RoomCreate
|
||||
}
|
||||
|
||||
// Find self-join event for room creator. This is usually index 1
|
||||
val roomCreatorUserId = (items.getOrNull(roomCreationEventIndex) as? MatrixTimelineItem.Event)?.event?.sender
|
||||
// If the parameter roomCreator is null, the creator is the sender of the RoomCreate Event.
|
||||
val roomCreatorUserId = roomCreator ?: (items.getOrNull(roomCreationEventIndex) as? MatrixTimelineItem.Event)?.event?.sender
|
||||
// Find self-join event for the room creator.
|
||||
// This is usually the second MatrixTimelineItem.Event (so index 2)
|
||||
val selfUserJoinedEventIndex = roomCreatorUserId?.let { creatorUserId ->
|
||||
items.indexOfFirst {
|
||||
val stateEventContent = (it as? MatrixTimelineItem.Event)?.event?.content as? RoomMembershipContent
|
||||
|
|
@ -56,6 +62,9 @@ class RoomBeginningPostProcessor(private val mode: Timeline.Mode) {
|
|||
}
|
||||
} ?: -1
|
||||
|
||||
if (roomCreationEventIndex == -1 && selfUserJoinedEventIndex == -1) {
|
||||
return items
|
||||
}
|
||||
// Remove items at the indices we found
|
||||
val newItems = items.toMutableList()
|
||||
if (selfUserJoinedEventIndex in newItems.indices) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue