mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-10-05 19:28:25 +00:00
Merge pull request #2030 from vitorpamplona/claude/nip89-compliance-modernize-BWso3
Add PlatformLinkTag parsing and NIP-89 app handler extensions
This commit is contained in:
+8
-7
@@ -41,6 +41,7 @@ import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
open class DiscoverNIP89FeedFilter(
|
||||
val account: Account,
|
||||
val targetKind: Int = 5300,
|
||||
) : AdditiveFeedFilter<Note>() {
|
||||
val lastAnnounced = TimeUtils.oneYearAgo()
|
||||
|
||||
@@ -61,7 +62,7 @@ open class DiscoverNIP89FeedFilter(
|
||||
override fun feed(): List<Note> {
|
||||
val notes =
|
||||
LocalCache.addressables.filterIntoSet(AppDefinitionEvent.KIND) { _, it ->
|
||||
acceptDVM(it)
|
||||
acceptApp(it)
|
||||
}
|
||||
|
||||
return sort(notes)
|
||||
@@ -75,29 +76,29 @@ open class DiscoverNIP89FeedFilter(
|
||||
account.hiddenUsers.flow.value,
|
||||
)
|
||||
|
||||
fun acceptDVM(note: Note): Boolean {
|
||||
fun acceptApp(note: Note): Boolean {
|
||||
val noteEvent = note.event
|
||||
return if (noteEvent is AppDefinitionEvent) {
|
||||
acceptDVM(noteEvent, note.relays)
|
||||
acceptApp(noteEvent, note.relays)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun acceptDVM(
|
||||
open fun acceptApp(
|
||||
noteEvent: AppDefinitionEvent,
|
||||
relays: List<NormalizedRelayUrl>,
|
||||
): Boolean {
|
||||
val filterParams = buildFilterParams(account)
|
||||
return noteEvent.appMetaData()?.subscription != true &&
|
||||
filterParams.match(noteEvent, relays) &&
|
||||
noteEvent.includeKind(5300) &&
|
||||
noteEvent.createdAt > lastAnnounced // && params.match(noteEvent)
|
||||
noteEvent.includeKind(targetKind) &&
|
||||
noteEvent.createdAt > lastAnnounced
|
||||
}
|
||||
|
||||
protected open fun innerApplyFilter(collection: Collection<Note>): Set<Note> =
|
||||
collection.filterTo(HashSet()) {
|
||||
acceptDVM(it)
|
||||
acceptApp(it)
|
||||
}
|
||||
|
||||
override fun sort(items: Set<Note>): List<Note> {
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.nip89AppHandlers.definition
|
||||
|
||||
fun AppDefinitionEvent.platformLinks() = tags.platformLinks()
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.nip89AppHandlers.definition
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArray
|
||||
import com.vitorpamplona.quartz.nip89AppHandlers.definition.tags.PlatformLinkTag
|
||||
|
||||
fun TagArray.platformLinks() = this.mapNotNull(PlatformLinkTag::parse)
|
||||
+1
-1
@@ -41,7 +41,7 @@ class PlatformLinkTag(
|
||||
}
|
||||
|
||||
fun parse(tag: Tag): PlatformLinkTag? {
|
||||
if (match(tag)) return PlatformLinkTag(tag[1], tag[2], tag.getOrNull(3))
|
||||
if (match(tag)) return PlatformLinkTag(tag[0], tag[1], tag.getOrNull(2))
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.nip89AppHandlers.recommendation
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArray
|
||||
import com.vitorpamplona.quartz.nip89AppHandlers.recommendation.tags.RecommendationTag
|
||||
|
||||
fun TagArray.recommendations() = this.mapNotNull(RecommendationTag::parse)
|
||||
|
||||
fun TagArray.recommendationAddresses() = this.mapNotNull(RecommendationTag::parseAddressId)
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.nip89AppHandlers.definition
|
||||
|
||||
import com.vitorpamplona.quartz.nip89AppHandlers.definition.tags.PlatformLinkTag
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertNull
|
||||
|
||||
class PlatformLinkTagTest {
|
||||
@Test
|
||||
fun parsesWebPlatformLinkWithEntityType() {
|
||||
val tag = arrayOf("web", "https://example.com/a/<bech32>", "nevent")
|
||||
val result = PlatformLinkTag.parse(tag)
|
||||
|
||||
assertNotNull(result)
|
||||
assertEquals("web", result.platform)
|
||||
assertEquals("https://example.com/a/<bech32>", result.uri)
|
||||
assertEquals("nevent", result.entityType)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parsesAndroidPlatformLink() {
|
||||
val tag = arrayOf("android", "amethyst://note/<bech32>", "note")
|
||||
val result = PlatformLinkTag.parse(tag)
|
||||
|
||||
assertNotNull(result)
|
||||
assertEquals("android", result.platform)
|
||||
assertEquals("amethyst://note/<bech32>", result.uri)
|
||||
assertEquals("note", result.entityType)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parsesIosPlatformLink() {
|
||||
val tag = arrayOf("ios", "damus://note/<bech32>", "naddr")
|
||||
val result = PlatformLinkTag.parse(tag)
|
||||
|
||||
assertNotNull(result)
|
||||
assertEquals("ios", result.platform)
|
||||
assertEquals("damus://note/<bech32>", result.uri)
|
||||
assertEquals("naddr", result.entityType)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rejectsTagWithOnlyOneElement() {
|
||||
val tag = arrayOf("web")
|
||||
assertNull(PlatformLinkTag.parse(tag))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rejectsUnknownPlatform() {
|
||||
val tag = arrayOf("windows", "https://example.com", "note")
|
||||
assertNull(PlatformLinkTag.parse(tag))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun roundTripPreservesValues() {
|
||||
val original = PlatformLinkTag("web", "https://example.com/e/<bech32>", "nevent")
|
||||
val tagArray = original.toTagArray()
|
||||
val parsed = PlatformLinkTag.parse(tagArray)
|
||||
|
||||
assertNotNull(parsed)
|
||||
assertEquals(original.platform, parsed.platform)
|
||||
assertEquals(original.uri, parsed.uri)
|
||||
assertEquals(original.entityType, parsed.entityType)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun roundTripWithoutEntityType() {
|
||||
val original = PlatformLinkTag("android", "amethyst://open/<bech32>", null)
|
||||
val tagArray = original.toTagArray()
|
||||
val parsed = PlatformLinkTag.parse(tagArray)
|
||||
|
||||
// Without entityType, tag only has 2 elements, so match requires has(2) which means 3 elements
|
||||
// This is expected behavior per NIP-89 spec (entityType is specified)
|
||||
assertNull(parsed)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user