add validations to draft notes

This commit is contained in:
greenart7c3
2024-03-20 10:25:41 -03:00
parent bc180ae210
commit 220ce75f19
7 changed files with 83 additions and 14 deletions
@@ -846,7 +846,14 @@ class Account(
}
suspend fun delete(note: Note) {
return delete(listOf(note))
if (note.isDraft()) {
note.event?.let {
val drafts = LocalCache.getDrafts(it.id())
return delete(drafts)
}
} else {
return delete(listOf(note))
}
}
suspend fun delete(notes: List<Note>) {
@@ -898,10 +905,17 @@ class Account(
fun broadcast(note: Note) {
note.event?.let {
if (it is WrappedEvent && it.host != null) {
it.host?.let { hostEvent -> Client.send(hostEvent) }
if (note.isDraft()) {
val drafts = LocalCache.getDrafts(it.id())
drafts.forEach { draftNote ->
broadcast(draftNote)
}
} else {
Client.send(it)
if (it is WrappedEvent && it.host != null) {
it.host?.let { hostEvent -> Client.send(hostEvent) }
} else {
Client.send(it)
}
}
}
}
@@ -930,6 +944,7 @@ class Account(
fun timestamp(note: Note) {
if (!isWriteable()) return
if (note.isDraft()) return
val id = note.event?.id() ?: note.idHex
@@ -1942,6 +1957,7 @@ class Account(
isPrivate: Boolean,
) {
if (!isWriteable()) return
if (note.isDraft()) return
if (note is AddressableNote) {
BookmarkListEvent.addReplaceable(
@@ -148,6 +148,14 @@ object LocalCache {
} ?: listOf()
}
fun getDrafts(eventId: String): List<Note> {
return drafts.filter {
it.value.any { it == eventId }
}.keys.mapNotNull {
checkGetOrCreateNote(it)
}
}
fun addDraft(
key: String,
value: String,
@@ -307,7 +307,12 @@ fun RenderZapRaiser(
}
LinearProgressIndicator(
modifier = remember(details) { Modifier.fillMaxWidth().height(if (details) 24.dp else 4.dp) },
modifier =
remember(details) {
Modifier
.fillMaxWidth()
.height(if (details) 24.dp else 4.dp)
},
color = color,
progress = { zapraiserStatus.progress },
)
@@ -587,6 +592,13 @@ fun ReplyReaction(
IconButton(
modifier = iconSizeModifier,
onClick = {
if (baseNote.isDraft()) {
accountViewModel.toast(
R.string.draft_note,
R.string.it_s_not_possible_to_reply_to_a_draft_note,
)
return@IconButton
}
if (accountViewModel.isWriteable()) {
onPress()
} else {
@@ -774,7 +786,8 @@ fun LikeReaction(
Box(
contentAlignment = Center,
modifier =
Modifier.size(iconSize)
Modifier
.size(iconSize)
.combinedClickable(
role = Role.Button,
interactionSource = remember { MutableInteractionSource() },
@@ -782,6 +795,7 @@ fun LikeReaction(
onClick = {
likeClick(
accountViewModel,
baseNote,
onMultipleChoices = { wantsToReact = true },
onWantsToSignReaction = { accountViewModel.reactToOrDelete(baseNote) },
)
@@ -884,9 +898,17 @@ fun ObserveLikeText(
private fun likeClick(
accountViewModel: AccountViewModel,
baseNote: Note,
onMultipleChoices: () -> Unit,
onWantsToSignReaction: () -> Unit,
) {
if (baseNote.isDraft()) {
accountViewModel.toast(
R.string.draft_note,
R.string.it_s_not_possible_to_react_to_a_draft_note,
)
return
}
if (accountViewModel.account.reactionChoices.isEmpty()) {
accountViewModel.toast(
R.string.no_reactions_setup,
@@ -1080,6 +1102,14 @@ fun zapClick(
onError: (String, String) -> Unit,
onPayViaIntent: (ImmutableList<ZapPaymentHandler.Payable>) -> Unit,
) {
if (baseNote.isDraft()) {
accountViewModel.toast(
R.string.draft_note,
R.string.it_s_not_possible_to_zap_to_a_draft_note,
)
return
}
if (accountViewModel.account.zapAmountChoices.isEmpty()) {
accountViewModel.toast(
context.getString(R.string.error_dialog_zap_error),
@@ -179,7 +179,7 @@ fun ZapCustomDialog(
)
ZapButton(
isActive = postViewModel.canSend(),
isActive = postViewModel.canSend() && !baseNote.isDraft(),
) {
accountViewModel.zap(
baseNote,
@@ -237,13 +237,15 @@ fun NoteDropDownMenu(
},
)
HorizontalDivider(thickness = DividerThickness)
DropdownMenuItem(
text = { Text(stringResource(R.string.edit_draft)) },
onClick = {
wantsToEditDraft.value = true
},
)
if (note.event is TextNoteEvent) {
if (!note.isDraft()) {
DropdownMenuItem(
text = { Text(stringResource(R.string.edit_draft)) },
onClick = {
wantsToEditDraft.value = true
},
)
}
if (note.event is TextNoteEvent && !note.isDraft()) {
if (state.isLoggedUser) {
DropdownMenuItem(
text = { Text(stringResource(R.string.edit_post)) },
@@ -1209,6 +1209,14 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
baseNote: Note,
onMore: () -> Unit,
) {
if (baseNote.isDraft()) {
toast(
R.string.draft_note,
R.string.it_s_not_possible_to_quote_to_a_draft_note,
)
return
}
if (isWriteable()) {
if (hasBoosted(baseNote)) {
deleteBoostsTo(baseNote)
+5
View File
@@ -821,4 +821,9 @@
<string name="accessibility_play_username">Play username as audio</string>
<string name="accessibility_scan_qr_code">Scan QR code</string>
<string name="accessibility_navigate_to_alby">Navigate to the third-party wallet provider Alby</string>
<string name="it_s_not_possible_to_reply_to_a_draft_note">It\'s not possible to reply a draft note</string>
<string name="it_s_not_possible_to_quote_to_a_draft_note">It\'s not possible to quote a draft note</string>
<string name="it_s_not_possible_to_react_to_a_draft_note">It\'s not possible to react a draft note</string>
<string name="it_s_not_possible_to_zap_to_a_draft_note">It\'s not possible to zap a draft note</string>
<string name="draft_note">Draft Note</string>
</resources>