From 589bb041b21c84f8f8890b9366f300987b69579a Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sat, 28 Mar 2026 19:58:04 -0400 Subject: [PATCH] Fixes refactoring issues by Claude. --- .../ThreadDualAxisChartAssemblerTest.kt | 1 + .../relays/eventsync/EventSyncTest.kt | 1 + .../com/vitorpamplona/amethyst/AppModules.kt | 1 + .../vitorpamplona/amethyst/model/Account.kt | 68 +++++++++---------- .../ui/screen/AccountSessionManager.kt | 14 ++-- .../ui/screen/loggedIn/AccountViewModel.kt | 1 + .../vitorpamplona/amethyst/desktop/Main.kt | 2 +- .../desktop/account/AccountManager.kt | 6 +- .../desktop/network/RelayConnectionManager.kt | 1 + .../desktop/cache/CoordinatorPipelineTest.kt | 4 +- 10 files changed, 53 insertions(+), 46 deletions(-) diff --git a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ThreadDualAxisChartAssemblerTest.kt b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ThreadDualAxisChartAssemblerTest.kt index 9902c067a..a591dd575 100644 --- a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ThreadDualAxisChartAssemblerTest.kt +++ b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ThreadDualAxisChartAssemblerTest.kt @@ -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 diff --git a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/eventsync/EventSyncTest.kt b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/eventsync/EventSyncTest.kt index 41dd0cc3b..f892f6740 100644 --- a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/eventsync/EventSyncTest.kt +++ b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/eventsync/EventSyncTest.kt @@ -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 diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt index 2f3690482..82670da42 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt @@ -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 diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index f3bfa0e95..647796249 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -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) = 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) { 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, ) { - 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, 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, ) { 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) { @@ -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) { @@ -1683,7 +1683,7 @@ class Account( override suspend fun sendGiftWraps(wraps: List) { 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) = sendLiterallyEverywhere(nip65RelayList.saveRelayList(relays)) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt index 4bd3202fd..220191607 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt @@ -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) } } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index 519d04998..dddd78535 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -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 diff --git a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/Main.kt b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/Main.kt index 96dcbad66..4c73e002b 100644 --- a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/Main.kt +++ b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/Main.kt @@ -193,7 +193,7 @@ fun main() { } Window( - onSubscriptionCloseduest = ::exitApplication, + onCloseRequest = ::exitApplication, state = windowState, title = "Amethyst", ) { diff --git a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/account/AccountManager.kt b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/account/AccountManager.kt index 535f3245c..7dd9b9f8e 100644 --- a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/account/AccountManager.kt +++ b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/account/AccountManager.kt @@ -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 { 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 { val listener = createLoginRelayListener() - var client: NostrClient? = null + var client: INostrClient? = null try { val ephemeralKeyPair = KeyPair() val uriData = NostrConnectLoginUseCase.generateUri(ephemeralKeyPair, NIP46_RELAYS, "Amethyst%20Desktop") diff --git a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/network/RelayConnectionManager.kt b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/network/RelayConnectionManager.kt index 54380dea8..2bc448b05 100644 --- a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/network/RelayConnectionManager.kt +++ b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/network/RelayConnectionManager.kt @@ -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 diff --git a/desktopApp/src/jvmTest/kotlin/com/vitorpamplona/amethyst/desktop/cache/CoordinatorPipelineTest.kt b/desktopApp/src/jvmTest/kotlin/com/vitorpamplona/amethyst/desktop/cache/CoordinatorPipelineTest.kt index e3092696c..36dbc87f8 100644 --- a/desktopApp/src/jvmTest/kotlin/com/vitorpamplona/amethyst/desktop/cache/CoordinatorPipelineTest.kt +++ b/desktopApp/src/jvmTest/kotlin/com/vitorpamplona/amethyst/desktop/cache/CoordinatorPipelineTest.kt @@ -103,11 +103,11 @@ class CoordinatorPipelineTest { filters: Map>, ) {} - override fun close(subId: String) { + override fun unsubscribe(subId: String) { openedSubs.remove(subId) } - override fun send( + override fun publish( event: Event, relayList: Set, ) {}