refactor: buildHashtagLabel takes an EventHintBundle

Replace the labeledEventId/relay/author trio with a single
EventHintBundle<out Event>, building the e-tag via the standard
EventHintBundle.toETag() idiom. The Account caller now passes the
note's event hint directly.

https://claude.ai/code/session_019gc3FipVBcndF9fmqCCfVX
This commit is contained in:
Claude
2026-05-30 21:23:56 +00:00
parent 8e7d169198
commit 3f4066c4b8
3 changed files with 24 additions and 19 deletions
@@ -769,13 +769,7 @@ class Account(
val eventHint = note.toEventHint<Event>() ?: return null
val template =
LabelEvent.buildHashtagLabel(
labeledEventId = eventHint.event.id,
labeledEventRelay = eventHint.relay?.url,
labeledEventAuthor = eventHint.event.pubKey,
hashtag = hashtag,
)
val template = LabelEvent.buildHashtagLabel(eventHint, hashtag)
val event = signer.sign(template)
val relays = computeRelayListToBroadcast(event)
@@ -24,6 +24,7 @@ import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.hints.AddressHintProvider
import com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle
import com.vitorpamplona.quartz.nip01Core.hints.EventHintProvider
import com.vitorpamplona.quartz.nip01Core.hints.PubKeyHintProvider
import com.vitorpamplona.quartz.nip01Core.hints.types.AddressHint
@@ -34,6 +35,7 @@ import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip01Core.tags.aTag.ATag
import com.vitorpamplona.quartz.nip01Core.tags.events.ETag
import com.vitorpamplona.quartz.nip01Core.tags.events.eTag
import com.vitorpamplona.quartz.nip01Core.tags.events.toETag
import com.vitorpamplona.quartz.nip01Core.tags.hashtags.HashtagTag
import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
import com.vitorpamplona.quartz.nip01Core.tags.people.pTag
@@ -127,18 +129,16 @@ class LabelEvent(
* follow-graph hashtag feeds match regardless of input case.
*/
fun buildHashtagLabel(
labeledEventId: HexKey,
labeledEventRelay: String? = null,
labeledEventAuthor: HexKey? = null,
labeledEvent: EventHintBundle<out Event>,
hashtag: String,
createdAt: Long = TimeUtils.now(),
) = buildEventLabel(
labeledEventId = labeledEventId,
labeledEventRelay = labeledEventRelay,
labeledEventAuthor = labeledEventAuthor,
labels = listOf(LabelTag(hashtag.removePrefix("#").lowercase(), HASHTAG_NAMESPACE)),
createdAt = createdAt,
)
) = eventTemplate<LabelEvent>(KIND, "", createdAt) {
alt(ALT)
eTag(labeledEvent.toETag())
val tag = LabelTag(hashtag.removePrefix("#").lowercase(), HASHTAG_NAMESPACE)
labelNamespace(tag.namespace)
label(tag)
}
/**
* Build a label event for labeling events.
@@ -22,6 +22,7 @@ package com.vitorpamplona.quartz.nip32Labeling
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip32Labeling.tags.LabelTag
import com.vitorpamplona.quartz.utils.EventFactory
@@ -162,10 +163,20 @@ class LabelEventTest {
@Test
fun testBuildHashtagLabel() {
val labeledEvent =
EventFactory.create<Event>(
id = testEventId,
pubKey = testPubKey,
createdAt = 1234567890L,
kind = 1,
tags = arrayOf(),
content = "hello",
sig = "c".repeat(128),
)
val template =
LabelEvent.buildHashtagLabel(
labeledEventId = testEventId,
labeledEventAuthor = testPubKey,
labeledEvent = EventHintBundle(labeledEvent),
hashtag = "#PhotoGraphy",
)