From e9fd62dc26bfa66a59b3da613df522fa21b6a10d Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 4 Mar 2024 15:37:29 -0500 Subject: [PATCH] Displaying correct edits on the new edit proposal --- .../amethyst/ui/note/NoteCompose.kt | 58 +++++++++++-------- .../amethyst/ui/screen/ThreadFeedView.kt | 1 - 2 files changed, 34 insertions(+), 25 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 e1922634a..70cd1cb2c 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 @@ -1136,6 +1136,11 @@ class EditState() { fun latest() = modificationsList.lastOrNull() + fun latestBefore(createdAt: Long?): Note? { + if (createdAt == null) return latest() + return modificationsList.lastOrNull { (it.createdAt() ?: Long.MAX_VALUE) < createdAt } + } + fun nextModification() { if (modificationToShowIndex < 0) { modificationToShowIndex = 0 @@ -1370,7 +1375,6 @@ private fun RenderNoteRow( makeItShort, canPreview, backgroundColor, - editState, accountViewModel, nav, ) @@ -1509,35 +1513,12 @@ fun RenderTextModificationEvent( makeItShort: Boolean, canPreview: Boolean, backgroundColor: MutableState, - editStateByAuthor: State>, accountViewModel: AccountViewModel, nav: (String) -> Unit, ) { val noteEvent = note.event as? TextNoteModificationEvent ?: return val noteAuthor = note.author ?: return - // val isAuthorTheLoggedUser = remember(note.event) { accountViewModel.isLoggedUser(note.author) } - - val editState = - remember { - derivedStateOf { - val loadable = editStateByAuthor.value as? GenericLoadable.Loaded - - val state = EditState() - - val latestChangeByAuthor = - if (loadable != null && loadable.loaded.hasModificationsToShow()) { - loadable.loaded.latest() - } else { - null - } - - state.updateModifications(listOfNotNull(latestChangeByAuthor, note)) - - GenericLoadable.Loaded(state) - } - } - val wantsToEditPost = remember { mutableStateOf(false) @@ -1550,6 +1531,13 @@ fun RenderTextModificationEvent( mutableStateOf(accountViewModel.isLoggedUser(authorOfTheOriginalNote)) } + noteEvent.editedNote()?.let { + LoadNote(baseNoteHex = it, accountViewModel = accountViewModel) { baseOriginalNote -> + baseOriginalNote?.let { + } + } + } + Card( modifier = MaterialTheme.colorScheme.imageModifier, ) { @@ -1583,6 +1571,28 @@ fun RenderTextModificationEvent( baseNote?.let { val noteState by baseNote.live().metadata.observeAsState() + val editStateOriginalNote = observeEdits(baseNote = baseNote, accountViewModel = accountViewModel) + + val editState = + remember(note) { + derivedStateOf { + val loadable = editStateOriginalNote.value as? GenericLoadable.Loaded + + val state = EditState() + + val latestChangeByAuthor = + if (loadable != null && loadable.loaded.hasModificationsToShow()) { + loadable.loaded.latestBefore(note.createdAt()) + } else { + null + } + + state.updateModifications(listOfNotNull(latestChangeByAuthor, note)) + + GenericLoadable.Loaded(state) + } + } + LaunchedEffect(key1 = noteState) { val newAuthor = accountViewModel.isLoggedUser(noteState?.note?.author) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt index a4d829f0a..5480f6ee9 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt @@ -576,7 +576,6 @@ fun NoteMaster( makeItShort = false, canPreview = true, backgroundColor, - editState, accountViewModel, nav, )