Don't show button to edit the post if the author of the original post is not the logged in user

This commit is contained in:
Vitor Pamplona
2024-03-04 13:16:34 -05:00
parent 2f45067949
commit cd2b5d78a1
2 changed files with 27 additions and 8 deletions
@@ -1516,7 +1516,7 @@ fun RenderTextModificationEvent(
val noteEvent = note.event as? TextNoteModificationEvent ?: return val noteEvent = note.event as? TextNoteModificationEvent ?: return
val noteAuthor = note.author ?: return val noteAuthor = note.author ?: return
val isAuthorTheLoggedUser = remember(note.event) { accountViewModel.isLoggedUser(note.author) } // val isAuthorTheLoggedUser = remember(note.event) { accountViewModel.isLoggedUser(note.author) }
val editState = val editState =
remember { remember {
@@ -1543,6 +1543,13 @@ fun RenderTextModificationEvent(
mutableStateOf(false) mutableStateOf(false)
} }
val isAuthorTheLoggedUser =
remember {
val authorOfTheOriginalNote = noteEvent.editedNote()?.let { accountViewModel.getNoteIfExists(it)?.author }
mutableStateOf(accountViewModel.isLoggedUser(authorOfTheOriginalNote))
}
Card( Card(
modifier = MaterialTheme.colorScheme.imageModifier, modifier = MaterialTheme.colorScheme.imageModifier,
) { ) {
@@ -1574,6 +1581,16 @@ fun RenderTextModificationEvent(
noteEvent.editedNote()?.let { noteEvent.editedNote()?.let {
LoadNote(baseNoteHex = it, accountViewModel = accountViewModel) { baseNote -> LoadNote(baseNoteHex = it, accountViewModel = accountViewModel) { baseNote ->
baseNote?.let { baseNote?.let {
val noteState by baseNote.live().metadata.observeAsState()
LaunchedEffect(key1 = noteState) {
val newAuthor = accountViewModel.isLoggedUser(noteState?.note?.author)
if (isAuthorTheLoggedUser.value != newAuthor) {
isAuthorTheLoggedUser.value = newAuthor
}
}
Column( Column(
modifier = modifier =
MaterialTheme.colorScheme.innerPostModifier.padding(Size10dp).clickable { MaterialTheme.colorScheme.innerPostModifier.padding(Size10dp).clickable {
@@ -1609,13 +1626,15 @@ fun RenderTextModificationEvent(
} }
} }
Spacer(modifier = StdVertSpacer) if (isAuthorTheLoggedUser.value) {
Spacer(modifier = StdVertSpacer)
Button( Button(
onClick = { wantsToEditPost.value = true }, onClick = { wantsToEditPost.value = true },
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
) { ) {
Text(text = stringResource(id = R.string.accept_the_suggestion)) Text(text = stringResource(id = R.string.accept_the_suggestion))
}
} }
} }
} }
+1 -1
View File
@@ -797,7 +797,7 @@
<string name="ots_info_description">There\'s proof this post was signed sometime before %1$s. The proof was stamped in the Bitcoin blockchain at that date and time.</string> <string name="ots_info_description">There\'s proof this post was signed sometime before %1$s. The proof was stamped in the Bitcoin blockchain at that date and time.</string>
<string name="edit_post">Edit Post</string> <string name="edit_post">Edit Post</string>
<string name="proposal_to_edit">Proposal to improve your post</string> <string name="proposal_to_edit">Proposal to improve a post</string>
<string name="message_to_author">Summary of changes</string> <string name="message_to_author">Summary of changes</string>
<string name="message_to_author_placeholder">Quick fixes…</string> <string name="message_to_author_placeholder">Quick fixes…</string>