Fixes quote-notes and reposted notes partially disappearing when they contain hidden users or words.

This commit is contained in:
Vitor Pamplona
2024-03-02 12:37:02 -05:00
parent 6725114b48
commit 16c171ec40
3 changed files with 105 additions and 3 deletions
@@ -37,15 +37,28 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.ui.components.mockAccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
import com.vitorpamplona.amethyst.ui.theme.ButtonPadding
import com.vitorpamplona.amethyst.ui.theme.DividerThickness
import com.vitorpamplona.amethyst.ui.theme.Size35dp
import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn
import kotlinx.collections.immutable.ImmutableSet
import kotlinx.collections.immutable.persistentSetOf
@Composable
@Preview
fun BlankNotePreview() {
ThemeComparisonColumn(
onDark = { BlankNote() },
onLight = { BlankNote() },
)
}
@Composable
fun BlankNote(
@@ -85,6 +98,32 @@ fun BlankNote(
}
}
@Composable
@Preview
fun HiddenNotePreview() {
val accountViewModel = mockAccountViewModel()
val nav: (String) -> Unit = {}
ThemeComparisonColumn(
onDark = {
HiddenNote(
reports = persistentSetOf<Note>(),
isHiddenAuthor = true,
accountViewModel = accountViewModel,
nav = nav,
) {}
},
onLight = {
HiddenNote(
reports = persistentSetOf<Note>(),
isHiddenAuthor = true,
accountViewModel = accountViewModel,
nav = nav,
) {}
},
)
}
@OptIn(ExperimentalLayoutApi::class)
@Composable
fun HiddenNote(
@@ -149,3 +188,56 @@ fun HiddenNote(
)
}
}
@Preview
@Composable
fun HiddenNoteByMePreview() {
ThemeComparisonColumn(
onDark = { HiddenNoteByMe {} },
onLight = { HiddenNoteByMe {} },
)
}
@Composable
fun HiddenNoteByMe(
modifier: Modifier = Modifier,
isQuote: Boolean = false,
onClick: () -> Unit,
) {
Column(modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally) {
Row(
modifier = Modifier.padding(horizontal = 20.dp),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.padding(30.dp),
) {
Text(
text = stringResource(R.string.post_was_hidden),
color = Color.Gray,
)
Button(
modifier = Modifier.padding(top = 10.dp),
onClick = onClick,
shape = ButtonBorder,
colors =
ButtonDefaults.buttonColors(
contentColor = MaterialTheme.colorScheme.primary,
),
contentPadding = ButtonPadding,
) {
Text(text = stringResource(R.string.show_anyway), color = Color.White)
}
}
}
if (!isQuote) {
Divider(
thickness = DividerThickness,
)
}
}
}
@@ -359,8 +359,13 @@ fun CheckHiddenNoteCompose(
}
.observeAsState(accountViewModel.isNoteHidden(note))
val showAnyway =
remember {
mutableStateOf(false)
}
Crossfade(targetState = isHidden, label = "CheckHiddenNoteCompose") {
if (!it) {
if (!it || showAnyway.value) {
LoadedNoteCompose(
note = note,
routeForLastRead = routeForLastRead,
@@ -374,6 +379,11 @@ fun CheckHiddenNoteCompose(
accountViewModel = accountViewModel,
nav = nav,
)
} else if (isQuotedNote || isBoostedNote) {
HiddenNoteByMe(
isQuote = true,
onClick = { showAnyway.value = true },
)
}
}
}
@@ -441,8 +451,7 @@ fun RenderReportState(
) {
var showReportedNote by remember(note) { mutableStateOf(false) }
Crossfade(targetState = !state.isAcceptable && !showReportedNote, label = "RenderReportState") {
showHiddenNote ->
Crossfade(targetState = !state.isAcceptable && !showReportedNote, label = "RenderReportState") { showHiddenNote ->
if (showHiddenNote) {
HiddenNote(
state.relevantReports,
+1
View File
@@ -7,6 +7,7 @@
<string name="your_profile_image">Your Profile Picture</string>
<string name="scan_qr">Scan QR</string>
<string name="show_anyway">Show Anyway</string>
<string name="post_was_hidden">This post was hidden because it mentions your hidden users or words</string>
<string name="post_was_flagged_as_inappropriate_by">Post was muted or reported by</string>
<string name="post_not_found">Event is loading or can\'t be found in your relay list</string>
<string name="channel_image">Channel Image</string>