diff --git a/features/space/impl/src/main/kotlin/io/element/android/features/space/impl/addroom/AddRoomToSpaceStateProvider.kt b/features/space/impl/src/main/kotlin/io/element/android/features/space/impl/addroom/AddRoomToSpaceStateProvider.kt index f9036f0452..add57bd4c4 100644 --- a/features/space/impl/src/main/kotlin/io/element/android/features/space/impl/addroom/AddRoomToSpaceStateProvider.kt +++ b/features/space/impl/src/main/kotlin/io/element/android/features/space/impl/addroom/AddRoomToSpaceStateProvider.kt @@ -87,6 +87,7 @@ internal fun aSelectRoomInfoList(): ImmutableList = listOf( canonicalAlias = null, avatarUrl = null, heroes = persistentListOf(), + isDm = false, isTombstoned = false, ), SelectRoomInfo( @@ -95,6 +96,7 @@ internal fun aSelectRoomInfoList(): ImmutableList = listOf( canonicalAlias = null, avatarUrl = null, heroes = persistentListOf(), + isDm = false, isTombstoned = false, ), SelectRoomInfo( @@ -103,6 +105,7 @@ internal fun aSelectRoomInfoList(): ImmutableList = listOf( canonicalAlias = null, avatarUrl = null, heroes = persistentListOf(), + isDm = false, isTombstoned = false, ), ).toImmutableList() diff --git a/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/components/SelectRoomInfoProvider.kt b/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/components/SelectRoomInfoProvider.kt index 731d499445..c6a4b9d474 100644 --- a/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/components/SelectRoomInfoProvider.kt +++ b/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/components/SelectRoomInfoProvider.kt @@ -31,6 +31,7 @@ fun aSelectRoomInfo( canonicalAlias: RoomAlias? = null, avatarUrl: String? = null, heroes: ImmutableList = persistentListOf(), + isDm: Boolean = false, isTombstoned: Boolean = false, ) = SelectRoomInfo( roomId = roomId, @@ -38,5 +39,6 @@ fun aSelectRoomInfo( canonicalAlias = canonicalAlias, avatarUrl = avatarUrl, heroes = heroes, + isDm = isDm, isTombstoned = isTombstoned, ) diff --git a/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/model/SelectRoomInfo.kt b/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/model/SelectRoomInfo.kt index d6981f62fd..fd13140e54 100644 --- a/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/model/SelectRoomInfo.kt +++ b/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/model/SelectRoomInfo.kt @@ -23,6 +23,7 @@ data class SelectRoomInfo( val canonicalAlias: RoomAlias?, val avatarUrl: String?, val heroes: ImmutableList, + val isDm: Boolean, val isTombstoned: Boolean, ) { fun getAvatarData(size: AvatarSize) = AvatarData( @@ -41,5 +42,6 @@ fun RoomInfo.toSelectRoomInfo() = SelectRoomInfo( avatarUrl = avatarUrl, heroes = heroes, canonicalAlias = canonicalAlias, + isDm = isDm, isTombstoned = successorRoom != null, ) diff --git a/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectStateProvider.kt b/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectStateProvider.kt index 9825f63cfd..c7fa907be2 100644 --- a/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectStateProvider.kt +++ b/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectStateProvider.kt @@ -84,6 +84,7 @@ internal fun aRoomSelectRoomList() = persistentListOf( heroes = persistentListOf( aMatrixUser(id = "@alice:example.org", displayName = "Alice"), ), + isDm = true, ), aSelectRoomInfo( roomId = RoomId("!room4:domain"), diff --git a/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectView.kt b/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectView.kt index 59643e4e4c..e16cce6fd9 100644 --- a/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectView.kt +++ b/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectView.kt @@ -260,7 +260,8 @@ private fun RoomSummaryView( maxLines = 1, overflow = TextOverflow.Ellipsis ) - val subtitle = roomInfo.canonicalAlias?.value ?: roomInfo.heroes.singleOrNull()?.userId?.value + val otherUserId = roomInfo.heroes.singleOrNull()?.userId?.takeIf { roomInfo.isDm } + val subtitle = roomInfo.canonicalAlias?.value ?: otherUserId?.value if (subtitle != null) { Text( text = subtitle, diff --git a/libraries/roomselect/impl/src/test/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectViewTest.kt b/libraries/roomselect/impl/src/test/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectViewTest.kt index 09e07247e9..db0219bb04 100644 --- a/libraries/roomselect/impl/src/test/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectViewTest.kt +++ b/libraries/roomselect/impl/src/test/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectViewTest.kt @@ -17,9 +17,12 @@ import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.v2.runAndroidComposeUiTest import io.element.android.libraries.designsystem.theme.components.SearchBarResultState import io.element.android.libraries.matrix.api.core.RoomId +import io.element.android.libraries.matrix.ui.components.aMatrixUser +import io.element.android.libraries.matrix.ui.components.aSelectRoomInfo import io.element.android.tests.testutils.EnsureNeverCalled import io.element.android.tests.testutils.EnsureNeverCalledWithParam import io.element.android.tests.testutils.robolectric.RobolectricTest +import kotlinx.collections.immutable.persistentListOf import org.junit.Test import org.robolectric.annotation.Config @@ -47,6 +50,28 @@ class RoomSelectViewTest : RobolectricTest() { onNodeWithText("Alice").assertIsDisplayed() onNodeWithText("@alice:example.org").assertIsDisplayed() } + + @Config(qualifiers = "h1024dp") + @Test + fun `a room which is not a direct message does not render the matrix id of its hero`() = runAndroidComposeUiTest { + setRoomSelectView( + aRoomSelectState( + resultState = SearchBarResultState.Results( + persistentListOf( + aSelectRoomInfo( + roomId = RoomId("!room:domain"), + name = "Room with a single hero", + heroes = persistentListOf( + aMatrixUser(id = "@alice:example.org", displayName = "Alice"), + ), + ), + ) + ), + ), + ) + onNodeWithText("Room with a single hero").assertIsDisplayed() + onNodeWithText("@alice:example.org").assertDoesNotExist() + } } private fun AndroidComposeUiTest.setRoomSelectView(