mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-10-05 19:28:25 +00:00
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:
@@ -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.
|
||||
|
||||
+13
-2
@@ -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",
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user