Finally adds markers to kind 1s

This commit is contained in:
Vitor Pamplona
2023-06-13 17:08:50 -04:00
parent 9b5c7ad23f
commit a346d31554
5 changed files with 65 additions and 6 deletions
@@ -497,7 +497,10 @@ class Account(
mentions: List<User>?, mentions: List<User>?,
tags: List<String>? = null, tags: List<String>? = null,
zapReceiver: String? = null, zapReceiver: String? = null,
wantsToMarkAsSensitive: Boolean wantsToMarkAsSensitive: Boolean,
replyingTo: String?,
root: String?,
directMentions: Set<HexKey>
) { ) {
if (!isWriteable()) return if (!isWriteable()) return
@@ -513,6 +516,9 @@ class Account(
extraTags = tags, extraTags = tags,
zapReceiver = zapReceiver, zapReceiver = zapReceiver,
markAsSensitive = wantsToMarkAsSensitive, markAsSensitive = wantsToMarkAsSensitive,
replyingTo = replyingTo,
root = root,
directMentions = directMentions,
privateKey = loggedIn.privKey!! privateKey = loggedIn.privKey!!
) )
@@ -21,6 +21,8 @@ class TextNoteEvent(
fun subject() = tags.firstOrNull() { it.size > 1 && it[0] == "subject" }?.get(1) fun subject() = tags.firstOrNull() { it.size > 1 && it[0] == "subject" }?.get(1)
fun root() = tags.firstOrNull() { it.size > 3 && it[3] == "root" }?.get(1)
companion object { companion object {
const val kind = 1 const val kind = 1
@@ -32,19 +34,44 @@ class TextNoteEvent(
extraTags: List<String>?, extraTags: List<String>?,
zapReceiver: String?, zapReceiver: String?,
markAsSensitive: Boolean, markAsSensitive: Boolean,
replyingTo: String?,
root: String?,
directMentions: Set<HexKey>,
privateKey: ByteArray, privateKey: ByteArray,
createdAt: Long = Date().time / 1000 createdAt: Long = Date().time / 1000
): TextNoteEvent { ): TextNoteEvent {
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey() val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
val tags = mutableListOf<List<String>>() val tags = mutableListOf<List<String>>()
replyTos?.forEach { replyTos?.forEach {
tags.add(listOf("e", it)) if (it == replyingTo) {
tags.add(listOf("e", it, "", "reply"))
} else if (it == root) {
tags.add(listOf("e", it, "", "root"))
} else if (it in directMentions) {
tags.add(listOf("e", it, "", "mention"))
} else {
tags.add(listOf("e", it))
}
} }
mentions?.forEach { mentions?.forEach {
tags.add(listOf("p", it)) if (it in directMentions) {
tags.add(listOf("p", it, "", "mention"))
} else {
tags.add(listOf("p", it))
}
} }
addresses?.forEach { addresses?.forEach {
tags.add(listOf("a", it.toTag())) val aTag = it.toTag()
if (aTag == replyingTo) {
tags.add(listOf("a", aTag, "", "reply"))
} else if (aTag == root) {
tags.add(listOf("a", aTag, "", "root"))
} else if (aTag in directMentions) {
tags.add(listOf("a", aTag, "", "mention"))
} else {
tags.add(listOf("a", aTag))
}
} }
findHashtags(msg).forEach { findHashtags(msg).forEach {
tags.add(listOf("t", it)) tags.add(listOf("t", it))
@@ -1,5 +1,6 @@
package com.vitorpamplona.amethyst.ui.actions package com.vitorpamplona.amethyst.ui.actions
import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
@@ -8,11 +9,16 @@ import com.vitorpamplona.amethyst.service.nip19.Nip19
class NewMessageTagger(var channelHex: String?, var mentions: List<User>?, var replyTos: List<Note>?, var message: String) { class NewMessageTagger(var channelHex: String?, var mentions: List<User>?, var replyTos: List<Note>?, var message: String) {
val directMentions = mutableSetOf<HexKey>()
fun addUserToMentions(user: User) { fun addUserToMentions(user: User) {
directMentions.add(user.pubkeyHex)
mentions = if (mentions?.contains(user) == true) mentions else mentions?.plus(user) ?: listOf(user) mentions = if (mentions?.contains(user) == true) mentions else mentions?.plus(user) ?: listOf(user)
} }
fun addNoteToReplyTos(note: Note) { fun addNoteToReplyTos(note: Note) {
directMentions.add(note.idHex)
note.author?.let { addUserToMentions(it) } note.author?.let { addUserToMentions(it) }
replyTos = if (replyTos?.contains(note) == true) replyTos else replyTos?.plus(note) ?: listOf(note) replyTos = if (replyTos?.contains(note) == true) replyTos else replyTos?.plus(note) ?: listOf(note)
} }
@@ -137,7 +137,24 @@ open class NewPostViewModel() : ViewModel() {
} else if (originalNote?.event is PrivateDmEvent) { } else if (originalNote?.event is PrivateDmEvent) {
account?.sendPrivateMessage(tagger.message, originalNote!!.author!!, originalNote!!, tagger.mentions, zapReceiver, wantsToMarkAsSensitive) account?.sendPrivateMessage(tagger.message, originalNote!!.author!!, originalNote!!, tagger.mentions, zapReceiver, wantsToMarkAsSensitive)
} else { } else {
account?.sendPost(tagger.message, tagger.replyTos, tagger.mentions, null, zapReceiver, wantsToMarkAsSensitive) // adds markers
val rootId =
(originalNote?.event as? TextNoteEvent)?.root() // if it has a marker as root
?: originalNote?.replyTo?.firstOrNull { it.event != null && it.replyTo?.isEmpty() == true }?.idHex // if it has loaded events with zero replies in the reply list
?: originalNote?.replyTo?.firstOrNull()?.idHex // old rules, first item is root.
val replyId = originalNote?.idHex
account?.sendPost(
message = tagger.message,
replyTo = tagger.replyTos,
mentions = tagger.mentions,
tags = null,
zapReceiver = zapReceiver,
wantsToMarkAsSensitive = wantsToMarkAsSensitive,
replyingTo = replyId,
root = rootId,
directMentions = tagger.directMentions
)
} }
cancel() cancel()
@@ -57,7 +57,10 @@ class AddBountyAmountViewModel : ViewModel() {
replyTo = listOfNotNull(bounty), replyTo = listOfNotNull(bounty),
mentions = listOfNotNull(bounty?.author), mentions = listOfNotNull(bounty?.author),
tags = listOf("bounty-added-reward"), tags = listOf("bounty-added-reward"),
wantsToMarkAsSensitive = false wantsToMarkAsSensitive = false,
replyingTo = null,
root = null,
directMentions = setOf()
) )
nextAmount = TextFieldValue("") nextAmount = TextFieldValue("")