From fbc1ea4ebb9842634aa9f8e2e4e81ae7a803a004 Mon Sep 17 00:00:00 2001 From: hzrd149 Date: Thu, 24 Aug 2023 10:37:46 -0500 Subject: [PATCH] fix bug where mentioning npub would freeze app --- .changeset/stupid-dodos-design.md | 5 +++ .../note/buttons/quote-repost-button.tsx | 16 ++++++- src/components/note/buttons/reply-button.tsx | 24 ---------- src/components/post-modal/index.tsx | 9 +++- src/helpers/nip19.ts | 14 +++++- src/helpers/nostr/event.ts | 44 ------------------- src/helpers/nostr/post.ts | 42 +++++++----------- src/helpers/nostr/stream.ts | 7 ++- src/helpers/regexp.ts | 2 - src/views/note/components/reply-form.tsx | 14 +++--- .../streams/stream/stream-chat/index.tsx | 1 + 11 files changed, 68 insertions(+), 110 deletions(-) create mode 100644 .changeset/stupid-dodos-design.md delete mode 100644 src/components/note/buttons/reply-button.tsx diff --git a/.changeset/stupid-dodos-design.md b/.changeset/stupid-dodos-design.md new file mode 100644 index 000000000..9f3c14cc4 --- /dev/null +++ b/.changeset/stupid-dodos-design.md @@ -0,0 +1,5 @@ +--- +"nostrudel": patch +--- + +fix bug where mentioning npub would freeze app diff --git a/src/components/note/buttons/quote-repost-button.tsx b/src/components/note/buttons/quote-repost-button.tsx index f6fc1ff8b..4d10752bb 100644 --- a/src/components/note/buttons/quote-repost-button.tsx +++ b/src/components/note/buttons/quote-repost-button.tsx @@ -1,16 +1,28 @@ import { useContext } from "react"; import { IconButton } from "@chakra-ui/react"; +import { Kind } from "nostr-tools"; +import dayjs from "dayjs"; + import { NostrEvent } from "../../../types/nostr-event"; import { QuoteRepostIcon } from "../../icons"; import { PostModalContext } from "../../../providers/post-modal-provider"; -import { buildQuoteRepost } from "../../../helpers/nostr/event"; import { useCurrentAccount } from "../../../hooks/use-current-account"; +import { getSharableNoteId } from "../../../helpers/nip19"; export function QuoteRepostButton({ event }: { event: NostrEvent }) { const account = useCurrentAccount(); const { openModal } = useContext(PostModalContext); - const handleClick = () => openModal(buildQuoteRepost(event)); + const handleClick = () => { + const nevent = getSharableNoteId(event.id); + const draft = { + kind: Kind.Text, + tags: [], + content: "nostr:" + nevent, + created_at: dayjs().unix(), + }; + openModal(draft); + }; return ( openModal(buildReply(event)); - - return ( - } - title="Reply" - aria-label="Reply" - onClick={reply} - isDisabled={account?.readonly ?? true} - /> - ); -} diff --git a/src/components/post-modal/index.tsx b/src/components/post-modal/index.tsx index 31de4c5ee..48651a623 100644 --- a/src/components/post-modal/index.tsx +++ b/src/components/post-modal/index.tsx @@ -14,6 +14,7 @@ import { useToast, } from "@chakra-ui/react"; import dayjs from "dayjs"; + import NostrPublishAction from "../../classes/nostr-publish-action"; import { getReferences } from "../../helpers/nostr/event"; import { useWriteRelayUrls } from "../../hooks/use-client-relays"; @@ -24,7 +25,8 @@ import { NoteLink } from "../note-link"; import { NoteContents } from "../note/note-contents"; import { PublishDetails } from "../publish-details"; import { TrustProvider } from "../../providers/trust"; -import { finalizeNote } from "../../helpers/nostr/post"; +import { ensureNotifyPubkeys, finalizeNote, getContentMentions } from "../../helpers/nostr/post"; +import { UserAvatarStack } from "../user-avatar-stack"; function emptyDraft(): DraftNostrEvent { return { @@ -77,7 +79,9 @@ export const PostModal = ({ isOpen, onClose, initialDraft }: PostModalProps) => const handleSubmit = async () => { setWaiting(true); - const updatedDraft = finalizeNote(draft); + let updatedDraft = finalizeNote(draft); + const contentMentions = getContentMentions(draft.content); + updatedDraft = ensureNotifyPubkeys(updatedDraft, contentMentions); const signed = await requestSignature(updatedDraft); setWaiting(false); if (!signed) return; @@ -144,6 +148,7 @@ export const PostModal = ({ isOpen, onClose, initialDraft }: PostModalProps) => isLoading={uploading} /> + {draft.content.length > 0 && } - + {getValues().content.length > 0 && (