Improves vanishing tests
This commit is contained in:
+23
-21
@@ -65,6 +65,8 @@ import com.vitorpamplona.amethyst.ui.navigation.topbars.TopBarWithBackButton
|
|||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.stringRes
|
import com.vitorpamplona.amethyst.ui.stringRes
|
||||||
import com.vitorpamplona.amethyst.ui.theme.DividerThickness
|
import com.vitorpamplona.amethyst.ui.theme.DividerThickness
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.displayUrl
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
@@ -79,7 +81,6 @@ fun VanishEventsScreen(
|
|||||||
|
|
||||||
val vanishEvents by viewModel.vanishEvents.collectAsStateWithLifecycle()
|
val vanishEvents by viewModel.vanishEvents.collectAsStateWithLifecycle()
|
||||||
val isLoading by viewModel.isLoading.collectAsStateWithLifecycle()
|
val isLoading by viewModel.isLoading.collectAsStateWithLifecycle()
|
||||||
val complianceResults by viewModel.complianceResults.collectAsStateWithLifecycle()
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
viewModel.load()
|
viewModel.load()
|
||||||
@@ -143,9 +144,8 @@ fun VanishEventsScreen(
|
|||||||
items(vanishEvents, key = { it.event.id }) { item ->
|
items(vanishEvents, key = { it.event.id }) { item ->
|
||||||
VanishEventCard(
|
VanishEventCard(
|
||||||
item = item,
|
item = item,
|
||||||
complianceResults = complianceResults,
|
onTestCompliance = { relay ->
|
||||||
onTestCompliance = { relayUrl, date ->
|
viewModel.testCompliance(item, relay)
|
||||||
viewModel.testCompliance(relayUrl, date)
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -160,8 +160,7 @@ fun VanishEventsScreen(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun VanishEventCard(
|
private fun VanishEventCard(
|
||||||
item: VanishEventItem,
|
item: VanishEventItem,
|
||||||
complianceResults: Map<String, ComplianceStatus>,
|
onTestCompliance: (NormalizedRelayUrl) -> Unit,
|
||||||
onTestCompliance: (String, Long) -> Unit,
|
|
||||||
) {
|
) {
|
||||||
Card(
|
Card(
|
||||||
modifier =
|
modifier =
|
||||||
@@ -230,14 +229,7 @@ private fun VanishEventCard(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
|
|
||||||
item.relays.forEach { relayUrl ->
|
RenderRelaysWithComplianceResults(item, onTestCompliance)
|
||||||
RelayComplianceRow(
|
|
||||||
relayUrl = relayUrl,
|
|
||||||
vanishDate = item.event.createdAt,
|
|
||||||
status = complianceResults["$relayUrl:${item.event.createdAt}"] ?: ComplianceStatus.UNTESTED,
|
|
||||||
onTest = { onTestCompliance(relayUrl, item.event.createdAt) },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.event.content.isNotBlank()) {
|
if (item.event.content.isNotBlank()) {
|
||||||
@@ -256,10 +248,24 @@ private fun VanishEventCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun RenderRelaysWithComplianceResults(
|
||||||
|
item: VanishEventItem,
|
||||||
|
onTestCompliance: (NormalizedRelayUrl) -> Unit,
|
||||||
|
) {
|
||||||
|
val complianceResults by item.complianceResults.collectAsStateWithLifecycle()
|
||||||
|
item.relays.forEach { relay ->
|
||||||
|
RelayComplianceRow(
|
||||||
|
relay = relay,
|
||||||
|
status = complianceResults[relay] ?: ComplianceStatus.UNTESTED,
|
||||||
|
onTest = { onTestCompliance(relay) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun RelayComplianceRow(
|
private fun RelayComplianceRow(
|
||||||
relayUrl: String,
|
relay: NormalizedRelayUrl,
|
||||||
vanishDate: Long,
|
|
||||||
status: ComplianceStatus,
|
status: ComplianceStatus,
|
||||||
onTest: () -> Unit,
|
onTest: () -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -271,11 +277,7 @@ private fun RelayComplianceRow(
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text =
|
text = relay.displayUrl(),
|
||||||
relayUrl
|
|
||||||
.removePrefix("wss://")
|
|
||||||
.removePrefix("ws://")
|
|
||||||
.removeSuffix("/"),
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
|
|||||||
+29
-23
@@ -27,18 +27,23 @@ import com.vitorpamplona.amethyst.model.Account
|
|||||||
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.downloadFirstEvent
|
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.downloadFirstEvent
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.query
|
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.query
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
import com.vitorpamplona.quartz.nip62RequestToVanish.RequestToVanishEvent
|
import com.vitorpamplona.quartz.nip62RequestToVanish.RequestToVanishEvent
|
||||||
import com.vitorpamplona.quartz.nip62RequestToVanish.tags.RelayTag
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
data class VanishEventItem(
|
data class VanishEventItem(
|
||||||
val event: RequestToVanishEvent,
|
val event: RequestToVanishEvent,
|
||||||
val relays: List<String>,
|
val relays: List<NormalizedRelayUrl>,
|
||||||
val isAllRelays: Boolean,
|
val isAllRelays: Boolean,
|
||||||
|
val complianceResults: MutableStateFlow<Map<NormalizedRelayUrl, ComplianceStatus>> =
|
||||||
|
MutableStateFlow(
|
||||||
|
relays.associateWith { ComplianceStatus.UNTESTED },
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
enum class ComplianceStatus {
|
enum class ComplianceStatus {
|
||||||
@@ -58,14 +63,10 @@ class VanishEventsViewModel : ViewModel() {
|
|||||||
private val _isLoading = MutableStateFlow(false)
|
private val _isLoading = MutableStateFlow(false)
|
||||||
val isLoading = _isLoading.asStateFlow()
|
val isLoading = _isLoading.asStateFlow()
|
||||||
|
|
||||||
private val _complianceResults = MutableStateFlow<Map<String, ComplianceStatus>>(emptyMap())
|
|
||||||
val complianceResults = _complianceResults.asStateFlow()
|
|
||||||
|
|
||||||
fun load() {
|
fun load() {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
_isLoading.value = true
|
_isLoading.value = true
|
||||||
_vanishEvents.value = emptyList()
|
_vanishEvents.value = emptyList()
|
||||||
_complianceResults.value = emptyMap()
|
|
||||||
|
|
||||||
val connectedRelays = account.client.connectedRelaysFlow().value
|
val connectedRelays = account.client.connectedRelaysFlow().value
|
||||||
if (connectedRelays.isEmpty()) {
|
if (connectedRelays.isEmpty()) {
|
||||||
@@ -86,7 +87,7 @@ class VanishEventsViewModel : ViewModel() {
|
|||||||
account.client.query(filters = filtersPerRelay).mapNotNull { event ->
|
account.client.query(filters = filtersPerRelay).mapNotNull { event ->
|
||||||
if (event is RequestToVanishEvent) {
|
if (event is RequestToVanishEvent) {
|
||||||
val relayTags = event.vanishFromRelays()
|
val relayTags = event.vanishFromRelays()
|
||||||
val isAll = relayTags.contains(RelayTag.EVERYWHERE)
|
val isAll = event.vanishFromAllRelays()
|
||||||
VanishEventItem(
|
VanishEventItem(
|
||||||
event = event,
|
event = event,
|
||||||
relays = relayTags,
|
relays = relayTags,
|
||||||
@@ -102,35 +103,40 @@ class VanishEventsViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testCompliance(
|
fun testCompliance(
|
||||||
relayUrl: String,
|
item: VanishEventItem,
|
||||||
vanishDate: Long,
|
relay: NormalizedRelayUrl,
|
||||||
) {
|
) {
|
||||||
val key = "$relayUrl:$vanishDate"
|
item.complianceResults.update {
|
||||||
_complianceResults.value = _complianceResults.value + (key to ComplianceStatus.TESTING)
|
it + (relay to ComplianceStatus.TESTING)
|
||||||
|
}
|
||||||
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val foundEvent =
|
val foundEvent =
|
||||||
account.client.downloadFirstEvent(
|
account.client.downloadFirstEvent(
|
||||||
relay = relayUrl,
|
relay = relay,
|
||||||
filter =
|
filter =
|
||||||
Filter(
|
Filter(
|
||||||
authors = listOf(account.pubKey),
|
authors = listOf(item.event.pubKey),
|
||||||
until = vanishDate - 1,
|
until = item.event.createdAt - 1,
|
||||||
limit = 1,
|
limit = 1,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
_complianceResults.value += (
|
item.complianceResults.update {
|
||||||
key to
|
it + (
|
||||||
if (foundEvent != null) {
|
relay to
|
||||||
ComplianceStatus.NON_COMPLIANT
|
if (foundEvent != null) {
|
||||||
} else {
|
ComplianceStatus.NON_COMPLIANT
|
||||||
ComplianceStatus.COMPLIANT
|
} else {
|
||||||
}
|
ComplianceStatus.COMPLIANT
|
||||||
)
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
_complianceResults.value += (key to ComplianceStatus.ERROR)
|
item.complianceResults.update {
|
||||||
|
it + (relay to ComplianceStatus.ERROR)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -23,14 +23,16 @@ package com.vitorpamplona.quartz.nip01Core.store.sqlite
|
|||||||
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
|
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.normalizeRelayUrl
|
||||||
import com.vitorpamplona.quartz.nip01Core.store.IEventStore
|
import com.vitorpamplona.quartz.nip01Core.store.IEventStore
|
||||||
|
|
||||||
class EventStore(
|
class EventStore(
|
||||||
dbName: String? = "events.db",
|
dbName: String? = "events.db",
|
||||||
relayUrl: String? = "wss://quartz.local",
|
relay: NormalizedRelayUrl? = "wss://quartz.local/".normalizeRelayUrl(),
|
||||||
val indexStrategy: IndexingStrategy = DefaultIndexingStrategy(),
|
val indexStrategy: IndexingStrategy = DefaultIndexingStrategy(),
|
||||||
) : IEventStore {
|
) : IEventStore {
|
||||||
val store = SQLiteEventStore(BundledSQLiteDriver(), dbName, relayUrl, indexStrategy)
|
val store = SQLiteEventStore(BundledSQLiteDriver(), dbName, relay, indexStrategy)
|
||||||
|
|
||||||
override fun insert(event: Event) = store.insertEvent(event)
|
override fun insert(event: Event) = store.insertEvent(event)
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -22,6 +22,7 @@ package com.vitorpamplona.quartz.nip01Core.store.sqlite
|
|||||||
|
|
||||||
import androidx.sqlite.SQLiteConnection
|
import androidx.sqlite.SQLiteConnection
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
import com.vitorpamplona.quartz.nip62RequestToVanish.RequestToVanishEvent
|
import com.vitorpamplona.quartz.nip62RequestToVanish.RequestToVanishEvent
|
||||||
|
|
||||||
class RightToVanishModule(
|
class RightToVanishModule(
|
||||||
@@ -100,11 +101,11 @@ class RightToVanishModule(
|
|||||||
|
|
||||||
fun insert(
|
fun insert(
|
||||||
event: Event,
|
event: Event,
|
||||||
relayUrl: String?,
|
relay: NormalizedRelayUrl?,
|
||||||
headerId: Long,
|
headerId: Long,
|
||||||
db: SQLiteConnection,
|
db: SQLiteConnection,
|
||||||
) {
|
) {
|
||||||
if (event is RequestToVanishEvent && event.shouldVanishFrom(relayUrl)) {
|
if (event is RequestToVanishEvent && event.shouldVanishFrom(relay)) {
|
||||||
db.prepare(insertRTV).use { stmt ->
|
db.prepare(insertRTV).use { stmt ->
|
||||||
stmt.bindLong(1, headerId)
|
stmt.bindLong(1, headerId)
|
||||||
stmt.bindLong(2, hasher(db).hash(event.pubKey))
|
stmt.bindLong(2, hasher(db).hash(event.pubKey))
|
||||||
|
|||||||
+3
-2
@@ -30,6 +30,7 @@ import com.vitorpamplona.quartz.nip01Core.core.Kind
|
|||||||
import com.vitorpamplona.quartz.nip01Core.core.OptimizedJsonMapper
|
import com.vitorpamplona.quartz.nip01Core.core.OptimizedJsonMapper
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.isEphemeral
|
import com.vitorpamplona.quartz.nip01Core.core.isEphemeral
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
import com.vitorpamplona.quartz.nip01Core.store.IEventStore
|
import com.vitorpamplona.quartz.nip01Core.store.IEventStore
|
||||||
import com.vitorpamplona.quartz.nip40Expiration.isExpired
|
import com.vitorpamplona.quartz.nip40Expiration.isExpired
|
||||||
import com.vitorpamplona.quartz.utils.EventFactory
|
import com.vitorpamplona.quartz.utils.EventFactory
|
||||||
@@ -40,7 +41,7 @@ import kotlinx.coroutines.withContext
|
|||||||
class SQLiteEventStore(
|
class SQLiteEventStore(
|
||||||
val driver: SQLiteDriver = BundledSQLiteDriver(),
|
val driver: SQLiteDriver = BundledSQLiteDriver(),
|
||||||
val dbName: String? = "events.db",
|
val dbName: String? = "events.db",
|
||||||
val relayUrl: String? = null,
|
val relay: NormalizedRelayUrl? = null,
|
||||||
val indexStrategy: IndexingStrategy = DefaultIndexingStrategy(),
|
val indexStrategy: IndexingStrategy = DefaultIndexingStrategy(),
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -182,7 +183,7 @@ class SQLiteEventStore(
|
|||||||
deletionModule.insert(event, db)
|
deletionModule.insert(event, db)
|
||||||
expirationModule.insert(event, headerId, db)
|
expirationModule.insert(event, headerId, db)
|
||||||
fullTextSearchModule.insert(event, headerId, db)
|
fullTextSearchModule.insert(event, headerId, db)
|
||||||
rightToVanishModule.insert(event, relayUrl, headerId, db)
|
rightToVanishModule.insert(event, relay, headerId, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun insertEvent(event: Event) {
|
fun insertEvent(event: Event) {
|
||||||
|
|||||||
+4
-1
@@ -28,6 +28,7 @@ import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
|||||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||||
import com.vitorpamplona.quartz.nip62RequestToVanish.tags.shouldVanishFrom
|
import com.vitorpamplona.quartz.nip62RequestToVanish.tags.shouldVanishFrom
|
||||||
import com.vitorpamplona.quartz.nip62RequestToVanish.tags.vanishFrom
|
import com.vitorpamplona.quartz.nip62RequestToVanish.tags.vanishFrom
|
||||||
|
import com.vitorpamplona.quartz.nip62RequestToVanish.tags.vanishFromAllRelays
|
||||||
import com.vitorpamplona.quartz.nip62RequestToVanish.tags.vanishFromEverywhere
|
import com.vitorpamplona.quartz.nip62RequestToVanish.tags.vanishFromEverywhere
|
||||||
import com.vitorpamplona.quartz.nip62RequestToVanish.tags.vanishFromRelays
|
import com.vitorpamplona.quartz.nip62RequestToVanish.tags.vanishFromRelays
|
||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
@@ -42,7 +43,9 @@ class RequestToVanishEvent(
|
|||||||
) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
|
) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
|
||||||
fun vanishFromRelays() = tags.vanishFromRelays()
|
fun vanishFromRelays() = tags.vanishFromRelays()
|
||||||
|
|
||||||
fun shouldVanishFrom(relayUrl: String?) = tags.shouldVanishFrom(relayUrl)
|
fun vanishFromAllRelays() = tags.vanishFromAllRelays()
|
||||||
|
|
||||||
|
fun shouldVanishFrom(relay: NormalizedRelayUrl?) = tags.shouldVanishFrom(relay)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val KIND = 62
|
const val KIND = 62
|
||||||
|
|||||||
+13
-4
@@ -22,6 +22,8 @@ package com.vitorpamplona.quartz.nip62RequestToVanish.tags
|
|||||||
|
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.has
|
import com.vitorpamplona.quartz.nip01Core.core.has
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.isLocalHost
|
||||||
import com.vitorpamplona.quartz.utils.ensure
|
import com.vitorpamplona.quartz.utils.ensure
|
||||||
|
|
||||||
class RelayTag {
|
class RelayTag {
|
||||||
@@ -33,16 +35,23 @@ class RelayTag {
|
|||||||
|
|
||||||
fun notMatch(tag: Array<String>) = !(tag.has(0) && tag[0] == TAG_NAME)
|
fun notMatch(tag: Array<String>) = !(tag.has(0) && tag[0] == TAG_NAME)
|
||||||
|
|
||||||
|
fun shouldVanishFromEverywhere(tag: Array<String>) = tag.has(1) && tag[0] == TAG_NAME && tag[1] == EVERYWHERE
|
||||||
|
|
||||||
fun shouldVanishFrom(
|
fun shouldVanishFrom(
|
||||||
tag: Array<String>,
|
tag: Array<String>,
|
||||||
relayUrl: String?,
|
relay: NormalizedRelayUrl,
|
||||||
) = tag.has(1) && tag[0] == TAG_NAME && (tag[1] == relayUrl || tag[1] == EVERYWHERE)
|
) = tag.has(1) && tag[0] == TAG_NAME && (tag[1] == relay.url || tag[1] == EVERYWHERE)
|
||||||
|
|
||||||
fun parse(tag: Array<String>): String? {
|
fun parse(tag: Array<String>): NormalizedRelayUrl? {
|
||||||
ensure(tag.has(1)) { return null }
|
ensure(tag.has(1)) { return null }
|
||||||
ensure(tag[0] == TAG_NAME) { return null }
|
ensure(tag[0] == TAG_NAME) { return null }
|
||||||
ensure(tag[1].isNotEmpty()) { return null }
|
ensure(tag[1].isNotEmpty()) { return null }
|
||||||
return tag[1]
|
|
||||||
|
val relay = RelayUrlNormalizer.normalizeOrNull(tag[1])
|
||||||
|
|
||||||
|
ensure(relay != null && !relay.isLocalHost()) { return null }
|
||||||
|
|
||||||
|
return relay
|
||||||
}
|
}
|
||||||
|
|
||||||
fun assemble(relay: NormalizedRelayUrl) = arrayOf(TAG_NAME, relay.url)
|
fun assemble(relay: NormalizedRelayUrl) = arrayOf(TAG_NAME, relay.url)
|
||||||
|
|||||||
+9
-1
@@ -22,7 +22,15 @@ package com.vitorpamplona.quartz.nip62RequestToVanish.tags
|
|||||||
|
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.TagArray
|
import com.vitorpamplona.quartz.nip01Core.core.TagArray
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.any
|
import com.vitorpamplona.quartz.nip01Core.core.any
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
|
|
||||||
fun TagArray.vanishFromRelays() = mapNotNull(RelayTag::parse)
|
fun TagArray.vanishFromRelays() = mapNotNull(RelayTag::parse)
|
||||||
|
|
||||||
fun TagArray.shouldVanishFrom(relayUrl: String?) = any(RelayTag::shouldVanishFrom, relayUrl)
|
fun TagArray.vanishFromAllRelays() = any(RelayTag::shouldVanishFromEverywhere)
|
||||||
|
|
||||||
|
fun TagArray.shouldVanishFrom(relay: NormalizedRelayUrl?): Boolean =
|
||||||
|
if (relay != null) {
|
||||||
|
any(RelayTag::shouldVanishFrom, relay)
|
||||||
|
} else {
|
||||||
|
any(RelayTag::shouldVanishFromEverywhere)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user