feat: add KeyPackage Relays section to AllRelayListScreen
Adds a new section after DM Relays that lets users manage the relays advertised in their MIP-00 KeyPackage Relay List (kind 10051). Mirrors the existing DM Relay pattern: state in KeyPackageRelayListState, backup in AccountSettings, and a ViewModel/view pair for the section. https://claude.ai/code/session_01B7kTUFAPvWarWd6fvQKNBy
This commit is contained in:
@@ -42,6 +42,7 @@ import com.vitorpamplona.amethyst.model.edits.PrivateStorageRelayListDecryptionC
|
||||
import com.vitorpamplona.amethyst.model.edits.PrivateStorageRelayListState
|
||||
import com.vitorpamplona.amethyst.model.localRelays.ForwardKind0ToLocalRelayState
|
||||
import com.vitorpamplona.amethyst.model.localRelays.LocalRelayListState
|
||||
import com.vitorpamplona.amethyst.model.marmot.KeyPackageRelayListState
|
||||
import com.vitorpamplona.amethyst.model.nip01UserMetadata.AccountHomeRelayState
|
||||
import com.vitorpamplona.amethyst.model.nip01UserMetadata.AccountOutboxRelayState
|
||||
import com.vitorpamplona.amethyst.model.nip01UserMetadata.NotificationInboxRelayState
|
||||
@@ -281,6 +282,8 @@ class Account(
|
||||
|
||||
val dmRelayList = DmRelayListState(signer, cache, scope, settings)
|
||||
|
||||
val keyPackageRelayList = KeyPackageRelayListState(signer, cache, scope, settings)
|
||||
|
||||
val privateStorageDecryptionCache = PrivateStorageRelayListDecryptionCache(signer)
|
||||
val privateStorageRelayList = PrivateStorageRelayListState(signer, cache, privateStorageDecryptionCache, scope, settings)
|
||||
|
||||
@@ -2471,6 +2474,8 @@ class Account(
|
||||
|
||||
suspend fun saveDMRelayList(dmRelays: List<NormalizedRelayUrl>) = sendLiterallyEverywhere(dmRelayList.saveRelayList(dmRelays))
|
||||
|
||||
suspend fun saveKeyPackageRelayList(keyPackageRelays: List<NormalizedRelayUrl>) = sendLiterallyEverywhere(keyPackageRelayList.saveRelayList(keyPackageRelays))
|
||||
|
||||
suspend fun savePrivateOutboxRelayList(relays: List<NormalizedRelayUrl>) = sendMyPublicAndPrivateOutbox(privateStorageRelayList.saveRelayList(relays))
|
||||
|
||||
suspend fun saveSearchRelayList(searchRelays: List<NormalizedRelayUrl>) = sendMyPublicAndPrivateOutbox(searchRelayList.saveRelayList(searchRelays))
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.vitorpamplona.amethyst.ui.actions.mediaServers.ServerName
|
||||
import com.vitorpamplona.amethyst.ui.screen.FeedDefinition
|
||||
import com.vitorpamplona.quartz.experimental.ephemChat.list.EphemeralChatListEvent
|
||||
import com.vitorpamplona.quartz.experimental.nipA3.PaymentTargetsEvent
|
||||
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageRelayListEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Address
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||
@@ -181,6 +182,7 @@ class AccountSettings(
|
||||
var backupUserMetadata: MetadataEvent? = null,
|
||||
var backupContactList: ContactListEvent? = null,
|
||||
var backupDMRelayList: ChatMessageRelayListEvent? = null,
|
||||
var backupKeyPackageRelayList: KeyPackageRelayListEvent? = null,
|
||||
var backupNIP65RelayList: AdvertisedRelayListEvent? = null,
|
||||
var backupSearchRelayList: SearchRelayListEvent? = null,
|
||||
var backupIndexRelayList: IndexerRelayListEvent? = null,
|
||||
@@ -594,6 +596,16 @@ class AccountSettings(
|
||||
}
|
||||
}
|
||||
|
||||
fun updateKeyPackageRelayList(newKeyPackageRelayList: KeyPackageRelayListEvent?) {
|
||||
if (newKeyPackageRelayList == null || newKeyPackageRelayList.tags.isEmpty()) return
|
||||
|
||||
// Events might be different objects, we have to compare their ids.
|
||||
if (backupKeyPackageRelayList?.id != newKeyPackageRelayList.id) {
|
||||
backupKeyPackageRelayList = newKeyPackageRelayList
|
||||
saveAccountSettings()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateNIP65RelayList(newNIP65RelayList: AdvertisedRelayListEvent?) {
|
||||
if (newNIP65RelayList == null || newNIP65RelayList.tags.isEmpty()) return
|
||||
|
||||
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.model.marmot
|
||||
|
||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||
import com.vitorpamplona.amethyst.model.LocalCache
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
import com.vitorpamplona.amethyst.model.NoteState
|
||||
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageRelayListEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class KeyPackageRelayListState(
|
||||
val signer: NostrSigner,
|
||||
val cache: LocalCache,
|
||||
val scope: CoroutineScope,
|
||||
val settings: AccountSettings,
|
||||
) {
|
||||
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||
val keyPackageListNote = cache.getOrCreateAddressableNote(getKeyPackageRelayListAddress())
|
||||
|
||||
fun getKeyPackageRelayListAddress() = KeyPackageRelayListEvent.createAddress(signer.pubKey)
|
||||
|
||||
fun getKeyPackageRelayListFlow(): StateFlow<NoteState> = keyPackageListNote.flow().metadata.stateFlow
|
||||
|
||||
fun getKeyPackageRelayList(): KeyPackageRelayListEvent? = keyPackageListNote.event as? KeyPackageRelayListEvent
|
||||
|
||||
fun normalizeKeyPackageRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
||||
val event = note.event as? KeyPackageRelayListEvent ?: settings.backupKeyPackageRelayList
|
||||
return event?.relays()?.toSet() ?: emptySet()
|
||||
}
|
||||
|
||||
val flow =
|
||||
getKeyPackageRelayListFlow()
|
||||
.map { normalizeKeyPackageRelayListWithBackup(it.note) }
|
||||
.onStart { emit(normalizeKeyPackageRelayListWithBackup(keyPackageListNote)) }
|
||||
.flowOn(Dispatchers.IO)
|
||||
.stateIn(
|
||||
scope,
|
||||
SharingStarted.Eagerly,
|
||||
emptySet(),
|
||||
)
|
||||
|
||||
suspend fun saveRelayList(relays: List<NormalizedRelayUrl>): KeyPackageRelayListEvent {
|
||||
val existing = getKeyPackageRelayList()
|
||||
return if (existing != null && existing.tags.isNotEmpty()) {
|
||||
KeyPackageRelayListEvent.updateRelayList(
|
||||
earlierVersion = existing,
|
||||
relays = relays,
|
||||
signer = signer,
|
||||
)
|
||||
} else {
|
||||
KeyPackageRelayListEvent.create(
|
||||
relays = relays,
|
||||
signer = signer,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
settings.backupKeyPackageRelayList?.let {
|
||||
Log.d("AccountRegisterObservers") { "Loading saved KeyPackage Relay List ${it.toJson()}" }
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
scope.launch(Dispatchers.IO) {
|
||||
cache.justConsumeMyOwnEvent(it)
|
||||
}
|
||||
}
|
||||
|
||||
scope.launch(Dispatchers.IO) {
|
||||
Log.d("AccountRegisterObservers", "MIP-00 KeyPackage Relay List Collector Start")
|
||||
getKeyPackageRelayListFlow().collect {
|
||||
Log.d("AccountRegisterObservers") { "Updating KeyPackage Relay List for ${signer.pubKey}" }
|
||||
(it.note.event as? KeyPackageRelayListEvent)?.let {
|
||||
settings.updateKeyPackageRelayList(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
-1
@@ -75,6 +75,8 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.feeds.RelayFeedsList
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.feeds.renderRelayFeedsItems
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.indexer.IndexerRelayListViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.indexer.renderIndexerItems
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.keyPackage.KeyPackageRelayListViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.keyPackage.renderKeyPackageItems
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.local.LocalRelayListViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.local.renderLocalItems
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.nip37.PrivateOutboxRelayListViewModel
|
||||
@@ -101,6 +103,7 @@ fun AllRelayListScreen(
|
||||
nav: INav,
|
||||
) {
|
||||
val dmViewModel: DMRelayListViewModel = viewModel()
|
||||
val keyPackageViewModel: KeyPackageRelayListViewModel = viewModel()
|
||||
val nip65ViewModel: Nip65RelayListViewModel = viewModel()
|
||||
val privateOutboxViewModel: PrivateOutboxRelayListViewModel = viewModel()
|
||||
val searchViewModel: SearchRelayListViewModel = viewModel()
|
||||
@@ -114,6 +117,7 @@ fun AllRelayListScreen(
|
||||
val relayFeedsViewModel: RelayFeedsListViewModel = viewModel()
|
||||
|
||||
dmViewModel.init(accountViewModel)
|
||||
keyPackageViewModel.init(accountViewModel)
|
||||
nip65ViewModel.init(accountViewModel)
|
||||
searchViewModel.init(accountViewModel)
|
||||
localViewModel.init(accountViewModel)
|
||||
@@ -128,6 +132,7 @@ fun AllRelayListScreen(
|
||||
|
||||
LaunchedEffect(accountViewModel) {
|
||||
dmViewModel.load()
|
||||
keyPackageViewModel.load()
|
||||
nip65ViewModel.load()
|
||||
searchViewModel.load()
|
||||
localViewModel.load()
|
||||
@@ -143,6 +148,7 @@ fun AllRelayListScreen(
|
||||
|
||||
MappedAllRelayListView(
|
||||
dmViewModel,
|
||||
keyPackageViewModel,
|
||||
nip65ViewModel,
|
||||
searchViewModel,
|
||||
localViewModel,
|
||||
@@ -163,6 +169,7 @@ fun AllRelayListScreen(
|
||||
@Composable
|
||||
fun MappedAllRelayListView(
|
||||
dmViewModel: DMRelayListViewModel,
|
||||
keyPackageViewModel: KeyPackageRelayListViewModel,
|
||||
nip65ViewModel: Nip65RelayListViewModel,
|
||||
searchViewModel: SearchRelayListViewModel,
|
||||
localViewModel: LocalRelayListViewModel,
|
||||
@@ -178,6 +185,7 @@ fun MappedAllRelayListView(
|
||||
nav: INav,
|
||||
) {
|
||||
val dmFeedState by dmViewModel.relays.collectAsStateWithLifecycle()
|
||||
val keyPackageFeedState by keyPackageViewModel.relays.collectAsStateWithLifecycle()
|
||||
val homeFeedState by nip65ViewModel.homeRelays.collectAsStateWithLifecycle()
|
||||
val notifFeedState by nip65ViewModel.notificationRelays.collectAsStateWithLifecycle()
|
||||
val privateOutboxFeedState by privateOutboxViewModel.relays.collectAsStateWithLifecycle()
|
||||
@@ -194,6 +202,7 @@ fun MappedAllRelayListView(
|
||||
val outboxCounts by nip65ViewModel.homeCountResults.collectAsStateWithLifecycle()
|
||||
val inboxCounts by nip65ViewModel.notifCountResults.collectAsStateWithLifecycle()
|
||||
val dmCounts by dmViewModel.countResults.collectAsStateWithLifecycle()
|
||||
val keyPackageCounts by keyPackageViewModel.countResults.collectAsStateWithLifecycle()
|
||||
val privateHomeCounts by privateOutboxViewModel.countResults.collectAsStateWithLifecycle()
|
||||
val proxyCounts by proxyViewModel.countResults.collectAsStateWithLifecycle()
|
||||
val indexerCounts by indexerViewModel.countResults.collectAsStateWithLifecycle()
|
||||
@@ -214,6 +223,11 @@ fun MappedAllRelayListView(
|
||||
onMove = { from, to -> dmViewModel.moveRelay(from, to) },
|
||||
itemCount = { dmFeedState.size },
|
||||
)
|
||||
val keyPackageDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> keyPackageViewModel.moveRelay(from, to) },
|
||||
itemCount = { keyPackageFeedState.size },
|
||||
)
|
||||
val privateOutboxDragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> privateOutboxViewModel.moveRelay(from, to) },
|
||||
@@ -284,6 +298,7 @@ fun MappedAllRelayListView(
|
||||
},
|
||||
onCancel = {
|
||||
dmViewModel.clear()
|
||||
keyPackageViewModel.clear()
|
||||
nip65ViewModel.clear()
|
||||
searchViewModel.clear()
|
||||
localViewModel.clear()
|
||||
@@ -298,6 +313,7 @@ fun MappedAllRelayListView(
|
||||
},
|
||||
onPost = {
|
||||
dmViewModel.create()
|
||||
keyPackageViewModel.create()
|
||||
nip65ViewModel.create()
|
||||
searchViewModel.create()
|
||||
localViewModel.create()
|
||||
@@ -315,7 +331,8 @@ fun MappedAllRelayListView(
|
||||
) { pad ->
|
||||
val anyDragging =
|
||||
homeDragState.isDragging || notifDragState.isDragging ||
|
||||
dmDragState.isDragging || privateOutboxDragState.isDragging ||
|
||||
dmDragState.isDragging || keyPackageDragState.isDragging ||
|
||||
privateOutboxDragState.isDragging ||
|
||||
proxyDragState.isDragging || broadcastDragState.isDragging ||
|
||||
indexerDragState.isDragging || searchDragState.isDragging ||
|
||||
localDragState.isDragging || trustedDragState.isDragging ||
|
||||
@@ -363,6 +380,15 @@ fun MappedAllRelayListView(
|
||||
}
|
||||
renderDMItems(dmFeedState, dmViewModel, accountViewModel, nav, dmCounts, dmDragState)
|
||||
|
||||
item {
|
||||
SettingsCategory(
|
||||
R.string.keypackage_section,
|
||||
R.string.keypackage_section_explainer,
|
||||
SettingsCategorySpacingWithHorzBorderModifier,
|
||||
)
|
||||
}
|
||||
renderKeyPackageItems(keyPackageFeedState, keyPackageViewModel, accountViewModel, nav, keyPackageCounts, keyPackageDragState)
|
||||
|
||||
item {
|
||||
SettingsCategory(
|
||||
R.string.private_outbox_section,
|
||||
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.keyPackage
|
||||
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListScope
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.vitorpamplona.amethyst.Amethyst
|
||||
import com.vitorpamplona.amethyst.ui.navigation.navs.INav
|
||||
import com.vitorpamplona.amethyst.ui.navigation.navs.rememberExtendedNav
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayUrlEditField
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.relaySetupInfoBuilder
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.rememberRelayDragState
|
||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.HorzHalfVertPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.HorzPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
|
||||
@Composable
|
||||
fun KeyPackageRelayList(
|
||||
postViewModel: KeyPackageRelayListViewModel,
|
||||
accountViewModel: AccountViewModel,
|
||||
onClose: () -> Unit,
|
||||
nav: INav,
|
||||
) {
|
||||
val feedState by postViewModel.relays.collectAsStateWithLifecycle()
|
||||
val newNav = rememberExtendedNav(nav, onClose)
|
||||
val dragState =
|
||||
rememberRelayDragState(
|
||||
onMove = { from, to -> postViewModel.moveRelay(from, to) },
|
||||
itemCount = { feedState.size },
|
||||
)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LazyColumn(
|
||||
contentPadding = FeedPadding,
|
||||
userScrollEnabled = !dragState.isDragging,
|
||||
) {
|
||||
renderKeyPackageItems(feedState, postViewModel, accountViewModel, newNav, dragState = dragState)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun LazyListScope.renderKeyPackageItems(
|
||||
feedState: List<BasicRelaySetupInfo>,
|
||||
postViewModel: KeyPackageRelayListViewModel,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
countResults: Map<NormalizedRelayUrl, RelayCountResult> = emptyMap(),
|
||||
dragState: RelayDragState? = null,
|
||||
) {
|
||||
itemsIndexed(feedState, key = { _, item -> "KeyPackage" + item.relay.url }) { index, item ->
|
||||
BasicRelaySetupInfoDialog(
|
||||
item,
|
||||
onDelete = { postViewModel.deleteRelay(item) },
|
||||
nip11CachedRetriever = Amethyst.instance.nip11Cache,
|
||||
modifier = HorzHalfVertPadding,
|
||||
countResult = countResults[item.relay],
|
||||
index = index,
|
||||
dragState = dragState,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
Spacer(modifier = StdVertSpacer)
|
||||
RelayUrlEditField(
|
||||
onNewRelay = { postViewModel.addRelay(relaySetupInfoBuilder(it)) },
|
||||
modifier = HorzPadding,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.keyPackage
|
||||
|
||||
import androidx.compose.runtime.Stable
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfoModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.CountFilter
|
||||
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
|
||||
@Stable
|
||||
class KeyPackageRelayListViewModel : BasicRelaySetupInfoModel() {
|
||||
override fun getRelayList(): List<NormalizedRelayUrl>? = account.keyPackageRelayList.getKeyPackageRelayList()?.relays()
|
||||
|
||||
override suspend fun saveRelayList(urlList: List<NormalizedRelayUrl>) {
|
||||
account.saveKeyPackageRelayList(urlList)
|
||||
}
|
||||
|
||||
override fun countFilters(relayUrl: NormalizedRelayUrl): List<CountFilter> =
|
||||
listOf(
|
||||
CountFilter(
|
||||
label = R.string.keypackage_section,
|
||||
filter =
|
||||
Filter(
|
||||
kinds = listOf(KeyPackageEvent.KIND),
|
||||
authors = listOf(account.pubKey),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -1562,6 +1562,8 @@
|
||||
<string name="private_inbox_section">DM Inbox Relays</string>
|
||||
<string name="private_inbox_section_explainer_profile">User receives DMs on these relays</string>
|
||||
<string name="private_inbox_section_explainer">Insert between 1–3 relays to serve as your private inbox. Others will use these relays to send DMs to you. DM Inbox relays should accept any message from anyone, but only allow you to download them. Good options are:\n - inbox.nostr.wine (paid)\n - auth.nostr1.com (free)\n - you.nostr1.com (personal relays - paid)</string>
|
||||
<string name="keypackage_section">KeyPackage Relays</string>
|
||||
<string name="keypackage_section_explainer">Relays where your MLS KeyPackages are published (MIP-00). Other users fetch these KeyPackages to invite you into Marmot group chats. Insert between 1–3 relays that accept KeyPackage events from you and allow public reads.</string>
|
||||
<string name="private_outbox_section">Private Home Relays</string>
|
||||
<string name="private_outbox_section_explainer">Insert between 1–3 relays to store events no one else can see, like your Drafts and/or app settings. Ideally, these relays are either local or require authentication before downloading each user\'s content.</string>
|
||||
<string name="kind_3_section">General Relays</string>
|
||||
|
||||
+15
@@ -69,6 +69,21 @@ class KeyPackageRelayListEvent(
|
||||
signer: NostrSigner,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
): KeyPackageRelayListEvent = signer.sign(createdAt, KIND, createTagArray(relays), "")
|
||||
|
||||
suspend fun updateRelayList(
|
||||
earlierVersion: KeyPackageRelayListEvent,
|
||||
relays: List<NormalizedRelayUrl>,
|
||||
signer: NostrSigner,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
): KeyPackageRelayListEvent {
|
||||
val tags =
|
||||
earlierVersion.tags
|
||||
.filter { it.isEmpty() || it[0] != RelayTag.TAG_NAME }
|
||||
.plus(relays.map { RelayTag.assemble(it) })
|
||||
.toTypedArray()
|
||||
|
||||
return signer.sign(createdAt, KIND, tags, earlierVersion.content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user