From cd2b5d78a182d386d6197c2040e3b6da53a1aa99 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 4 Mar 2024 13:16:34 -0500 Subject: [PATCH] Don't show button to edit the post if the author of the original post is not the logged in user --- .../amethyst/ui/note/NoteCompose.kt | 33 +++++++++++++++---- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt index c4077a767..e1922634a 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt @@ -1516,7 +1516,7 @@ fun RenderTextModificationEvent( val noteEvent = note.event as? TextNoteModificationEvent ?: 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 = remember { @@ -1543,6 +1543,13 @@ fun RenderTextModificationEvent( mutableStateOf(false) } + val isAuthorTheLoggedUser = + remember { + val authorOfTheOriginalNote = noteEvent.editedNote()?.let { accountViewModel.getNoteIfExists(it)?.author } + + mutableStateOf(accountViewModel.isLoggedUser(authorOfTheOriginalNote)) + } + Card( modifier = MaterialTheme.colorScheme.imageModifier, ) { @@ -1574,6 +1581,16 @@ fun RenderTextModificationEvent( noteEvent.editedNote()?.let { LoadNote(baseNoteHex = it, accountViewModel = accountViewModel) { baseNote -> 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( modifier = MaterialTheme.colorScheme.innerPostModifier.padding(Size10dp).clickable { @@ -1609,13 +1626,15 @@ fun RenderTextModificationEvent( } } - Spacer(modifier = StdVertSpacer) + if (isAuthorTheLoggedUser.value) { + Spacer(modifier = StdVertSpacer) - Button( - onClick = { wantsToEditPost.value = true }, - modifier = Modifier.fillMaxWidth(), - ) { - Text(text = stringResource(id = R.string.accept_the_suggestion)) + Button( + onClick = { wantsToEditPost.value = true }, + modifier = Modifier.fillMaxWidth(), + ) { + Text(text = stringResource(id = R.string.accept_the_suggestion)) + } } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 296eb4049..5963977bc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -797,7 +797,7 @@ There\'s proof this post was signed sometime before %1$s. The proof was stamped in the Bitcoin blockchain at that date and time. Edit Post - Proposal to improve your post + Proposal to improve a post Summary of changes Quick fixes…