Refactoring some of the old nomenclature of Kind 1 tags.

This commit is contained in:
Vitor Pamplona
2023-12-29 14:25:14 -05:00
parent 941ed77f22
commit 57430c4366
4 changed files with 39 additions and 39 deletions

View File

@@ -12,8 +12,8 @@ import com.vitorpamplona.quartz.encoders.toNpub
class NewMessageTagger( class NewMessageTagger(
var message: String, var message: String,
var mentions: List<User>? = null, var pTags: List<User>? = null,
var replyTos: List<Note>? = null, var eTags: List<Note>? = null,
var channelHex: String? = null, var channelHex: String? = null,
var dao: Dao var dao: Dao
) { ) {
@@ -22,24 +22,24 @@ class NewMessageTagger(
fun addUserToMentions(user: User) { fun addUserToMentions(user: User) {
directMentions.add(user.pubkeyHex) directMentions.add(user.pubkeyHex)
mentions = if (mentions?.contains(user) == true) mentions else mentions?.plus(user) ?: listOf(user) pTags = if (pTags?.contains(user) == true) pTags else pTags?.plus(user) ?: listOf(user)
} }
fun addNoteToReplyTos(note: Note) { fun addNoteToReplyTos(note: Note) {
directMentions.add(note.idHex) 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) eTags = if (eTags?.contains(note) == true) eTags else eTags?.plus(note) ?: listOf(note)
} }
fun tagIndex(user: User): Int { fun tagIndex(user: User): Int {
// Postr Events assembles replies before mentions in the tag order // Postr Events assembles replies before mentions in the tag order
return (if (channelHex != null) 1 else 0) + (replyTos?.size ?: 0) + (mentions?.indexOf(user) ?: 0) return (if (channelHex != null) 1 else 0) + (eTags?.size ?: 0) + (pTags?.indexOf(user) ?: 0)
} }
fun tagIndex(note: Note): Int { fun tagIndex(note: Note): Int {
// Postr Events assembles replies before mentions in the tag order // Postr Events assembles replies before mentions in the tag order
return (if (channelHex != null) 1 else 0) + (replyTos?.indexOf(note) ?: 0) return (if (channelHex != null) 1 else 0) + (eTags?.indexOf(note) ?: 0)
} }
suspend fun run() { suspend fun run() {

View File

@@ -335,7 +335,7 @@ fun NewPostView(
} }
Row() { Row() {
Notifying(postViewModel.mentions?.toImmutableList()) { Notifying(postViewModel.pTags?.toImmutableList()) {
postViewModel.removeFromReplyList(it) postViewModel.removeFromReplyList(it)
} }
} }

View File

@@ -66,8 +66,8 @@ open class NewPostViewModel() : ViewModel() {
var originalNote: Note? = null var originalNote: Note? = null
var mentions by mutableStateOf<List<User>?>(null) var pTags by mutableStateOf<List<User>?>(null)
var replyTos by mutableStateOf<List<Note>?>(null) var eTags by mutableStateOf<List<Note>?>(null)
var nip94attachments by mutableStateOf<List<FileHeaderEvent>>(emptyList()) var nip94attachments by mutableStateOf<List<FileHeaderEvent>>(emptyList())
var nip95attachments by mutableStateOf<List<Pair<FileStorageEvent, FileStorageHeaderEvent>>>(emptyList()) var nip95attachments by mutableStateOf<List<Pair<FileStorageEvent, FileStorageHeaderEvent>>>(emptyList())
@@ -145,9 +145,9 @@ open class NewPostViewModel() : ViewModel() {
originalNote = replyingTo originalNote = replyingTo
replyingTo?.let { replyNote -> replyingTo?.let { replyNote ->
if (replyNote.event is BaseTextNoteEvent) { if (replyNote.event is BaseTextNoteEvent) {
this.replyTos = (replyNote.replyTo ?: emptyList()).plus(replyNote) this.eTags = (replyNote.replyTo ?: emptyList()).plus(replyNote)
} else { } else {
this.replyTos = listOf(replyNote) this.eTags = listOf(replyNote)
} }
if (replyNote.event !is CommunityDefinitionEvent) { if (replyNote.event !is CommunityDefinitionEvent) {
@@ -157,15 +157,15 @@ open class NewPostViewModel() : ViewModel() {
?.map { LocalCache.getOrCreateUser(it) } ?: emptyList() ?.map { LocalCache.getOrCreateUser(it) } ?: emptyList()
if (currentMentions.contains(replyUser)) { if (currentMentions.contains(replyUser)) {
this.mentions = currentMentions this.pTags = currentMentions
} else { } else {
this.mentions = currentMentions.plus(replyUser) this.pTags = currentMentions.plus(replyUser)
} }
} }
} }
} ?: run { } ?: run {
replyTos = null eTags = null
mentions = null pTags = null
} }
quote?.let { quote?.let {
@@ -199,12 +199,12 @@ open class NewPostViewModel() : ViewModel() {
return return
} }
val tagger = NewMessageTagger(message.text, mentions, replyTos, originalNote?.channelHex(), accountViewModel!!) val tagger = NewMessageTagger(message.text, pTags, eTags, originalNote?.channelHex(), accountViewModel!!)
tagger.run() tagger.run()
val toUsersTagger = NewMessageTagger(toUsers.text, null, null, null, accountViewModel!!) val toUsersTagger = NewMessageTagger(toUsers.text, null, null, null, accountViewModel!!)
toUsersTagger.run() toUsersTagger.run()
val dmUsers = toUsersTagger.mentions val dmUsers = toUsersTagger.pTags
val zapReceiver = if (wantsForwardZapTo) { val zapReceiver = if (wantsForwardZapTo) {
forwardZapTo.items.map { forwardZapTo.items.map {
@@ -229,7 +229,7 @@ open class NewPostViewModel() : ViewModel() {
val localZapRaiserAmount = if (wantsZapraiser) zapRaiserAmount else null val localZapRaiserAmount = if (wantsZapraiser) zapRaiserAmount else null
nip95attachments.forEach { nip95attachments.forEach {
if (replyTos?.contains(LocalCache.getNoteIfExists(it.second.id)) == true) { if (eTags?.contains(LocalCache.getNoteIfExists(it.second.id)) == true) {
account?.sendNip95(it.first, it.second, relayList) account?.sendNip95(it.first, it.second, relayList)
} }
} }
@@ -244,12 +244,12 @@ open class NewPostViewModel() : ViewModel() {
if (originalNote?.channelHex() != null) { if (originalNote?.channelHex() != null) {
if (originalNote is AddressableEvent && originalNote?.address() != null) { if (originalNote is AddressableEvent && originalNote?.address() != null) {
account?.sendLiveMessage(tagger.message, originalNote?.address()!!, tagger.replyTos, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount, geoHash, nip94attachments = usedAttachments) account?.sendLiveMessage(tagger.message, originalNote?.address()!!, tagger.eTags, tagger.pTags, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount, geoHash, nip94attachments = usedAttachments)
} else { } else {
account?.sendChannelMessage(tagger.message, tagger.channelHex!!, tagger.replyTos, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount, geoHash, nip94attachments = usedAttachments) account?.sendChannelMessage(tagger.message, tagger.channelHex!!, tagger.eTags, tagger.pTags, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount, geoHash, nip94attachments = usedAttachments)
} }
} else if (originalNote?.event is PrivateDmEvent) { } else if (originalNote?.event is PrivateDmEvent) {
account?.sendPrivateMessage(tagger.message, originalNote!!.author!!, originalNote!!, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount, geoHash) account?.sendPrivateMessage(tagger.message, originalNote!!.author!!, originalNote!!, tagger.pTags, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount, geoHash)
} else if (originalNote?.event is ChatMessageEvent) { } else if (originalNote?.event is ChatMessageEvent) {
val receivers = (originalNote?.event as ChatMessageEvent).recipientsPubKey().plus(originalNote?.author?.pubkeyHex).filterNotNull().toSet().toList() val receivers = (originalNote?.event as ChatMessageEvent).recipientsPubKey().plus(originalNote?.author?.pubkeyHex).filterNotNull().toSet().toList()
@@ -258,7 +258,7 @@ open class NewPostViewModel() : ViewModel() {
toUsers = receivers, toUsers = receivers,
subject = subject.text.ifBlank { null }, subject = subject.text.ifBlank { null },
replyingTo = originalNote!!, replyingTo = originalNote!!,
mentions = tagger.mentions, mentions = tagger.pTags,
wantsToMarkAsSensitive = wantsToMarkAsSensitive, wantsToMarkAsSensitive = wantsToMarkAsSensitive,
zapReceiver = zapReceiver, zapReceiver = zapReceiver,
zapRaiserAmount = localZapRaiserAmount, zapRaiserAmount = localZapRaiserAmount,
@@ -270,8 +270,8 @@ open class NewPostViewModel() : ViewModel() {
message = tagger.message, message = tagger.message,
toUsers = dmUsers.map { it.pubkeyHex }, toUsers = dmUsers.map { it.pubkeyHex },
subject = subject.text.ifBlank { null }, subject = subject.text.ifBlank { null },
replyingTo = tagger.replyTos?.firstOrNull(), replyingTo = tagger.eTags?.firstOrNull(),
mentions = tagger.mentions, mentions = tagger.pTags,
wantsToMarkAsSensitive = wantsToMarkAsSensitive, wantsToMarkAsSensitive = wantsToMarkAsSensitive,
zapReceiver = zapReceiver, zapReceiver = zapReceiver,
zapRaiserAmount = localZapRaiserAmount, zapRaiserAmount = localZapRaiserAmount,
@@ -282,7 +282,7 @@ open class NewPostViewModel() : ViewModel() {
message = tagger.message, message = tagger.message,
toUser = dmUsers.first().pubkeyHex, toUser = dmUsers.first().pubkeyHex,
replyingTo = originalNote, replyingTo = originalNote,
mentions = tagger.mentions, mentions = tagger.pTags,
wantsToMarkAsSensitive = wantsToMarkAsSensitive, wantsToMarkAsSensitive = wantsToMarkAsSensitive,
zapReceiver = zapReceiver, zapReceiver = zapReceiver,
zapRaiserAmount = localZapRaiserAmount, zapRaiserAmount = localZapRaiserAmount,
@@ -293,8 +293,8 @@ open class NewPostViewModel() : ViewModel() {
if (wantsPoll) { if (wantsPoll) {
account?.sendPoll( account?.sendPoll(
tagger.message, tagger.message,
tagger.replyTos, tagger.eTags,
tagger.mentions, tagger.pTags,
pollOptions, pollOptions,
valueMaximum, valueMaximum,
valueMinimum, valueMinimum,
@@ -313,8 +313,8 @@ open class NewPostViewModel() : ViewModel() {
price = Price(price.text, "SATS", null), price = Price(price.text, "SATS", null),
condition = condition, condition = condition,
message = tagger.message, message = tagger.message,
replyTo = tagger.replyTos, replyTo = tagger.eTags,
mentions = tagger.mentions, mentions = tagger.pTags,
location = locationText.text, location = locationText.text,
category = category.text, category = category.text,
directMentions = tagger.directMentions, directMentions = tagger.directMentions,
@@ -337,8 +337,8 @@ open class NewPostViewModel() : ViewModel() {
account?.sendPost( account?.sendPost(
message = tagger.message, message = tagger.message,
replyTo = tagger.replyTos, replyTo = tagger.eTags,
mentions = tagger.mentions, mentions = tagger.pTags,
tags = null, tags = null,
zapReceiver = zapReceiver, zapReceiver = zapReceiver,
wantsToMarkAsSensitive = wantsToMarkAsSensitive, wantsToMarkAsSensitive = wantsToMarkAsSensitive,
@@ -441,7 +441,7 @@ open class NewPostViewModel() : ViewModel() {
contentToAddUrl = null contentToAddUrl = null
urlPreview = null urlPreview = null
isUploadingImage = false isUploadingImage = false
mentions = null pTags = null
wantsDirectMessage = false wantsDirectMessage = false
@@ -483,7 +483,7 @@ open class NewPostViewModel() : ViewModel() {
} }
open fun removeFromReplyList(userToRemove: User) { open fun removeFromReplyList(userToRemove: User) {
mentions = mentions?.filter { it != userToRemove } pTags = pTags?.filter { it != userToRemove }
} }
open fun updateMessage(it: TextFieldValue) { open fun updateMessage(it: TextFieldValue) {

View File

@@ -281,8 +281,8 @@ fun ChannelScreen(
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
val tagger = NewMessageTagger( val tagger = NewMessageTagger(
message = newPostModel.message.text, message = newPostModel.message.text,
mentions = listOfNotNull(replyTo.value?.author), pTags = listOfNotNull(replyTo.value?.author),
replyTos = listOfNotNull(replyTo.value), eTags = listOfNotNull(replyTo.value),
channelHex = channel.idHex, channelHex = channel.idHex,
dao = accountViewModel dao = accountViewModel
) )
@@ -291,16 +291,16 @@ fun ChannelScreen(
accountViewModel.account.sendChannelMessage( accountViewModel.account.sendChannelMessage(
message = tagger.message, message = tagger.message,
toChannel = channel.idHex, toChannel = channel.idHex,
replyTo = tagger.replyTos, replyTo = tagger.eTags,
mentions = tagger.mentions, mentions = tagger.pTags,
wantsToMarkAsSensitive = false wantsToMarkAsSensitive = false
) )
} else if (channel is LiveActivitiesChannel) { } else if (channel is LiveActivitiesChannel) {
accountViewModel.account.sendLiveMessage( accountViewModel.account.sendLiveMessage(
message = tagger.message, message = tagger.message,
toChannel = channel.address, toChannel = channel.address,
replyTo = tagger.replyTos, replyTo = tagger.eTags,
mentions = tagger.mentions, mentions = tagger.pTags,
wantsToMarkAsSensitive = false wantsToMarkAsSensitive = false
) )
} }