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 6ad8d1a928..698198ed9b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -195,7 +195,6 @@ import com.vitorpamplona.quartz.nip94FileMetadata.mimeType import com.vitorpamplona.quartz.nip94FileMetadata.originalHash import com.vitorpamplona.quartz.nip94FileMetadata.tags.DimensionTag import com.vitorpamplona.quartz.nip98HttpAuth.HTTPAuthorizationEvent -import com.vitorpamplona.quartz.nipB7Blossom.BlossomAuthorizationEvent import com.vitorpamplona.quartz.utils.tryAndWait import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.DelicateCoroutinesApi @@ -229,7 +228,7 @@ import kotlin.coroutines.resume class Account( val settings: AccountSettings = AccountSettings(KeyPair()), val signer: NostrSigner = settings.createSigner(), - val geolocationFlow: StateFlow, + geolocationFlow: StateFlow, val cache: LocalCache, val client: NostrClient, val scope: CoroutineScope, @@ -698,28 +697,12 @@ class Account( hash: HexKey, size: Long, alt: String, - ): BlossomAuthorizationEvent? { - if (!isWriteable()) return null - - return tryAndWait { continuation -> - BlossomAuthorizationEvent.createUploadAuth(hash, size, alt, signer) { - continuation.resume(it) - } - } - } + ) = blossomServers.createBlossomUploadAuth(hash, size, alt) suspend fun createBlossomDeleteAuth( hash: HexKey, alt: String, - ): BlossomAuthorizationEvent? { - if (!isWriteable()) return null - - return tryAndWait { continuation -> - BlossomAuthorizationEvent.createDeleteAuth(hash, alt, signer) { - continuation.resume(it) - } - } - } + ) = blossomServers.createBlossomDeleteAuth(hash, alt) suspend fun boost(note: Note) { RepostAction.repost(note, signer) { @@ -1849,31 +1832,11 @@ class Account( relay: IRelayClient, challenge: String, ) { - createAuthEvent(relay.url, challenge) { + RelayAuthEvent.create(relay.url, challenge, signer) { client.sendIfExists(it, relay.url) } } - fun createAuthEvent( - relayUrl: NormalizedRelayUrl, - challenge: String, - onReady: (RelayAuthEvent) -> Unit, - ) { - if (!isWriteable()) return - - RelayAuthEvent.create(relayUrl, challenge, signer, onReady = onReady) - } - - fun createAuthEvent( - relayUrls: List, - challenge: String, - onReady: (RelayAuthEvent) -> Unit, - ) { - if (!isWriteable()) return - - RelayAuthEvent.create(relayUrls, challenge, signer, onReady = onReady) - } - fun isInPrivateBookmarks( note: Note, onReady: (Boolean) -> Unit, @@ -2096,45 +2059,21 @@ class Account( ).toSet() } - fun saveDMRelayList(dmRelays: List) { - if (!isWriteable()) return - dmRelayList.saveRelayList(dmRelays, ::sendMyPublicAndPrivateOutbox) - } + fun saveDMRelayList(dmRelays: List) = dmRelayList.saveRelayList(dmRelays, ::sendMyPublicAndPrivateOutbox) - fun savePrivateOutboxRelayList(relays: List) { - if (!isWriteable()) return - privateStorageRelayList.saveRelayList(relays, ::sendMyPublicAndPrivateOutbox) - } + fun savePrivateOutboxRelayList(relays: List) = privateStorageRelayList.saveRelayList(relays, ::sendMyPublicAndPrivateOutbox) - fun saveSearchRelayList(searchRelays: List) { - if (!isWriteable()) return - searchRelayList.saveRelayList(searchRelays, ::sendMyPublicAndPrivateOutbox) - } + fun saveSearchRelayList(searchRelays: List) = searchRelayList.saveRelayList(searchRelays, ::sendMyPublicAndPrivateOutbox) - fun saveTrustedRelayList(trustedRelays: List) { - if (!isWriteable()) return - trustedRelayList.saveRelayList(trustedRelays, ::sendMyPublicAndPrivateOutbox) - } + fun saveTrustedRelayList(trustedRelays: List) = trustedRelayList.saveRelayList(trustedRelays, ::sendMyPublicAndPrivateOutbox) - fun saveBlockedRelayList(blockedRelays: List) { - if (!isWriteable()) return - blockedRelayList.saveRelayList(blockedRelays, ::sendMyPublicAndPrivateOutbox) - } + fun saveBlockedRelayList(blockedRelays: List) = blockedRelayList.saveRelayList(blockedRelays, ::sendMyPublicAndPrivateOutbox) - fun sendNip65RelayList(relays: List) { - if (!isWriteable()) return - nip65RelayList.saveRelayList(relays, ::sendMyPublicAndPrivateOutbox) - } + fun sendNip65RelayList(relays: List) = nip65RelayList.saveRelayList(relays, ::sendMyPublicAndPrivateOutbox) - fun sendFileServersList(servers: List) { - if (!isWriteable()) return - fileStorageServers.saveFileServersList(servers, ::sendMyPublicAndPrivateOutbox) - } + fun sendFileServersList(servers: List) = fileStorageServers.saveFileServersList(servers, ::sendMyPublicAndPrivateOutbox) - fun sendBlossomServersList(servers: List) { - if (!isWriteable()) return - blossomServers.saveBlossomServersList(servers, ::sendMyPublicAndPrivateOutbox) - } + fun sendBlossomServersList(servers: List) = blossomServers.saveBlossomServersList(servers, ::sendMyPublicAndPrivateOutbox) fun getAllPeopleLists(): List = getAllPeopleLists(signer.pubKey) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/edits/PrivateStorageRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/edits/PrivateStorageRelayListState.kt index adec4d59bf..5c7510c8ca 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/edits/PrivateStorageRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/edits/PrivateStorageRelayListState.kt @@ -75,6 +75,7 @@ class PrivateStorageRelayListState( relays: List, onDone: (PrivateOutboxRelayListEvent) -> Unit, ) { + if (!signer.isWriteable()) return val relayListForPrivateOutbox = getPrivateOutboxRelayList() if (relayListForPrivateOutbox != null && !relayListForPrivateOutbox.cachedPrivateTags().isNullOrEmpty()) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip17Dms/DmRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip17Dms/DmRelayListState.kt index 711ea3a933..d7be6fa974 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip17Dms/DmRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip17Dms/DmRelayListState.kt @@ -75,6 +75,8 @@ class DmRelayListState( dmRelays: List, onDone: (ChatMessageRelayListEvent) -> Unit, ) { + if (!signer.isWriteable()) return + val relayListForDMs = getDMRelayList() if (relayListForDMs != null && relayListForDMs.tags.isNotEmpty()) { ChatMessageRelayListEvent.updateRelayList( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip50Search/SearchRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip50Search/SearchRelayListState.kt index 5f4a751061..5fc3202159 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip50Search/SearchRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip50Search/SearchRelayListState.kt @@ -76,6 +76,7 @@ class SearchRelayListState( searchRelays: List, onDone: (SearchRelayListEvent) -> Unit, ) { + if (!signer.isWriteable()) return val relayListForSearch = getSearchRelayList() if (relayListForSearch != null && relayListForSearch.tags.isNotEmpty()) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/BlockedRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/BlockedRelayListState.kt index 14dcbbefc4..b897955254 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/BlockedRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/BlockedRelayListState.kt @@ -75,6 +75,7 @@ class BlockedRelayListState( blockedRelays: List, onDone: (BlockedRelayListEvent) -> Unit, ) { + if (!signer.isWriteable()) return val relayListForBlocked = getBlockedRelayList() if (relayListForBlocked != null && relayListForBlocked.tags.isNotEmpty()) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/TrustedRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/TrustedRelayListState.kt index dc611b54fc..f1137b7bbe 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/TrustedRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/TrustedRelayListState.kt @@ -75,6 +75,7 @@ class TrustedRelayListState( trustedRelays: List, onDone: (TrustedRelayListEvent) -> Unit, ) { + if (!signer.isWriteable()) return val relayListForTrusted = getTrustedRelayList() if (relayListForTrusted != null && relayListForTrusted.tags.isNotEmpty()) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip96FileStorage/FileStorageServerListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip96FileStorage/FileStorageServerListState.kt index bccbc05725..943dad95f9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip96FileStorage/FileStorageServerListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip96FileStorage/FileStorageServerListState.kt @@ -70,6 +70,7 @@ class FileStorageServerListState( servers: List, onDone: (FileServersEvent) -> Unit, ) { + if (!signer.isWriteable()) return val serverList = getFileServersList() val template = diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nipB7Blossom/BlossomServerListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nipB7Blossom/BlossomServerListState.kt index a85941bade..69c910da80 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nipB7Blossom/BlossomServerListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nipB7Blossom/BlossomServerListState.kt @@ -25,9 +25,12 @@ import com.vitorpamplona.amethyst.model.AddressableNote import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.NoteState +import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner import com.vitorpamplona.quartz.nip96FileStorage.config.FileServersEvent +import com.vitorpamplona.quartz.nipB7Blossom.BlossomAuthorizationEvent import com.vitorpamplona.quartz.nipB7Blossom.BlossomServersEvent +import com.vitorpamplona.quartz.utils.tryAndWait import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.SharingStarted @@ -36,6 +39,7 @@ import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn +import kotlin.coroutines.resume class BlossomServerListState( val signer: NostrSigner, @@ -71,6 +75,8 @@ class BlossomServerListState( servers: List, onDone: (BlossomServersEvent) -> Unit, ) { + if (!signer.isWriteable()) return + val serverList = getBlossomServersList() if (serverList != null && serverList.tags.isNotEmpty()) { @@ -88,4 +94,31 @@ class BlossomServerListState( ) } } + + suspend fun createBlossomUploadAuth( + hash: HexKey, + size: Long, + alt: String, + ): BlossomAuthorizationEvent? { + if (!signer.isWriteable()) return null + + return tryAndWait { continuation -> + BlossomAuthorizationEvent.createUploadAuth(hash, size, alt, signer) { + continuation.resume(it) + } + } + } + + suspend fun createBlossomDeleteAuth( + hash: HexKey, + alt: String, + ): BlossomAuthorizationEvent? { + if (!signer.isWriteable()) return null + + return tryAndWait { continuation -> + BlossomAuthorizationEvent.createDeleteAuth(hash, alt, signer) { + continuation.resume(it) + } + } + } }