mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-04-11 13:20:37 +02:00
correct @ mentions when making posts
This commit is contained in:
parent
d4ba16ef51
commit
676703fd9c
@ -29,7 +29,13 @@ import { ArrowDownSIcon, ArrowUpSIcon, ImageIcon } from "../icons";
|
||||
import { NoteContents } from "../note/note-contents";
|
||||
import { PublishDetails } from "../publish-details";
|
||||
import { TrustProvider } from "../../providers/trust";
|
||||
import { createEmojiTags, ensureNotifyPubkeys, finalizeNote, getContentMentions } from "../../helpers/nostr/post";
|
||||
import {
|
||||
correctContentMentions,
|
||||
createEmojiTags,
|
||||
ensureNotifyPubkeys,
|
||||
finalizeNote,
|
||||
getContentMentions,
|
||||
} from "../../helpers/nostr/post";
|
||||
import { UserAvatarStack } from "../compact-user-stack";
|
||||
import MagicTextArea, { RefType } from "../magic-textarea";
|
||||
import { useContextEmojis } from "../../providers/emoji-provider";
|
||||
@ -95,6 +101,8 @@ export default function PostModal({
|
||||
created_at: dayjs().unix(),
|
||||
});
|
||||
|
||||
updatedDraft.content = correctContentMentions(updatedDraft.content);
|
||||
|
||||
if (nsfw) {
|
||||
updatedDraft.tags.push(nsfwReason ? ["content-warning", nsfwReason] : ["content-warning"]);
|
||||
}
|
||||
@ -119,7 +127,7 @@ export default function PostModal({
|
||||
});
|
||||
|
||||
const canSubmit = getValues().content.length > 0;
|
||||
const mentions = getContentMentions(getValues().content);
|
||||
const mentions = getContentMentions(correctContentMentions(getValues().content));
|
||||
|
||||
const renderContent = () => {
|
||||
if (publishAction) {
|
||||
|
@ -61,6 +61,10 @@ export function ensureNotifyPubkeys(draft: DraftNostrEvent, pubkeys: string[]) {
|
||||
return updated;
|
||||
}
|
||||
|
||||
export function correctContentMentions(content: string) {
|
||||
return content.replace(/(\s|^)(?:@)?(npub1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58})/gi, "$1nostr:$2");
|
||||
}
|
||||
|
||||
export function getContentMentions(content: string) {
|
||||
const matched = content.matchAll(/nostr:(npub1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58})/gi);
|
||||
return Array.from(matched)
|
||||
@ -107,7 +111,8 @@ export function createEmojiTags(draft: DraftNostrEvent, emojis: Emoji[]) {
|
||||
}
|
||||
|
||||
export function finalizeNote(draft: DraftNostrEvent) {
|
||||
let updated = draft;
|
||||
let updated: DraftNostrEvent = { ...draft, tags: Array.from(draft.tags) };
|
||||
updated.content = correctContentMentions(updated.content);
|
||||
updated = createHashtagTags(updated);
|
||||
return updated;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user