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:
@@ -134,6 +134,7 @@ import com.vitorpamplona.quartz.nip51Lists.appCurationSet.AppCurationSetEvent
|
||||
import com.vitorpamplona.quartz.nip51Lists.articleCurationSet.ArticleCurationSetEvent
|
||||
import com.vitorpamplona.quartz.nip51Lists.bookmarkList.BookmarkListEvent
|
||||
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.geohashList.GeohashListEvent
|
||||
import com.vitorpamplona.quartz.nip51Lists.gitAuthorList.GitAuthorListEvent
|
||||
@@ -422,6 +423,7 @@ class EventFactory {
|
||||
GoodWikiAuthorListEvent.KIND -> GoodWikiAuthorListEvent(id, pubKey, createdAt, tags, content, sig)
|
||||
GoodWikiRelayListEvent.KIND -> GoodWikiRelayListEvent(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)
|
||||
HighlightEvent.KIND -> HighlightEvent(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