mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-18 05:41:56 +01:00
Fixes content sensitivity for NIP-54 images.
This commit is contained in:
parent
d88eb014b7
commit
6638defbb9
@ -103,6 +103,7 @@ class RichTextParser() {
|
||||
hash = frags["x"],
|
||||
blurhash = frags["blurhash"],
|
||||
dim = frags["dim"],
|
||||
contentWarning = frags["content-warning"],
|
||||
)
|
||||
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
||||
val frags = Nip44UrlParser().parse(fullUrl)
|
||||
@ -112,6 +113,7 @@ class RichTextParser() {
|
||||
hash = frags["x"],
|
||||
blurhash = frags["blurhash"],
|
||||
dim = frags["dim"],
|
||||
contentWarning = frags["content-warning"],
|
||||
)
|
||||
} else {
|
||||
null
|
||||
|
@ -279,6 +279,7 @@ fun ImageVideoPost(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
SettingSwitchItem(
|
||||
modifier = Modifier.fillMaxWidth().padding(8.dp),
|
||||
checked = postViewModel.sensitiveContent,
|
||||
onCheckedChange = { postViewModel.sensitiveContent = it },
|
||||
title = R.string.add_sensitive_content_label,
|
||||
|
@ -1716,6 +1716,7 @@ fun ImageVideoDescription(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
SettingSwitchItem(
|
||||
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),
|
||||
checked = sensitiveContent,
|
||||
onCheckedChange = { sensitiveContent = it },
|
||||
title = R.string.add_sensitive_content_label,
|
||||
@ -1764,7 +1765,7 @@ fun ImageVideoDescription(
|
||||
|
||||
@Composable
|
||||
fun SettingSwitchItem(
|
||||
modifier: Modifier = Modifier,
|
||||
modifier: Modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
checked: Boolean,
|
||||
onCheckedChange: (Boolean) -> Unit,
|
||||
title: Int,
|
||||
@ -1774,8 +1775,6 @@ fun SettingSwitchItem(
|
||||
Row(
|
||||
modifier =
|
||||
modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
.toggleable(
|
||||
value = checked,
|
||||
enabled = enabled,
|
||||
@ -1786,7 +1785,7 @@ fun SettingSwitchItem(
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.weight(1.0f),
|
||||
verticalArrangement = Arrangement.spacedBy(3.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(Size5dp),
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = title),
|
||||
|
@ -264,7 +264,7 @@ open class NewPostViewModel() : ViewModel() {
|
||||
}
|
||||
|
||||
val urls = findURLs(tagger.message)
|
||||
val usedAttachments = nip94attachments.filter { it.urls().intersect(urls).isNotEmpty() }
|
||||
val usedAttachments = nip94attachments.filter { it.urls().intersect(urls.toSet()).isNotEmpty() }
|
||||
usedAttachments.forEach { account?.sendHeader(it, relayList, {}) }
|
||||
|
||||
if (originalNote?.channelHex() != null) {
|
||||
@ -846,9 +846,7 @@ open class NewPostViewModel() : ViewModel() {
|
||||
alt?.ifBlank { null }?.let { "alt=${URLEncoder.encode(it, "utf-8")}" },
|
||||
blurHash?.ifBlank { null }?.let { "blurhash=${URLEncoder.encode(it, "utf-8")}" },
|
||||
x?.ifBlank { null }?.let { "x=${URLEncoder.encode(it, "utf-8")}" },
|
||||
sensitiveContent
|
||||
?.ifBlank { null }
|
||||
?.let { "content-warning=${URLEncoder.encode(it, "utf-8")}" },
|
||||
sensitiveContent?.let { "content-warning=${URLEncoder.encode(it, "utf-8")}" },
|
||||
)
|
||||
.joinToString("&")
|
||||
|
||||
|
@ -74,8 +74,17 @@ fun SensitivityWarning(
|
||||
accountViewModel: AccountViewModel,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val hasSensitiveContent = remember(event) { event.isSensitive() ?: false }
|
||||
val hasSensitiveContent = remember(event) { event.isSensitive() }
|
||||
|
||||
SensitivityWarning(hasSensitiveContent, accountViewModel, content)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SensitivityWarning(
|
||||
hasSensitiveContent: Boolean,
|
||||
accountViewModel: AccountViewModel,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
if (hasSensitiveContent) {
|
||||
SensitivityWarning(accountViewModel, content)
|
||||
} else {
|
||||
|
@ -161,6 +161,7 @@ class ZoomableUrlImage(
|
||||
val blurhash: String? = null,
|
||||
dim: String? = null,
|
||||
uri: String? = null,
|
||||
val contentWarning: String? = null,
|
||||
) : ZoomableUrlContent(url, description, hash, dim, uri)
|
||||
|
||||
@Immutable
|
||||
@ -173,6 +174,7 @@ class ZoomableUrlVideo(
|
||||
val artworkUri: String? = null,
|
||||
val authorName: String? = null,
|
||||
val blurhash: String? = null,
|
||||
val contentWarning: String? = null,
|
||||
) : ZoomableUrlContent(url, description, hash, dim, uri)
|
||||
|
||||
@Immutable
|
||||
@ -265,20 +267,24 @@ fun ZoomableContentView(
|
||||
|
||||
when (content) {
|
||||
is ZoomableUrlImage ->
|
||||
UrlImageView(content, mainImageModifier, accountViewModel = accountViewModel)
|
||||
SensitivityWarning(content.contentWarning != null, accountViewModel) {
|
||||
UrlImageView(content, mainImageModifier, accountViewModel = accountViewModel)
|
||||
}
|
||||
is ZoomableUrlVideo ->
|
||||
VideoView(
|
||||
videoUri = content.url,
|
||||
title = content.description,
|
||||
artworkUri = content.artworkUri,
|
||||
authorName = content.authorName,
|
||||
dimensions = content.dim,
|
||||
blurhash = content.blurhash,
|
||||
roundedCorner = roundedCorner,
|
||||
nostrUriCallback = content.uri,
|
||||
onDialog = { dialogOpen = true },
|
||||
accountViewModel = accountViewModel,
|
||||
)
|
||||
SensitivityWarning(content.contentWarning != null, accountViewModel) {
|
||||
VideoView(
|
||||
videoUri = content.url,
|
||||
title = content.description,
|
||||
artworkUri = content.artworkUri,
|
||||
authorName = content.authorName,
|
||||
dimensions = content.dim,
|
||||
blurhash = content.blurhash,
|
||||
roundedCorner = roundedCorner,
|
||||
nostrUriCallback = content.uri,
|
||||
onDialog = { dialogOpen = true },
|
||||
accountViewModel = accountViewModel,
|
||||
)
|
||||
}
|
||||
is ZoomableLocalImage ->
|
||||
LocalImageView(content, mainImageModifier, accountViewModel = accountViewModel)
|
||||
is ZoomableLocalVideo ->
|
||||
@ -387,13 +393,13 @@ private fun UrlImageView(
|
||||
val myModifier =
|
||||
remember {
|
||||
mainImageModifier.widthIn(max = maxWidth).heightIn(max = maxHeight)
|
||||
/* Is this necessary? It makes images bleed into other pages
|
||||
/* Is this necessary? It makes images bleed into other pages
|
||||
.run {
|
||||
aspectRatio(content.dim)?.let { ratio ->
|
||||
this.aspectRatio(ratio, false)
|
||||
} ?: this
|
||||
}
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
val contentScale =
|
||||
|
Loading…
x
Reference in New Issue
Block a user