Adding content-sensitivity warnings for LiveStreams

This commit is contained in:
Vitor Pamplona 2023-07-07 15:17:20 -04:00
parent 9c7265565e
commit d35d6a44fe
3 changed files with 51 additions and 24 deletions

View File

@ -34,6 +34,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.service.model.EventInterface
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
@ -43,7 +44,18 @@ fun SensitivityWarning(
accountViewModel: AccountViewModel,
content: @Composable () -> Unit
) {
val hasSensitiveContent = remember(note) { note.event?.isSensitive() ?: false }
note.event?.let {
SensitivityWarning(it, accountViewModel, content)
}
}
@Composable
fun SensitivityWarning(
event: EventInterface,
accountViewModel: AccountViewModel,
content: @Composable () -> Unit
) {
val hasSensitiveContent = remember(event) { event.isSensitive() ?: false }
if (hasSensitiveContent) {
SensitivityWarning(accountViewModel, content)

View File

@ -56,6 +56,7 @@ import com.vitorpamplona.amethyst.service.model.LiveActivitiesEvent
import com.vitorpamplona.amethyst.service.model.LiveActivitiesEvent.Companion.STATUS_ENDED
import com.vitorpamplona.amethyst.service.model.LiveActivitiesEvent.Companion.STATUS_LIVE
import com.vitorpamplona.amethyst.service.model.LiveActivitiesEvent.Companion.STATUS_PLANNED
import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
import com.vitorpamplona.amethyst.ui.screen.equalImmutableLists
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ChannelHeader
@ -321,11 +322,16 @@ fun InnerChannelCardWithReactions(
nav: (String) -> Unit
) {
Column(StdPadding) {
RenderNoteRow(
baseNote,
accountViewModel,
nav
)
SensitivityWarning(
note = baseNote,
accountViewModel = accountViewModel
) {
RenderNoteRow(
baseNote,
accountViewModel,
nav
)
}
}
}

View File

@ -99,6 +99,7 @@ import com.vitorpamplona.amethyst.ui.actions.UploadFromGallery
import com.vitorpamplona.amethyst.ui.actions.toImmutableListOfLists
import com.vitorpamplona.amethyst.ui.components.LoadNote
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
import com.vitorpamplona.amethyst.ui.components.ZoomableContentView
import com.vitorpamplona.amethyst.ui.components.ZoomableUrlVideo
@ -580,7 +581,7 @@ fun ChannelHeader(
) {
Column(Modifier.fillMaxWidth()) {
if (showVideo && baseChannel is LiveActivitiesChannel) {
ShowVideoStreaming(baseChannel)
ShowVideoStreaming(baseChannel, accountViewModel)
}
var expanded = remember { mutableStateOf(false) }
@ -607,26 +608,34 @@ fun ChannelHeader(
@Composable
private fun ShowVideoStreaming(
baseChannel: LiveActivitiesChannel
baseChannel: LiveActivitiesChannel,
accountViewModel: AccountViewModel
) {
val streamingUrl by baseChannel.live.map {
val activity = it.channel as? LiveActivitiesChannel
activity?.info?.streaming()
}.distinctUntilChanged().observeAsState(baseChannel.info?.streaming())
baseChannel.info?.let {
SensitivityWarning(
event = it,
accountViewModel = accountViewModel
) {
val streamingUrl by baseChannel.live.map {
val activity = it.channel as? LiveActivitiesChannel
activity?.info?.streaming()
}.distinctUntilChanged().observeAsState(baseChannel.info?.streaming())
streamingUrl?.let {
CheckIfUrlIsOnline(it) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = remember { Modifier.heightIn(max = 300.dp) }
) {
val zoomableUrlVideo = remember(it) {
ZoomableUrlVideo(url = it)
streamingUrl?.let {
CheckIfUrlIsOnline(it) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = remember { Modifier.heightIn(max = 300.dp) }
) {
val zoomableUrlVideo = remember(it) {
ZoomableUrlVideo(url = it)
}
ZoomableContentView(
content = zoomableUrlVideo
)
}
}
ZoomableContentView(
content = zoomableUrlVideo
)
}
}
}