From 065a90f7741f73f8f943b6de3402a5d7c6b36202 Mon Sep 17 00:00:00 2001 From: hzrd149 Date: Sat, 6 Jan 2024 16:10:21 -0600 Subject: [PATCH] Show quotes as mentions in notifications --- .changeset/cuddly-planets-dress.md | 5 +++++ src/components/post-modal/index.tsx | 6 +++--- src/helpers/nostr/post.ts | 4 ++-- src/views/channels/components/send-message-form.tsx | 4 ++-- src/views/notifications/notification-item.tsx | 6 +++++- src/views/thread/components/reply-form.tsx | 4 ++-- 6 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 .changeset/cuddly-planets-dress.md diff --git a/.changeset/cuddly-planets-dress.md b/.changeset/cuddly-planets-dress.md new file mode 100644 index 000000000..b393addf9 --- /dev/null +++ b/.changeset/cuddly-planets-dress.md @@ -0,0 +1,5 @@ +--- +"nostrudel": patch +--- + +Show quotes as mentions in notifications diff --git a/src/components/post-modal/index.tsx b/src/components/post-modal/index.tsx index e7f359389..5217989f2 100644 --- a/src/components/post-modal/index.tsx +++ b/src/components/post-modal/index.tsx @@ -34,7 +34,7 @@ import { createEmojiTags, ensureNotifyPubkeys, finalizeNote, - getContentMentions, + getPubkeysMentionedInContent, setZapSplit, } from "../../helpers/nostr/post"; import { UserAvatarStack } from "../compact-user-stack"; @@ -126,7 +126,7 @@ export default function PostModal({ updatedDraft.tags.push(["subject", subject]); } - const contentMentions = getContentMentions(updatedDraft.content); + const contentMentions = getPubkeysMentionedInContent(updatedDraft.content); updatedDraft = createEmojiTags(updatedDraft, emojis); updatedDraft = ensureNotifyPubkeys(updatedDraft, contentMentions); if (split.length > 0) { @@ -146,7 +146,7 @@ export default function PostModal({ }); const canSubmit = getValues().content.length > 0; - const mentions = getContentMentions(correctContentMentions(getValues().content)); + const mentions = getPubkeysMentionedInContent(correctContentMentions(getValues().content)); const previewDraft = useThrottle(getDraft(), 500); diff --git a/src/helpers/nostr/post.ts b/src/helpers/nostr/post.ts index ba0fbd56a..7fa6c44ea 100644 --- a/src/helpers/nostr/post.ts +++ b/src/helpers/nostr/post.ts @@ -67,7 +67,7 @@ export function correctContentMentions(content: string) { return content.replace(/(\s|^)(?:@)?(npub1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58})/gi, "$1nostr:$2"); } -export function getContentMentions(content: string) { +export function getPubkeysMentionedInContent(content: string) { const matched = content.matchAll(getMatchNostrLink()); const pubkeys: string[] = []; @@ -96,7 +96,7 @@ export function getContentMentions(content: string) { } export function ensureNotifyContentMentions(draft: DraftNostrEvent) { - const mentions = getContentMentions(draft.content); + const mentions = getPubkeysMentionedInContent(draft.content); return mentions.length > 0 ? ensureNotifyPubkeys(draft, mentions) : draft; } diff --git a/src/views/channels/components/send-message-form.tsx b/src/views/channels/components/send-message-form.tsx index f20d45746..53cb11fe0 100644 --- a/src/views/channels/components/send-message-form.tsx +++ b/src/views/channels/components/send-message-form.tsx @@ -10,7 +10,7 @@ import { useTextAreaUploadFileWithForm } from "../../../hooks/use-textarea-uploa import clientRelaysService from "../../../services/client-relays"; import { DraftNostrEvent, NostrEvent } from "../../../types/nostr-event"; import NostrPublishAction from "../../../classes/nostr-publish-action"; -import { createEmojiTags, ensureNotifyPubkeys, getContentMentions } from "../../../helpers/nostr/post"; +import { createEmojiTags, ensureNotifyPubkeys, getPubkeysMentionedInContent } from "../../../helpers/nostr/post"; import { useContextEmojis } from "../../../providers/global/emoji-provider"; export default function ChannelMessageForm({ @@ -46,7 +46,7 @@ export default function ChannelMessageForm({ created_at: dayjs().unix(), }; - const contentMentions = getContentMentions(draft.content); + const contentMentions = getPubkeysMentionedInContent(draft.content); draft = createEmojiTags(draft, emojis); draft = ensureNotifyPubkeys(draft, contentMentions); diff --git a/src/views/notifications/notification-item.tsx b/src/views/notifications/notification-item.tsx index cb339217e..91576b268 100644 --- a/src/views/notifications/notification-item.tsx +++ b/src/views/notifications/notification-item.tsx @@ -18,6 +18,7 @@ import { AtIcon, ChevronDownIcon, ChevronUpIcon, LightningIcon, ReplyIcon, Repos import useSingleEvent from "../../hooks/use-single-event"; import { TORRENT_COMMENT_KIND } from "../../helpers/nostr/torrents"; import NotificationIconEntry from "./components/notification-icon-entry"; +import { getPubkeysMentionedInContent } from "../../helpers/nostr/post"; export const ExpandableToggleButton = ({ toggle, @@ -37,10 +38,13 @@ const NoteNotification = forwardRef(({ ev const parent = useSingleEvent(refs.reply?.e?.id); const isReplyingToMe = !!refs.reply?.e?.id && (parent ? parent.pubkey === account.pubkey : true); + // is the "p" tag directly mentioned in the content const isMentioned = isMentionedInContent(event, account.pubkey); + // is the pubkey mentioned in any way in the content + const isQuoted = !isMentioned && getPubkeysMentionedInContent(event.content).includes(account.pubkey); if (isReplyingToMe) return ; - else if (isMentioned) return ; + else if (isMentioned || isQuoted) return ; else return null; }); const ReplyNotification = forwardRef(({ event }, ref) => ( diff --git a/src/views/thread/components/reply-form.tsx b/src/views/thread/components/reply-form.tsx index 347d42626..0e20a8bb4 100644 --- a/src/views/thread/components/reply-form.tsx +++ b/src/views/thread/components/reply-form.tsx @@ -14,7 +14,7 @@ import { createEmojiTags, ensureNotifyPubkeys, finalizeNote, - getContentMentions, + getPubkeysMentionedInContent, } from "../../../helpers/nostr/post"; import useCurrentAccount from "../../../hooks/use-current-account"; import { useSigningContext } from "../../../providers/global/signing-provider"; @@ -47,7 +47,7 @@ export default function ReplyForm({ item, onCancel, onSubmitted, replyKind = Kin content: "", }, }); - const contentMentions = getContentMentions(getValues().content); + const contentMentions = getPubkeysMentionedInContent(getValues().content); const notifyPubkeys = unique([...threadMembers, ...contentMentions]); watch("content");