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