mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Merge pull request #7562 from hayaksi1/fix/1548-dm-preview-sender
Drop the sender's name from the room list preview of two-person rooms
This commit is contained in:
+6
-1
@@ -19,6 +19,7 @@ import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
|||||||
import io.element.android.libraries.eventformatter.api.RoomLatestEventFormatter
|
import io.element.android.libraries.eventformatter.api.RoomLatestEventFormatter
|
||||||
import io.element.android.libraries.matrix.api.room.CallIntentConsensus
|
import io.element.android.libraries.matrix.api.room.CallIntentConsensus
|
||||||
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
|
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
|
||||||
|
import io.element.android.libraries.matrix.api.room.RoomInfo
|
||||||
import io.element.android.libraries.matrix.api.roomlist.LatestEventValue
|
import io.element.android.libraries.matrix.api.roomlist.LatestEventValue
|
||||||
import io.element.android.libraries.matrix.api.roomlist.RoomSummary
|
import io.element.android.libraries.matrix.api.roomlist.RoomSummary
|
||||||
import io.element.android.libraries.matrix.ui.model.dmUserStatus
|
import io.element.android.libraries.matrix.ui.model.dmUserStatus
|
||||||
@@ -47,7 +48,7 @@ class RoomListRoomSummaryFactory(
|
|||||||
mode = DateFormatterMode.TimeOrDate,
|
mode = DateFormatterMode.TimeOrDate,
|
||||||
useRelative = true,
|
useRelative = true,
|
||||||
),
|
),
|
||||||
latestEvent = computeLatestEvent(roomSummary.latestEvent, roomInfo.isDm),
|
latestEvent = computeLatestEvent(roomSummary.latestEvent, roomInfo.hasOnlyTwoMembers()),
|
||||||
avatarData = avatarData,
|
avatarData = avatarData,
|
||||||
userDefinedNotificationMode = roomInfo.userDefinedNotificationMode,
|
userDefinedNotificationMode = roomInfo.userDefinedNotificationMode,
|
||||||
hasRoomCall = roomInfo.hasRoomCall,
|
hasRoomCall = roomInfo.hasRoomCall,
|
||||||
@@ -81,6 +82,10 @@ class RoomListRoomSummaryFactory(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun RoomInfo.hasOnlyTwoMembers(): Boolean {
|
||||||
|
return isDm || activeMembersCount <= 2
|
||||||
|
}
|
||||||
|
|
||||||
private fun computeLatestEvent(latestEvent: LatestEventValue, dm: Boolean): LatestEvent {
|
private fun computeLatestEvent(latestEvent: LatestEventValue, dm: Boolean): LatestEvent {
|
||||||
return when (latestEvent) {
|
return when (latestEvent) {
|
||||||
is LatestEventValue.None -> {
|
is LatestEventValue.None -> {
|
||||||
|
|||||||
+26
@@ -8,10 +8,36 @@
|
|||||||
|
|
||||||
package io.element.android.features.home.impl.datasource
|
package io.element.android.features.home.impl.datasource
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.libraries.dateformatter.api.DateFormatter
|
import io.element.android.libraries.dateformatter.api.DateFormatter
|
||||||
import io.element.android.libraries.dateformatter.test.FakeDateFormatter
|
import io.element.android.libraries.dateformatter.test.FakeDateFormatter
|
||||||
import io.element.android.libraries.eventformatter.api.RoomLatestEventFormatter
|
import io.element.android.libraries.eventformatter.api.RoomLatestEventFormatter
|
||||||
import io.element.android.libraries.eventformatter.test.FakeRoomLatestEventFormatter
|
import io.element.android.libraries.eventformatter.test.FakeRoomLatestEventFormatter
|
||||||
|
import io.element.android.libraries.matrix.test.room.aRoomInfo
|
||||||
|
import io.element.android.libraries.matrix.test.room.aRoomSummary
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class RoomListRoomSummaryFactoryTest {
|
||||||
|
@Test
|
||||||
|
fun `a room with two members does not prefix its preview with the sender`() {
|
||||||
|
val formatter = FakeRoomLatestEventFormatter()
|
||||||
|
val factory = aRoomListRoomSummaryFactory(roomLatestEventFormatter = formatter)
|
||||||
|
|
||||||
|
factory.create(aRoomSummary(info = aRoomInfo(isDm = false, activeMembersCount = 2)))
|
||||||
|
|
||||||
|
assertThat(formatter.lastIsDmRoom).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a room with more than two members prefixes its preview with the sender`() {
|
||||||
|
val formatter = FakeRoomLatestEventFormatter()
|
||||||
|
val factory = aRoomListRoomSummaryFactory(roomLatestEventFormatter = formatter)
|
||||||
|
|
||||||
|
factory.create(aRoomSummary(info = aRoomInfo(isDm = false, activeMembersCount = 3)))
|
||||||
|
|
||||||
|
assertThat(formatter.lastIsDmRoom).isFalse()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun aRoomListRoomSummaryFactory(
|
fun aRoomListRoomSummaryFactory(
|
||||||
dateFormatter: DateFormatter = FakeDateFormatter { _, _, _ -> "Today" },
|
dateFormatter: DateFormatter = FakeDateFormatter { _, _, _ -> "Today" },
|
||||||
|
|||||||
+5
@@ -14,11 +14,16 @@ import io.element.android.libraries.matrix.api.roomlist.LatestEventValue
|
|||||||
class FakeRoomLatestEventFormatter : RoomLatestEventFormatter {
|
class FakeRoomLatestEventFormatter : RoomLatestEventFormatter {
|
||||||
private var result: CharSequence? = null
|
private var result: CharSequence? = null
|
||||||
|
|
||||||
|
var lastIsDmRoom: Boolean? = null
|
||||||
|
private set
|
||||||
|
|
||||||
override fun format(latestEvent: LatestEventValue.Local, isDmRoom: Boolean): CharSequence? {
|
override fun format(latestEvent: LatestEventValue.Local, isDmRoom: Boolean): CharSequence? {
|
||||||
|
lastIsDmRoom = isDmRoom
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun format(latestEvent: LatestEventValue.Remote, isDmRoom: Boolean): CharSequence? {
|
override fun format(latestEvent: LatestEventValue.Remote, isDmRoom: Boolean): CharSequence? {
|
||||||
|
lastIsDmRoom = isDmRoom
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user