mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-29 08:20:51 +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())
|
||||
|
||||
event.editedNote()?.let {
|
||||
getNoteIfExists(it)?.let { editedNote ->
|
||||
checkGetOrCreateNote(it)?.let { editedNote ->
|
||||
modificationCache.remove(editedNote.idHex)
|
||||
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.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
@ -115,6 +114,7 @@ import kotlinx.coroutines.withContext
|
||||
fun EditPostView(
|
||||
onClose: () -> Unit,
|
||||
edit: Note,
|
||||
versionLookingAt: Note?,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
@ -128,7 +128,7 @@ fun EditPostView(
|
||||
var relayList = remember { accountViewModel.account.activeWriteRelays().toImmutableList() }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
postViewModel.load(edit, accountViewModel)
|
||||
postViewModel.load(edit, versionLookingAt, accountViewModel)
|
||||
|
||||
launch(Dispatchers.IO) {
|
||||
postViewModel.imageUploadingError.collect { error ->
|
||||
|
@ -82,6 +82,7 @@ open class EditPostViewModel() : ViewModel() {
|
||||
|
||||
open fun load(
|
||||
edit: Note,
|
||||
versionLookingAt: Note?,
|
||||
accountViewModel: AccountViewModel,
|
||||
) {
|
||||
this.accountViewModel = accountViewModel
|
||||
@ -90,7 +91,7 @@ open class EditPostViewModel() : ViewModel() {
|
||||
canAddInvoice = accountViewModel.userProfile().info?.lnAddress() != null
|
||||
contentToAddUrl = null
|
||||
|
||||
message = TextFieldValue(edit.event?.content() ?: "")
|
||||
message = TextFieldValue(versionLookingAt?.event?.content() ?: edit.event?.content() ?: "")
|
||||
urlPreview = findUrlInMessage()
|
||||
|
||||
editedFromNote = edit
|
||||
|
@ -167,7 +167,7 @@ fun BadgeCompose(
|
||||
tint = MaterialTheme.colorScheme.placeholderText,
|
||||
)
|
||||
|
||||
NoteDropDownMenu(note, popupExpanded, accountViewModel, nav)
|
||||
NoteDropDownMenu(note, popupExpanded, null, accountViewModel, nav)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ fun MessageSetCompose(
|
||||
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.loggedIn.AccountViewModel
|
||||
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.NotificationIconModifierSmaller
|
||||
import com.vitorpamplona.amethyst.ui.theme.Size10dp
|
||||
@ -158,7 +159,7 @@ fun MultiSetCompose(
|
||||
NoteCompose(
|
||||
baseNote = baseNote,
|
||||
routeForLastRead = null,
|
||||
modifier = remember { Modifier.padding(top = 5.dp) },
|
||||
modifier = HalfTopPadding,
|
||||
isBoostedNote = true,
|
||||
showHidden = showHidden,
|
||||
parentBackgroundColor = backgroundColor,
|
||||
@ -166,7 +167,7 @@ fun MultiSetCompose(
|
||||
nav = nav,
|
||||
)
|
||||
|
||||
NoteDropDownMenu(baseNote, popupExpanded, accountViewModel, nav)
|
||||
NoteDropDownMenu(baseNote, popupExpanded, null, accountViewModel, nav)
|
||||
}
|
||||
|
||||
Divider(
|
||||
|
@ -782,7 +782,7 @@ fun LongCommunityHeader(
|
||||
)
|
||||
Spacer(DoubleHorzSpacer)
|
||||
NormalTimeAgo(baseNote = baseNote, Modifier.weight(1f))
|
||||
MoreOptionsButton(baseNote, accountViewModel, nav)
|
||||
MoreOptionsButton(baseNote, null, accountViewModel, nav)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2907,7 +2907,7 @@ fun FirstUserInfoRow(
|
||||
|
||||
TimeAgo(baseNote)
|
||||
|
||||
MoreOptionsButton(baseNote, accountViewModel, nav)
|
||||
MoreOptionsButton(baseNote, editState, accountViewModel, nav)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2916,6 +2916,10 @@ fun observeEdits(
|
||||
baseNote: Note,
|
||||
accountViewModel: AccountViewModel,
|
||||
): State<GenericLoadable<EditState>> {
|
||||
if (baseNote.event !is TextNoteEvent) {
|
||||
return remember { mutableStateOf(GenericLoadable.Empty<EditState>()) }
|
||||
}
|
||||
|
||||
val editState =
|
||||
remember(baseNote.idHex) {
|
||||
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) {
|
||||
updatedNote.value?.note?.let {
|
||||
updatedNote?.note?.let {
|
||||
accountViewModel.findModificationEventsForNote(it) { newModifications ->
|
||||
if (newModifications.isEmpty()) {
|
||||
if (editState.value !is GenericLoadable.Empty) {
|
||||
@ -2999,6 +3003,7 @@ private fun BoostedMark() {
|
||||
@Composable
|
||||
fun MoreOptionsButton(
|
||||
baseNote: Note,
|
||||
editState: State<GenericLoadable<EditState>>? = null,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
@ -3014,6 +3019,7 @@ fun MoreOptionsButton(
|
||||
NoteDropDownMenu(
|
||||
baseNote,
|
||||
popupExpanded,
|
||||
editState,
|
||||
accountViewModel,
|
||||
nav,
|
||||
)
|
||||
@ -3834,9 +3840,8 @@ private fun RenderShortRepositoryHeader(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
val noteState = baseNote.live().metadata.observeAsState()
|
||||
val note = remember(noteState) { noteState.value?.note } ?: return
|
||||
val noteEvent = note.event as? GitRepositoryEvent ?: return
|
||||
val noteState by baseNote.live().metadata.observeAsState()
|
||||
val noteEvent = noteState?.note?.event as? GitRepositoryEvent ?: return
|
||||
|
||||
Column(
|
||||
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.LaunchedEffect
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
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.User
|
||||
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.RobohashFallbackAsyncImage
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
@ -456,6 +458,7 @@ data class DropDownParams(
|
||||
fun NoteDropDownMenu(
|
||||
note: Note,
|
||||
popupExpanded: MutableState<Boolean>,
|
||||
editState: State<GenericLoadable<EditState>>? = null,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
@ -482,12 +485,19 @@ fun NoteDropDownMenu(
|
||||
}
|
||||
|
||||
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(
|
||||
onClose = {
|
||||
popupExpanded.value = false
|
||||
wantsToEditPost.value = false
|
||||
},
|
||||
edit = note,
|
||||
versionLookingAt = versionLookingAt,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
|
@ -438,7 +438,7 @@ fun NoteMaster(
|
||||
tint = MaterialTheme.colorScheme.placeholderText,
|
||||
)
|
||||
|
||||
NoteDropDownMenu(baseNote, moreActionsExpanded, accountViewModel, nav)
|
||||
NoteDropDownMenu(baseNote, moreActionsExpanded, editState, accountViewModel, nav)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -710,8 +710,8 @@ fun ShortChannelHeader(
|
||||
nav: (String) -> Unit,
|
||||
showFlag: Boolean,
|
||||
) {
|
||||
val channelState = baseChannel.live.observeAsState()
|
||||
val channel = remember(channelState) { channelState.value?.channel } ?: return
|
||||
val channelState by baseChannel.live.observeAsState()
|
||||
val channel = channelState?.channel ?: return
|
||||
|
||||
val automaticallyShowProfilePicture =
|
||||
remember {
|
||||
@ -782,8 +782,8 @@ fun LongChannelHeader(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
val channelState = baseChannel.live.observeAsState()
|
||||
val channel = remember(channelState) { channelState.value?.channel } ?: return
|
||||
val channelState by baseChannel.live.observeAsState()
|
||||
val channel = channelState?.channel ?: return
|
||||
|
||||
Row(
|
||||
lineModifier,
|
||||
@ -865,7 +865,7 @@ fun LongChannelHeader(
|
||||
)
|
||||
Spacer(DoubleHorzSpacer)
|
||||
NormalTimeAgo(note, remember { Modifier.weight(1f) })
|
||||
MoreOptionsButton(note, accountViewModel, nav)
|
||||
MoreOptionsButton(note, null, accountViewModel, nav)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -406,6 +406,7 @@ private fun VideoUserOptionAction(
|
||||
NoteDropDownMenu(
|
||||
note,
|
||||
popupExpanded,
|
||||
null,
|
||||
accountViewModel,
|
||||
nav,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user