Make the RoomListRoomSummaryFactory.createPlaceholder and RoomListRoomSummaryFactory.createFakeList functions static ones

This commit is contained in:
Jorge Martín
2024-02-02 13:04:28 +01:00
parent b390215701
commit b0ce6e7d89
2 changed files with 25 additions and 23 deletions

View File

@@ -115,7 +115,7 @@ class RoomListDataSource @Inject constructor(
private suspend fun buildAndEmitAllRooms(roomSummaries: List<RoomSummary>) {
if (diffCache.isEmpty()) {
_allRooms.emit(
roomListRoomSummaryFactory.createFakeList()
RoomListRoomSummaryFactory.createFakeList()
)
} else {
val roomListRoomSummaries = ArrayList<RoomListRoomSummary>()
@@ -135,7 +135,7 @@ class RoomListDataSource @Inject constructor(
private fun buildAndCacheItem(roomSummaries: List<RoomSummary>, index: Int): RoomListRoomSummary? {
val roomListRoomSummary = when (val roomSummary = roomSummaries.getOrNull(index)) {
is RoomSummary.Empty -> roomListRoomSummaryFactory.createPlaceholder(roomSummary.identifier)
is RoomSummary.Empty -> RoomListRoomSummaryFactory.createPlaceholder(roomSummary.identifier)
is RoomSummary.Filled -> roomListRoomSummaryFactory.create(roomSummary)
null -> null
}

View File

@@ -32,28 +32,30 @@ class RoomListRoomSummaryFactory @Inject constructor(
private val lastMessageTimestampFormatter: LastMessageTimestampFormatter,
private val roomLastMessageFormatter: RoomLastMessageFormatter,
) {
fun createPlaceholder(id: String): RoomListRoomSummary {
return RoomListRoomSummary(
id = id,
roomId = RoomId("!aRoom:domain"),
isPlaceholder = true,
name = "Short name",
timestamp = "hh:mm",
lastMessage = "Last message for placeholder",
avatarData = AvatarData(id, "S", size = AvatarSize.RoomListItem),
numberOfUnreadMessages = 0,
numberOfUnreadMentions = 0,
numberOfUnreadNotifications = 0,
userDefinedNotificationMode = null,
hasRoomCall = false,
isDm = false,
)
}
companion object {
fun createPlaceholder(id: String): RoomListRoomSummary {
return RoomListRoomSummary(
id = id,
roomId = RoomId(id),
isPlaceholder = true,
name = "Short name",
timestamp = "hh:mm",
lastMessage = "Last message for placeholder",
avatarData = AvatarData(id, "S", size = AvatarSize.RoomListItem),
numberOfUnreadMessages = 0,
numberOfUnreadMentions = 0,
numberOfUnreadNotifications = 0,
userDefinedNotificationMode = null,
hasRoomCall = false,
isDm = false,
)
}
fun createFakeList(): ImmutableList<RoomListRoomSummary> {
return List(16) {
createPlaceholder("!fakeRoom$it:domain")
}.toImmutableList()
fun createFakeList(): ImmutableList<RoomListRoomSummary> {
return List(16) {
createPlaceholder("!fakeRoom$it:domain")
}.toImmutableList()
}
}
fun create(roomSummary: RoomSummary.Filled): RoomListRoomSummary {