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