Minor refactoring in Account
This commit is contained in:
@@ -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<LocationState.LocationResult>,
|
||||
geolocationFlow: StateFlow<LocationState.LocationResult>,
|
||||
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<NormalizedRelayUrl>,
|
||||
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<NormalizedRelayUrl>) {
|
||||
if (!isWriteable()) return
|
||||
dmRelayList.saveRelayList(dmRelays, ::sendMyPublicAndPrivateOutbox)
|
||||
}
|
||||
fun saveDMRelayList(dmRelays: List<NormalizedRelayUrl>) = dmRelayList.saveRelayList(dmRelays, ::sendMyPublicAndPrivateOutbox)
|
||||
|
||||
fun savePrivateOutboxRelayList(relays: List<NormalizedRelayUrl>) {
|
||||
if (!isWriteable()) return
|
||||
privateStorageRelayList.saveRelayList(relays, ::sendMyPublicAndPrivateOutbox)
|
||||
}
|
||||
fun savePrivateOutboxRelayList(relays: List<NormalizedRelayUrl>) = privateStorageRelayList.saveRelayList(relays, ::sendMyPublicAndPrivateOutbox)
|
||||
|
||||
fun saveSearchRelayList(searchRelays: List<NormalizedRelayUrl>) {
|
||||
if (!isWriteable()) return
|
||||
searchRelayList.saveRelayList(searchRelays, ::sendMyPublicAndPrivateOutbox)
|
||||
}
|
||||
fun saveSearchRelayList(searchRelays: List<NormalizedRelayUrl>) = searchRelayList.saveRelayList(searchRelays, ::sendMyPublicAndPrivateOutbox)
|
||||
|
||||
fun saveTrustedRelayList(trustedRelays: List<NormalizedRelayUrl>) {
|
||||
if (!isWriteable()) return
|
||||
trustedRelayList.saveRelayList(trustedRelays, ::sendMyPublicAndPrivateOutbox)
|
||||
}
|
||||
fun saveTrustedRelayList(trustedRelays: List<NormalizedRelayUrl>) = trustedRelayList.saveRelayList(trustedRelays, ::sendMyPublicAndPrivateOutbox)
|
||||
|
||||
fun saveBlockedRelayList(blockedRelays: List<NormalizedRelayUrl>) {
|
||||
if (!isWriteable()) return
|
||||
blockedRelayList.saveRelayList(blockedRelays, ::sendMyPublicAndPrivateOutbox)
|
||||
}
|
||||
fun saveBlockedRelayList(blockedRelays: List<NormalizedRelayUrl>) = blockedRelayList.saveRelayList(blockedRelays, ::sendMyPublicAndPrivateOutbox)
|
||||
|
||||
fun sendNip65RelayList(relays: List<AdvertisedRelayInfo>) {
|
||||
if (!isWriteable()) return
|
||||
nip65RelayList.saveRelayList(relays, ::sendMyPublicAndPrivateOutbox)
|
||||
}
|
||||
fun sendNip65RelayList(relays: List<AdvertisedRelayInfo>) = nip65RelayList.saveRelayList(relays, ::sendMyPublicAndPrivateOutbox)
|
||||
|
||||
fun sendFileServersList(servers: List<String>) {
|
||||
if (!isWriteable()) return
|
||||
fileStorageServers.saveFileServersList(servers, ::sendMyPublicAndPrivateOutbox)
|
||||
}
|
||||
fun sendFileServersList(servers: List<String>) = fileStorageServers.saveFileServersList(servers, ::sendMyPublicAndPrivateOutbox)
|
||||
|
||||
fun sendBlossomServersList(servers: List<String>) {
|
||||
if (!isWriteable()) return
|
||||
blossomServers.saveBlossomServersList(servers, ::sendMyPublicAndPrivateOutbox)
|
||||
}
|
||||
fun sendBlossomServersList(servers: List<String>) = blossomServers.saveBlossomServersList(servers, ::sendMyPublicAndPrivateOutbox)
|
||||
|
||||
fun getAllPeopleLists(): List<AddressableNote> = getAllPeopleLists(signer.pubKey)
|
||||
|
||||
|
||||
+1
@@ -75,6 +75,7 @@ class PrivateStorageRelayListState(
|
||||
relays: List<NormalizedRelayUrl>,
|
||||
onDone: (PrivateOutboxRelayListEvent) -> Unit,
|
||||
) {
|
||||
if (!signer.isWriteable()) return
|
||||
val relayListForPrivateOutbox = getPrivateOutboxRelayList()
|
||||
|
||||
if (relayListForPrivateOutbox != null && !relayListForPrivateOutbox.cachedPrivateTags().isNullOrEmpty()) {
|
||||
|
||||
@@ -75,6 +75,8 @@ class DmRelayListState(
|
||||
dmRelays: List<NormalizedRelayUrl>,
|
||||
onDone: (ChatMessageRelayListEvent) -> Unit,
|
||||
) {
|
||||
if (!signer.isWriteable()) return
|
||||
|
||||
val relayListForDMs = getDMRelayList()
|
||||
if (relayListForDMs != null && relayListForDMs.tags.isNotEmpty()) {
|
||||
ChatMessageRelayListEvent.updateRelayList(
|
||||
|
||||
+1
@@ -76,6 +76,7 @@ class SearchRelayListState(
|
||||
searchRelays: List<NormalizedRelayUrl>,
|
||||
onDone: (SearchRelayListEvent) -> Unit,
|
||||
) {
|
||||
if (!signer.isWriteable()) return
|
||||
val relayListForSearch = getSearchRelayList()
|
||||
|
||||
if (relayListForSearch != null && relayListForSearch.tags.isNotEmpty()) {
|
||||
|
||||
+1
@@ -75,6 +75,7 @@ class BlockedRelayListState(
|
||||
blockedRelays: List<NormalizedRelayUrl>,
|
||||
onDone: (BlockedRelayListEvent) -> Unit,
|
||||
) {
|
||||
if (!signer.isWriteable()) return
|
||||
val relayListForBlocked = getBlockedRelayList()
|
||||
|
||||
if (relayListForBlocked != null && relayListForBlocked.tags.isNotEmpty()) {
|
||||
|
||||
+1
@@ -75,6 +75,7 @@ class TrustedRelayListState(
|
||||
trustedRelays: List<NormalizedRelayUrl>,
|
||||
onDone: (TrustedRelayListEvent) -> Unit,
|
||||
) {
|
||||
if (!signer.isWriteable()) return
|
||||
val relayListForTrusted = getTrustedRelayList()
|
||||
|
||||
if (relayListForTrusted != null && relayListForTrusted.tags.isNotEmpty()) {
|
||||
|
||||
+1
@@ -70,6 +70,7 @@ class FileStorageServerListState(
|
||||
servers: List<String>,
|
||||
onDone: (FileServersEvent) -> Unit,
|
||||
) {
|
||||
if (!signer.isWriteable()) return
|
||||
val serverList = getFileServersList()
|
||||
|
||||
val template =
|
||||
|
||||
+33
@@ -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<String>,
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user