Add relay hints to mentioned notes

This commit is contained in:
Bojan Mojsilovic 2024-04-04 09:39:53 +02:00
parent c77656d6b8
commit e6104ff4ad
2 changed files with 13 additions and 6 deletions

View File

@ -13,7 +13,7 @@ import { getUserProfiles } from "../../../lib/profile";
import { subscribeTo } from "../../../sockets"; import { subscribeTo } from "../../../sockets";
import { convertToNotes, referencesToTags } from "../../../stores/note"; import { convertToNotes, referencesToTags } from "../../../stores/note";
import { convertToUser, nip05Verification, truncateNpub, userName } from "../../../stores/profile"; import { convertToUser, nip05Verification, truncateNpub, userName } from "../../../stores/profile";
import { EmojiOption, FeedPage, NostrMentionContent, NostrNoteContent, NostrStatsContent, NostrUserContent, PrimalNote, PrimalUser, SendNoteResult } from "../../../types/primal"; import { EmojiOption, FeedPage, NostrMentionContent, NostrNoteContent, NostrRelayHint, NostrStatsContent, NostrUserContent, PrimalNote, PrimalUser, SendNoteResult } from "../../../types/primal";
import { debounce, getScreenCordinates, isVisibleInContainer, uuidv4 } from "../../../utils"; import { debounce, getScreenCordinates, isVisibleInContainer, uuidv4 } from "../../../utils";
import Avatar from "../../Avatar/Avatar"; import Avatar from "../../Avatar/Avatar";
import EmbeddedNote from "../../EmbeddedNote/EmbeddedNote"; import EmbeddedNote from "../../EmbeddedNote/EmbeddedNote";
@ -99,6 +99,8 @@ const EditBox: Component<{
const [fileToUpload, setFileToUpload] = createSignal<File | undefined>(); const [fileToUpload, setFileToUpload] = createSignal<File | undefined>();
const [relayHints, setRelayHints] = createStore<Record<string, string>>({});
const location = useLocation(); const location = useLocation();
let currentPath = location.pathname; let currentPath = location.pathname;
@ -474,7 +476,7 @@ const EditBox: Component<{
const addQuote = (quote: string | undefined) => { const addQuote = (quote: string | undefined) => {
setMessage((msg) => { setMessage((msg) => {
if (!textArea || !quote) return msg; if (!textArea || !quote) return msg;
let position = textArea.selectionStart; let position = textArea.selectionStart + 2;
const isEmptyMessage = msg.length === 0; const isEmptyMessage = msg.length === 0;
@ -494,6 +496,7 @@ const EditBox: Component<{
textArea.selectionEnd = position; textArea.selectionEnd = position;
return newMsg; return newMsg;
}); });
}; };
createEffect(() => { createEffect(() => {
@ -628,7 +631,7 @@ const EditBox: Component<{
}); });
if (account) { if (account) {
let tags = referencesToTags(messageToSend); let tags = referencesToTags(messageToSend, relayHints);
const rep = props.replyToNote; const rep = props.replyToNote;
if (rep) { if (rep) {
@ -961,6 +964,11 @@ const EditBox: Component<{
); );
return; return;
} }
if (content.kind === Kind.RelayHint) {
const hints = JSON.parse(content.content) as Record<string, string>;
setRelayHints(() => ({ ...hints }))
}
} }
}); });
@ -1006,7 +1014,6 @@ const EditBox: Component<{
}); });
setParsedMessage(parsed); setParsedMessage(parsed);
}; };

View File

@ -388,7 +388,7 @@ type NoteStore = {
reposts: Record<string, string> | undefined, reposts: Record<string, string> | undefined,
} }
export const referencesToTags = (value: string) => { export const referencesToTags = (value: string, relayHints: Record<string, string>) => {
const regexHashtag = /(?:\s|^)#[^\s!@#$%^&*(),.?":{}|<>]+/ig; const regexHashtag = /(?:\s|^)#[^\s!@#$%^&*(),.?":{}|<>]+/ig;
const regexMention = const regexMention =
/\bnostr:((note|npub|nevent|nprofile)1\w+)\b|#\[(\d+)\]/g; /\bnostr:((note|npub|nevent|nprofile)1\w+)\b|#\[(\d+)\]/g;
@ -422,7 +422,7 @@ export const referencesToTags = (value: string) => {
} }
if (decoded.type === 'note') { if (decoded.type === 'note') {
tags.push(['e', decoded.data, '', 'mention']); tags.push(['e', decoded.data, relayHints ? relayHints[decoded.data] : '', 'mention']);
return; return;
} }