mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-03-26 17:52:18 +01:00
mention zapper when quoting a zap
This commit is contained in:
parent
4f62750e7f
commit
878190a895
@ -1,11 +1,13 @@
|
||||
import { useCallback, useContext, useMemo } from "react";
|
||||
import { MenuItem, useToast } from "@chakra-ui/react";
|
||||
import { kinds, nip19 } from "nostr-tools";
|
||||
|
||||
import { NostrEvent } from "../../types/nostr-event";
|
||||
import { QuoteEventIcon } from "../icons";
|
||||
import useUserMetadata from "../../hooks/use-user-metadata";
|
||||
import { PostModalContext } from "../../providers/route/post-modal-provider";
|
||||
import relayHintService from "../../services/event-relay-hint";
|
||||
import { getParsedZap } from "../../helpers/nostr/zaps";
|
||||
|
||||
export default function QuoteEventMenuItem({ event }: { event: NostrEvent }) {
|
||||
const toast = useToast();
|
||||
@ -14,7 +16,16 @@ export default function QuoteEventMenuItem({ event }: { event: NostrEvent }) {
|
||||
const { openModal } = useContext(PostModalContext);
|
||||
|
||||
const share = useCallback(async () => {
|
||||
openModal({ cacheFormKey: null, initContent: "\nnostr:" + address });
|
||||
let content = "";
|
||||
|
||||
// if its a zap, mention the original author
|
||||
if (event.kind === kinds.Zap) {
|
||||
const parsed = getParsedZap(event);
|
||||
if (parsed) content += "nostr:" + nip19.npubEncode(parsed.event.pubkey) + "\n";
|
||||
}
|
||||
|
||||
content += "\nnostr:" + address;
|
||||
openModal({ cacheFormKey: null, initContent: content });
|
||||
}, [metadata, event, toast, address]);
|
||||
|
||||
return (
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { PropsWithChildren, ReactNode, useCallback, useState } from "react";
|
||||
import { PropsWithChildren, ReactNode, useMemo } from "react";
|
||||
import {
|
||||
Modal,
|
||||
ModalOverlay,
|
||||
@ -19,10 +19,9 @@ import {
|
||||
import { ModalProps } from "@chakra-ui/react";
|
||||
import { nip19 } from "nostr-tools";
|
||||
|
||||
import { getContentTagRefs, getThreadReferences } from "../../helpers/nostr/event";
|
||||
import { getContentPointers, getContentTagRefs, getThreadReferences } from "../../helpers/nostr/event";
|
||||
import { NostrEvent } from "../../types/nostr-event";
|
||||
import RawValue from "./raw-value";
|
||||
import { usePublishEvent } from "../../providers/global/publish-provider";
|
||||
import { CopyIconButton } from "../copy-icon-button";
|
||||
import DebugEventTags from "./event-tags";
|
||||
import relayHintService from "../../services/event-relay-hint";
|
||||
@ -60,13 +59,7 @@ function JsonCode({ data }: { data: any }) {
|
||||
}
|
||||
|
||||
export default function EventDebugModal({ event, ...props }: { event: NostrEvent } & Omit<ModalProps, "children">) {
|
||||
const publish = usePublishEvent();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const broadcast = useCallback(async () => {
|
||||
setLoading(true);
|
||||
await publish("Broadcast", event);
|
||||
setLoading(false);
|
||||
}, []);
|
||||
const contentRefs = useMemo(() => getContentPointers(event.content), [event]);
|
||||
|
||||
return (
|
||||
<Modal size="6xl" {...props}>
|
||||
@ -90,6 +83,18 @@ export default function EventDebugModal({ event, ...props }: { event: NostrEvent
|
||||
<Code whiteSpace="pre" overflowX="auto" width="100%" p="4">
|
||||
{event.content}
|
||||
</Code>
|
||||
|
||||
<Heading size="md" px="2">
|
||||
embeds
|
||||
</Heading>
|
||||
{contentRefs.map((pointer, i) => (
|
||||
<>
|
||||
<Code whiteSpace="pre" overflowX="auto" width="100%" p="4">
|
||||
{pointer.type + "\n"}
|
||||
{JSON.stringify(pointer.data, null, 2)}
|
||||
</Code>
|
||||
</>
|
||||
))}
|
||||
</Section>
|
||||
<Section
|
||||
label="JSON"
|
||||
|
@ -5,7 +5,7 @@ import { nanoid } from "nanoid";
|
||||
|
||||
import { ATag, DraftNostrEvent, ETag, isATag, isDTag, isETag, isPTag, NostrEvent, Tag } from "../../types/nostr-event";
|
||||
import { getMatchNostrLink } from "../regexp";
|
||||
import { AddressPointer, EventPointer } from "nostr-tools/lib/types/nip19";
|
||||
import { AddressPointer, DecodeResult, EventPointer } from "nostr-tools/lib/types/nip19";
|
||||
import { safeJson } from "../parse";
|
||||
import { safeDecode } from "../nip19";
|
||||
import { safeRelayUrl, safeRelayUrls } from "../relay";
|
||||
@ -64,6 +64,19 @@ export function isRepost(event: NostrEvent | DraftNostrEvent) {
|
||||
return isRepost;
|
||||
}
|
||||
|
||||
export function getContentPointers(content: string) {
|
||||
const pointers: DecodeResult[] = [];
|
||||
|
||||
const linkMatches = Array.from(content.matchAll(getMatchNostrLink()));
|
||||
for (const [_, _prefix, link] of linkMatches) {
|
||||
const decoded = safeDecode(link);
|
||||
if (!decoded) continue;
|
||||
pointers.push(decoded);
|
||||
}
|
||||
|
||||
return pointers;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an array of tags that are referenced in the content
|
||||
* either with the legacy #[0] syntax or nostr:xxxxx links
|
||||
|
Loading…
x
Reference in New Issue
Block a user