Fixes relay hints when they disagree with our findings.

This commit is contained in:
Vitor Pamplona
2025-08-19 12:20:49 -04:00
parent d539eca8bb
commit 5685f227f9
4 changed files with 63 additions and 13 deletions

View File

@@ -201,16 +201,19 @@ open class Note(
} }
fun relayHintUrl(): NormalizedRelayUrl? { fun relayHintUrl(): NormalizedRelayUrl? {
val authorRelay = author?.latestMetadataRelay val currentOutbox = author?.outboxRelays()?.toSet()
return if (relays.isNotEmpty()) { return if (relays.isNotEmpty()) {
if (authorRelay != null && relays.any { it == authorRelay }) { if (currentOutbox != null && currentOutbox.isNotEmpty()) {
authorRelay val relayMatchesOutbox = relays.firstOrNull { it in currentOutbox }
} else { if (relayMatchesOutbox != null) {
relays.firstOrNull() return relayMatchesOutbox
}
} }
return relays.firstOrNull()
} else { } else {
null currentOutbox?.firstOrNull() ?: author?.latestMetadataRelay
} }
} }

View File

@@ -86,7 +86,9 @@ import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
import com.vitorpamplona.quartz.nip10Notes.content.findHashtags import com.vitorpamplona.quartz.nip10Notes.content.findHashtags
import com.vitorpamplona.quartz.nip10Notes.content.findNostrUris import com.vitorpamplona.quartz.nip10Notes.content.findNostrUris
import com.vitorpamplona.quartz.nip10Notes.content.findURLs import com.vitorpamplona.quartz.nip10Notes.content.findURLs
import com.vitorpamplona.quartz.nip10Notes.tags.markedETags
import com.vitorpamplona.quartz.nip10Notes.tags.notify import com.vitorpamplona.quartz.nip10Notes.tags.notify
import com.vitorpamplona.quartz.nip10Notes.tags.prepareETagsAsReplyTo
import com.vitorpamplona.quartz.nip18Reposts.quotes.quotes import com.vitorpamplona.quartz.nip18Reposts.quotes.quotes
import com.vitorpamplona.quartz.nip18Reposts.quotes.taggedQuoteIds import com.vitorpamplona.quartz.nip18Reposts.quotes.taggedQuoteIds
import com.vitorpamplona.quartz.nip22Comments.CommentEvent import com.vitorpamplona.quartz.nip22Comments.CommentEvent
@@ -544,12 +546,47 @@ open class ShortNotePostViewModel :
imetas(usedAttachments) imetas(usedAttachments)
} }
} else { } else {
TextNoteEvent.build( TextNoteEvent.build(tagger.message) {
note = tagger.message, val replyingTo = originalNote?.toEventHint<TextNoteEvent>()
replyingTo = originalNote?.toEventHint<TextNoteEvent>(), val forkingFrom = forkedFromNote?.toEventHint<TextNoteEvent>()
forkingFrom = forkedFromNote?.toEventHint<TextNoteEvent>(),
) { if (replyingTo != null || forkingFrom != null) {
tagger.pTags?.let { pTagList -> notify(pTagList.map { it.toPTag() }) } val tags = prepareETagsAsReplyTo(replyingTo, forkingFrom)
// fixes wrong tags from previous clients
tags.forEach {
val note = accountViewModel.getNoteIfExists(it.eventId)
val ourAuthor = note?.author?.pubkeyHex
val ourHint = note?.relayHintUrl()
if (it.author == null || it.author?.isBlank() == true) {
it.author = ourAuthor
} else {
if (ourAuthor != null && it.author != ourAuthor) {
it.author = ourAuthor
}
}
if (it.relay == null) {
it.relay = ourHint
} else {
if (ourHint != null && it.relay != ourHint) {
it.relay = ourHint
}
}
}
markedETags(tags)
}
tagger.pTags?.let { userList ->
val tags =
userList.map {
val tag = it.toPTag()
if (tag.relayHint == null) {
tag.copy(relayHint = LocalCache.relayHints.hintsForKey(it.pubkeyHex).firstOrNull())
} else {
tag
}
}
notify(tags)
}
hashtags(findHashtags(tagger.message)) hashtags(findHashtags(tagger.message))
references(findURLs(tagger.message)) references(findURLs(tagger.message))

View File

@@ -118,6 +118,15 @@ class TextNoteEvent(
return ALT + msg.take(50) + "..." return ALT + msg.take(50) + "..."
} }
fun build(
note: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<TextNoteEvent>.() -> Unit = {},
) = eventTemplate(KIND, note, createdAt) {
alt(shortedMessageForAlt(note))
initializer()
}
fun build( fun build(
note: String, note: String,
replyingTo: EventHintBundle<TextNoteEvent>? = null, replyingTo: EventHintBundle<TextNoteEvent>? = null,

View File

@@ -20,6 +20,7 @@
*/ */
package com.vitorpamplona.quartz.nip10Notes.tags package com.vitorpamplona.quartz.nip10Notes.tags
import android.R.attr.tag
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.tags.people.PTag import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
import com.vitorpamplona.quartz.nip10Notes.BaseThreadedEvent import com.vitorpamplona.quartz.nip10Notes.BaseThreadedEvent
@@ -27,7 +28,7 @@ import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
fun <T : BaseThreadedEvent> TagArrayBuilder<T>.markedETag(tag: MarkedETag) = add(tag.toTagArray()) fun <T : BaseThreadedEvent> TagArrayBuilder<T>.markedETag(tag: MarkedETag) = add(tag.toTagArray())
fun <T : BaseThreadedEvent> TagArrayBuilder<T>.markedETags(tag: List<MarkedETag>) = addAll(tag.map { it.toTagArray() }) fun <T : BaseThreadedEvent> TagArrayBuilder<T>.markedETags(tags: List<MarkedETag>) = addAll(tags.map { it.toTagArray() })
fun TagArrayBuilder<TextNoteEvent>.notify(tag: PTag) = add(tag.toTagArray()) fun TagArrayBuilder<TextNoteEvent>.notify(tag: PTag) = add(tag.toTagArray())