Yokan / rebuild
Course 1 8624561

TogetherUiBinding.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/screens/together/TogetherUiBinding.kt

implementation37 lines
1package eu.friedcutlet.yokan.ui.screens.together23import eu.friedcutlet.yokan.services.together.ProfileTogetherSession4import eu.friedcutlet.yokan.services.together.RoomClient5import eu.friedcutlet.yokan.services.together.RoomConnection6import eu.friedcutlet.yokan.services.together.RoomRole7import eu.friedcutlet.yokan.services.together.RoomState8import kotlinx.coroutines.Job910internal fun roomDrives(room: RoomState?, driving: Boolean): Boolean =11    room?.connection == RoomConnection.Open &&12        (room.role == RoomRole.Host || (room.role == RoomRole.CoHost && driving))1314/** Captured room capability. Old clients, disposed screens and stale room snapshots fail closed. */15internal class TogetherUiBinding(16    private val together: ProfileTogetherSession,17    private val client: RoomClient?,18    private val job: Job,19    private val isUiActive: () -> Boolean = { true },20) {21    fun active(): Boolean = job.isActive && isUiActive() && client != null && together.owns(client)2223    fun current(room: RoomState?): Boolean = active() && room != null && client?.state?.value == room2425    fun drives(): Boolean = active() && roomDrives(client?.state?.value, together.driving.value)2627    fun followsMedia(room: RoomState?): Boolean = active() && room != null &&28        client?.state?.value?.let { current ->29            current.connection == RoomConnection.Open && current.media == room.media &&30                together.following.value && !roomDrives(current, together.driving.value)31        } == true3233    fun follows(room: RoomState?): Boolean = followsMedia(room) &&34        client?.state?.value?.position == room?.position3536    fun close() { job.cancel() }37}38

Search chapters, reference and source filenames.