Only show a Matrix ID in the room picker for a direct message

heroes is populated for any room whose name is derived from its members,
not only for direct messages, so a two person room that is not a DM
showed a member's Matrix ID as its subtitle.

Carry isDm on SelectRoomInfo and read the hero only when it is set. The
canonical alias still takes precedence, so nothing changes for a room
that has one.
This commit is contained in:
hayaksi1
2026-08-10 16:46:58 +03:00
parent acb9e0e082
commit 629dc15a86
6 changed files with 35 additions and 1 deletions
@@ -87,6 +87,7 @@ internal fun aSelectRoomInfoList(): ImmutableList<SelectRoomInfo> = listOf(
canonicalAlias = null, canonicalAlias = null,
avatarUrl = null, avatarUrl = null,
heroes = persistentListOf(), heroes = persistentListOf(),
isDm = false,
isTombstoned = false, isTombstoned = false,
), ),
SelectRoomInfo( SelectRoomInfo(
@@ -95,6 +96,7 @@ internal fun aSelectRoomInfoList(): ImmutableList<SelectRoomInfo> = listOf(
canonicalAlias = null, canonicalAlias = null,
avatarUrl = null, avatarUrl = null,
heroes = persistentListOf(), heroes = persistentListOf(),
isDm = false,
isTombstoned = false, isTombstoned = false,
), ),
SelectRoomInfo( SelectRoomInfo(
@@ -103,6 +105,7 @@ internal fun aSelectRoomInfoList(): ImmutableList<SelectRoomInfo> = listOf(
canonicalAlias = null, canonicalAlias = null,
avatarUrl = null, avatarUrl = null,
heroes = persistentListOf(), heroes = persistentListOf(),
isDm = false,
isTombstoned = false, isTombstoned = false,
), ),
).toImmutableList() ).toImmutableList()
@@ -31,6 +31,7 @@ fun aSelectRoomInfo(
canonicalAlias: RoomAlias? = null, canonicalAlias: RoomAlias? = null,
avatarUrl: String? = null, avatarUrl: String? = null,
heroes: ImmutableList<MatrixUser> = persistentListOf(), heroes: ImmutableList<MatrixUser> = persistentListOf(),
isDm: Boolean = false,
isTombstoned: Boolean = false, isTombstoned: Boolean = false,
) = SelectRoomInfo( ) = SelectRoomInfo(
roomId = roomId, roomId = roomId,
@@ -38,5 +39,6 @@ fun aSelectRoomInfo(
canonicalAlias = canonicalAlias, canonicalAlias = canonicalAlias,
avatarUrl = avatarUrl, avatarUrl = avatarUrl,
heroes = heroes, heroes = heroes,
isDm = isDm,
isTombstoned = isTombstoned, isTombstoned = isTombstoned,
) )
@@ -23,6 +23,7 @@ data class SelectRoomInfo(
val canonicalAlias: RoomAlias?, val canonicalAlias: RoomAlias?,
val avatarUrl: String?, val avatarUrl: String?,
val heroes: ImmutableList<MatrixUser>, val heroes: ImmutableList<MatrixUser>,
val isDm: Boolean,
val isTombstoned: Boolean, val isTombstoned: Boolean,
) { ) {
fun getAvatarData(size: AvatarSize) = AvatarData( fun getAvatarData(size: AvatarSize) = AvatarData(
@@ -41,5 +42,6 @@ fun RoomInfo.toSelectRoomInfo() = SelectRoomInfo(
avatarUrl = avatarUrl, avatarUrl = avatarUrl,
heroes = heroes, heroes = heroes,
canonicalAlias = canonicalAlias, canonicalAlias = canonicalAlias,
isDm = isDm,
isTombstoned = successorRoom != null, isTombstoned = successorRoom != null,
) )
@@ -84,6 +84,7 @@ internal fun aRoomSelectRoomList() = persistentListOf(
heroes = persistentListOf( heroes = persistentListOf(
aMatrixUser(id = "@alice:example.org", displayName = "Alice"), aMatrixUser(id = "@alice:example.org", displayName = "Alice"),
), ),
isDm = true,
), ),
aSelectRoomInfo( aSelectRoomInfo(
roomId = RoomId("!room4:domain"), roomId = RoomId("!room4:domain"),
@@ -260,7 +260,8 @@ private fun RoomSummaryView(
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis 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) { if (subtitle != null) {
Text( Text(
text = subtitle, text = subtitle,
@@ -17,9 +17,12 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.v2.runAndroidComposeUiTest import androidx.compose.ui.test.v2.runAndroidComposeUiTest
import io.element.android.libraries.designsystem.theme.components.SearchBarResultState import io.element.android.libraries.designsystem.theme.components.SearchBarResultState
import io.element.android.libraries.matrix.api.core.RoomId 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.EnsureNeverCalled
import io.element.android.tests.testutils.EnsureNeverCalledWithParam import io.element.android.tests.testutils.EnsureNeverCalledWithParam
import io.element.android.tests.testutils.robolectric.RobolectricTest import io.element.android.tests.testutils.robolectric.RobolectricTest
import kotlinx.collections.immutable.persistentListOf
import org.junit.Test import org.junit.Test
import org.robolectric.annotation.Config import org.robolectric.annotation.Config
@@ -47,6 +50,28 @@ class RoomSelectViewTest : RobolectricTest() {
onNodeWithText("Alice").assertIsDisplayed() onNodeWithText("Alice").assertIsDisplayed()
onNodeWithText("@alice:example.org").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<ComponentActivity>.setRoomSelectView( private fun AndroidComposeUiTest<ComponentActivity>.setRoomSelectView(