From 20bc8142113da897ac9073ee7c37cda2c4066068 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 1 Jul 2024 16:40:37 -0400 Subject: [PATCH 1/3] Fixes tag. From "relay" to "server" on kind 10096 --- .../quartz/events/FileServersEvent.kt | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/events/FileServersEvent.kt b/quartz/src/main/java/com/vitorpamplona/quartz/events/FileServersEvent.kt index 2bdbcab03..aff726ddc 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/events/FileServersEvent.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/events/FileServersEvent.kt @@ -37,34 +37,30 @@ class FileServersEvent( ) : BaseAddressableEvent(id, pubKey, createdAt, KIND, tags, content, sig) { override fun dTag() = FIXED_D_TAG - fun servers(): List { - return tags.mapNotNull { - if (it.size > 1 && it[0] == "relay") { + fun servers(): List = + tags.mapNotNull { + if (it.size > 1 && it[0] == "server") { it[1] } else { null } } - } companion object { const val KIND = 10096 const val FIXED_D_TAG = "" const val ALT = "File servers used by the author" - fun createAddressATag(pubKey: HexKey): ATag { - return ATag(KIND, pubKey, FIXED_D_TAG, null) - } + fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null) - fun createAddressTag(pubKey: HexKey): String { - return ATag.assembleATag(KIND, pubKey, FIXED_D_TAG) - } + fun createAddressTag(pubKey: HexKey): String = ATag.assembleATag(KIND, pubKey, FIXED_D_TAG) - fun createTagArray(servers: List): Array> { - return servers.map { - arrayOf("server", it) - }.plusElement(arrayOf("alt", "Relay list to use for Search")).toTypedArray() - } + fun createTagArray(servers: List): Array> = + servers + .map { + arrayOf("server", it) + }.plusElement(arrayOf("alt", "Relay list to use for Search")) + .toTypedArray() fun updateRelayList( earlierVersion: FileServersEvent, @@ -74,11 +70,13 @@ class FileServersEvent( onReady: (FileServersEvent) -> Unit, ) { val tags = - earlierVersion.tags.filter { it[0] != "server" }.plus( - relays.map { - arrayOf("server", it) - }, - ).toTypedArray() + earlierVersion.tags + .filter { it[0] != "server" } + .plus( + relays.map { + arrayOf("server", it) + }, + ).toTypedArray() signer.sign(createdAt, KIND, tags, earlierVersion.content, onReady) } From c7280cf1be979a87dc5c7bf1c41ef4c163d8452c Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 1 Jul 2024 17:12:01 -0400 Subject: [PATCH 2/3] Observes and shows only the user's selected NIP96 servers for uploading options --- .../amethyst/ui/actions/NewMediaView.kt | 21 ++++++++++++++++++- .../amethyst/ui/actions/NewPostView.kt | 20 +++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewMediaView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewMediaView.kt index 28df2df0f..a6576355e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewMediaView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewMediaView.kt @@ -49,6 +49,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue @@ -71,6 +72,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.TextSpinner import com.vitorpamplona.amethyst.ui.screen.loggedIn.TitleExplainer import com.vitorpamplona.amethyst.ui.stringRes import com.vitorpamplona.amethyst.ui.theme.placeholderText +import com.vitorpamplona.quartz.events.FileServersEvent import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Dispatchers @@ -189,8 +191,25 @@ fun ImageVideoPost( postViewModel: NewMediaModel, accountViewModel: AccountViewModel, ) { + val listOfNip96ServersNote = + accountViewModel.account + .getFileServersNote() + .live() + .metadata + .observeAsState() + val fileServers = - Nip96MediaServers.DEFAULT.map { ServerOption(it, false) } + + ( + (listOfNip96ServersNote.value?.note?.event as? FileServersEvent)?.servers()?.map { + ServerOption( + Nip96MediaServers.ServerName( + it, + it, + ), + false, + ) + } ?: Nip96MediaServers.DEFAULT.map { ServerOption(it, false) } + ) + listOf( ServerOption( Nip96MediaServers.ServerName( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt index b8f4019b9..ad69a8bec 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt @@ -168,6 +168,7 @@ import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.replyModifier import com.vitorpamplona.amethyst.ui.theme.subtleBorder import com.vitorpamplona.quartz.events.ClassifiedsEvent +import com.vitorpamplona.quartz.events.FileServersEvent import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.CancellationException @@ -1620,8 +1621,25 @@ fun ImageVideoDescription( val isImage = mediaType.startsWith("image") val isVideo = mediaType.startsWith("video") + val listOfNip96ServersNote = + accountViewModel.account + .getFileServersNote() + .live() + .metadata + .observeAsState() + val fileServers = - Nip96MediaServers.DEFAULT.map { ServerOption(it, false) } + + ( + (listOfNip96ServersNote.value?.note?.event as? FileServersEvent)?.servers()?.map { + ServerOption( + Nip96MediaServers.ServerName( + it, + it, + ), + false, + ) + } ?: Nip96MediaServers.DEFAULT.map { ServerOption(it, false) } + ) + listOf( ServerOption( Nip96MediaServers.ServerName( From 9ed1dbac72cb1e133cebd8cffb1962db81c82b89 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 1 Jul 2024 17:13:37 -0400 Subject: [PATCH 3/3] Updates lifecycle to 2.8.3 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 787c98808..afcd46518 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -24,7 +24,7 @@ kotlin = "1.9.24" kotlinxCollectionsImmutable = "0.3.7" languageId = "17.0.5" lazysodiumAndroid = "5.1.0" -lifecycleRuntimeKtx = "2.8.2" +lifecycleRuntimeKtx = "2.8.3" lightcompressor = "1.3.2" markdown = "077a2cde64" media3 = "1.3.1"