add draft support for other event kinds

This commit is contained in:
greenart7c3 2024-03-15 12:35:14 -03:00
parent f3f8bc1b65
commit 2bc2890d08
13 changed files with 112 additions and 48 deletions

View File

@ -1311,6 +1311,7 @@ class Account(
relayList: List<Relay>? = null,
geohash: String? = null,
nip94attachments: List<Event>? = null,
draftTag: String?,
) {
if (!isWriteable()) return
@ -1338,14 +1339,22 @@ class Account(
geohash = geohash,
nip94attachments = nip94attachments,
signer = signer,
isDraft = draftTag != null,
) {
Client.send(it, relayList = relayList)
LocalCache.justConsume(it, null)
if (draftTag != null) {
DraftEvent.create(draftTag, it, signer) { draftEvent ->
Client.send(draftEvent, relayList = relayList)
LocalCache.justConsume(draftEvent, null)
}
} else {
Client.send(it, relayList = relayList)
LocalCache.justConsume(it, null)
replyTo?.forEach { it.event?.let { Client.send(it, relayList = relayList) } }
addresses?.forEach {
LocalCache.getAddressableNoteIfExists(it.toTag())?.event?.let {
Client.send(it, relayList = relayList)
replyTo?.forEach { it.event?.let { Client.send(it, relayList = relayList) } }
addresses?.forEach {
LocalCache.getAddressableNoteIfExists(it.toTag())?.event?.let {
Client.send(it, relayList = relayList)
}
}
}
}
@ -1366,6 +1375,7 @@ class Account(
relayList: List<Relay>? = null,
geohash: String? = null,
nip94attachments: List<FileHeaderEvent>? = null,
draftTag: String?,
) {
if (!isWriteable()) return
@ -1389,20 +1399,28 @@ class Account(
nip94attachments = nip94attachments,
forkedFrom = forkedFrom,
signer = signer,
isDraft = draftTag != null,
) {
Client.send(it, relayList = relayList)
LocalCache.justConsume(it, null)
// broadcast replied notes
replyingTo?.let {
LocalCache.getNoteIfExists(replyingTo)?.event?.let {
Client.send(it, relayList = relayList)
if (draftTag != null) {
DraftEvent.create(draftTag, it, signer) { draftEvent ->
Client.send(draftEvent, relayList = relayList)
LocalCache.justConsume(draftEvent, null)
}
}
replyTo?.forEach { it.event?.let { Client.send(it, relayList = relayList) } }
addresses?.forEach {
LocalCache.getAddressableNoteIfExists(it.toTag())?.event?.let {
Client.send(it, relayList = relayList)
} else {
Client.send(it, relayList = relayList)
LocalCache.justConsume(it, null)
// broadcast replied notes
replyingTo?.let {
LocalCache.getNoteIfExists(replyingTo)?.event?.let {
Client.send(it, relayList = relayList)
}
}
replyTo?.forEach { it.event?.let { Client.send(it, relayList = relayList) } }
addresses?.forEach {
LocalCache.getAddressableNoteIfExists(it.toTag())?.event?.let {
Client.send(it, relayList = relayList)
}
}
}
}
@ -1512,6 +1530,7 @@ class Account(
relayList: List<Relay>? = null,
geohash: String? = null,
nip94attachments: List<FileHeaderEvent>? = null,
draftTag: String?,
) {
if (!isWriteable()) return
@ -1535,15 +1554,23 @@ class Account(
zapRaiserAmount = zapRaiserAmount,
geohash = geohash,
nip94attachments = nip94attachments,
isDraft = draftTag != null,
) {
Client.send(it, relayList = relayList)
LocalCache.justConsume(it, null)
if (draftTag != null) {
DraftEvent.create(draftTag, it, signer) { draftEvent ->
Client.send(draftEvent, relayList = relayList)
LocalCache.justConsume(draftEvent, null)
}
} else {
Client.send(it, relayList = relayList)
LocalCache.justConsume(it, null)
// Rebroadcast replies and tags to the current relay set
replyTo?.forEach { it.event?.let { Client.send(it, relayList = relayList) } }
addresses?.forEach {
LocalCache.getAddressableNoteIfExists(it.toTag())?.event?.let {
Client.send(it, relayList = relayList)
// Rebroadcast replies and tags to the current relay set
replyTo?.forEach { it.event?.let { Client.send(it, relayList = relayList) } }
addresses?.forEach {
LocalCache.getAddressableNoteIfExists(it.toTag())?.event?.let {
Client.send(it, relayList = relayList)
}
}
}
}
@ -1559,6 +1586,7 @@ class Account(
zapRaiserAmount: Long? = null,
geohash: String? = null,
nip94attachments: List<FileHeaderEvent>? = null,
draftTag: String?,
) {
if (!isWriteable()) return
@ -1576,9 +1604,17 @@ class Account(
geohash = geohash,
nip94attachments = nip94attachments,
signer = signer,
isDraft = draftTag != null,
) {
Client.send(it)
LocalCache.justConsume(it, null)
if (draftTag != null) {
DraftEvent.create(draftTag, it, signer) { draftEvent ->
Client.send(draftEvent)
LocalCache.justConsume(draftEvent, null)
}
} else {
Client.send(it)
LocalCache.justConsume(it, null)
}
}
}
@ -1592,6 +1628,7 @@ class Account(
zapRaiserAmount: Long? = null,
geohash: String? = null,
nip94attachments: List<FileHeaderEvent>? = null,
draftTag: String?,
) {
if (!isWriteable()) return
@ -1610,9 +1647,17 @@ class Account(
geohash = geohash,
nip94attachments = nip94attachments,
signer = signer,
isDraft = draftTag != null,
) {
Client.send(it)
LocalCache.justConsume(it, null)
if (draftTag != null) {
DraftEvent.create(draftTag, it, signer) { draftEvent ->
Client.send(draftEvent)
LocalCache.justConsume(draftEvent, null)
}
} else {
Client.send(it)
LocalCache.justConsume(it, null)
}
}
}
@ -1626,6 +1671,7 @@ class Account(
zapRaiserAmount: Long? = null,
geohash: String? = null,
nip94attachments: List<FileHeaderEvent>? = null,
draftTag: String?,
) {
sendPrivateMessage(
message,
@ -1637,6 +1683,7 @@ class Account(
zapRaiserAmount,
geohash,
nip94attachments,
draftTag,
)
}
@ -1650,6 +1697,7 @@ class Account(
zapRaiserAmount: Long? = null,
geohash: String? = null,
nip94attachments: List<FileHeaderEvent>? = null,
draftTag: String?,
) {
if (!isWriteable()) return
@ -1669,9 +1717,17 @@ class Account(
nip94attachments = nip94attachments,
signer = signer,
advertiseNip18 = false,
isDraft = draftTag != null,
) {
Client.send(it)
LocalCache.consume(it, null)
if (draftTag != null) {
DraftEvent.create(draftTag, it, signer) { draftEvent ->
Client.send(draftEvent)
LocalCache.justConsume(draftEvent, null)
}
} else {
Client.send(it)
LocalCache.consume(it, null)
}
}
}

View File

@ -106,7 +106,6 @@ open class Note(val idHex: String) {
var event: EventInterface? = null
var author: User? = null
var replyTo: List<Note>? = null
var draft: String? = null
// These fields are updated every time an event related to this note is received.
var replies = listOf<Note>()
@ -184,13 +183,9 @@ open class Note(val idHex: String) {
open fun createdAt() = event?.createdAt()
fun updateDraft(id: String) {
draft = id
}
fun isDraft(): Boolean {
draft?.let {
return it.isNotBlank()
event?.let {
return it.sig().isBlank()
}
return false
}

View File

@ -281,8 +281,6 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
event.plainContent(account.signer) {
LocalCache.justConsume(it, relay)
val draftNote = LocalCache.getNoteIfExists(it.id)
draftNote?.updateDraft(event.id)
}
}

View File

@ -371,6 +371,7 @@ open class NewPostViewModel() : ViewModel() {
zapRaiserAmount = localZapRaiserAmount,
geohash = geoHash,
nip94attachments = usedAttachments,
draftTag = localDraft,
)
} else {
account?.sendChannelMessage(
@ -383,6 +384,7 @@ open class NewPostViewModel() : ViewModel() {
zapRaiserAmount = localZapRaiserAmount,
geohash = geoHash,
nip94attachments = usedAttachments,
draftTag = localDraft,
)
}
} else if (originalNote?.event is PrivateDmEvent) {
@ -396,6 +398,7 @@ open class NewPostViewModel() : ViewModel() {
zapRaiserAmount = localZapRaiserAmount,
geohash = geoHash,
nip94attachments = usedAttachments,
draftTag = localDraft,
)
} else if (originalNote?.event is ChatMessageEvent) {
val receivers =
@ -443,6 +446,7 @@ open class NewPostViewModel() : ViewModel() {
zapRaiserAmount = localZapRaiserAmount,
geohash = geoHash,
nip94attachments = usedAttachments,
draftTag = localDraft,
)
}
} else if (originalNote?.event is GitIssueEvent) {
@ -483,6 +487,7 @@ open class NewPostViewModel() : ViewModel() {
relayList = relayList,
geohash = geoHash,
nip94attachments = usedAttachments,
draftTag = localDraft,
)
} else {
if (wantsPoll) {
@ -501,6 +506,7 @@ open class NewPostViewModel() : ViewModel() {
relayList,
geoHash,
nip94attachments = usedAttachments,
draftTag = localDraft,
)
} else if (wantsProduct) {
account?.sendClassifieds(
@ -519,6 +525,7 @@ open class NewPostViewModel() : ViewModel() {
relayList = relayList,
geohash = geoHash,
nip94attachments = usedAttachments,
draftTag = localDraft,
)
} else {
// adds markers
@ -555,7 +562,7 @@ open class NewPostViewModel() : ViewModel() {
relayList = relayList,
geohash = geoHash,
nip94attachments = usedAttachments,
draftTag = draftTag,
draftTag = localDraft,
)
}
}

View File

@ -1171,7 +1171,6 @@ fun FirstUserInfoRow(
}
if (baseNote.isDraft()) {
Spacer(StdHorzSpacer)
DisplayDraft()
}

View File

@ -325,6 +325,7 @@ fun ChannelScreen(
mentions = tagger.pTags,
wantsToMarkAsSensitive = false,
nip94attachments = usedAttachments,
draftTag = null,
)
} else if (channel is LiveActivitiesChannel) {
accountViewModel.account.sendLiveMessage(
@ -334,6 +335,7 @@ fun ChannelScreen(
mentions = tagger.pTags,
wantsToMarkAsSensitive = false,
nip94attachments = usedAttachments,
draftTag = null,
)
}
newPostModel.message = TextFieldValue("")

View File

@ -348,6 +348,7 @@ fun ChatroomScreen(
mentions = null,
wantsToMarkAsSensitive = false,
nip94attachments = usedAttachments,
draftTag = null,
)
}

View File

@ -60,6 +60,7 @@ class ChannelMessageEvent(
zapRaiserAmount: Long?,
geohash: String? = null,
nip94attachments: List<FileHeaderEvent>? = null,
isDraft: Boolean,
onReady: (ChannelMessageEvent) -> Unit,
) {
val tags =
@ -87,7 +88,7 @@ class ChannelMessageEvent(
arrayOf("alt", ALT),
)
signer.sign(createdAt, KIND, tags.toTypedArray(), message, onReady)
signer.sign(createdAt, KIND, tags.toTypedArray(), message, onReady, isDraft)
}
}
}

View File

@ -93,6 +93,7 @@ class ClassifiedsEvent(
nip94attachments: List<Event>? = null,
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
isDraft: Boolean,
onReady: (ClassifiedsEvent) -> Unit,
) {
val tags = mutableListOf<Array<String>>()
@ -172,7 +173,7 @@ class ClassifiedsEvent(
}
tags.add(arrayOf("alt", ALT))
signer.sign(createdAt, KIND, tags.toTypedArray(), message, onReady)
signer.sign(createdAt, KIND, tags.toTypedArray(), message, onReady, isDraft)
}
}
}

View File

@ -94,6 +94,7 @@ class GitReplyEvent(
forkedFrom: Event? = null,
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
isDraft: Boolean,
onReady: (GitReplyEvent) -> Unit,
) {
val tags = mutableListOf<Array<String>>()
@ -156,7 +157,7 @@ class GitReplyEvent(
}
tags.add(arrayOf("alt", "a git issue reply"))
signer.sign(createdAt, KIND, tags.toTypedArray(), msg, onReady)
signer.sign(createdAt, KIND, tags.toTypedArray(), msg, onReady, isDraft)
}
}
}

View File

@ -72,6 +72,7 @@ class LiveActivitiesChatMessageEvent(
zapRaiserAmount: Long?,
geohash: String? = null,
nip94attachments: List<FileHeaderEvent>? = null,
isDraft: Boolean,
onReady: (LiveActivitiesChatMessageEvent) -> Unit,
) {
val content = message
@ -98,7 +99,7 @@ class LiveActivitiesChatMessageEvent(
}
tags.add(arrayOf("alt", ALT))
signer.sign(createdAt, KIND, tags.toTypedArray(), content, onReady)
signer.sign(createdAt, KIND, tags.toTypedArray(), content, onReady, isDraft)
}
}
}

View File

@ -80,6 +80,7 @@ class PollNoteEvent(
zapRaiserAmount: Long?,
geohash: String? = null,
nip94attachments: List<FileHeaderEvent>? = null,
isDraft: Boolean,
onReady: (PollNoteEvent) -> Unit,
) {
val tags = mutableListOf<Array<String>>()
@ -112,7 +113,7 @@ class PollNoteEvent(
}
tags.add(arrayOf("alt", ALT))
signer.sign(createdAt, KIND, tags.toTypedArray(), msg, onReady)
signer.sign(createdAt, KIND, tags.toTypedArray(), msg, onReady, isDraft)
}
}
}

View File

@ -124,6 +124,7 @@ class PrivateDmEvent(
zapRaiserAmount: Long?,
geohash: String? = null,
nip94attachments: List<FileHeaderEvent>? = null,
isDraft: Boolean,
onReady: (PrivateDmEvent) -> Unit,
) {
var message = msg
@ -165,7 +166,7 @@ class PrivateDmEvent(
tags.add(arrayOf("alt", ALT))
signer.nip04Encrypt(message, recipientPubKey) { content ->
signer.sign(createdAt, KIND, tags.toTypedArray(), content, onReady)
signer.sign(createdAt, KIND, tags.toTypedArray(), content, onReady, isDraft)
}
}
}