Generalizes the SensitivityWarning to Note.

This commit is contained in:
Vitor Pamplona
2023-06-22 12:04:11 -04:00
parent 32b2b1ace8
commit ad353d2d1a
3 changed files with 21 additions and 13 deletions
@@ -33,19 +33,34 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
@Composable @Composable
fun SensitivityWarning( fun SensitivityWarning(
hasSensitiveContent: Boolean, note: Note,
accountViewModel: AccountViewModel,
content: @Composable () -> Unit
) {
val hasSensitiveContent = remember(note.event) { note.event?.isSensitive() ?: false }
if (hasSensitiveContent) {
SensitivityWarning(accountViewModel, content)
} else {
content()
}
}
@Composable
fun SensitivityWarning(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
content: @Composable () -> Unit content: @Composable () -> Unit
) { ) {
val accountState by accountViewModel.accountLiveData.observeAsState() val accountState by accountViewModel.accountLiveData.observeAsState()
var showContentWarningNote by remember(accountState) { var showContentWarningNote by remember(accountState) {
mutableStateOf(accountState?.account?.showSensitiveContent != true && hasSensitiveContent) mutableStateOf(accountState?.account?.showSensitiveContent != true)
} }
if (showContentWarningNote) { if (showContentWarningNote) {
@@ -610,10 +610,8 @@ private fun RenderRegularTextNote(
val modifier = remember { Modifier.padding(top = 5.dp) } val modifier = remember { Modifier.padding(top = 5.dp) }
if (eventContent != null) { if (eventContent != null) {
val hasSensitiveContent = remember(note.event) { note.event?.isSensitive() ?: false }
SensitivityWarning( SensitivityWarning(
hasSensitiveContent = hasSensitiveContent, note = note,
accountViewModel = accountViewModel accountViewModel = accountViewModel
) { ) {
TranslatableRichTextViewer( TranslatableRichTextViewer(
@@ -817,10 +817,8 @@ fun RenderTextEvent(
overflow = TextOverflow.Ellipsis overflow = TextOverflow.Ellipsis
) )
} else { } else {
val hasSensitiveContent = remember(note.event) { note.event?.isSensitive() ?: false }
SensitivityWarning( SensitivityWarning(
hasSensitiveContent = hasSensitiveContent, note = note,
accountViewModel = accountViewModel accountViewModel = accountViewModel
) { ) {
val modifier = remember(note) { Modifier.fillMaxWidth() } val modifier = remember(note) { Modifier.fillMaxWidth() }
@@ -863,12 +861,10 @@ fun RenderPoll(
overflow = TextOverflow.Ellipsis overflow = TextOverflow.Ellipsis
) )
} else { } else {
val hasSensitiveContent = remember(note.event) { note.event?.isSensitive() ?: false }
val tags = remember(note) { note.event?.tags()?.toImmutableListOfLists() ?: ImmutableListOfLists() } val tags = remember(note) { note.event?.tags()?.toImmutableListOfLists() ?: ImmutableListOfLists() }
SensitivityWarning( SensitivityWarning(
hasSensitiveContent = hasSensitiveContent, note = note,
accountViewModel = accountViewModel accountViewModel = accountViewModel
) { ) {
TranslatableRichTextViewer( TranslatableRichTextViewer(
@@ -1119,9 +1115,8 @@ private fun RenderPrivateMessage(
overflow = TextOverflow.Ellipsis overflow = TextOverflow.Ellipsis
) )
} else { } else {
val hasSensitiveContent = remember(note.event) { note.event?.isSensitive() ?: false }
SensitivityWarning( SensitivityWarning(
hasSensitiveContent = hasSensitiveContent, note = note,
accountViewModel = accountViewModel accountViewModel = accountViewModel
) { ) {
TranslatableRichTextViewer( TranslatableRichTextViewer(