mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-10-01 17:31:13 +00:00
Add relay hints to mentioned notes
This commit is contained in:
parent
c77656d6b8
commit
e6104ff4ad
@ -13,7 +13,7 @@ import { getUserProfiles } from "../../../lib/profile";
|
||||
import { subscribeTo } from "../../../sockets";
|
||||
import { convertToNotes, referencesToTags } from "../../../stores/note";
|
||||
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 Avatar from "../../Avatar/Avatar";
|
||||
import EmbeddedNote from "../../EmbeddedNote/EmbeddedNote";
|
||||
@ -99,6 +99,8 @@ const EditBox: Component<{
|
||||
|
||||
const [fileToUpload, setFileToUpload] = createSignal<File | undefined>();
|
||||
|
||||
const [relayHints, setRelayHints] = createStore<Record<string, string>>({});
|
||||
|
||||
const location = useLocation();
|
||||
|
||||
let currentPath = location.pathname;
|
||||
@ -474,7 +476,7 @@ const EditBox: Component<{
|
||||
const addQuote = (quote: string | undefined) => {
|
||||
setMessage((msg) => {
|
||||
if (!textArea || !quote) return msg;
|
||||
let position = textArea.selectionStart;
|
||||
let position = textArea.selectionStart + 2;
|
||||
|
||||
const isEmptyMessage = msg.length === 0;
|
||||
|
||||
@ -494,6 +496,7 @@ const EditBox: Component<{
|
||||
textArea.selectionEnd = position;
|
||||
return newMsg;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
createEffect(() => {
|
||||
@ -628,7 +631,7 @@ const EditBox: Component<{
|
||||
});
|
||||
|
||||
if (account) {
|
||||
let tags = referencesToTags(messageToSend);
|
||||
let tags = referencesToTags(messageToSend, relayHints);
|
||||
const rep = props.replyToNote;
|
||||
|
||||
if (rep) {
|
||||
@ -961,6 +964,11 @@ const EditBox: Component<{
|
||||
);
|
||||
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);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -388,7 +388,7 @@ type NoteStore = {
|
||||
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 regexMention =
|
||||
/\bnostr:((note|npub|nevent|nprofile)1\w+)\b|#\[(\d+)\]/g;
|
||||
@ -422,7 +422,7 @@ export const referencesToTags = (value: string) => {
|
||||
}
|
||||
|
||||
if (decoded.type === 'note') {
|
||||
tags.push(['e', decoded.data, '', 'mention']);
|
||||
tags.push(['e', decoded.data, relayHints ? relayHints[decoded.data] : '', 'mention']);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user