2024-09-24 21:12:38 +00:00
|
|
|
<script lang="ts">
|
2025-04-09 22:32:18 +00:00
|
|
|
import * as nip19 from "nostr-tools/nip19"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {derived, writable} from "svelte/store"
|
|
|
|
|
import {removeUndefined} from "@welshman/lib"
|
|
|
|
|
import type {Maybe} from "@welshman/lib"
|
2025-04-15 18:03:27 +00:00
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {Address, MESSAGE, eventOutbox, relays as relaySelections, seen} from "@welshman/util"
|
2024-11-19 21:24:18 +00:00
|
|
|
import Button from "@lib/components/Button.svelte"
|
2024-10-01 21:55:33 +00:00
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
2024-09-24 21:12:38 +00:00
|
|
|
import NoteCard from "@app/components/NoteCard.svelte"
|
2026-06-16 00:56:07 +00:00
|
|
|
import NoteContent from "@app/components/NoteContent.svelte"
|
2025-10-06 18:23:19 +00:00
|
|
|
import NoteContentMinimal from "@app/components/NoteContentMinimal.svelte"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {router} from "@app/core"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {deriveEvent} from "@app/repository"
|
|
|
|
|
import {entityLink} from "@app/env"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {goToEvent} from "@app/routes"
|
2024-09-24 21:12:38 +00:00
|
|
|
|
2025-04-15 18:03:27 +00:00
|
|
|
type Props = {
|
|
|
|
|
value: any
|
|
|
|
|
event: TrustedEvent
|
|
|
|
|
url?: string
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-06 18:23:19 +00:00
|
|
|
const {value, event, url}: Props = $props()
|
2024-09-24 21:12:38 +00:00
|
|
|
|
2025-04-15 18:03:27 +00:00
|
|
|
const {id, identifier, kind, pubkey, relays = []} = value
|
2024-12-10 18:49:21 +00:00
|
|
|
const idOrAddress = id || new Address(kind, pubkey, identifier).toString()
|
2026-07-28 16:16:26 +00:00
|
|
|
const ref = {id, pubkey, kind, identifier, relays}
|
2025-04-15 18:03:27 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
// Start with the hints we were handed, then widen to everything the router can work out:
|
|
|
|
|
// where the quoted event has been seen, its author's outbox, and — since whoever quoted it
|
|
|
|
|
// must have seen it — the relays the quoting event came from.
|
|
|
|
|
const mergedRelays = writable(removeUndefined([...relays, url]))
|
|
|
|
|
|
|
|
|
|
$router.resolver
|
|
|
|
|
.relays([
|
|
|
|
|
...relaySelections(removeUndefined([url])),
|
|
|
|
|
seen(ref),
|
|
|
|
|
eventOutbox(ref),
|
|
|
|
|
seen(event, 0.5),
|
|
|
|
|
])
|
|
|
|
|
.then(urls => mergedRelays.set(urls))
|
|
|
|
|
|
|
|
|
|
const quote = derived(mergedRelays, ($mergedRelays, set: (event: Maybe<TrustedEvent>) => void) =>
|
|
|
|
|
deriveEvent(idOrAddress, $mergedRelays).subscribe(set),
|
|
|
|
|
)
|
2025-04-15 18:03:27 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const entity = derived(mergedRelays, $mergedRelays =>
|
|
|
|
|
id
|
|
|
|
|
? nip19.neventEncode({id, relays: $mergedRelays})
|
|
|
|
|
: new Address(kind, pubkey, identifier, $mergedRelays).toNaddr(),
|
|
|
|
|
)
|
2024-10-24 16:21:34 +00:00
|
|
|
|
2025-02-04 01:21:46 +00:00
|
|
|
const onclick = () => {
|
2024-11-19 21:24:18 +00:00
|
|
|
if ($quote) {
|
2025-06-05 17:55:16 +00:00
|
|
|
goToEvent($quote)
|
|
|
|
|
} else {
|
2026-07-28 16:16:26 +00:00
|
|
|
window.open(entityLink($entity))
|
2024-11-19 21:24:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-09-24 21:12:38 +00:00
|
|
|
</script>
|
|
|
|
|
|
2025-10-06 18:23:19 +00:00
|
|
|
<Button class="my-2 block w-full max-w-full text-left" {onclick}>
|
2024-11-18 22:39:43 +00:00
|
|
|
{#if $quote}
|
2026-06-16 00:56:07 +00:00
|
|
|
{#if $quote.content.trim().match(/^(nostr:)?nevent1[a-z0-9]+$/)}
|
|
|
|
|
<NoteContent {url} event={$quote} />
|
|
|
|
|
{:else if $quote.kind === MESSAGE}
|
2025-05-29 21:45:04 +00:00
|
|
|
<div
|
2026-06-24 20:56:53 +00:00
|
|
|
class="border-l-2 border-solid py-1 pl-2 opacity-90"
|
|
|
|
|
style="border-left-color: var(--primary); background-color: color-mix(in srgb, var(--primary) 10%, var(--surface-more) 90%);">
|
2025-10-06 18:23:19 +00:00
|
|
|
<NoteContentMinimal trimParent {url} event={$quote} />
|
2025-05-29 21:45:04 +00:00
|
|
|
</div>
|
|
|
|
|
{:else}
|
2026-06-23 16:41:13 +00:00
|
|
|
<NoteCard
|
|
|
|
|
event={$quote}
|
|
|
|
|
{url}
|
2026-06-24 20:56:53 +00:00
|
|
|
class="border border-solid rounded-2xl p-4"
|
|
|
|
|
style="border-color: var(--line)">
|
2025-10-06 18:23:19 +00:00
|
|
|
<NoteContentMinimal {url} event={$quote} />
|
2025-05-29 21:45:04 +00:00
|
|
|
</NoteCard>
|
|
|
|
|
{/if}
|
2024-10-01 21:55:33 +00:00
|
|
|
{:else}
|
2026-06-24 20:56:53 +00:00
|
|
|
<div class="rounded-2xl p-4">
|
2024-10-01 21:55:33 +00:00
|
|
|
<Spinner loading>Loading event...</Spinner>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2024-11-19 21:24:18 +00:00
|
|
|
</Button>
|