Fix npub entities in notes

This commit is contained in:
Jonathan Staab 2023-04-24 11:59:15 -05:00
parent 1719da5562
commit db583e7ff2
4 changed files with 20 additions and 5 deletions

View File

@ -1,10 +1,13 @@
# Current
- [ ] Fix notifications, separate into mentions/replies and other
- [ ] Render npubs properly http://localhost:5173/nevent1qqsqqr7r9w95lvj79zpsykup2d995jqhyxdntq98tu6tsvmjuh5ak9spz3mhxue69uhhyetvv9ujuerpd46hxtnfduyyc40u
- [ ] Links/topics/mentions open modals
- [ ] Render link previews inline rather than at bottom, check NostrReport for this
- [ ] Wait for an auth challenge based on relay document to avoid missing first few REQs
- [ ] Extract libraries
- Cursor
- parseContent
- Tags
- [ ] Image classification
- https://github.com/bhky/opennsfw2

View File

@ -122,18 +122,18 @@
<br />
{/each}
{:else if type === "topic"}
<Anchor stopPropagation on:click={() => openTopic(value)}>#{value}</Anchor>
<Anchor killEvent on:click={() => openTopic(value)}>#{value}</Anchor>
{:else if type === "link"}
<Anchor external href={value}>
{value.replace(/https?:\/\/(www\.)?/, "")}
</Anchor>
{:else if type.startsWith("nostr:")}
{#if value.pubkey}
@<Anchor stopPropagation on:click={() => goToPerson(value.pubkey)}>
@<Anchor killEvent on:click={() => goToPerson(value.pubkey)}>
{displayPerson(getPersonWithFallback(value.pubkey))}
</Anchor>
{:else}
<Anchor stopPropagation href={"/" + value.entity}>
<Anchor killEvent href={"/" + value.entity}>
{value.entity.slice(0, 16) + "..."}
</Anchor>
{/if}

View File

@ -2,9 +2,11 @@
import cx from "classnames"
import {navigate} from "svelte-routing"
import {switcher} from "hurdak/lib/hurdak"
import {killEvent as _killEvent} from "src/util/html"
import {createEventDispatcher} from "svelte"
export let stopPropagation = false
export let killEvent = false
export let external = false
export let loading = false
export let type = "anchor"
@ -35,6 +37,10 @@
)
const onClick = e => {
if (killEvent) {
_killEvent(e)
}
if (stopPropagation) {
e.stopPropagation()
}

View File

@ -215,7 +215,13 @@ export const parseContent = ({content, tags = []}) => {
try {
const entity = bech32.replace("nostr:", "")
const {type, data} = nip19.decode(entity) as {type: string; data: object}
const value = type === "note" ? {id: data} : data
let value = data
if (type === "note") {
value = {id: data}
} else if (type === "npub") {
value = {pubkey: data}
}
return [`nostr:${type}`, bech32, {...value, entity}]
} catch (e) {