Skip to content

Commit

Permalink
Dont show comment content when its deleted or removed. (#1371)
Browse files Browse the repository at this point in the history
- Fixes #1335
  • Loading branch information
dessalines committed Feb 11, 2024
1 parent 998e30f commit 92791be
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
14 changes: 14 additions & 0 deletions app/src/main/java/com/jerboa/datatypes/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package com.jerboa.datatypes

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.jerboa.R
import it.vercruysse.lemmyapi.v0x19.datatypes.Comment
import it.vercruysse.lemmyapi.v0x19.datatypes.Person

fun Person.getDisplayName(): String = this.display_name ?: this.name

@Composable
fun Comment.getContent(): String =
if (this.removed) {
stringResource(R.string.comment_body_removed)
} else if (this.deleted) {
stringResource(R.string.comment_body_deleted)
} else {
this.content
}
14 changes: 3 additions & 11 deletions app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.jerboa.border
import com.jerboa.buildCommentsTree
import com.jerboa.calculateCommentOffset
import com.jerboa.datatypes.BanFromCommunityData
import com.jerboa.datatypes.getContent
import com.jerboa.datatypes.sampleCommentView
import com.jerboa.datatypes.sampleCommunity
import com.jerboa.datatypes.samplePost
Expand Down Expand Up @@ -151,25 +152,16 @@ fun CommentBody(
onClick: () -> Unit,
onLongClick: ((View) -> Boolean),
) {
val content =
if (comment.removed) {
stringResource(R.string.comment_body_removed)
} else if (comment.deleted) {
stringResource(R.string.comment_body_deleted)
} else {
comment.content
}

if (viewSource) {
SelectionContainer {
Text(
text = comment.content,
text = comment.getContent(),
fontFamily = FontFamily.Monospace,
)
}
} else {
MyMarkdownText(
markdown = content,
markdown = comment.getContent(),
onClick = onClick,
onLongClick = onLongClick,
modifier = Modifier.padding(0.dp, 0.dp, 0.dp, MEDIUM_PADDING),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.jerboa.R
import com.jerboa.api.API
import com.jerboa.copyToClipboard
import com.jerboa.datatypes.BanFromCommunityData
import com.jerboa.datatypes.getContent
import com.jerboa.ui.components.common.BanFromCommunityPopupMenuItem
import com.jerboa.ui.components.common.BanPersonPopupMenuItem
import com.jerboa.ui.components.common.PopupMenuItem
Expand Down Expand Up @@ -102,12 +103,13 @@ fun CommentOptionsDropdown(
).show()
},
)
val content = commentView.comment.getContent()
PopupMenuItem(
text = stringResource(R.string.comment_node_copy_comment),
icon = Icons.Outlined.ContentCopy,
onClick = {
onDismissRequest()
if (copyToClipboard(ctx, commentView.comment.content, "comment")) {
if (copyToClipboard(ctx, content, "comment")) {
Toast.makeText(
ctx,
ctx.getString(R.string.comment_node_comment_copied),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import com.jerboa.R
import com.jerboa.copyToClipboard
import com.jerboa.datatypes.getContent
import com.jerboa.ui.components.common.PopupMenuItem
import com.jerboa.util.cascade.CascadeCenteredDropdownMenu
import it.vercruysse.lemmyapi.v0x19.datatypes.Person
Expand Down Expand Up @@ -83,12 +84,13 @@ fun CommentMentionsOptionsDropdown(
).show()
},
)
val content = personMentionView.comment.getContent()
PopupMenuItem(
text = stringResource(R.string.comment_node_copy_comment),
icon = Icons.Outlined.ContentCopy,
onClick = {
onDismissRequest()
if (copyToClipboard(ctx, personMentionView.comment.content, "comment")) {
if (copyToClipboard(ctx, content, "comment")) {
Toast.makeText(ctx, ctx.getString(R.string.comment_node_comment_copied), Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(ctx, ctx.getString(R.string.generic_error), Toast.LENGTH_SHORT).show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview
import com.jerboa.R
import com.jerboa.datatypes.getContent
import com.jerboa.datatypes.sampleCommentView
import com.jerboa.db.entity.Account
import com.jerboa.ui.components.comment.CommentNodeHeader
Expand Down Expand Up @@ -51,7 +52,7 @@ fun RepliedComment(
showScores = showScores,
)
SelectionContainer {
Text(text = commentView.comment.content)
Text(text = commentView.comment.getContent())
}
}
}
Expand All @@ -75,7 +76,7 @@ fun RepliedCommentReply(
showScores = showScores,
)
SelectionContainer {
Text(text = commentReplyView.comment.content)
Text(text = commentReplyView.comment.getContent())
}
}
}
Expand All @@ -99,7 +100,7 @@ fun RepliedMentionReply(
showScores = showScores,
)
SelectionContainer {
Text(text = personMentionView.comment.content)
Text(text = personMentionView.comment.getContent())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import com.jerboa.R
import com.jerboa.copyToClipboard
import com.jerboa.datatypes.getContent
import com.jerboa.ui.components.common.PopupMenuItem
import com.jerboa.util.cascade.CascadeCenteredDropdownMenu
import it.vercruysse.lemmyapi.v0x19.datatypes.CommentReplyView
Expand Down Expand Up @@ -79,12 +80,13 @@ fun CommentReplyOptionsDropdown(
).show()
},
)
val content = commentReplyView.comment.getContent()
PopupMenuItem(
text = stringResource(R.string.comment_node_copy_comment),
icon = Icons.Outlined.ContentCopy,
onClick = {
onDismissRequest()
if (copyToClipboard(ctx, commentReplyView.comment.content, "comment")) {
if (copyToClipboard(ctx, content, "comment")) {
Toast.makeText(ctx, ctx.getString(R.string.comment_node_comment_copied), Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(ctx, ctx.getString(R.string.generic_error), Toast.LENGTH_SHORT).show()
Expand Down

0 comments on commit 92791be

Please sign in to comment.