load post from draft
This commit is contained in:
@@ -190,7 +190,7 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
this.account = accountViewModel.account
|
this.account = accountViewModel.account
|
||||||
|
|
||||||
if (draft != null) {
|
if (draft != null) {
|
||||||
loadfromDraft(draft)
|
loadfromDraft(draft, accountViewModel)
|
||||||
} else {
|
} else {
|
||||||
originalNote = replyingTo
|
originalNote = replyingTo
|
||||||
replyingTo?.let { replyNote ->
|
replyingTo?.let { replyNote ->
|
||||||
@@ -305,8 +305,68 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadfromDraft(draft: Note?) {
|
private fun loadfromDraft(
|
||||||
// TODO: finish the loadfromDraft method
|
draft: Note,
|
||||||
|
accountViewModel: AccountViewModel,
|
||||||
|
) {
|
||||||
|
Log.d("draft", draft.event?.toJson().toString())
|
||||||
|
|
||||||
|
canAddInvoice = accountViewModel.userProfile().info?.lnAddress() != null
|
||||||
|
canAddZapRaiser = accountViewModel.userProfile().info?.lnAddress() != null
|
||||||
|
contentToAddUrl = null
|
||||||
|
|
||||||
|
val localfowardZapTo = draft.event?.tags()?.filter { it.size > 1 && it[0] == "zap" } ?: listOf()
|
||||||
|
forwardZapTo = Split()
|
||||||
|
localfowardZapTo.forEach {
|
||||||
|
val user = LocalCache.getOrCreateUser(it[1])
|
||||||
|
val value = it.last().toFloatOrNull() ?: 0f
|
||||||
|
forwardZapTo.addItem(user, value)
|
||||||
|
}
|
||||||
|
forwardZapToEditting = TextFieldValue("")
|
||||||
|
wantsForwardZapTo = localfowardZapTo.isNotEmpty()
|
||||||
|
|
||||||
|
wantsToMarkAsSensitive = draft.event?.tags()?.any { it.size > 1 && it[0] == "content-warning" } ?: false
|
||||||
|
wantsToAddGeoHash = draft.event?.tags()?.any { it.size > 1 && it[0] == "g" } ?: false
|
||||||
|
val zapraiser = draft.event?.tags()?.filter { it.size > 1 && it[0] == "zapraiser" } ?: listOf()
|
||||||
|
wantsZapraiser = zapraiser.isNotEmpty()
|
||||||
|
zapRaiserAmount = null
|
||||||
|
if (wantsZapraiser) {
|
||||||
|
zapRaiserAmount = zapraiser.first()[1].toLongOrNull() ?: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
eTags =
|
||||||
|
draft.event?.tags()?.filter { it.size > 1 && it[0] == "e" && it.getOrNull(3) != "fork" }?.map {
|
||||||
|
val forked = it[3] == "fork"
|
||||||
|
val note = LocalCache.getOrCreateNote(it[1])
|
||||||
|
if (forked) {
|
||||||
|
forkedFromNote = note
|
||||||
|
}
|
||||||
|
note
|
||||||
|
}
|
||||||
|
|
||||||
|
pTags =
|
||||||
|
draft.event?.tags()?.filter { it.size > 1 && it[0] == "p" }?.map {
|
||||||
|
LocalCache.getOrCreateUser(it[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
draft.event?.tags()?.filter { it.size > 1 && it[0] == "e" && it.getOrNull(3) == "fork" }?.forEach {
|
||||||
|
val note = LocalCache.getOrCreateNote(it[1])
|
||||||
|
forkedFromNote = note
|
||||||
|
}
|
||||||
|
|
||||||
|
originalNote =
|
||||||
|
draft.event?.tags()?.filter { it.size > 1 && it[0] == "e" && it.getOrNull(3) == "root" }?.map {
|
||||||
|
LocalCache.getOrCreateNote(it[1])
|
||||||
|
}?.firstOrNull()
|
||||||
|
|
||||||
|
canUsePoll = originalNote?.event !is PrivateDmEvent && originalNote?.channelHex() == null
|
||||||
|
|
||||||
|
if (forwardZapTo.items.isNotEmpty()) {
|
||||||
|
wantsForwardZapTo = true
|
||||||
|
}
|
||||||
|
|
||||||
|
message = TextFieldValue(draft.event?.content() ?: "")
|
||||||
|
urlPreview = findUrlInMessage()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendPost(
|
fun sendPost(
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ fun ZapRaiserRequest(
|
|||||||
} else {
|
} else {
|
||||||
newPostViewModel.zapRaiserAmount = it.toLongOrNull()
|
newPostViewModel.zapRaiserAmount = it.toLongOrNull()
|
||||||
}
|
}
|
||||||
|
newPostViewModel.saveDraft()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
placeholder = {
|
placeholder = {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import androidx.core.content.ContextCompat
|
|||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.ui.actions.EditPostView
|
import com.vitorpamplona.amethyst.ui.actions.EditPostView
|
||||||
|
import com.vitorpamplona.amethyst.ui.actions.NewPostView
|
||||||
import com.vitorpamplona.amethyst.ui.components.GenericLoadable
|
import com.vitorpamplona.amethyst.ui.components.GenericLoadable
|
||||||
import com.vitorpamplona.amethyst.ui.note.VerticalDotsIcon
|
import com.vitorpamplona.amethyst.ui.note.VerticalDotsIcon
|
||||||
import com.vitorpamplona.amethyst.ui.note.externalLinkForNote
|
import com.vitorpamplona.amethyst.ui.note.externalLinkForNote
|
||||||
@@ -122,6 +123,11 @@ fun NoteDropDownMenu(
|
|||||||
mutableStateOf(false)
|
mutableStateOf(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val wantsToEditDraft =
|
||||||
|
remember {
|
||||||
|
mutableStateOf(false)
|
||||||
|
}
|
||||||
|
|
||||||
if (wantsToEditPost.value) {
|
if (wantsToEditPost.value) {
|
||||||
// avoids changing while drafting a note and a new event shows up.
|
// avoids changing while drafting a note and a new event shows up.
|
||||||
val versionLookingAt =
|
val versionLookingAt =
|
||||||
@@ -141,6 +147,18 @@ fun NoteDropDownMenu(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wantsToEditDraft.value) {
|
||||||
|
NewPostView(
|
||||||
|
onClose = {
|
||||||
|
popupExpanded.value = false
|
||||||
|
wantsToEditDraft.value = false
|
||||||
|
},
|
||||||
|
accountViewModel = accountViewModel,
|
||||||
|
draft = note,
|
||||||
|
nav = nav,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
DropdownMenu(
|
DropdownMenu(
|
||||||
expanded = popupExpanded.value,
|
expanded = popupExpanded.value,
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
@@ -219,6 +237,12 @@ fun NoteDropDownMenu(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
HorizontalDivider(thickness = DividerThickness)
|
HorizontalDivider(thickness = DividerThickness)
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(stringResource(R.string.edit_draft)) },
|
||||||
|
onClick = {
|
||||||
|
wantsToEditDraft.value = true
|
||||||
|
},
|
||||||
|
)
|
||||||
if (note.event is TextNoteEvent) {
|
if (note.event is TextNoteEvent) {
|
||||||
if (state.isLoggedUser) {
|
if (state.isLoggedUser) {
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
|
|||||||
Reference in New Issue
Block a user