From 11aa5346f9e3852664f60dada0801164034b961f Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 18 Jun 2025 17:40:24 +0200 Subject: [PATCH 1/2] fix (room upgrade) : room predecessor banner should be displayed for DM too --- .../components/TimelineItemVirtualRow.kt | 1 + .../virtual/TimelineItemRoomBeginningView.kt | 69 +++++++++++-------- .../RoomBeginningPostProcessor.kt | 14 +--- .../RoomBeginningPostProcessorTest.kt | 4 +- 4 files changed, 45 insertions(+), 43 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemVirtualRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemVirtualRow.kt index 6f49bffab1..45b167b68f 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemVirtualRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemVirtualRow.kt @@ -45,6 +45,7 @@ fun TimelineItemVirtualRow( TimelineItemRoomBeginningView( predecessorRoom = timelineRoomInfo.predecessorRoom, roomName = timelineRoomInfo.name, + isDm = timelineRoomInfo.isDm, onPredecessorRoomClick = { roomId -> eventSink(TimelineEvents.NavigateToRoom(roomId)) }, diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/virtual/TimelineItemRoomBeginningView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/virtual/TimelineItemRoomBeginningView.kt index dccb1433fc..72035cdc3d 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/virtual/TimelineItemRoomBeginningView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/virtual/TimelineItemRoomBeginningView.kt @@ -25,6 +25,7 @@ import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.designsystem.text.toAnnotatedString import io.element.android.libraries.designsystem.theme.components.Text +import io.element.android.libraries.designsystem.utils.allBooleans import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.matrix.api.core.RoomId import io.element.android.libraries.matrix.api.room.tombstone.PredecessorRoom @@ -33,6 +34,7 @@ import io.element.android.libraries.matrix.api.room.tombstone.PredecessorRoom fun TimelineItemRoomBeginningView( roomName: String?, predecessorRoom: PredecessorRoom?, + isDm: Boolean, onPredecessorRoomClick: (RoomId) -> Unit, modifier: Modifier = Modifier ) { @@ -48,24 +50,26 @@ fun TimelineItemRoomBeginningView( submitText = stringResource(R.string.screen_room_timeline_upgraded_room_action) ) } - - Box( - modifier = Modifier + // Only display for non-DM room + if (!isDm) { + Box( + modifier = Modifier .fillMaxWidth() .padding(horizontal = 16.dp, vertical = 8.dp), - contentAlignment = Alignment.Center, - ) { - val text = if (roomName == null) { - stringResource(id = R.string.screen_room_timeline_beginning_of_room_no_name) - } else { - stringResource(id = R.string.screen_room_timeline_beginning_of_room, roomName) + contentAlignment = Alignment.Center, + ) { + val text = if (roomName == null) { + stringResource(id = R.string.screen_room_timeline_beginning_of_room_no_name) + } else { + stringResource(id = R.string.screen_room_timeline_beginning_of_room, roomName) + } + Text( + color = ElementTheme.colors.textSecondary, + style = ElementTheme.typography.fontBodyMdRegular, + text = text, + textAlign = TextAlign.Center, + ) } - Text( - color = ElementTheme.colors.textSecondary, - style = ElementTheme.typography.fontBodyMdRegular, - text = text, - textAlign = TextAlign.Center, - ) } } } @@ -74,20 +78,25 @@ fun TimelineItemRoomBeginningView( @Composable internal fun TimelineItemRoomBeginningViewPreview() = ElementPreview { Column(verticalArrangement = spacedBy(16.dp)) { - TimelineItemRoomBeginningView( - predecessorRoom = null, - roomName = null, - onPredecessorRoomClick = {}, - ) - TimelineItemRoomBeginningView( - predecessorRoom = null, - roomName = "Room Name", - onPredecessorRoomClick = {}, - ) - TimelineItemRoomBeginningView( - predecessorRoom = PredecessorRoom(RoomId("!roomId:matrix.org"), EventId("\$eventId:matrix.org")), - roomName = "Room Name", - onPredecessorRoomClick = {}, - ) + allBooleans.forEach { isDm -> + TimelineItemRoomBeginningView( + predecessorRoom = null, + roomName = null, + isDm = isDm, + onPredecessorRoomClick = {}, + ) + TimelineItemRoomBeginningView( + predecessorRoom = null, + roomName = "Room Name", + isDm = isDm, + onPredecessorRoomClick = {}, + ) + TimelineItemRoomBeginningView( + predecessorRoom = PredecessorRoom(RoomId("!roomId:matrix.org"), EventId("\$eventId:matrix.org")), + roomName = "Room Name", + isDm = isDm, + onPredecessorRoomClick = {}, + ) + } } } diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/RoomBeginningPostProcessor.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/RoomBeginningPostProcessor.kt index 4dded4519d..8403f63188 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/RoomBeginningPostProcessor.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/RoomBeginningPostProcessor.kt @@ -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, roomCreator: UserId?, hasMoreToLoadBackwards: Boolean): List { - 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, roomCreator: UserId?): List { // 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, ) diff --git a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/RoomBeginningPostProcessorTest.kt b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/RoomBeginningPostProcessorTest.kt index bb1e4581a1..ba0bef4266 100644 --- a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/RoomBeginningPostProcessorTest.kt +++ b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/RoomBeginningPostProcessorTest.kt @@ -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 From 6b8c43d6564d37c90b6fde8d6d6e96f953343d56 Mon Sep 17 00:00:00 2001 From: ElementBot Date: Wed, 18 Jun 2025 15:55:53 +0000 Subject: [PATCH 2/2] Update screenshots --- ...ponents.virtual_TimelineItemRoomBeginningView_Day_0_en.png | 4 ++-- ...nents.virtual_TimelineItemRoomBeginningView_Night_0_en.png | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.virtual_TimelineItemRoomBeginningView_Day_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.virtual_TimelineItemRoomBeginningView_Day_0_en.png index b46fcdcc5c..829cf58db8 100644 --- a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.virtual_TimelineItemRoomBeginningView_Day_0_en.png +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.virtual_TimelineItemRoomBeginningView_Day_0_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:abf66dd56be501e27477d83f97eed4c948fdf049130d46dc5a23e46e4cf18dfc -size 33561 +oid sha256:f4494a2cf13d267a1051ea3fbe4476d2354b8c7827d1b93aabacf5bbe063dc3a +size 49269 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.virtual_TimelineItemRoomBeginningView_Night_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.virtual_TimelineItemRoomBeginningView_Night_0_en.png index 806c68d57e..8e03a6e18d 100644 --- a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.virtual_TimelineItemRoomBeginningView_Night_0_en.png +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.virtual_TimelineItemRoomBeginningView_Night_0_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:603ce16c8ce5e92c6cf1b2639be69e0dc64b99c1c7f1879762661258d222fd84 -size 36317 +oid sha256:affff20aa09000132ffa8535a81d888263e9d530144c8b96e15d25c1873254c9 +size 54426