feat(dvm-favorites): timeout, tests, and merged "All favourite DVMs" chip
1. DVM response timeout. FavoriteDvmOrchestrator now times out after 20s if neither a 6300 response nor any 7000 status arrives, and sets errorMessage = "timeout" on the snapshot so the home banner switches from the "Asking…" spinner to a Retry button instead of hanging forever. 2. Tests. FavoriteDvmListEventTest covers create/add/remove round trips and the fixed-empty d-tag invariant; FavoriteDvmTopNavFilter match by id and by `a` address; FilterHomePostsByDvmIdsTest covers the two-relay-set split (content fetch on user relays, listen on DVM relays) and the multi-requestId merge case. Also registered kind 10090 in EventFactory so Quartz can deserialise FavoriteDvmListEvent (required for the round-trip tests and for reading the list back from relays). 3. Merged "All favourite DVMs" chip. New TopFilter.AllFavoriteDvms that unions every favourite's latest 6300 response into one feed. AllFavoriteDvmsFeedFlow uses flatMapLatest over the favourite-list flow so subscriptions rewire when the user adds/removes a DVM. FavoriteDvmTopNavPerRelayFilterSet now carries Set<HexKey> requestIds (was a single nullable) so the filter can subscribe to N kind 6300/7000 streams in one REQ per DVM relay. Banner renders "Asking your favourite DVMs for feeds…" while all are pending and a single Retry-all on collective error; pull-to-refresh re-issues every DVM's kind-5300.
This commit is contained in:
@@ -427,6 +427,7 @@ class Account(
|
|||||||
signer = signer,
|
signer = signer,
|
||||||
scope = scope,
|
scope = scope,
|
||||||
favoriteDvmOrchestrator = favoriteDvmOrchestrator,
|
favoriteDvmOrchestrator = favoriteDvmOrchestrator,
|
||||||
|
favoriteDvmAddresses = favoriteDvmList.flow,
|
||||||
).flow
|
).flow
|
||||||
|
|
||||||
// App-ready Feeds
|
// App-ready Feeds
|
||||||
|
|||||||
@@ -160,6 +160,8 @@ sealed class TopFilter(
|
|||||||
class FavoriteDvm(
|
class FavoriteDvm(
|
||||||
val address: Address,
|
val address: Address,
|
||||||
) : TopFilter("FavoriteDvm/${address.toValue()}")
|
) : TopFilter("FavoriteDvm/${address.toValue()}")
|
||||||
|
|
||||||
|
@Serializable object AllFavoriteDvms : TopFilter(" All Favourite DVMs ")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
|
|||||||
+20
@@ -32,6 +32,7 @@ import kotlinx.coroutines.CancellationException
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
@@ -41,6 +42,8 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
|
||||||
|
private const val RESPONSE_TIMEOUT_MS = 20_000L
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immutable snapshot of a favourite DVM's current request/response state.
|
* Immutable snapshot of a favourite DVM's current request/response state.
|
||||||
*
|
*
|
||||||
@@ -166,6 +169,23 @@ class FavoriteDvmOrchestrator(
|
|||||||
seed.update { it.copy(latestStatus = status) }
|
seed.update { it.copy(latestStatus = status) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If nothing arrives within RESPONSE_TIMEOUT_MS (neither a 6300
|
||||||
|
// response nor any 7000 status), surface an error so the banner
|
||||||
|
// can show Retry instead of spinning forever.
|
||||||
|
launch {
|
||||||
|
delay(RESPONSE_TIMEOUT_MS)
|
||||||
|
val current = seed.value
|
||||||
|
val stillWaiting =
|
||||||
|
current.requestId == requestId &&
|
||||||
|
current.ids.isEmpty() &&
|
||||||
|
current.addresses.isEmpty() &&
|
||||||
|
current.latestStatus == null &&
|
||||||
|
current.errorMessage == null
|
||||||
|
if (stillWaiting) {
|
||||||
|
seed.update { it.copy(errorMessage = "timeout") }
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (e is CancellationException) throw e
|
if (e is CancellationException) throw e
|
||||||
Log.w("FavoriteDvmOrchestrator", "Failed to start DVM request: ${e.message}", e)
|
Log.w("FavoriteDvmOrchestrator", "Failed to start DVM request: ${e.message}", e)
|
||||||
|
|||||||
+12
@@ -31,12 +31,14 @@ import com.vitorpamplona.amethyst.model.topNavFeeds.allUserFollows.Kind3UserFoll
|
|||||||
import com.vitorpamplona.amethyst.model.topNavFeeds.aroundMe.AroundMeFeedFlow
|
import com.vitorpamplona.amethyst.model.topNavFeeds.aroundMe.AroundMeFeedFlow
|
||||||
import com.vitorpamplona.amethyst.model.topNavFeeds.aroundMe.GeohashFeedFlow
|
import com.vitorpamplona.amethyst.model.topNavFeeds.aroundMe.GeohashFeedFlow
|
||||||
import com.vitorpamplona.amethyst.model.topNavFeeds.chess.ChessFeedFlow
|
import com.vitorpamplona.amethyst.model.topNavFeeds.chess.ChessFeedFlow
|
||||||
|
import com.vitorpamplona.amethyst.model.topNavFeeds.favoriteDvm.AllFavoriteDvmsFeedFlow
|
||||||
import com.vitorpamplona.amethyst.model.topNavFeeds.favoriteDvm.FavoriteDvmFeedFlow
|
import com.vitorpamplona.amethyst.model.topNavFeeds.favoriteDvm.FavoriteDvmFeedFlow
|
||||||
import com.vitorpamplona.amethyst.model.topNavFeeds.global.GlobalFeedFlow
|
import com.vitorpamplona.amethyst.model.topNavFeeds.global.GlobalFeedFlow
|
||||||
import com.vitorpamplona.amethyst.model.topNavFeeds.hashtag.HashtagFeedFlow
|
import com.vitorpamplona.amethyst.model.topNavFeeds.hashtag.HashtagFeedFlow
|
||||||
import com.vitorpamplona.amethyst.model.topNavFeeds.noteBased.NoteFeedFlow
|
import com.vitorpamplona.amethyst.model.topNavFeeds.noteBased.NoteFeedFlow
|
||||||
import com.vitorpamplona.amethyst.model.topNavFeeds.relay.RelayFeedFlow
|
import com.vitorpamplona.amethyst.model.topNavFeeds.relay.RelayFeedFlow
|
||||||
import com.vitorpamplona.amethyst.service.location.LocationState
|
import com.vitorpamplona.amethyst.service.location.LocationState
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.core.Address
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.normalizeRelayUrl
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.normalizeRelayUrl
|
||||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||||
@@ -65,6 +67,7 @@ class FeedTopNavFilterState(
|
|||||||
val signer: NostrSigner,
|
val signer: NostrSigner,
|
||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val favoriteDvmOrchestrator: FavoriteDvmOrchestrator,
|
val favoriteDvmOrchestrator: FavoriteDvmOrchestrator,
|
||||||
|
val favoriteDvmAddresses: StateFlow<Set<Address>>,
|
||||||
) {
|
) {
|
||||||
fun loadFlowsFor(listName: TopFilter): IFeedFlowsType =
|
fun loadFlowsFor(listName: TopFilter): IFeedFlowsType =
|
||||||
when (listName) {
|
when (listName) {
|
||||||
@@ -154,6 +157,15 @@ class FeedTopNavFilterState(
|
|||||||
proxyRelays = proxyRelays,
|
proxyRelays = proxyRelays,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TopFilter.AllFavoriteDvms -> {
|
||||||
|
AllFavoriteDvmsFeedFlow(
|
||||||
|
favoriteDvmAddresses = favoriteDvmAddresses,
|
||||||
|
orchestrator = favoriteDvmOrchestrator,
|
||||||
|
outboxRelays = followsRelays,
|
||||||
|
proxyRelays = proxyRelays,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
|
|||||||
+115
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* 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.topNavFeeds.favoriteDvm
|
||||||
|
|
||||||
|
import com.vitorpamplona.amethyst.model.dvms.FavoriteDvmOrchestrator
|
||||||
|
import com.vitorpamplona.amethyst.model.dvms.FavoriteDvmSnapshot
|
||||||
|
import com.vitorpamplona.amethyst.model.topNavFeeds.IFeedFlowsType
|
||||||
|
import com.vitorpamplona.amethyst.model.topNavFeeds.IFeedTopNavFilter
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.core.Address
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.FlowCollector
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Feed flow that merges snapshots from every currently-favourited DVM into a
|
||||||
|
* single [AllFavoriteDvmsTopNavFilter]. Re-wires subscriptions whenever the
|
||||||
|
* favourite set changes.
|
||||||
|
*/
|
||||||
|
class AllFavoriteDvmsFeedFlow(
|
||||||
|
val favoriteDvmAddresses: StateFlow<Set<Address>>,
|
||||||
|
val orchestrator: FavoriteDvmOrchestrator,
|
||||||
|
val outboxRelays: StateFlow<Set<NormalizedRelayUrl>>,
|
||||||
|
val proxyRelays: StateFlow<Set<NormalizedRelayUrl>>,
|
||||||
|
) : IFeedFlowsType {
|
||||||
|
private fun resolveContentRelays(
|
||||||
|
outbox: Set<NormalizedRelayUrl>,
|
||||||
|
proxy: Set<NormalizedRelayUrl>,
|
||||||
|
): Set<NormalizedRelayUrl> = if (proxy.isNotEmpty()) proxy else outbox
|
||||||
|
|
||||||
|
private fun merge(
|
||||||
|
snapshots: List<FavoriteDvmSnapshot>,
|
||||||
|
contentRelays: Set<NormalizedRelayUrl>,
|
||||||
|
): AllFavoriteDvmsTopNavFilter {
|
||||||
|
val ids = mutableSetOf<String>()
|
||||||
|
val addresses = mutableSetOf<String>()
|
||||||
|
val listen = mutableSetOf<NormalizedRelayUrl>()
|
||||||
|
val requestIds = mutableSetOf<String>()
|
||||||
|
snapshots.forEach { snap ->
|
||||||
|
ids += snap.ids
|
||||||
|
addresses += snap.addresses
|
||||||
|
listen += snap.responseRelays
|
||||||
|
snap.requestId?.let { requestIds += it }
|
||||||
|
}
|
||||||
|
return AllFavoriteDvmsTopNavFilter(
|
||||||
|
acceptedIds = ids,
|
||||||
|
acceptedAddresses = addresses,
|
||||||
|
contentRelays = contentRelays,
|
||||||
|
listenRelays = listen,
|
||||||
|
requestIds = requestIds,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun emptyFilter(contentRelays: Set<NormalizedRelayUrl>): AllFavoriteDvmsTopNavFilter =
|
||||||
|
AllFavoriteDvmsTopNavFilter(
|
||||||
|
acceptedIds = emptySet(),
|
||||||
|
acceptedAddresses = emptySet(),
|
||||||
|
contentRelays = contentRelays,
|
||||||
|
listenRelays = emptySet(),
|
||||||
|
requestIds = emptySet(),
|
||||||
|
)
|
||||||
|
|
||||||
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
|
override fun flow(): Flow<IFeedTopNavFilter> =
|
||||||
|
favoriteDvmAddresses.flatMapLatest { addresses ->
|
||||||
|
if (addresses.isEmpty()) {
|
||||||
|
combine(outboxRelays, proxyRelays) { outbox, proxy ->
|
||||||
|
emptyFilter(resolveContentRelays(outbox, proxy))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val snapshotFlows: List<Flow<FavoriteDvmSnapshot>> = addresses.map { orchestrator.observe(it) }
|
||||||
|
combine(snapshotFlows) { it.toList() }
|
||||||
|
.let { merged ->
|
||||||
|
combine(merged, outboxRelays, proxyRelays) { snaps, outbox, proxy ->
|
||||||
|
merge(snaps, resolveContentRelays(outbox, proxy))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun startValue(): AllFavoriteDvmsTopNavFilter {
|
||||||
|
val contentRelays = resolveContentRelays(outboxRelays.value, proxyRelays.value)
|
||||||
|
val addresses = favoriteDvmAddresses.value
|
||||||
|
return if (addresses.isEmpty()) {
|
||||||
|
emptyFilter(contentRelays)
|
||||||
|
} else {
|
||||||
|
merge(addresses.map { orchestrator.observe(it).value }, contentRelays)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun startValue(collector: FlowCollector<IFeedTopNavFilter>) {
|
||||||
|
collector.emit(startValue())
|
||||||
|
}
|
||||||
|
}
|
||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* 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.topNavFeeds.favoriteDvm
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Immutable
|
||||||
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
|
import com.vitorpamplona.amethyst.model.topNavFeeds.IFeedTopNavFilter
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.core.AddressableEvent
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Top-nav filter that unions the latest kind-6300 responses from every currently
|
||||||
|
* favourited DVM. Behaves like [FavoriteDvmTopNavFilter] (pure membership check
|
||||||
|
* against a snapshot), but the accepted set is the union across N DVMs and the
|
||||||
|
* request-id list carries one entry per DVM for the relay-listen subscription.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
class AllFavoriteDvmsTopNavFilter(
|
||||||
|
val acceptedIds: Set<HexKey>,
|
||||||
|
val acceptedAddresses: Set<String>,
|
||||||
|
val contentRelays: Set<NormalizedRelayUrl>,
|
||||||
|
val listenRelays: Set<NormalizedRelayUrl>,
|
||||||
|
val requestIds: Set<HexKey>,
|
||||||
|
) : IFeedTopNavFilter {
|
||||||
|
override fun matchAuthor(pubkey: HexKey): Boolean = true
|
||||||
|
|
||||||
|
override fun match(noteEvent: Event): Boolean =
|
||||||
|
noteEvent.id in acceptedIds ||
|
||||||
|
(noteEvent is AddressableEvent && noteEvent.addressTag() in acceptedAddresses)
|
||||||
|
|
||||||
|
override fun toPerRelayFlow(cache: LocalCache): Flow<FavoriteDvmTopNavPerRelayFilterSet> = MutableStateFlow(startValue(cache))
|
||||||
|
|
||||||
|
override fun startValue(cache: LocalCache): FavoriteDvmTopNavPerRelayFilterSet =
|
||||||
|
FavoriteDvmTopNavPerRelayFilterSet(
|
||||||
|
contentFetches =
|
||||||
|
contentRelays.associateWith {
|
||||||
|
FavoriteDvmTopNavPerRelayFilter(
|
||||||
|
ids = acceptedIds,
|
||||||
|
addresses = acceptedAddresses,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
listenRelays = listenRelays,
|
||||||
|
requestIds = requestIds,
|
||||||
|
)
|
||||||
|
}
|
||||||
+1
-1
@@ -65,6 +65,6 @@ class FavoriteDvmTopNavFilter(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
listenRelays = listenRelays,
|
listenRelays = listenRelays,
|
||||||
requestId = requestId,
|
requestIds = setOfNotNull(requestId),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-3
@@ -29,11 +29,14 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
|||||||
*
|
*
|
||||||
* - [contentFetches] — for each user-configured content relay, the ids/addresses
|
* - [contentFetches] — for each user-configured content relay, the ids/addresses
|
||||||
* we want to pull (the actual notes the DVM curated).
|
* we want to pull (the actual notes the DVM curated).
|
||||||
* - [listenRelays] — the DVM's own publish relays (where it will deliver future
|
* - [listenRelays] — the union of DVM publish relays across all active DVMs
|
||||||
* kind 6300 / 7000 events for this request).
|
* (where they will deliver future kind 6300 / 7000 events for their requests).
|
||||||
|
* - [requestIds] — the set of currently-active kind-5300 request ids to listen
|
||||||
|
* for. A single-DVM filter carries one; the merged "All favourite DVMs"
|
||||||
|
* filter carries one per favourite DVM.
|
||||||
*/
|
*/
|
||||||
class FavoriteDvmTopNavPerRelayFilterSet(
|
class FavoriteDvmTopNavPerRelayFilterSet(
|
||||||
val contentFetches: Map<NormalizedRelayUrl, FavoriteDvmTopNavPerRelayFilter>,
|
val contentFetches: Map<NormalizedRelayUrl, FavoriteDvmTopNavPerRelayFilter>,
|
||||||
val listenRelays: Set<NormalizedRelayUrl>,
|
val listenRelays: Set<NormalizedRelayUrl>,
|
||||||
val requestId: HexKey?,
|
val requestIds: Set<HexKey>,
|
||||||
) : IFeedTopNavPerRelayFilterSet
|
) : IFeedTopNavPerRelayFilterSet
|
||||||
|
|||||||
+5
@@ -399,6 +399,7 @@ private fun groupFeedDefinitions(options: ImmutableList<FeedDefinition>): Map<Fe
|
|||||||
when (entry.item.code) {
|
when (entry.item.code) {
|
||||||
is TopFilter.AroundMe -> FeedGroup.LOCATIONS
|
is TopFilter.AroundMe -> FeedGroup.LOCATIONS
|
||||||
is TopFilter.Global -> FeedGroup.RELAYS
|
is TopFilter.Global -> FeedGroup.RELAYS
|
||||||
|
is TopFilter.AllFavoriteDvms -> FeedGroup.DVMS
|
||||||
else -> FeedGroup.FEEDS
|
else -> FeedGroup.FEEDS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -567,6 +568,10 @@ private fun FeedIcon(
|
|||||||
Icons.Outlined.AutoAwesome
|
Icons.Outlined.AutoAwesome
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is TopFilter.AllFavoriteDvms -> {
|
||||||
|
Icons.Outlined.AutoAwesome
|
||||||
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
when (item.name) {
|
when (item.name) {
|
||||||
is GeoHashName -> Icons.Outlined.LocationOn
|
is GeoHashName -> Icons.Outlined.LocationOn
|
||||||
|
|||||||
@@ -98,6 +98,12 @@ class TopNavFilterState(
|
|||||||
name = ResourceName(R.string.follow_list_chess),
|
name = ResourceName(R.string.follow_list_chess),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val allFavoriteDvmsFollow =
|
||||||
|
FeedDefinition(
|
||||||
|
code = TopFilter.AllFavoriteDvms,
|
||||||
|
name = ResourceName(R.string.follow_list_all_favorite_dvms),
|
||||||
|
)
|
||||||
|
|
||||||
val defaultLists = persistentListOf(allFollows, userFollows, kind3Follows, aroundMe, globalFollow, muteListFollow)
|
val defaultLists = persistentListOf(allFollows, userFollows, kind3Follows, aroundMe, globalFollow, muteListFollow)
|
||||||
|
|
||||||
fun mergePeopleLists(
|
fun mergePeopleLists(
|
||||||
@@ -192,7 +198,12 @@ class TopNavFilterState(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (communities + hashtags + geotags + relays + favoriteDvms).sortedBy { it.name.name() }
|
// Only show the "All favourite DVMs" meta-chip when there is at least one
|
||||||
|
// real favourite to merge; otherwise the chip opens to an empty feed.
|
||||||
|
val allFavorites =
|
||||||
|
if (favoriteDvms.isNotEmpty()) listOf(allFavoriteDvmsFollow) else emptyList()
|
||||||
|
|
||||||
|
return (communities + hashtags + geotags + relays + allFavorites + favoriteDvms).sortedBy { it.name.name() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
|
|||||||
+131
-75
@@ -42,6 +42,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.TopFilter
|
import com.vitorpamplona.amethyst.model.TopFilter
|
||||||
|
import com.vitorpamplona.amethyst.model.dvms.FavoriteDvmSnapshot
|
||||||
import com.vitorpamplona.amethyst.service.relayClient.reqCommand.event.observeNoteAndMap
|
import com.vitorpamplona.amethyst.service.relayClient.reqCommand.event.observeNoteAndMap
|
||||||
import com.vitorpamplona.amethyst.ui.components.LoadNote
|
import com.vitorpamplona.amethyst.ui.components.LoadNote
|
||||||
import com.vitorpamplona.amethyst.ui.components.LoadingAnimation
|
import com.vitorpamplona.amethyst.ui.components.LoadingAnimation
|
||||||
@@ -61,8 +62,19 @@ fun HomeDvmStatusBanner(
|
|||||||
val topFilter by accountViewModel.account.settings.defaultHomeFollowList
|
val topFilter by accountViewModel.account.settings.defaultHomeFollowList
|
||||||
.collectAsStateWithLifecycle()
|
.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
val favDvm = topFilter as? TopFilter.FavoriteDvm ?: return
|
when (val filter = topFilter) {
|
||||||
|
is TopFilter.FavoriteDvm -> SingleDvmBanner(filter, accountViewModel, nav)
|
||||||
|
is TopFilter.AllFavoriteDvms -> AllFavoriteDvmsBanner(accountViewModel)
|
||||||
|
else -> Unit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun SingleDvmBanner(
|
||||||
|
favDvm: TopFilter.FavoriteDvm,
|
||||||
|
accountViewModel: AccountViewModel,
|
||||||
|
nav: INav,
|
||||||
|
) {
|
||||||
val snapshot by accountViewModel.account.favoriteDvmOrchestrator
|
val snapshot by accountViewModel.account.favoriteDvmOrchestrator
|
||||||
.observe(favDvm.address)
|
.observe(favDvm.address)
|
||||||
.collectAsStateWithLifecycle()
|
.collectAsStateWithLifecycle()
|
||||||
@@ -83,86 +95,133 @@ fun HomeDvmStatusBanner(
|
|||||||
?: ""
|
?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface(
|
BannerCard {
|
||||||
modifier =
|
val status = snapshot.latestStatus?.status()
|
||||||
Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 12.dp, vertical = 6.dp),
|
|
||||||
shape = RoundedCornerShape(12.dp),
|
|
||||||
color = MaterialTheme.colorScheme.surfaceContainerLow,
|
|
||||||
) {
|
|
||||||
Column(modifier = Modifier.padding(12.dp)) {
|
|
||||||
val status = snapshot.latestStatus?.status()
|
|
||||||
|
|
||||||
when {
|
when {
|
||||||
snapshot.errorMessage != null -> {
|
snapshot.errorMessage != null -> {
|
||||||
BannerMessageRow(
|
BannerMessageRow(
|
||||||
message = stringRes(R.string.dvm_home_status_error),
|
message = stringRes(R.string.dvm_home_status_error),
|
||||||
showSpinner = false,
|
showSpinner = false,
|
||||||
)
|
)
|
||||||
|
Spacer(modifier = StdVertSpacer)
|
||||||
|
RetryButton { accountViewModel.refreshFavoriteDvm(favDvm.address) }
|
||||||
|
}
|
||||||
|
|
||||||
|
status?.code == "payment-required" -> {
|
||||||
|
BannerMessageRow(
|
||||||
|
message =
|
||||||
|
status.description.ifBlank {
|
||||||
|
stringRes(R.string.dvm_home_status_payment_required)
|
||||||
|
},
|
||||||
|
showSpinner = false,
|
||||||
|
)
|
||||||
|
Spacer(modifier = StdVertSpacer)
|
||||||
|
var statusOverride by remember { mutableStateOf<String?>(null) }
|
||||||
|
val msg = statusOverride
|
||||||
|
if (msg != null) {
|
||||||
|
Text(text = msg, style = MaterialTheme.typography.bodySmall)
|
||||||
Spacer(modifier = StdVertSpacer)
|
Spacer(modifier = StdVertSpacer)
|
||||||
RetryButton(favDvm, accountViewModel)
|
|
||||||
}
|
}
|
||||||
|
snapshot.latestStatus?.let {
|
||||||
status?.code == "payment-required" -> {
|
DvmPaymentActions(
|
||||||
BannerMessageRow(
|
latestStatus = it,
|
||||||
message =
|
accountViewModel = accountViewModel,
|
||||||
status.description.ifBlank {
|
nav = nav,
|
||||||
stringRes(R.string.dvm_home_status_payment_required)
|
onStatusUpdate = { statusOverride = it },
|
||||||
},
|
|
||||||
showSpinner = false,
|
|
||||||
)
|
|
||||||
Spacer(modifier = StdVertSpacer)
|
|
||||||
var statusOverride by remember { mutableStateOf<String?>(null) }
|
|
||||||
val msg = statusOverride
|
|
||||||
if (msg != null) {
|
|
||||||
Text(text = msg, style = MaterialTheme.typography.bodySmall)
|
|
||||||
Spacer(modifier = StdVertSpacer)
|
|
||||||
}
|
|
||||||
snapshot.latestStatus?.let {
|
|
||||||
DvmPaymentActions(
|
|
||||||
latestStatus = it,
|
|
||||||
accountViewModel = accountViewModel,
|
|
||||||
nav = nav,
|
|
||||||
onStatusUpdate = { statusOverride = it },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
status?.code == "error" -> {
|
|
||||||
BannerMessageRow(
|
|
||||||
message =
|
|
||||||
status.description.ifBlank {
|
|
||||||
stringRes(R.string.dvm_home_status_error)
|
|
||||||
},
|
|
||||||
showSpinner = false,
|
|
||||||
)
|
|
||||||
Spacer(modifier = StdVertSpacer)
|
|
||||||
RetryButton(favDvm, accountViewModel)
|
|
||||||
}
|
|
||||||
|
|
||||||
status?.code == "processing" -> {
|
|
||||||
BannerMessageRow(
|
|
||||||
message =
|
|
||||||
status.description.ifBlank {
|
|
||||||
stringRes(R.string.dvm_home_status_processing)
|
|
||||||
},
|
|
||||||
showSpinner = true,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
BannerMessageRow(
|
|
||||||
message = stringRes(R.string.dvm_home_status_requesting, resolvedName),
|
|
||||||
showSpinner = true,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status?.code == "error" -> {
|
||||||
|
BannerMessageRow(
|
||||||
|
message =
|
||||||
|
status.description.ifBlank {
|
||||||
|
stringRes(R.string.dvm_home_status_error)
|
||||||
|
},
|
||||||
|
showSpinner = false,
|
||||||
|
)
|
||||||
|
Spacer(modifier = StdVertSpacer)
|
||||||
|
RetryButton { accountViewModel.refreshFavoriteDvm(favDvm.address) }
|
||||||
|
}
|
||||||
|
|
||||||
|
status?.code == "processing" -> {
|
||||||
|
BannerMessageRow(
|
||||||
|
message =
|
||||||
|
status.description.ifBlank {
|
||||||
|
stringRes(R.string.dvm_home_status_processing)
|
||||||
|
},
|
||||||
|
showSpinner = true,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
BannerMessageRow(
|
||||||
|
message = stringRes(R.string.dvm_home_status_requesting, resolvedName),
|
||||||
|
showSpinner = true,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun AllFavoriteDvmsBanner(accountViewModel: AccountViewModel) {
|
||||||
|
val addresses by accountViewModel.account.favoriteDvmList.flow
|
||||||
|
.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
|
if (addresses.isEmpty()) return
|
||||||
|
|
||||||
|
// Observe each DVM's snapshot so we can decide whether to hide the banner
|
||||||
|
// based on the aggregate state. Hide it as soon as any DVM has produced a
|
||||||
|
// feed; only error out when every one of them has errored.
|
||||||
|
val snapshots: List<FavoriteDvmSnapshot> =
|
||||||
|
addresses.map { address ->
|
||||||
|
val snap by accountViewModel.account.favoriteDvmOrchestrator
|
||||||
|
.observe(address)
|
||||||
|
.collectAsStateWithLifecycle()
|
||||||
|
snap
|
||||||
|
}
|
||||||
|
|
||||||
|
val anyResponded = snapshots.any { it.ids.isNotEmpty() || it.addresses.isNotEmpty() }
|
||||||
|
if (anyResponded) return
|
||||||
|
|
||||||
|
val allErrored = snapshots.all { it.errorMessage != null || it.latestStatus?.status()?.code == "error" }
|
||||||
|
|
||||||
|
BannerCard {
|
||||||
|
if (allErrored) {
|
||||||
|
BannerMessageRow(
|
||||||
|
message = stringRes(R.string.dvm_home_status_error),
|
||||||
|
showSpinner = false,
|
||||||
|
)
|
||||||
|
Spacer(modifier = StdVertSpacer)
|
||||||
|
RetryButton {
|
||||||
|
addresses.forEach { accountViewModel.refreshFavoriteDvm(it) }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
BannerMessageRow(
|
||||||
|
message = stringRes(R.string.dvm_home_status_requesting_all),
|
||||||
|
showSpinner = true,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun BannerCard(content: @Composable () -> Unit) {
|
||||||
|
Surface(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 12.dp, vertical = 6.dp),
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
color = MaterialTheme.colorScheme.surfaceContainerLow,
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier.padding(12.dp)) { content() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun BannerMessageRow(
|
private fun BannerMessageRow(
|
||||||
message: String,
|
message: String,
|
||||||
@@ -185,11 +244,8 @@ private fun BannerMessageRow(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun RetryButton(
|
private fun RetryButton(onClick: () -> Unit) {
|
||||||
favDvm: TopFilter.FavoriteDvm,
|
OutlinedButton(onClick = onClick) {
|
||||||
accountViewModel: AccountViewModel,
|
|
||||||
) {
|
|
||||||
OutlinedButton(onClick = { accountViewModel.refreshFavoriteDvm(favDvm.address) }) {
|
|
||||||
Text(stringRes(R.string.dvm_home_retry))
|
Text(stringRes(R.string.dvm_home_retry))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-5
@@ -284,14 +284,17 @@ fun HomeFeeds(
|
|||||||
) {
|
) {
|
||||||
val activeFilter by accountViewModel.account.settings.defaultHomeFollowList
|
val activeFilter by accountViewModel.account.settings.defaultHomeFollowList
|
||||||
.collectAsStateWithLifecycle()
|
.collectAsStateWithLifecycle()
|
||||||
val activeDvm = activeFilter as? TopFilter.FavoriteDvm
|
val favoriteDvmAddresses by accountViewModel.account.favoriteDvmList.flow
|
||||||
|
.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
val onRefresh: () -> Unit = {
|
val onRefresh: () -> Unit = {
|
||||||
feedState.invalidateData()
|
feedState.invalidateData()
|
||||||
if (activeDvm != null) {
|
// Swiping down on Home should also re-issue the kind-5300 request(s) so the
|
||||||
// Swiping down on Home should also re-issue the kind-5300 request so the
|
// DVM(s) produce fresh feeds, not just re-render whatever's cached.
|
||||||
// DVM produces a fresh feed, not just re-render whatever's cached.
|
when (val filter = activeFilter) {
|
||||||
accountViewModel.refreshFavoriteDvm(activeDvm.address)
|
is TopFilter.FavoriteDvm -> accountViewModel.refreshFavoriteDvm(filter.address)
|
||||||
|
is TopFilter.AllFavoriteDvms -> favoriteDvmAddresses.forEach { accountViewModel.refreshFavoriteDvm(it) }
|
||||||
|
else -> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -56,10 +56,10 @@ fun filterHomePostsByDvmIds(
|
|||||||
out += contentFetchFilters(relay, filter)
|
out += contentFetchFilters(relay, filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
val requestId = set.requestId
|
if (set.requestIds.isNotEmpty()) {
|
||||||
if (requestId != null) {
|
val requestIds = set.requestIds.toList()
|
||||||
set.listenRelays.forEach { relay ->
|
set.listenRelays.forEach { relay ->
|
||||||
out += responseListenFilter(relay, requestId)
|
out += responseListenFilter(relay, requestIds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ private fun contentFetchFilters(
|
|||||||
|
|
||||||
private fun responseListenFilter(
|
private fun responseListenFilter(
|
||||||
relay: NormalizedRelayUrl,
|
relay: NormalizedRelayUrl,
|
||||||
requestId: HexKey,
|
requestIds: List<HexKey>,
|
||||||
) = RelayBasedFilter(
|
) = RelayBasedFilter(
|
||||||
relay = relay,
|
relay = relay,
|
||||||
filter =
|
filter =
|
||||||
@@ -111,7 +111,7 @@ private fun responseListenFilter(
|
|||||||
NIP90ContentDiscoveryResponseEvent.KIND,
|
NIP90ContentDiscoveryResponseEvent.KIND,
|
||||||
NIP90StatusEvent.KIND,
|
NIP90StatusEvent.KIND,
|
||||||
),
|
),
|
||||||
tags = mapOf("e" to listOf(requestId)),
|
tags = mapOf("e" to requestIds),
|
||||||
limit = 10,
|
limit = 10 * requestIds.size,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1729,6 +1729,7 @@
|
|||||||
<string name="feed_group_communities">Communities</string>
|
<string name="feed_group_communities">Communities</string>
|
||||||
<string name="feed_group_lists">Lists</string>
|
<string name="feed_group_lists">Lists</string>
|
||||||
<string name="feed_group_dvms">DVMs</string>
|
<string name="feed_group_dvms">DVMs</string>
|
||||||
|
<string name="follow_list_all_favorite_dvms">All favourite DVMs</string>
|
||||||
<string name="feed_group_relays">Relays</string>
|
<string name="feed_group_relays">Relays</string>
|
||||||
|
|
||||||
<string name="add_dvm_to_favorites">Add DVM to favorites</string>
|
<string name="add_dvm_to_favorites">Add DVM to favorites</string>
|
||||||
@@ -1737,6 +1738,7 @@
|
|||||||
<string name="favorite_dvms_explainer">Content-discovery DVMs you starred here appear as filter chips on the Home feed. Open Discover to add more.</string>
|
<string name="favorite_dvms_explainer">Content-discovery DVMs you starred here appear as filter chips on the Home feed. Open Discover to add more.</string>
|
||||||
<string name="favorite_dvms_empty">No favourite DVMs yet. Open Discover, tap a content-discovery DVM, and star it to add it here.</string>
|
<string name="favorite_dvms_empty">No favourite DVMs yet. Open Discover, tap a content-discovery DVM, and star it to add it here.</string>
|
||||||
<string name="dvm_home_status_requesting">Asking %1$s for a feed…</string>
|
<string name="dvm_home_status_requesting">Asking %1$s for a feed…</string>
|
||||||
|
<string name="dvm_home_status_requesting_all">Asking your favourite DVMs for feeds…</string>
|
||||||
<string name="dvm_home_status_processing">Processing your feed…</string>
|
<string name="dvm_home_status_processing">Processing your feed…</string>
|
||||||
<string name="dvm_home_status_payment_required">This DVM requires payment</string>
|
<string name="dvm_home_status_payment_required">This DVM requires payment</string>
|
||||||
<string name="dvm_home_status_error">DVM returned an error</string>
|
<string name="dvm_home_status_error">DVM returned an error</string>
|
||||||
|
|||||||
+129
@@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* 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.topNavFeeds.favoriteDvm
|
||||||
|
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.core.Address
|
||||||
|
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
|
||||||
|
import com.vitorpamplona.quartz.nip23LongContent.LongTextNoteEvent
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class FavoriteDvmTopNavFilterTest {
|
||||||
|
private fun textNote(id: String) = TextNoteEvent(id = id, pubKey = "a".repeat(64), createdAt = 1, tags = emptyArray(), content = "", sig = "x".repeat(128))
|
||||||
|
|
||||||
|
private fun longFormNote(
|
||||||
|
pubkey: String,
|
||||||
|
dTag: String,
|
||||||
|
) = LongTextNoteEvent(
|
||||||
|
id = "0".repeat(64),
|
||||||
|
pubKey = pubkey,
|
||||||
|
createdAt = 1,
|
||||||
|
tags = arrayOf(arrayOf("d", dTag)),
|
||||||
|
content = "",
|
||||||
|
sig = "x".repeat(128),
|
||||||
|
)
|
||||||
|
|
||||||
|
private val dvmAddress = Address(31990, "d".repeat(64), "content")
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun matchesNoteWhoseIdIsInAcceptedSet() {
|
||||||
|
val filter =
|
||||||
|
FavoriteDvmTopNavFilter(
|
||||||
|
dvmAddress = dvmAddress,
|
||||||
|
acceptedIds = setOf("1".repeat(64)),
|
||||||
|
acceptedAddresses = emptySet(),
|
||||||
|
contentRelays = emptySet(),
|
||||||
|
listenRelays = emptySet(),
|
||||||
|
requestId = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(filter.match(textNote("1".repeat(64))))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun rejectsNoteNotInAcceptedSet() {
|
||||||
|
val filter =
|
||||||
|
FavoriteDvmTopNavFilter(
|
||||||
|
dvmAddress = dvmAddress,
|
||||||
|
acceptedIds = setOf("1".repeat(64)),
|
||||||
|
acceptedAddresses = emptySet(),
|
||||||
|
contentRelays = emptySet(),
|
||||||
|
listenRelays = emptySet(),
|
||||||
|
requestId = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertFalse(filter.match(textNote("2".repeat(64))))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun matchesAddressableEventByAddressTag() {
|
||||||
|
val articleAuthor = "c".repeat(64)
|
||||||
|
val articleDTag = "my-post"
|
||||||
|
val articleAddress = "30023:$articleAuthor:$articleDTag"
|
||||||
|
|
||||||
|
val filter =
|
||||||
|
FavoriteDvmTopNavFilter(
|
||||||
|
dvmAddress = dvmAddress,
|
||||||
|
acceptedIds = emptySet(),
|
||||||
|
acceptedAddresses = setOf(articleAddress),
|
||||||
|
contentRelays = emptySet(),
|
||||||
|
listenRelays = emptySet(),
|
||||||
|
requestId = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(filter.match(longFormNote(articleAuthor, articleDTag)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nullRequestIdCollapsesToEmptyRequestIdsInFilterSet() {
|
||||||
|
val filter =
|
||||||
|
FavoriteDvmTopNavFilter(
|
||||||
|
dvmAddress = dvmAddress,
|
||||||
|
acceptedIds = emptySet(),
|
||||||
|
acceptedAddresses = emptySet(),
|
||||||
|
contentRelays = emptySet(),
|
||||||
|
listenRelays = emptySet(),
|
||||||
|
requestId = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
// passing a LocalCache is only needed because the method demands it;
|
||||||
|
// FavoriteDvmTopNavFilter.startValue doesn't actually consult it.
|
||||||
|
val set = filter.startValue(com.vitorpamplona.amethyst.model.LocalCache)
|
||||||
|
assertTrue(set.requestIds.isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nonNullRequestIdProducesSingletonInFilterSet() {
|
||||||
|
val filter =
|
||||||
|
FavoriteDvmTopNavFilter(
|
||||||
|
dvmAddress = dvmAddress,
|
||||||
|
acceptedIds = emptySet(),
|
||||||
|
acceptedAddresses = emptySet(),
|
||||||
|
contentRelays = emptySet(),
|
||||||
|
listenRelays = emptySet(),
|
||||||
|
requestId = "9".repeat(64),
|
||||||
|
)
|
||||||
|
|
||||||
|
val set = filter.startValue(com.vitorpamplona.amethyst.model.LocalCache)
|
||||||
|
assertTrue(set.requestIds == setOf("9".repeat(64)))
|
||||||
|
}
|
||||||
|
}
|
||||||
+136
@@ -0,0 +1,136 @@
|
|||||||
|
/*
|
||||||
|
* 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.home.datasource.nip90Dvms
|
||||||
|
|
||||||
|
import com.vitorpamplona.amethyst.model.topNavFeeds.favoriteDvm.FavoriteDvmTopNavPerRelayFilter
|
||||||
|
import com.vitorpamplona.amethyst.model.topNavFeeds.favoriteDvm.FavoriteDvmTopNavPerRelayFilterSet
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
|
||||||
|
import com.vitorpamplona.quartz.nip90Dvms.contentDiscoveryResponse.NIP90ContentDiscoveryResponseEvent
|
||||||
|
import com.vitorpamplona.quartz.nip90Dvms.status.NIP90StatusEvent
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertNotNull
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class FilterHomePostsByDvmIdsTest {
|
||||||
|
private val userRelay = RelayUrlNormalizer.normalizeOrNull("wss://user.example/")!!
|
||||||
|
private val dvmRelay = RelayUrlNormalizer.normalizeOrNull("wss://dvm.example/")!!
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyFilterSetProducesNoRequests() {
|
||||||
|
val set =
|
||||||
|
FavoriteDvmTopNavPerRelayFilterSet(
|
||||||
|
contentFetches = emptyMap(),
|
||||||
|
listenRelays = emptySet(),
|
||||||
|
requestIds = emptySet(),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(filterHomePostsByDvmIds(set, since = null, defaultSince = null).isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun contentFetchIssuedOnUserRelayWithIdsFilter() {
|
||||||
|
val ids = setOf("a".repeat(64), "b".repeat(64))
|
||||||
|
val set =
|
||||||
|
FavoriteDvmTopNavPerRelayFilterSet(
|
||||||
|
contentFetches =
|
||||||
|
mapOf(userRelay to FavoriteDvmTopNavPerRelayFilter(ids = ids, addresses = emptySet())),
|
||||||
|
listenRelays = emptySet(),
|
||||||
|
requestIds = emptySet(),
|
||||||
|
)
|
||||||
|
|
||||||
|
val filters = filterHomePostsByDvmIds(set, since = null, defaultSince = null)
|
||||||
|
|
||||||
|
assertEquals(1, filters.size)
|
||||||
|
val single = filters.single()
|
||||||
|
assertEquals(userRelay, single.relay)
|
||||||
|
assertEquals(ids.sorted(), single.filter.ids?.sorted())
|
||||||
|
// Content fetch should not be restricted to a kind — the DVM curates freely.
|
||||||
|
assertEquals(null, single.filter.kinds)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun listenFilterIssuedOnDvmRelayWithKinds6300And7000() {
|
||||||
|
val requestId = "9".repeat(64)
|
||||||
|
val set =
|
||||||
|
FavoriteDvmTopNavPerRelayFilterSet(
|
||||||
|
contentFetches = emptyMap(),
|
||||||
|
listenRelays = setOf(dvmRelay),
|
||||||
|
requestIds = setOf(requestId),
|
||||||
|
)
|
||||||
|
|
||||||
|
val filters = filterHomePostsByDvmIds(set, since = null, defaultSince = null)
|
||||||
|
|
||||||
|
assertEquals(1, filters.size)
|
||||||
|
val listen = filters.single()
|
||||||
|
assertEquals(dvmRelay, listen.relay)
|
||||||
|
assertEquals(
|
||||||
|
listOf(NIP90ContentDiscoveryResponseEvent.KIND, NIP90StatusEvent.KIND),
|
||||||
|
listen.filter.kinds,
|
||||||
|
)
|
||||||
|
val eTag = listen.filter.tags?.get("e")
|
||||||
|
assertNotNull(eTag)
|
||||||
|
assertEquals(listOf(requestId), eTag)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun mergedRequestIdsAllRideOnOneListenFilterPerRelay() {
|
||||||
|
val req1 = "1".repeat(64)
|
||||||
|
val req2 = "2".repeat(64)
|
||||||
|
val set =
|
||||||
|
FavoriteDvmTopNavPerRelayFilterSet(
|
||||||
|
contentFetches = emptyMap(),
|
||||||
|
listenRelays = setOf(dvmRelay),
|
||||||
|
requestIds = setOf(req1, req2),
|
||||||
|
)
|
||||||
|
|
||||||
|
val filters = filterHomePostsByDvmIds(set, since = null, defaultSince = null)
|
||||||
|
|
||||||
|
assertEquals(1, filters.size)
|
||||||
|
val eTag =
|
||||||
|
filters
|
||||||
|
.single()
|
||||||
|
.filter.tags
|
||||||
|
?.get("e")
|
||||||
|
.orEmpty()
|
||||||
|
assertTrue(eTag.containsAll(listOf(req1, req2)))
|
||||||
|
assertEquals(2, eTag.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun contentAndListenSubscriptionsSplitAcrossTheirRespectiveRelays() {
|
||||||
|
val ids = setOf("a".repeat(64))
|
||||||
|
val requestId = "9".repeat(64)
|
||||||
|
val set =
|
||||||
|
FavoriteDvmTopNavPerRelayFilterSet(
|
||||||
|
contentFetches =
|
||||||
|
mapOf(userRelay to FavoriteDvmTopNavPerRelayFilter(ids = ids, addresses = emptySet())),
|
||||||
|
listenRelays = setOf(dvmRelay),
|
||||||
|
requestIds = setOf(requestId),
|
||||||
|
)
|
||||||
|
|
||||||
|
val filters = filterHomePostsByDvmIds(set, since = null, defaultSince = null)
|
||||||
|
|
||||||
|
assertEquals(2, filters.size)
|
||||||
|
assertTrue(filters.any { it.relay == userRelay && it.filter.ids != null })
|
||||||
|
assertTrue(filters.any { it.relay == dvmRelay && it.filter.kinds != null })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -134,6 +134,7 @@ import com.vitorpamplona.quartz.nip51Lists.appCurationSet.AppCurationSetEvent
|
|||||||
import com.vitorpamplona.quartz.nip51Lists.articleCurationSet.ArticleCurationSetEvent
|
import com.vitorpamplona.quartz.nip51Lists.articleCurationSet.ArticleCurationSetEvent
|
||||||
import com.vitorpamplona.quartz.nip51Lists.bookmarkList.BookmarkListEvent
|
import com.vitorpamplona.quartz.nip51Lists.bookmarkList.BookmarkListEvent
|
||||||
import com.vitorpamplona.quartz.nip51Lists.bookmarkList.OldBookmarkListEvent
|
import com.vitorpamplona.quartz.nip51Lists.bookmarkList.OldBookmarkListEvent
|
||||||
|
import com.vitorpamplona.quartz.nip51Lists.favoriteDvmList.FavoriteDvmListEvent
|
||||||
import com.vitorpamplona.quartz.nip51Lists.followList.FollowListEvent
|
import com.vitorpamplona.quartz.nip51Lists.followList.FollowListEvent
|
||||||
import com.vitorpamplona.quartz.nip51Lists.geohashList.GeohashListEvent
|
import com.vitorpamplona.quartz.nip51Lists.geohashList.GeohashListEvent
|
||||||
import com.vitorpamplona.quartz.nip51Lists.gitAuthorList.GitAuthorListEvent
|
import com.vitorpamplona.quartz.nip51Lists.gitAuthorList.GitAuthorListEvent
|
||||||
@@ -422,6 +423,7 @@ class EventFactory {
|
|||||||
GoodWikiAuthorListEvent.KIND -> GoodWikiAuthorListEvent(id, pubKey, createdAt, tags, content, sig)
|
GoodWikiAuthorListEvent.KIND -> GoodWikiAuthorListEvent(id, pubKey, createdAt, tags, content, sig)
|
||||||
GoodWikiRelayListEvent.KIND -> GoodWikiRelayListEvent(id, pubKey, createdAt, tags, content, sig)
|
GoodWikiRelayListEvent.KIND -> GoodWikiRelayListEvent(id, pubKey, createdAt, tags, content, sig)
|
||||||
GoalEvent.KIND -> GoalEvent(id, pubKey, createdAt, tags, content, sig)
|
GoalEvent.KIND -> GoalEvent(id, pubKey, createdAt, tags, content, sig)
|
||||||
|
FavoriteDvmListEvent.KIND -> FavoriteDvmListEvent(id, pubKey, createdAt, tags, content, sig)
|
||||||
HashtagListEvent.KIND -> HashtagListEvent(id, pubKey, createdAt, tags, content, sig)
|
HashtagListEvent.KIND -> HashtagListEvent(id, pubKey, createdAt, tags, content, sig)
|
||||||
HighlightEvent.KIND -> HighlightEvent(id, pubKey, createdAt, tags, content, sig)
|
HighlightEvent.KIND -> HighlightEvent(id, pubKey, createdAt, tags, content, sig)
|
||||||
HTTPAuthorizationEvent.KIND -> HTTPAuthorizationEvent(id, pubKey, createdAt, tags, content, sig)
|
HTTPAuthorizationEvent.KIND -> HTTPAuthorizationEvent(id, pubKey, createdAt, tags, content, sig)
|
||||||
|
|||||||
+159
@@ -0,0 +1,159 @@
|
|||||||
|
/*
|
||||||
|
* 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.quartz.nip51Lists.favoriteDvmList
|
||||||
|
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.core.Address
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
|
||||||
|
import com.vitorpamplona.quartz.nip51Lists.bookmarkList.tags.AddressBookmark
|
||||||
|
import com.vitorpamplona.quartz.utils.nsecToKeyPair
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertFalse
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
class FavoriteDvmListEventTest {
|
||||||
|
private val signer = NostrSignerInternal("nsec10g0wheggqn9dawlc0yuv6adnat6n09anr7eyykevw2dm8xa5fffs0wsdsr".nsecToKeyPair())
|
||||||
|
|
||||||
|
private fun dvm(
|
||||||
|
pubkey: String,
|
||||||
|
dTag: String = "content-discovery",
|
||||||
|
) = AddressBookmark(Address(31990, pubkey, dTag))
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun kindMatchesSpec() {
|
||||||
|
assertEquals(10090, FavoriteDvmListEvent.KIND)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addressesAreReplaceableWithFixedDTag() {
|
||||||
|
val address = FavoriteDvmListEvent.createAddress("a".repeat(64))
|
||||||
|
assertEquals(10090, address.kind)
|
||||||
|
assertEquals("", address.dTag)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun createStoresDvmAsATag() =
|
||||||
|
runTest {
|
||||||
|
val dvm = dvm("a".repeat(64))
|
||||||
|
|
||||||
|
val event =
|
||||||
|
FavoriteDvmListEvent.create(
|
||||||
|
dvm = dvm,
|
||||||
|
isPrivate = false,
|
||||||
|
signer = signer,
|
||||||
|
createdAt = 1740669816,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(10090, event.kind)
|
||||||
|
assertTrue(
|
||||||
|
event.tags.any { it.size >= 2 && it[0] == "a" && it[1] == dvm.address.toValue() },
|
||||||
|
"public a tag for the favourited DVM should be present",
|
||||||
|
)
|
||||||
|
val favorites = event.publicFavoriteDvms()
|
||||||
|
assertEquals(1, favorites.size)
|
||||||
|
assertEquals(dvm.address, favorites.first().address)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addAppendsWithoutDuplicatingExistingEntry() =
|
||||||
|
runTest {
|
||||||
|
val dvm = dvm("a".repeat(64))
|
||||||
|
|
||||||
|
val initial =
|
||||||
|
FavoriteDvmListEvent.create(
|
||||||
|
dvm = dvm,
|
||||||
|
isPrivate = false,
|
||||||
|
signer = signer,
|
||||||
|
createdAt = 1740669816,
|
||||||
|
)
|
||||||
|
|
||||||
|
val afterDupeAdd =
|
||||||
|
FavoriteDvmListEvent.add(
|
||||||
|
earlierVersion = initial,
|
||||||
|
dvm = dvm,
|
||||||
|
isPrivate = false,
|
||||||
|
signer = signer,
|
||||||
|
createdAt = 1740669817,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
1,
|
||||||
|
afterDupeAdd.publicFavoriteDvms().count { it.address == dvm.address },
|
||||||
|
"re-adding the same DVM must not produce a duplicate tag",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addPreservesOtherFavorites() =
|
||||||
|
runTest {
|
||||||
|
val first = dvm("a".repeat(64))
|
||||||
|
val second = dvm("b".repeat(64))
|
||||||
|
|
||||||
|
val initial =
|
||||||
|
FavoriteDvmListEvent.create(
|
||||||
|
dvm = first,
|
||||||
|
isPrivate = false,
|
||||||
|
signer = signer,
|
||||||
|
createdAt = 1740669816,
|
||||||
|
)
|
||||||
|
|
||||||
|
val after =
|
||||||
|
FavoriteDvmListEvent.add(
|
||||||
|
earlierVersion = initial,
|
||||||
|
dvm = second,
|
||||||
|
isPrivate = false,
|
||||||
|
signer = signer,
|
||||||
|
createdAt = 1740669817,
|
||||||
|
)
|
||||||
|
|
||||||
|
val addresses = after.publicFavoriteDvms().map { it.address }.toSet()
|
||||||
|
assertTrue(first.address in addresses)
|
||||||
|
assertTrue(second.address in addresses)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun removeDropsTheRequestedDvmOnly() =
|
||||||
|
runTest {
|
||||||
|
val first = dvm("a".repeat(64))
|
||||||
|
val second = dvm("b".repeat(64))
|
||||||
|
|
||||||
|
val initial =
|
||||||
|
FavoriteDvmListEvent.create(
|
||||||
|
publicDvms = listOf(first, second),
|
||||||
|
privateDvms = emptyList(),
|
||||||
|
signer = signer,
|
||||||
|
createdAt = 1740669816,
|
||||||
|
)
|
||||||
|
|
||||||
|
val after =
|
||||||
|
FavoriteDvmListEvent.remove(
|
||||||
|
earlierVersion = initial,
|
||||||
|
dvm = first.address,
|
||||||
|
signer = signer,
|
||||||
|
createdAt = 1740669817,
|
||||||
|
)
|
||||||
|
|
||||||
|
val addresses = after.publicFavoriteDvms().map { it.address }.toSet()
|
||||||
|
assertFalse(first.address in addresses, "removed DVM should not survive")
|
||||||
|
assertTrue(second.address in addresses, "other DVMs should be preserved")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user