mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-10-05 17:55:01 +02:00
mention zapper when quoting a zap
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
import { useCallback, useContext, useMemo } from "react";
|
import { useCallback, useContext, useMemo } from "react";
|
||||||
import { MenuItem, useToast } from "@chakra-ui/react";
|
import { MenuItem, useToast } from "@chakra-ui/react";
|
||||||
|
import { kinds, nip19 } from "nostr-tools";
|
||||||
|
|
||||||
import { NostrEvent } from "../../types/nostr-event";
|
import { NostrEvent } from "../../types/nostr-event";
|
||||||
import { QuoteEventIcon } from "../icons";
|
import { QuoteEventIcon } from "../icons";
|
||||||
import useUserMetadata from "../../hooks/use-user-metadata";
|
import useUserMetadata from "../../hooks/use-user-metadata";
|
||||||
import { PostModalContext } from "../../providers/route/post-modal-provider";
|
import { PostModalContext } from "../../providers/route/post-modal-provider";
|
||||||
import relayHintService from "../../services/event-relay-hint";
|
import relayHintService from "../../services/event-relay-hint";
|
||||||
|
import { getParsedZap } from "../../helpers/nostr/zaps";
|
||||||
|
|
||||||
export default function QuoteEventMenuItem({ event }: { event: NostrEvent }) {
|
export default function QuoteEventMenuItem({ event }: { event: NostrEvent }) {
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
@@ -14,7 +16,16 @@ export default function QuoteEventMenuItem({ event }: { event: NostrEvent }) {
|
|||||||
const { openModal } = useContext(PostModalContext);
|
const { openModal } = useContext(PostModalContext);
|
||||||
|
|
||||||
const share = useCallback(async () => {
|
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]);
|
}, [metadata, event, toast, address]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { PropsWithChildren, ReactNode, useCallback, useState } from "react";
|
import { PropsWithChildren, ReactNode, useMemo } from "react";
|
||||||
import {
|
import {
|
||||||
Modal,
|
Modal,
|
||||||
ModalOverlay,
|
ModalOverlay,
|
||||||
@@ -19,10 +19,9 @@ import {
|
|||||||
import { ModalProps } from "@chakra-ui/react";
|
import { ModalProps } from "@chakra-ui/react";
|
||||||
import { nip19 } from "nostr-tools";
|
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 { NostrEvent } from "../../types/nostr-event";
|
||||||
import RawValue from "./raw-value";
|
import RawValue from "./raw-value";
|
||||||
import { usePublishEvent } from "../../providers/global/publish-provider";
|
|
||||||
import { CopyIconButton } from "../copy-icon-button";
|
import { CopyIconButton } from "../copy-icon-button";
|
||||||
import DebugEventTags from "./event-tags";
|
import DebugEventTags from "./event-tags";
|
||||||
import relayHintService from "../../services/event-relay-hint";
|
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">) {
|
export default function EventDebugModal({ event, ...props }: { event: NostrEvent } & Omit<ModalProps, "children">) {
|
||||||
const publish = usePublishEvent();
|
const contentRefs = useMemo(() => getContentPointers(event.content), [event]);
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const broadcast = useCallback(async () => {
|
|
||||||
setLoading(true);
|
|
||||||
await publish("Broadcast", event);
|
|
||||||
setLoading(false);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal size="6xl" {...props}>
|
<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">
|
<Code whiteSpace="pre" overflowX="auto" width="100%" p="4">
|
||||||
{event.content}
|
{event.content}
|
||||||
</Code>
|
</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>
|
||||||
<Section
|
<Section
|
||||||
label="JSON"
|
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 { ATag, DraftNostrEvent, ETag, isATag, isDTag, isETag, isPTag, NostrEvent, Tag } from "../../types/nostr-event";
|
||||||
import { getMatchNostrLink } from "../regexp";
|
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 { safeJson } from "../parse";
|
||||||
import { safeDecode } from "../nip19";
|
import { safeDecode } from "../nip19";
|
||||||
import { safeRelayUrl, safeRelayUrls } from "../relay";
|
import { safeRelayUrl, safeRelayUrls } from "../relay";
|
||||||
@@ -64,6 +64,19 @@ export function isRepost(event: NostrEvent | DraftNostrEvent) {
|
|||||||
return isRepost;
|
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
|
* returns an array of tags that are referenced in the content
|
||||||
* either with the legacy #[0] syntax or nostr:xxxxx links
|
* either with the legacy #[0] syntax or nostr:xxxxx links
|
||||||
|
Reference in New Issue
Block a user