fix (room upgrade) : room predecessor banner should be displayed for DM too
This commit is contained in:
@@ -45,6 +45,7 @@ fun TimelineItemVirtualRow(
|
||||
TimelineItemRoomBeginningView(
|
||||
predecessorRoom = timelineRoomInfo.predecessorRoom,
|
||||
roomName = timelineRoomInfo.name,
|
||||
isDm = timelineRoomInfo.isDm,
|
||||
onPredecessorRoomClick = { roomId ->
|
||||
eventSink(TimelineEvents.NavigateToRoom(roomId))
|
||||
},
|
||||
|
||||
@@ -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 = {},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user