Fixes refactoring issues by Claude.

This commit is contained in:
Vitor Pamplona
2026-03-28 19:58:04 -04:00
parent ff9b619d26
commit 589bb041b2
10 changed files with 53 additions and 46 deletions
@@ -33,6 +33,7 @@ import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.crypto.verify
import com.vitorpamplona.quartz.nip01Core.jackson.JacksonMapper
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip01Core.tags.aTag.ATag
import com.vitorpamplona.quartz.nip03Timestamp.EmptyOtsResolverBuilder
@@ -24,6 +24,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.amethyst.model.Constants
import com.vitorpamplona.amethyst.service.okhttp.DefaultContentTypeInterceptor
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.RelayLogger
import com.vitorpamplona.quartz.nip01Core.relay.client.auth.RelayAuthenticator
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.normalizeRelayUrl
@@ -69,6 +69,7 @@ import com.vitorpamplona.amethyst.ui.screen.UiSettingsState
import com.vitorpamplona.amethyst.ui.tor.TorManager
import com.vitorpamplona.quartz.nip01Core.core.Address
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.RelayLogger
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.RelayOfflineTracker
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.stats.RelayReqStats
@@ -664,7 +664,7 @@ class Account(
myRelayList.addAll(it.relays)
}
client.send(deletionEvent, myRelayList)
client.publish(deletionEvent, myRelayList)
cache.justConsumeMyOwnEvent(deletionEvent)
}
}
@@ -678,7 +678,7 @@ class Account(
if (event.pubKey != signer.pubKey) return
val deletionEvent = signer.sign(DeletionEvent.build(listOf(event)))
client.send(deletionEvent, outboxRelays.flow.value + additionalRelays)
client.publish(deletionEvent, outboxRelays.flow.value + additionalRelays)
cache.justConsumeMyOwnEvent(deletionEvent)
}
@@ -952,11 +952,11 @@ class Account(
},
)?.let { downloadedEvent ->
val toRelays = computeRelayListToBroadcast(downloadedEvent)
client.send(downloadedEvent, toRelays)
client.publish(downloadedEvent, toRelays)
}
}
} else {
client.send(noteEvent, computeRelayListToBroadcast(note))
client.publish(noteEvent, computeRelayListToBroadcast(note))
}
}
}
@@ -1004,7 +1004,7 @@ class Account(
val relays = outboxRelays.flow.value + commEvent.relayUrls() + community.relays + (post.author?.inboxRelays() ?: emptyList())
cache.justConsumeMyOwnEvent(signedEvent)
client.send(signedEvent, relays)
client.publish(signedEvent, relays)
}
fun sendAutomatic(events: List<Event>) = events.forEach { sendAutomatic(it) }
@@ -1027,7 +1027,7 @@ class Account(
val signedEvent = signer.sign(template)
cache.justConsumeMyOwnEvent(signedEvent)
client.send(signedEvent, computeRelayListToBroadcast(signedEvent))
client.publish(signedEvent, computeRelayListToBroadcast(signedEvent))
}
suspend fun deleteWebBookmark(event: WebBookmarkEvent) {
@@ -1037,7 +1037,7 @@ class Account(
val signedEvent = signer.sign(template)
cache.justConsumeMyOwnEvent(signedEvent)
client.send(signedEvent, computeRelayListToBroadcast(signedEvent))
client.publish(signedEvent, computeRelayListToBroadcast(signedEvent))
}
fun sendMyPublicAndPrivateOutbox(event: Event?) {
@@ -1048,7 +1048,7 @@ class Account(
fun sendMyPublicAndPrivateOutbox(events: List<Event>) {
events.forEach {
client.send(it, outboxRelays.flow.value)
client.publish(it, outboxRelays.flow.value)
cache.justConsumeMyOwnEvent(it)
}
}
@@ -1071,7 +1071,7 @@ class Account(
cache.justConsumeMyOwnEvent(signedEvent)
client.send(signedEvent, computeRelayListToBroadcast(signedEvent))
client.publish(signedEvent, computeRelayListToBroadcast(signedEvent))
}
}
@@ -1107,10 +1107,10 @@ class Account(
val relayList = computeRelayListToBroadcast(signedEvent)
client.send(data, relayList = relayList)
client.publish(data, relayList = relayList)
cache.justConsumeMyOwnEvent(data)
client.send(signedEvent, relayList = relayList)
client.publish(signedEvent, relayList = relayList)
cache.justConsumeMyOwnEvent(signedEvent)
return cache.getNoteIfExists(signedEvent.id)
@@ -1131,8 +1131,8 @@ class Account(
signedEvent: FileStorageHeaderEvent,
relayList: Set<NormalizedRelayUrl>,
) {
client.send(data, relayList = relayList)
client.send(signedEvent, relayList = relayList)
client.publish(data, relayList = relayList)
client.publish(signedEvent, relayList = relayList)
}
fun sendHeader(
@@ -1140,7 +1140,7 @@ class Account(
relayList: Set<NormalizedRelayUrl>,
onReady: (Note) -> Unit,
) {
client.send(signedEvent, relayList = relayList)
client.publish(signedEvent, relayList = relayList)
cache.justConsumeMyOwnEvent(signedEvent)
cache.getNoteIfExists(signedEvent.id)?.let { onReady(it) }
@@ -1322,7 +1322,7 @@ class Account(
client.publish(event, relayList)
broadcast.forEach { client.send(it, relayList) }
broadcast.forEach { client.publish(it, relayList) }
return event
}
@@ -1346,7 +1346,7 @@ class Account(
client.publish(event, relayList)
broadcast.forEach { client.send(it, relayList) }
broadcast.forEach { client.publish(it, relayList) }
return event
}
@@ -1378,7 +1378,7 @@ class Account(
extraNotesToBroadcast: List<Event>,
) {
cache.justConsumeMyOwnEvent(event)
extraNotesToBroadcast.forEach { client.send(it, relays) }
extraNotesToBroadcast.forEach { client.publish(it, relays) }
}
suspend fun createAndSendDraftIgnoreErrors(
@@ -1410,9 +1410,9 @@ class Account(
val relayList = (privateStorageRelayList.flow.value + localRelayList.flow.value + extraRelays).toSet()
if (relayList.isNotEmpty()) {
client.send(draftEvent, relayList)
client.publish(draftEvent, relayList)
broadcast.forEach {
client.send(it, relayList.toSet())
client.publish(it, relayList.toSet())
}
}
}
@@ -1439,8 +1439,8 @@ class Account(
cache.justConsumeMyOwnEvent(deletionEvent)
if (relayList.isNotEmpty()) {
client.send(deletedDraft, relayList)
client.send(deletionEvent, relayList)
client.publish(deletedDraft, relayList)
client.publish(deletionEvent, relayList)
}
}
@@ -1552,9 +1552,9 @@ class Account(
} else {
val it = signer.sign(template)
cache.justConsumeMyOwnEvent(it)
client.send(it, relayList = relayList)
client.publish(it, relayList = relayList)
mapEntitiesToNotes(quotes).forEach { it.event?.let { client.send(it, relayList = relayList) } }
mapEntitiesToNotes(quotes).forEach { it.event?.let { client.publish(it, relayList = relayList) } }
}
}
@@ -1597,9 +1597,9 @@ class Account(
} else {
val it = signer.sign(template)
cache.justConsumeMyOwnEvent(it)
client.send(it, relayList = relayList)
client.publish(it, relayList = relayList)
broadcastNotes.forEach { it.event?.let { client.send(it, relayList = relayList) } }
broadcastNotes.forEach { it.event?.let { client.publish(it, relayList = relayList) } }
}
}
@@ -1624,8 +1624,8 @@ class Account(
val newEvent = signer.sign(template)
cache.justConsumeMyOwnEvent(newEvent)
client.send(newEvent, relayList = relays)
client.send(bountyEvent, relayList = relays)
client.publish(newEvent, relayList = relays)
client.publish(bountyEvent, relayList = relays)
}
suspend fun sendEdit(
@@ -1654,7 +1654,7 @@ class Account(
client.publish(event, relayList = relayList)
broadcast.forEach { client.send(it, relayList) }
broadcast.forEach { client.publish(it, relayList) }
}
override suspend fun sendNip04PrivateMessage(eventTemplate: EventTemplate<PrivateDmEvent>) {
@@ -1665,7 +1665,7 @@ class Account(
val destinationRelays = recipient?.let { cache.getOrCreateUser(it).dmInboxRelays() } ?: emptyList()
cache.justConsumeMyOwnEvent(newEvent)
client.send(newEvent, outboxRelays.flow.value + destinationRelays)
client.publish(newEvent, outboxRelays.flow.value + destinationRelays)
}
override suspend fun sendNip17EncryptedFile(template: EventTemplate<ChatMessageEncryptedFileHeaderEvent>) {
@@ -1683,7 +1683,7 @@ class Account(
override suspend fun sendGiftWraps(wraps: List<GiftWrapEvent>) {
wraps.forEach { wrap ->
val relayList = computeRelayListToBroadcast(wrap)
client.send(wrap, relayList)
client.publish(wrap, relayList)
}
}
@@ -1704,7 +1704,7 @@ class Account(
}
val relayList = computeRelayListToBroadcast(wrap)
client.send(wrap, relayList)
client.publish(wrap, relayList)
}
}
@@ -1892,7 +1892,7 @@ class Account(
cache.justConsumeMyOwnEvent(request)
onReady(request)
delay(100)
client.send(request, relayList)
client.publish(request, relayList)
}
fun cachedDecryptContent(note: Note): String? = cachedDecryptContent(note.event)
@@ -2060,7 +2060,7 @@ class Account(
val template = RequestToVanishEvent.build(relays, reason, createdAt)
val signedEvent = signer.sign(template)
cache.justConsumeMyOwnEvent(signedEvent)
client.send(signedEvent, outboxRelays.flow.value + relays.toSet())
client.publish(signedEvent, outboxRelays.flow.value + relays.toSet())
}
suspend fun requestToVanishFromEverywhere(
@@ -2072,7 +2072,7 @@ class Account(
val template = RequestToVanishEvent.buildVanishFromEverywhere(reason, createdAt)
val signedEvent = signer.sign(template)
cache.justConsumeMyOwnEvent(signedEvent)
client.send(signedEvent, followPlusAllMineWithIndex.flow.value + client.availableRelaysFlow().value)
client.publish(signedEvent, followPlusAllMineWithIndex.flow.value + client.availableRelaysFlow().value)
}
suspend fun sendNip65RelayList(relays: List<AdvertisedRelayInfo>) = sendLiterallyEverywhere(nip65RelayList.saveRelayList(relays))
@@ -289,13 +289,13 @@ class AccountSessionManager(
val client = clientBuilder()
accountSettings.backupUserMetadata?.let { client.send(it, toPost) }
accountSettings.backupContactList?.let { client.send(it, toPost) }
accountSettings.backupNIP65RelayList?.let { client.send(it, toPost) }
accountSettings.backupDMRelayList?.let { client.send(it, toPost) }
accountSettings.backupSearchRelayList?.let { client.send(it, toPost) }
accountSettings.backupIndexRelayList?.let { client.send(it, toPost) }
accountSettings.backupRelayFeedsList?.let { client.send(it, toPost) }
accountSettings.backupUserMetadata?.let { client.publish(it, toPost) }
accountSettings.backupContactList?.let { client.publish(it, toPost) }
accountSettings.backupNIP65RelayList?.let { client.publish(it, toPost) }
accountSettings.backupDMRelayList?.let { client.publish(it, toPost) }
accountSettings.backupSearchRelayList?.let { client.publish(it, toPost) }
accountSettings.backupIndexRelayList?.let { client.publish(it, toPost) }
accountSettings.backupRelayFeedsList?.let { client.publish(it, toPost) }
}
}
}
@@ -98,6 +98,7 @@ import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle
import com.vitorpamplona.quartz.nip01Core.relay.client.EmptyNostrClient
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.RelayOfflineTracker
import com.vitorpamplona.quartz.nip01Core.relay.client.auth.EmptyIAuthStatus
import com.vitorpamplona.quartz.nip01Core.relay.client.auth.RelayAuthenticator
@@ -193,7 +193,7 @@ fun main() {
}
Window(
onSubscriptionCloseduest = ::exitApplication,
onCloseRequest = ::exitApplication,
state = windowState,
title = "Amethyst",
) {
@@ -30,6 +30,8 @@ import com.vitorpamplona.amethyst.desktop.network.DesktopHttpClient
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.Message
@@ -302,7 +304,7 @@ class AccountManager internal constructor(
suspend fun loginWithBunker(bunkerUri: String): Result<AccountState.LoggedIn> {
val listener = createLoginRelayListener()
var client: NostrClient? = null
var client: INostrClient? = null
try {
val ephemeralKeyPair = KeyPair()
val ephemeralSigner = NostrSignerInternal(ephemeralKeyPair)
@@ -363,7 +365,7 @@ class AccountManager internal constructor(
suspend fun loginWithNostrConnect(onUriGenerated: (String) -> Unit): Result<AccountState.LoggedIn> {
val listener = createLoginRelayListener()
var client: NostrClient? = null
var client: INostrClient? = null
try {
val ephemeralKeyPair = KeyPair()
val uriData = NostrConnectLoginUseCase.generateUri(ephemeralKeyPair, NIP46_RELAYS, "Amethyst%20Desktop")
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.desktop.network
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.SubscriptionListener
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
@@ -103,11 +103,11 @@ class CoordinatorPipelineTest {
filters: Map<NormalizedRelayUrl, List<Filter>>,
) {}
override fun close(subId: String) {
override fun unsubscribe(subId: String) {
openedSubs.remove(subId)
}
override fun send(
override fun publish(
event: Event,
relayList: Set<NormalizedRelayUrl>,
) {}