Merge pull request #4896 from element-hq/feature/fga/fix_dm_predecessor_room_banner
fix (room upgrade) : room predecessor banner on DM room
This commit is contained in:
commit
a8d96a6292
6 changed files with 49 additions and 47 deletions
|
|
@ -14,11 +14,10 @@ import io.element.android.libraries.matrix.api.timeline.item.event.MembershipCha
|
|||
import io.element.android.libraries.matrix.api.timeline.item.event.OtherState
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.RoomMembershipContent
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.StateContent
|
||||
import io.element.android.libraries.matrix.api.timeline.item.virtual.VirtualTimelineItem
|
||||
|
||||
/**
|
||||
* This timeline post-processor removes the room creation event and the self-join event from the timeline for DMs
|
||||
* or add the RoomBeginning item for non DM room.
|
||||
* or add the RoomBeginning item.
|
||||
*/
|
||||
class RoomBeginningPostProcessor(private val mode: Timeline.Mode) {
|
||||
fun process(
|
||||
|
|
@ -30,7 +29,7 @@ class RoomBeginningPostProcessor(private val mode: Timeline.Mode) {
|
|||
return when {
|
||||
items.isEmpty() -> items
|
||||
mode == Timeline.Mode.PINNED_EVENTS -> items
|
||||
isDm -> processForDM(items, roomCreator, hasMoreToLoadBackwards)
|
||||
isDm -> processForDM(items, roomCreator)
|
||||
hasMoreToLoadBackwards -> items
|
||||
else -> processForRoom(items)
|
||||
}
|
||||
|
|
@ -41,13 +40,7 @@ class RoomBeginningPostProcessor(private val mode: Timeline.Mode) {
|
|||
return items
|
||||
}
|
||||
|
||||
private fun processForDM(items: List<MatrixTimelineItem>, roomCreator: UserId?, hasMoreToLoadBackwards: Boolean): List<MatrixTimelineItem> {
|
||||
val roomBeginningItemIndex = if (!hasMoreToLoadBackwards) {
|
||||
items.indexOfFirst { it is MatrixTimelineItem.Virtual && it.virtual is VirtualTimelineItem.RoomBeginning }.takeIf { it >= 0 }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
@ -69,7 +62,6 @@ class RoomBeginningPostProcessor(private val mode: Timeline.Mode) {
|
|||
}
|
||||
|
||||
val indicesToRemove = listOfNotNull(
|
||||
roomBeginningItemIndex,
|
||||
roomCreationEventIndex,
|
||||
selfUserJoinedEventIndex,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class RoomBeginningPostProcessorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `processor removes timeline start, room creation event and self-join event from DM timeline`() {
|
||||
fun `processor removes room creation event and self-join event from DM timeline`() {
|
||||
val timelineItems = listOf(
|
||||
timelineStartEvent,
|
||||
roomCreateEvent,
|
||||
|
|
@ -63,7 +63,7 @@ class RoomBeginningPostProcessorTest {
|
|||
roomCreator = A_USER_ID,
|
||||
hasMoreToLoadBackwards = false,
|
||||
)
|
||||
assertThat(processedItems).isEmpty()
|
||||
assertThat(processedItems).containsExactly(timelineStartEvent)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue