Show quotes as mentions in notifications

This commit is contained in:
hzrd149
2024-01-06 16:10:21 -06:00
parent 4fb0faaa71
commit 065a90f774
6 changed files with 19 additions and 10 deletions

View File

@@ -0,0 +1,5 @@
---
"nostrudel": patch
---
Show quotes as mentions in notifications

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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<HTMLDivElement, { event: NostrEvent }>(({ 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 <ReplyNotification event={event} ref={ref} />;
else if (isMentioned) return <MentionNotification event={event} ref={ref} />;
else if (isMentioned || isQuoted) return <MentionNotification event={event} ref={ref} />;
else return null;
});
const ReplyNotification = forwardRef<HTMLDivElement, { event: NostrEvent }>(({ event }, ref) => (

View File

@@ -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");