Let roomBadges be a computed val of RoomDetailsState
This commit is contained in:
parent
97cd7d3096
commit
eddbcb9499
5 changed files with 74 additions and 86 deletions
|
|
@ -43,7 +43,6 @@ import io.element.android.libraries.matrix.ui.room.getDirectRoomMember
|
|||
import io.element.android.libraries.matrix.ui.room.isOwnUserAdmin
|
||||
import io.element.android.services.analytics.api.AnalyticsService
|
||||
import io.element.android.services.analyticsproviders.api.trackers.captureInteraction
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
|
|
@ -113,21 +112,6 @@ class RoomDetailsPresenter @Inject constructor(
|
|||
|
||||
val roomNotificationSettingsState by room.roomNotificationSettingsStateFlow.collectAsState()
|
||||
|
||||
val roomBadges by produceState(persistentListOf(), isPublic) {
|
||||
value = buildList {
|
||||
if (room.isEncrypted || isPublic) {
|
||||
if (room.isEncrypted) {
|
||||
add(RoomBadge.ENCRYPTED)
|
||||
} else {
|
||||
add(RoomBadge.NOT_ENCRYPTED)
|
||||
}
|
||||
}
|
||||
if (isPublic) {
|
||||
add(RoomBadge.PUBLIC)
|
||||
}
|
||||
}.toPersistentList()
|
||||
}
|
||||
|
||||
fun handleEvents(event: RoomDetailsEvent) {
|
||||
when (event) {
|
||||
RoomDetailsEvent.LeaveRoom ->
|
||||
|
|
@ -167,7 +151,6 @@ class RoomDetailsPresenter @Inject constructor(
|
|||
isFavorite = isFavorite,
|
||||
displayRolesAndPermissionsSettings = !room.isDm && isUserAdmin,
|
||||
isPublic = isPublic,
|
||||
roomBadges = roomBadges,
|
||||
heroes = roomInfo?.heroes.orEmpty().toPersistentList(),
|
||||
canShowPinnedMessages = canShowPinnedMessages,
|
||||
pinnedMessagesCount = pinnedMessagesCount,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import io.element.android.libraries.matrix.api.room.RoomMember
|
|||
import io.element.android.libraries.matrix.api.room.RoomNotificationSettings
|
||||
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
data class RoomDetailsState(
|
||||
val roomId: RoomId,
|
||||
|
|
@ -36,12 +37,24 @@ data class RoomDetailsState(
|
|||
val isFavorite: Boolean,
|
||||
val displayRolesAndPermissionsSettings: Boolean,
|
||||
val isPublic: Boolean,
|
||||
val roomBadges: ImmutableList<RoomBadge>,
|
||||
val heroes: ImmutableList<MatrixUser>,
|
||||
val canShowPinnedMessages: Boolean,
|
||||
val pinnedMessagesCount: Int?,
|
||||
val eventSink: (RoomDetailsEvent) -> Unit
|
||||
)
|
||||
) {
|
||||
val roomBadges = buildList {
|
||||
if (isEncrypted || isPublic) {
|
||||
if (isEncrypted) {
|
||||
add(RoomBadge.ENCRYPTED)
|
||||
} else {
|
||||
add(RoomBadge.NOT_ENCRYPTED)
|
||||
}
|
||||
}
|
||||
if (isPublic) {
|
||||
add(RoomBadge.PUBLIC)
|
||||
}
|
||||
}.toPersistentList()
|
||||
}
|
||||
|
||||
@Immutable
|
||||
sealed interface RoomDetailsType {
|
||||
|
|
|
|||
|
|
@ -96,18 +96,6 @@ fun aRoomDetailsState(
|
|||
isFavorite: Boolean = false,
|
||||
displayAdminSettings: Boolean = false,
|
||||
isPublic: Boolean = true,
|
||||
roomBadges: List<RoomBadge> = buildList {
|
||||
if (isEncrypted || isPublic) {
|
||||
if (isEncrypted) {
|
||||
add(RoomBadge.ENCRYPTED)
|
||||
} else {
|
||||
add(RoomBadge.NOT_ENCRYPTED)
|
||||
}
|
||||
}
|
||||
if (isPublic) {
|
||||
add(RoomBadge.PUBLIC)
|
||||
}
|
||||
},
|
||||
heroes: List<MatrixUser> = emptyList(),
|
||||
canShowPinnedMessages: Boolean = true,
|
||||
pinnedMessagesCount: Int? = null,
|
||||
|
|
@ -131,7 +119,6 @@ fun aRoomDetailsState(
|
|||
isFavorite = isFavorite,
|
||||
displayRolesAndPermissionsSettings = displayAdminSettings,
|
||||
isPublic = isPublic,
|
||||
roomBadges = roomBadges.toPersistentList(),
|
||||
heroes = heroes.toPersistentList(),
|
||||
canShowPinnedMessages = canShowPinnedMessages,
|
||||
pinnedMessagesCount = pinnedMessagesCount,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue