Merge branch 'vitorpamplona:main' into unifiedpush-updates

This commit is contained in:
KotlinGeekDev
2024-05-30 15:07:48 +00:00
committed by GitHub
8 changed files with 104 additions and 43 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="KotlinJpsPluginSettings"> <component name="KotlinJpsPluginSettings">
<option name="version" value="1.9.23" /> <option name="version" value="1.9.24" />
</component> </component>
</project> </project>
+1 -1
View File
@@ -143,7 +143,7 @@ android {
composeOptions { composeOptions {
// Should match compose version : https://developer.android.com/jetpack/androidx/releases/compose-kotlin // Should match compose version : https://developer.android.com/jetpack/androidx/releases/compose-kotlin
kotlinCompilerExtensionVersion "1.5.11" kotlinCompilerExtensionVersion "1.5.14"
} }
packagingOptions { packagingOptions {
resources { resources {
@@ -2161,17 +2161,6 @@ class Account(
return LocalCache.getOrCreateAddressableNote(aTag) return LocalCache.getOrCreateAddressableNote(aTag)
} }
fun getFileServersNote(): AddressableNote {
val aTag =
ATag(
FileServersEvent.KIND,
userProfile().pubkeyHex,
"",
null,
)
return LocalCache.getOrCreateAddressableNote(aTag)
}
fun getBlockList(): PeopleListEvent? { fun getBlockList(): PeopleListEvent? {
return getBlockListNote().event as? PeopleListEvent return getBlockListNote().event as? PeopleListEvent
} }
@@ -2180,10 +2169,6 @@ class Account(
return getMuteListNote().event as? MuteListEvent return getMuteListNote().event as? MuteListEvent
} }
fun getFileServersList(): FileServersEvent? {
return getFileServersNote().event as? FileServersEvent
}
fun hideWord(word: String) { fun hideWord(word: String) {
val muteList = getMuteList() val muteList = getMuteList()
@@ -2688,10 +2673,7 @@ class Account(
fun saveSearchRelayList(searchRelays: List<String>) { fun saveSearchRelayList(searchRelays: List<String>) {
if (!isWriteable()) return if (!isWriteable()) return
val relayListForSearch = val relayListForSearch = getSearchRelayList()
LocalCache.getOrCreateAddressableNote(
SearchRelayListEvent.createAddressATag(signer.pubKey),
).event as? SearchRelayListEvent
if (relayListForSearch != null && relayListForSearch.tags.isNotEmpty()) { if (relayListForSearch != null && relayListForSearch.tags.isNotEmpty()) {
SearchRelayListEvent.updateRelayList( SearchRelayListEvent.updateRelayList(
@@ -2730,10 +2712,7 @@ class Account(
fun sendNip65RelayList(relays: List<AdvertisedRelayListEvent.AdvertisedRelayInfo>) { fun sendNip65RelayList(relays: List<AdvertisedRelayListEvent.AdvertisedRelayInfo>) {
if (!isWriteable()) return if (!isWriteable()) return
val nip65RelayList = val nip65RelayList = getNIP65RelayList()
LocalCache.getOrCreateAddressableNote(
AdvertisedRelayListEvent.createAddressATag(signer.pubKey),
).event as? AdvertisedRelayListEvent
if (nip65RelayList != null) { if (nip65RelayList != null) {
AdvertisedRelayListEvent.updateRelayList( AdvertisedRelayListEvent.updateRelayList(
@@ -2755,6 +2734,43 @@ class Account(
} }
} }
fun getFileServersList(): FileServersEvent? {
return getFileServersNote().event as? FileServersEvent
}
fun getFileServersListFlow(): StateFlow<NoteState> {
return getFileServersNote().flow().metadata.stateFlow
}
fun getFileServersNote(): AddressableNote {
return LocalCache.getOrCreateAddressableNote(FileServersEvent.createAddressATag(userProfile().pubkeyHex))
}
fun sendFileServersList(servers: List<String>) {
if (!isWriteable()) return
val serverList = getFileServersList()
if (serverList != null && serverList.tags.isNotEmpty()) {
FileServersEvent.updateRelayList(
earlierVersion = serverList,
relays = servers,
signer = signer,
) {
Client.send(it)
LocalCache.justConsume(it, null)
}
} else {
FileServersEvent.createFromScratch(
relays = servers,
signer = signer,
) {
Client.send(it)
LocalCache.justConsume(it, null)
}
}
}
fun setHideDeleteRequestDialog() { fun setHideDeleteRequestDialog() {
hideDeleteRequestDialog = true hideDeleteRequestDialog = true
saveable.invalidateData() saveable.invalidateData()
@@ -45,6 +45,7 @@ import com.vitorpamplona.quartz.events.DraftEvent
import com.vitorpamplona.quartz.events.EmojiPackSelectionEvent import com.vitorpamplona.quartz.events.EmojiPackSelectionEvent
import com.vitorpamplona.quartz.events.Event import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.events.EventInterface import com.vitorpamplona.quartz.events.EventInterface
import com.vitorpamplona.quartz.events.FileServersEvent
import com.vitorpamplona.quartz.events.GenericRepostEvent import com.vitorpamplona.quartz.events.GenericRepostEvent
import com.vitorpamplona.quartz.events.GiftWrapEvent import com.vitorpamplona.quartz.events.GiftWrapEvent
import com.vitorpamplona.quartz.events.GitIssueEvent import com.vitorpamplona.quartz.events.GitIssueEvent
@@ -123,6 +124,7 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
AdvertisedRelayListEvent.KIND, AdvertisedRelayListEvent.KIND,
ChatMessageRelayListEvent.KIND, ChatMessageRelayListEvent.KIND,
SearchRelayListEvent.KIND, SearchRelayListEvent.KIND,
FileServersEvent.KIND,
MuteListEvent.KIND, MuteListEvent.KIND,
PeopleListEvent.KIND, PeopleListEvent.KIND,
), ),
@@ -42,7 +42,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Tab import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow import androidx.compose.material3.TabRow
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.DisposableEffect
@@ -80,7 +79,6 @@ import com.vitorpamplona.amethyst.ui.theme.placeholderText
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
@Composable @Composable
fun ChatroomListScreen( fun ChatroomListScreen(
knownFeedViewModel: NostrChatroomListKnownFeedViewModel, knownFeedViewModel: NostrChatroomListKnownFeedViewModel,
+1 -1
View File
@@ -38,7 +38,7 @@ android {
} }
composeOptions { composeOptions {
// Should match compose version : https://developer.android.com/jetpack/androidx/releases/compose-kotlin // Should match compose version : https://developer.android.com/jetpack/androidx/releases/compose-kotlin
kotlinCompilerExtensionVersion "1.5.11" kotlinCompilerExtensionVersion "1.5.14"
} }
} }
+8 -8
View File
@@ -3,11 +3,10 @@ accompanistAdaptive = "0.34.0"
activityCompose = "1.9.0" activityCompose = "1.9.0"
agp = "8.4.1" agp = "8.4.1"
androidKotlinGeohash = "1.0" androidKotlinGeohash = "1.0"
androidLifecycle = "2.7.0"
androidxJunit = "1.2.0-beta01" androidxJunit = "1.2.0-beta01"
appcompat = "1.6.1" appcompat = "1.7.0"
audiowaveform = "1.1.1" audiowaveform = "1.1.1"
benchmark = "1.2.3" benchmark = "1.2.4"
benchmarkJunit4 = "1.2.4" benchmarkJunit4 = "1.2.4"
biometricKtx = "1.2.0-alpha05" biometricKtx = "1.2.0-alpha05"
blurhash = "1.0.0" blurhash = "1.0.0"
@@ -21,10 +20,11 @@ gms = "4.4.1"
jacksonModuleKotlin = "2.17.1" jacksonModuleKotlin = "2.17.1"
jna = "5.14.0" jna = "5.14.0"
junit = "4.13.2" junit = "4.13.2"
kotlin = "1.9.23" kotlin = "1.9.24"
kotlinxCollectionsImmutable = "0.3.7" kotlinxCollectionsImmutable = "0.3.7"
languageId = "17.0.5" languageId = "17.0.5"
lazysodiumAndroid = "5.1.0" lazysodiumAndroid = "5.1.0"
lifecycleRuntimeKtx = "2.7.0"
lightcompressor = "1.3.2" lightcompressor = "1.3.2"
markdown = "077a2cde64" markdown = "077a2cde64"
media3 = "1.3.1" media3 = "1.3.1"
@@ -59,10 +59,10 @@ androidx-fragment-ktx = { group = "androidx.fragment", name = "fragment-ktx", ve
androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation" } androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidxJunit" } androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidxJunit" }
androidx-junit-ktx = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "androidxJunit" } androidx-junit-ktx = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "androidxJunit" }
androidx-lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version.ref = "androidLifecycle" } androidx-lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "androidLifecycle" } androidx-lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "lifecycleRuntimeKtx" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "androidLifecycle" } androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "androidLifecycle" } androidx-lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycleRuntimeKtx" }
androidx-material-icons = { group = "androidx.compose.material", name = "material-icons-extended" } androidx-material-icons = { group = "androidx.compose.material", name = "material-icons-extended" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" } androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-material3-windowSize = { group = "androidx.compose.material3", name = "material3-window-size-class" } androidx-material3-windowSize = { group = "androidx.compose.material3", name = "material3-window-size-class" }
@@ -21,6 +21,7 @@
package com.vitorpamplona.quartz.events package com.vitorpamplona.quartz.events
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.encoders.ATag
import com.vitorpamplona.quartz.encoders.HexKey import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.signers.NostrSigner import com.vitorpamplona.quartz.signers.NostrSigner
import com.vitorpamplona.quartz.utils.TimeUtils import com.vitorpamplona.quartz.utils.TimeUtils
@@ -36,24 +37,68 @@ class FileServersEvent(
) : BaseAddressableEvent(id, pubKey, createdAt, KIND, tags, content, sig) { ) : BaseAddressableEvent(id, pubKey, createdAt, KIND, tags, content, sig) {
override fun dTag() = FIXED_D_TAG override fun dTag() = FIXED_D_TAG
fun servers(): List<String> {
return tags.mapNotNull {
if (it.size > 1 && it[0] == "relay") {
it[1]
} else {
null
}
}
}
companion object { companion object {
const val KIND = 10096 const val KIND = 10096
const val FIXED_D_TAG = "" const val FIXED_D_TAG = ""
const val ALT = "File servers used by the author" const val ALT = "File servers used by the author"
fun create( fun createAddressATag(pubKey: HexKey): ATag {
listOfServers: List<String>, return ATag(KIND, pubKey, FIXED_D_TAG, null)
}
fun createAddressTag(pubKey: HexKey): String {
return ATag.assembleATag(KIND, pubKey, FIXED_D_TAG)
}
fun createTagArray(servers: List<String>): Array<Array<String>> {
return servers.map {
arrayOf("server", it)
}.plusElement(arrayOf("alt", "Relay list to use for Search")).toTypedArray()
}
fun updateRelayList(
earlierVersion: FileServersEvent,
relays: List<String>,
signer: NostrSigner, signer: NostrSigner,
createdAt: Long = TimeUtils.now(), createdAt: Long = TimeUtils.now(),
onReady: (FileServersEvent) -> Unit, onReady: (FileServersEvent) -> Unit,
) { ) {
val msg = "" val tags =
val tags = mutableListOf<Array<String>>() earlierVersion.tags.filter { it[0] != "server" }.plus(
relays.map {
arrayOf("server", it)
},
).toTypedArray()
listOfServers.forEach { tags.add(arrayOf("server", it)) } signer.sign(createdAt, KIND, tags, earlierVersion.content, onReady)
tags.add(arrayOf("alt", ALT)) }
signer.sign(createdAt, KIND, tags.toTypedArray(), msg, onReady) fun createFromScratch(
relays: List<String>,
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
onReady: (FileServersEvent) -> Unit,
) {
create(relays, signer, createdAt, onReady)
}
fun create(
servers: List<String>,
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
onReady: (FileServersEvent) -> Unit,
) {
signer.sign(createdAt, KIND, createTagArray(servers), "", onReady)
} }
} }
} }