mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-29 16:30:49 +00:00
Editting the current version of the post instead of only the original post.
This commit is contained in:
parent
b1a355691a
commit
af784a5bda
@ -1404,7 +1404,7 @@ object LocalCache {
|
|||||||
note.loadEvent(event, author, emptyList())
|
note.loadEvent(event, author, emptyList())
|
||||||
|
|
||||||
event.editedNote()?.let {
|
event.editedNote()?.let {
|
||||||
getNoteIfExists(it)?.let { editedNote ->
|
checkGetOrCreateNote(it)?.let { editedNote ->
|
||||||
modificationCache.remove(editedNote.idHex)
|
modificationCache.remove(editedNote.idHex)
|
||||||
editedNote.liveSet?.innerModifications?.invalidateData()
|
editedNote.liveSet?.innerModifications?.invalidateData()
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ import androidx.compose.foundation.layout.heightIn
|
|||||||
import androidx.compose.foundation.layout.imePadding
|
import androidx.compose.foundation.layout.imePadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
@ -115,6 +114,7 @@ import kotlinx.coroutines.withContext
|
|||||||
fun EditPostView(
|
fun EditPostView(
|
||||||
onClose: () -> Unit,
|
onClose: () -> Unit,
|
||||||
edit: Note,
|
edit: Note,
|
||||||
|
versionLookingAt: Note?,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
@ -128,7 +128,7 @@ fun EditPostView(
|
|||||||
var relayList = remember { accountViewModel.account.activeWriteRelays().toImmutableList() }
|
var relayList = remember { accountViewModel.account.activeWriteRelays().toImmutableList() }
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
postViewModel.load(edit, accountViewModel)
|
postViewModel.load(edit, versionLookingAt, accountViewModel)
|
||||||
|
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
postViewModel.imageUploadingError.collect { error ->
|
postViewModel.imageUploadingError.collect { error ->
|
||||||
|
@ -82,6 +82,7 @@ open class EditPostViewModel() : ViewModel() {
|
|||||||
|
|
||||||
open fun load(
|
open fun load(
|
||||||
edit: Note,
|
edit: Note,
|
||||||
|
versionLookingAt: Note?,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
) {
|
) {
|
||||||
this.accountViewModel = accountViewModel
|
this.accountViewModel = accountViewModel
|
||||||
@ -90,7 +91,7 @@ open class EditPostViewModel() : ViewModel() {
|
|||||||
canAddInvoice = accountViewModel.userProfile().info?.lnAddress() != null
|
canAddInvoice = accountViewModel.userProfile().info?.lnAddress() != null
|
||||||
contentToAddUrl = null
|
contentToAddUrl = null
|
||||||
|
|
||||||
message = TextFieldValue(edit.event?.content() ?: "")
|
message = TextFieldValue(versionLookingAt?.event?.content() ?: edit.event?.content() ?: "")
|
||||||
urlPreview = findUrlInMessage()
|
urlPreview = findUrlInMessage()
|
||||||
|
|
||||||
editedFromNote = edit
|
editedFromNote = edit
|
||||||
|
@ -167,7 +167,7 @@ fun BadgeCompose(
|
|||||||
tint = MaterialTheme.colorScheme.placeholderText,
|
tint = MaterialTheme.colorScheme.placeholderText,
|
||||||
)
|
)
|
||||||
|
|
||||||
NoteDropDownMenu(note, popupExpanded, accountViewModel, nav)
|
NoteDropDownMenu(note, popupExpanded, null, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ fun MessageSetCompose(
|
|||||||
nav = nav,
|
nav = nav,
|
||||||
)
|
)
|
||||||
|
|
||||||
NoteDropDownMenu(baseNote, popupExpanded, accountViewModel, nav)
|
NoteDropDownMenu(baseNote, popupExpanded, null, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@ import com.vitorpamplona.amethyst.ui.screen.CombinedZap
|
|||||||
import com.vitorpamplona.amethyst.ui.screen.MultiSetCard
|
import com.vitorpamplona.amethyst.ui.screen.MultiSetCard
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.DividerThickness
|
import com.vitorpamplona.amethyst.ui.theme.DividerThickness
|
||||||
|
import com.vitorpamplona.amethyst.ui.theme.HalfTopPadding
|
||||||
import com.vitorpamplona.amethyst.ui.theme.NotificationIconModifier
|
import com.vitorpamplona.amethyst.ui.theme.NotificationIconModifier
|
||||||
import com.vitorpamplona.amethyst.ui.theme.NotificationIconModifierSmaller
|
import com.vitorpamplona.amethyst.ui.theme.NotificationIconModifierSmaller
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Size10dp
|
import com.vitorpamplona.amethyst.ui.theme.Size10dp
|
||||||
@ -158,7 +159,7 @@ fun MultiSetCompose(
|
|||||||
NoteCompose(
|
NoteCompose(
|
||||||
baseNote = baseNote,
|
baseNote = baseNote,
|
||||||
routeForLastRead = null,
|
routeForLastRead = null,
|
||||||
modifier = remember { Modifier.padding(top = 5.dp) },
|
modifier = HalfTopPadding,
|
||||||
isBoostedNote = true,
|
isBoostedNote = true,
|
||||||
showHidden = showHidden,
|
showHidden = showHidden,
|
||||||
parentBackgroundColor = backgroundColor,
|
parentBackgroundColor = backgroundColor,
|
||||||
@ -166,7 +167,7 @@ fun MultiSetCompose(
|
|||||||
nav = nav,
|
nav = nav,
|
||||||
)
|
)
|
||||||
|
|
||||||
NoteDropDownMenu(baseNote, popupExpanded, accountViewModel, nav)
|
NoteDropDownMenu(baseNote, popupExpanded, null, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
|
|
||||||
Divider(
|
Divider(
|
||||||
|
@ -782,7 +782,7 @@ fun LongCommunityHeader(
|
|||||||
)
|
)
|
||||||
Spacer(DoubleHorzSpacer)
|
Spacer(DoubleHorzSpacer)
|
||||||
NormalTimeAgo(baseNote = baseNote, Modifier.weight(1f))
|
NormalTimeAgo(baseNote = baseNote, Modifier.weight(1f))
|
||||||
MoreOptionsButton(baseNote, accountViewModel, nav)
|
MoreOptionsButton(baseNote, null, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2907,7 +2907,7 @@ fun FirstUserInfoRow(
|
|||||||
|
|
||||||
TimeAgo(baseNote)
|
TimeAgo(baseNote)
|
||||||
|
|
||||||
MoreOptionsButton(baseNote, accountViewModel, nav)
|
MoreOptionsButton(baseNote, editState, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2916,6 +2916,10 @@ fun observeEdits(
|
|||||||
baseNote: Note,
|
baseNote: Note,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
): State<GenericLoadable<EditState>> {
|
): State<GenericLoadable<EditState>> {
|
||||||
|
if (baseNote.event !is TextNoteEvent) {
|
||||||
|
return remember { mutableStateOf(GenericLoadable.Empty<EditState>()) }
|
||||||
|
}
|
||||||
|
|
||||||
val editState =
|
val editState =
|
||||||
remember(baseNote.idHex) {
|
remember(baseNote.idHex) {
|
||||||
val cached = accountViewModel.cachedModificationEventsForNote(baseNote)
|
val cached = accountViewModel.cachedModificationEventsForNote(baseNote)
|
||||||
@ -2934,10 +2938,10 @@ fun observeEdits(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val updatedNote = baseNote.live().innerModifications.observeAsState()
|
val updatedNote by baseNote.live().innerModifications.observeAsState()
|
||||||
|
|
||||||
LaunchedEffect(key1 = updatedNote) {
|
LaunchedEffect(key1 = updatedNote) {
|
||||||
updatedNote.value?.note?.let {
|
updatedNote?.note?.let {
|
||||||
accountViewModel.findModificationEventsForNote(it) { newModifications ->
|
accountViewModel.findModificationEventsForNote(it) { newModifications ->
|
||||||
if (newModifications.isEmpty()) {
|
if (newModifications.isEmpty()) {
|
||||||
if (editState.value !is GenericLoadable.Empty) {
|
if (editState.value !is GenericLoadable.Empty) {
|
||||||
@ -2999,6 +3003,7 @@ private fun BoostedMark() {
|
|||||||
@Composable
|
@Composable
|
||||||
fun MoreOptionsButton(
|
fun MoreOptionsButton(
|
||||||
baseNote: Note,
|
baseNote: Note,
|
||||||
|
editState: State<GenericLoadable<EditState>>? = null,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
@ -3014,6 +3019,7 @@ fun MoreOptionsButton(
|
|||||||
NoteDropDownMenu(
|
NoteDropDownMenu(
|
||||||
baseNote,
|
baseNote,
|
||||||
popupExpanded,
|
popupExpanded,
|
||||||
|
editState,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
nav,
|
nav,
|
||||||
)
|
)
|
||||||
@ -3834,9 +3840,8 @@ private fun RenderShortRepositoryHeader(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val noteState = baseNote.live().metadata.observeAsState()
|
val noteState by baseNote.live().metadata.observeAsState()
|
||||||
val note = remember(noteState) { noteState.value?.note } ?: return
|
val noteEvent = noteState?.note?.event as? GitRepositoryEvent ?: return
|
||||||
val noteEvent = note.event as? GitRepositoryEvent ?: return
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = MaterialTheme.colorScheme.replyModifier.padding(10.dp),
|
modifier = MaterialTheme.colorScheme.replyModifier.padding(10.dp),
|
||||||
|
@ -43,6 +43,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.derivedStateOf
|
import androidx.compose.runtime.derivedStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
@ -67,6 +68,7 @@ import com.vitorpamplona.amethyst.R
|
|||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.ui.actions.EditPostView
|
import com.vitorpamplona.amethyst.ui.actions.EditPostView
|
||||||
|
import com.vitorpamplona.amethyst.ui.components.GenericLoadable
|
||||||
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImage
|
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImage
|
||||||
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
|
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
@ -456,6 +458,7 @@ data class DropDownParams(
|
|||||||
fun NoteDropDownMenu(
|
fun NoteDropDownMenu(
|
||||||
note: Note,
|
note: Note,
|
||||||
popupExpanded: MutableState<Boolean>,
|
popupExpanded: MutableState<Boolean>,
|
||||||
|
editState: State<GenericLoadable<EditState>>? = null,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
@ -482,12 +485,19 @@ fun NoteDropDownMenu(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wantsToEditPost.value) {
|
if (wantsToEditPost.value) {
|
||||||
|
// avoids changing while drafting a note and a new event shows up.
|
||||||
|
val versionLookingAt =
|
||||||
|
remember {
|
||||||
|
(editState?.value as? GenericLoadable.Loaded)?.loaded?.modificationToShow?.value
|
||||||
|
}
|
||||||
|
|
||||||
EditPostView(
|
EditPostView(
|
||||||
onClose = {
|
onClose = {
|
||||||
popupExpanded.value = false
|
popupExpanded.value = false
|
||||||
wantsToEditPost.value = false
|
wantsToEditPost.value = false
|
||||||
},
|
},
|
||||||
edit = note,
|
edit = note,
|
||||||
|
versionLookingAt = versionLookingAt,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
nav = nav,
|
nav = nav,
|
||||||
)
|
)
|
||||||
|
@ -438,7 +438,7 @@ fun NoteMaster(
|
|||||||
tint = MaterialTheme.colorScheme.placeholderText,
|
tint = MaterialTheme.colorScheme.placeholderText,
|
||||||
)
|
)
|
||||||
|
|
||||||
NoteDropDownMenu(baseNote, moreActionsExpanded, accountViewModel, nav)
|
NoteDropDownMenu(baseNote, moreActionsExpanded, editState, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,8 +710,8 @@ fun ShortChannelHeader(
|
|||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
showFlag: Boolean,
|
showFlag: Boolean,
|
||||||
) {
|
) {
|
||||||
val channelState = baseChannel.live.observeAsState()
|
val channelState by baseChannel.live.observeAsState()
|
||||||
val channel = remember(channelState) { channelState.value?.channel } ?: return
|
val channel = channelState?.channel ?: return
|
||||||
|
|
||||||
val automaticallyShowProfilePicture =
|
val automaticallyShowProfilePicture =
|
||||||
remember {
|
remember {
|
||||||
@ -782,8 +782,8 @@ fun LongChannelHeader(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val channelState = baseChannel.live.observeAsState()
|
val channelState by baseChannel.live.observeAsState()
|
||||||
val channel = remember(channelState) { channelState.value?.channel } ?: return
|
val channel = channelState?.channel ?: return
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
lineModifier,
|
lineModifier,
|
||||||
@ -865,7 +865,7 @@ fun LongChannelHeader(
|
|||||||
)
|
)
|
||||||
Spacer(DoubleHorzSpacer)
|
Spacer(DoubleHorzSpacer)
|
||||||
NormalTimeAgo(note, remember { Modifier.weight(1f) })
|
NormalTimeAgo(note, remember { Modifier.weight(1f) })
|
||||||
MoreOptionsButton(note, accountViewModel, nav)
|
MoreOptionsButton(note, null, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,6 +406,7 @@ private fun VideoUserOptionAction(
|
|||||||
NoteDropDownMenu(
|
NoteDropDownMenu(
|
||||||
note,
|
note,
|
||||||
popupExpanded,
|
popupExpanded,
|
||||||
|
null,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
nav,
|
nav,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user