forked from Kieran/snort
chore: always add prefix on encode
This commit is contained in:
parent
81df18ea4e
commit
a081f9655e
@ -1,4 +1,4 @@
|
|||||||
import { NostrEvent, NostrLink } from "@snort/system";
|
import { NostrEvent, NostrLink, NostrPrefix } from "@snort/system";
|
||||||
import useEventPublisher from "Hooks/useEventPublisher";
|
import useEventPublisher from "Hooks/useEventPublisher";
|
||||||
import Icon from "Icons/Icon";
|
import Icon from "Icons/Icon";
|
||||||
import Spinner from "Icons/Spinner";
|
import Spinner from "Icons/Spinner";
|
||||||
@ -36,7 +36,9 @@ export default function WriteMessage({ chat }: { chat: Chat }) {
|
|||||||
if (file) {
|
if (file) {
|
||||||
const rx = await uploader.upload(file, file.name);
|
const rx = await uploader.upload(file, file.name);
|
||||||
if (rx.header) {
|
if (rx.header) {
|
||||||
const link = `nostr:${new NostrLink(CONFIG.eventLinkPrefix, rx.header.id, rx.header.kind).encode()}`;
|
const link = `nostr:${new NostrLink(NostrPrefix.Event, rx.header.id, rx.header.kind).encode(
|
||||||
|
CONFIG.eventLinkPrefix,
|
||||||
|
)}`;
|
||||||
setMsg(`${msg ? `${msg}\n` : ""}${link}`);
|
setMsg(`${msg ? `${msg}\n` : ""}${link}`);
|
||||||
setOtherEvents([...otherEvents, rx.header]);
|
setOtherEvents([...otherEvents, rx.header]);
|
||||||
} else if (rx.url) {
|
} else if (rx.url) {
|
||||||
|
@ -168,7 +168,9 @@ export function NoteCreator() {
|
|||||||
const rx = await uploader.upload(file, file.name);
|
const rx = await uploader.upload(file, file.name);
|
||||||
note.update(v => {
|
note.update(v => {
|
||||||
if (rx.header) {
|
if (rx.header) {
|
||||||
const link = `nostr:${new NostrLink(CONFIG.eventLinkPrefix, rx.header.id, rx.header.kind).encode()}`;
|
const link = `nostr:${new NostrLink(NostrPrefix.Event, rx.header.id, rx.header.kind).encode(
|
||||||
|
CONFIG.eventLinkPrefix,
|
||||||
|
)}`;
|
||||||
v.note = `${v.note ? `${v.note}\n` : ""}${link}`;
|
v.note = `${v.note ? `${v.note}\n` : ""}${link}`;
|
||||||
v.otherEvents = [...(v.otherEvents ?? []), rx.header];
|
v.otherEvents = [...(v.otherEvents ?? []), rx.header];
|
||||||
} else if (rx.url) {
|
} else if (rx.url) {
|
||||||
|
@ -203,6 +203,7 @@ export function NoteInner(props: NoteProps) {
|
|||||||
const pubMentions =
|
const pubMentions =
|
||||||
mentions.length > maxMentions ? mentions?.slice(0, maxMentions).map(renderMention) : mentions?.map(renderMention);
|
mentions.length > maxMentions ? mentions?.slice(0, maxMentions).map(renderMention) : mentions?.map(renderMention);
|
||||||
const others = mentions.length > maxMentions ? formatMessage(messages.Others, { n: othersLength }) : "";
|
const others = mentions.length > maxMentions ? formatMessage(messages.Others, { n: othersLength }) : "";
|
||||||
|
const link = replyLink?.encode(CONFIG.eventLinkPrefix);
|
||||||
return (
|
return (
|
||||||
<div className="reply">
|
<div className="reply">
|
||||||
re:
|
re:
|
||||||
@ -211,7 +212,7 @@ export function NoteInner(props: NoteProps) {
|
|||||||
{pubMentions} {others}
|
{pubMentions} {others}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
replyLink && <Link to={`/${replyLink.encode()}`}>{replyLink.encode().substring(0, 12)}</Link>
|
replyLink && <Link to={`/${link}`}>{link?.substring(0, 12)}</Link>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -37,12 +37,12 @@ export function ProfileLink({
|
|||||||
return `/${username}`;
|
return `/${username}`;
|
||||||
}
|
}
|
||||||
return `/${new NostrLink(
|
return `/${new NostrLink(
|
||||||
CONFIG.profileLinkPrefix,
|
NostrPrefix.Profile,
|
||||||
pubkey,
|
pubkey,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
relays ? randomSample(relays, 3) : undefined,
|
relays ? randomSample(relays, 3) : undefined,
|
||||||
).encode()}`;
|
).encode(CONFIG.profileLinkPrefix)}`;
|
||||||
}
|
}
|
||||||
if (link && (link.type === NostrPrefix.Profile || link.type === NostrPrefix.PublicKey)) {
|
if (link && (link.type === NostrPrefix.Profile || link.type === NostrPrefix.PublicKey)) {
|
||||||
return `/${link.encode()}`;
|
return `/${link.encode()}`;
|
||||||
|
@ -39,7 +39,7 @@ export default function useThreadFeed(link: NostrLink) {
|
|||||||
const links = store.data
|
const links = store.data
|
||||||
.map(a => [
|
.map(a => [
|
||||||
NostrLink.fromEvent(a),
|
NostrLink.fromEvent(a),
|
||||||
...a.tags.filter(a => a[0] === "e" || a[0] === "a").map(v => NostrLink.fromTag(v, CONFIG.eventLinkPrefix)),
|
...a.tags.filter(a => a[0] === "e" || a[0] === "a").map(v => NostrLink.fromTag(v)),
|
||||||
])
|
])
|
||||||
.flat();
|
.flat();
|
||||||
setAllEvents(links);
|
setAllEvents(links);
|
||||||
@ -51,15 +51,12 @@ export default function useThreadFeed(link: NostrLink) {
|
|||||||
const rootOrReplyAsRoot = t?.root ?? t?.replyTo;
|
const rootOrReplyAsRoot = t?.root ?? t?.replyTo;
|
||||||
if (rootOrReplyAsRoot) {
|
if (rootOrReplyAsRoot) {
|
||||||
setRoot(
|
setRoot(
|
||||||
NostrLink.fromTag(
|
NostrLink.fromTag([
|
||||||
[
|
rootOrReplyAsRoot.key,
|
||||||
rootOrReplyAsRoot.key,
|
rootOrReplyAsRoot.value ?? "",
|
||||||
rootOrReplyAsRoot.value ?? "",
|
rootOrReplyAsRoot.relay ?? "",
|
||||||
rootOrReplyAsRoot.relay ?? "",
|
...(rootOrReplyAsRoot.marker ?? []),
|
||||||
...(rootOrReplyAsRoot.marker ?? []),
|
]),
|
||||||
],
|
|
||||||
CONFIG.eventLinkPrefix,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,12 +128,12 @@ export class NostrLink {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromThreadTag(tag: Tag, eventLinkPrefix = NostrPrefix.Event) {
|
static fromThreadTag(tag: Tag) {
|
||||||
const relay = tag.relay ? [tag.relay] : undefined;
|
const relay = tag.relay ? [tag.relay] : undefined;
|
||||||
|
|
||||||
switch (tag.key) {
|
switch (tag.key) {
|
||||||
case "e": {
|
case "e": {
|
||||||
return new NostrLink(eventLinkPrefix, unwrap(tag.value), undefined, undefined, relay);
|
return new NostrLink(NostrPrefix.Event, unwrap(tag.value), undefined, undefined, relay);
|
||||||
}
|
}
|
||||||
case "p": {
|
case "p": {
|
||||||
return new NostrLink(NostrPrefix.Profile, unwrap(tag.value), undefined, undefined, relay);
|
return new NostrLink(NostrPrefix.Profile, unwrap(tag.value), undefined, undefined, relay);
|
||||||
@ -146,11 +146,11 @@ export class NostrLink {
|
|||||||
throw new Error(`Unknown tag kind ${tag.key}`);
|
throw new Error(`Unknown tag kind ${tag.key}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromTag(tag: Array<string>, eventLinkPrefix = NostrPrefix.Event) {
|
static fromTag(tag: Array<string>) {
|
||||||
const relays = tag.length > 2 ? [tag[2]] : undefined;
|
const relays = tag.length > 2 ? [tag[2]] : undefined;
|
||||||
switch (tag[0]) {
|
switch (tag[0]) {
|
||||||
case "e": {
|
case "e": {
|
||||||
return new NostrLink(eventLinkPrefix, tag[1], undefined, undefined, relays);
|
return new NostrLink(NostrPrefix.Event, tag[1], undefined, undefined, relays);
|
||||||
}
|
}
|
||||||
case "p": {
|
case "p": {
|
||||||
return new NostrLink(NostrPrefix.Profile, tag[1], undefined, undefined, relays);
|
return new NostrLink(NostrPrefix.Profile, tag[1], undefined, undefined, relays);
|
||||||
|
Loading…
Reference in New Issue
Block a user