From baaa984d0d0c366e78acce3fbd6affcfe098746f Mon Sep 17 00:00:00 2001 From: Believethehype <1097224+believethehype@users.noreply.github.com> Date: Mon, 13 May 2024 22:43:38 +0200 Subject: [PATCH] add nip90 content discovery request --- .../loggedIn/NIP90ContentDiscoveryScreen.kt | 36 ++++++----- .../NIP90ContentDiscoveryRequestEvent.kt | 60 +++++++++++++++++++ 2 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 quartz/src/main/java/com/vitorpamplona/quartz/events/NIP90ContentDiscoveryRequestEvent.kt diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/NIP90ContentDiscoveryScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/NIP90ContentDiscoveryScreen.kt index ee7fd853a..b4ac148e7 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/NIP90ContentDiscoveryScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/NIP90ContentDiscoveryScreen.kt @@ -72,25 +72,31 @@ private fun RenderNostrNIP90ContentDiscoveryScreen( if (DVMID != null) { Text(text = "Debug: DVM KEY:\n " + DVMID) } - // TODO Send KIND 5300 Event with p tag = DVMID - /*note.event?.let { - ReactionEvent.create(emojiUrl, it, signer) { - Client.send(it) - LocalCache.consume(it) + if (DVMID != null) { + // TODO 1 Send KIND 5300 Event with p tag = DVMID (crashes) + + /* + var signer = accountViewModel.account.signer + NIP90ContentDiscoveryRequestEvent.create(DVMID, signer) { + // Client.send(it) + // LocalCache.justConsume(it, null) } - }*/ - // TODO PARSE AND LOAD RESULTS FROM KIND 6300 REPLY to resultfeedmodel (RN this still is the bookmark list) - // TODO Render Results + */ - HorizontalPager(state = pagerState) { - RefresheableFeedView( - resultFeedViewModel, - null, - accountViewModel = accountViewModel, - nav = nav, - ) + // TODO 2 PARSE AND LOAD RESULTS FROM KIND 6300 REPLY to resultfeedmodel (RN this still is the bookmark list) + + // TODO 3 Render Results (hopefully works when 2 is working) + + HorizontalPager(state = pagerState) { + RefresheableFeedView( + resultFeedViewModel, + null, + accountViewModel = accountViewModel, + nav = nav, + ) + } } } } diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/events/NIP90ContentDiscoveryRequestEvent.kt b/quartz/src/main/java/com/vitorpamplona/quartz/events/NIP90ContentDiscoveryRequestEvent.kt new file mode 100644 index 000000000..d8dbf27b8 --- /dev/null +++ b/quartz/src/main/java/com/vitorpamplona/quartz/events/NIP90ContentDiscoveryRequestEvent.kt @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2024 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.events + +import androidx.compose.runtime.Immutable +import androidx.compose.runtime.Stable +import com.vitorpamplona.quartz.encoders.HexKey +import com.vitorpamplona.quartz.signers.NostrSigner +import com.vitorpamplona.quartz.utils.TimeUtils + +@Stable +@Immutable +class NIP90ContentDiscoveryRequestEvent( + id: HexKey, + pubKey: HexKey, + createdAt: Long, + tags: Array>, + content: String, + sig: HexKey, +) : BaseAddressableEvent(id, pubKey, createdAt, KIND, tags, content, sig) { + @Transient private var cachedMetadata: AppMetadata? = null + + companion object { + const val KIND = 5300 + + fun create( + addressedDVM: String, + signer: NostrSigner, + createdAt: Long = TimeUtils.now(), + onReady: (NIP90ContentDiscoveryRequestEvent) -> Unit, + ) { + val content = "" + + // val clientTag = arrayOf("client", "Amethyst") + + val tags = mutableListOf>() + tags.add(arrayOf("p", addressedDVM)) + tags.add(arrayOf("alt", "NIP90 Content Discovery request")) + signer.sign(createdAt, KIND, tags.toTypedArray(), content, onReady) + } + } +}