Skip to content

Commit

Permalink
Make Discord sounds unstoppable
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Nov 10, 2024
1 parent b191fca commit 88e602a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
9 changes: 5 additions & 4 deletions app/shared/src/commonMain/kotlin/components/SoundContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fun SoundContainer(model: SoundListViewModel) {
.scrollable(rememberScrollState(), Orientation.Vertical)
) {
items(state.sounds) { group ->
SoundGroup(group, state.playingSound, model::reportError, unavailableFor)
SoundGroup(group, state.playingSound, model::reportError, unavailableFor, !state.canBeStopped)
}
}
}
Expand All @@ -142,7 +142,8 @@ private fun SoundGroup(
group: SoundGroup,
playingSound: Id<Sound>?,
errorReporter: ErrorReporter,
unavailableFor: String?
unavailableFor: String?,
disabled: Boolean
) = BoxWithConstraints(Modifier.padding(horizontal = 5.dp)) {
val maxWidth = constraints.maxWidth
var visible by remember { mutableStateOf(true) }
Expand Down Expand Up @@ -190,7 +191,7 @@ private fun SoundGroup(
description = sound.description,
playing = sound.id == playingSound,
reportError = errorReporter,
disabled = unavailableFor != null
disabled = unavailableFor != null || disabled
)
}
}
Expand Down Expand Up @@ -225,7 +226,7 @@ fun SoundCard(
description: String?,
playing: Boolean,
reportError: ErrorReporter,
disabled: Boolean
disabled: Boolean,
) {
val coroutineScope = rememberCoroutineScope { Dispatchers.IO }
val corners = RoundedCornerShape(10.dp)
Expand Down
4 changes: 2 additions & 2 deletions app/shared/src/commonMain/kotlin/components/SoundList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private val LOG = KotlinLogging.logger {}
data class SoundListState(
val playingSound: Id<Sound>? = null,
val sounds: List<SoundGroup> = emptyList(),
val canBeStopped: Boolean = true,
val available: Boolean = false,
val channelMismatch: Boolean = false,
val offline: Boolean = false
Expand Down Expand Up @@ -87,7 +88,7 @@ class SoundListViewModel(
when (event) {
is VoiceStateUpdateEvent -> handle(event.voiceState)
is InterfaceAvailabilityChangeEvent -> {
_uiState.update { it.copy(available = event.available, playingSound = event.playingSongId) }
_uiState.update { it.copy(available = event.available, playingSound = event.playingSongId, canBeStopped = event.canBeStopped) }
}

is SoundDeletedEvent -> {
Expand Down Expand Up @@ -161,7 +162,6 @@ fun SoundList(
}
}


AnimatedVisibility(!baseState.loading, enter = fadeIn(), exit = fadeOut(), modifier = Modifier.fillMaxSize()) {
SoundContainer(model)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SoundPlayer(guild: GuildBehavior) : CoroutineScope {
locked = !available
coroutineScope {
getUsersInChannel(channel).forEach {
sendEvent(it, InterfaceAvailabilityChangeEvent(available || it == user, playingSound?.id))
sendEvent(it, InterfaceAvailabilityChangeEvent(available || it == user, playingSound?.id, playingSound?.isDiscord != true))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ public sealed interface HasSound {
*
* @property available whether the player is now locked or not
* @property playingSongId the id of the sound which is currently playing if any
* @property canBeStopped whether the current sound can be stopped
*/
@Serializable
@SerialName("interface_availability_change")
public data class InterfaceAvailabilityChangeEvent(val available: Boolean, val playingSongId: Id<Sound>?) : Event
public data class InterfaceAvailabilityChangeEvent(
val available: Boolean,
val playingSongId: Id<Sound>?,
val canBeStopped: Boolean
) : Event

/**
* Event indicating that the current users voice state has updated.
Expand Down

0 comments on commit 88e602a

Please sign in to comment.