bug: tryParseNostrLink
This commit is contained in:
parent
fdf3d855df
commit
7992601f46
@ -1,11 +1,11 @@
|
||||
import { Link } from "react-router-dom";
|
||||
import { NostrPrefix, parseNostrLink } from "@snort/system";
|
||||
import { NostrPrefix, tryParseNostrLink } from "@snort/system";
|
||||
|
||||
import Mention from "Element/Mention";
|
||||
import NoteQuote from "Element/NoteQuote";
|
||||
|
||||
export default function NostrLink({ link, depth }: { link: string; depth?: number }) {
|
||||
const nav = parseNostrLink(link);
|
||||
const nav = tryParseNostrLink(link);
|
||||
|
||||
if (nav?.type === NostrPrefix.PublicKey || nav?.type === NostrPrefix.Profile) {
|
||||
return <Mention pubkey={nav.id} relays={nav.relays} />;
|
||||
|
@ -218,9 +218,9 @@ export default function Thread() {
|
||||
const location = useLocation();
|
||||
|
||||
const link = parseNostrLink(params.id ?? "", NostrPrefix.Note);
|
||||
const thread = useThreadFeed(unwrap(link));
|
||||
const thread = useThreadFeed(link);
|
||||
|
||||
const [currentId, setCurrentId] = useState(link?.id);
|
||||
const [currentId, setCurrentId] = useState(link.id);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const isSingleNote = thread.data?.filter(a => a.kind === EventKind.TextNote).length === 1;
|
||||
|
@ -2,7 +2,7 @@ import "./ProfilePage.css";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useIntl, FormattedMessage } from "react-intl";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { encodeTLV, EventKind, HexKey, NostrPrefix, parseNostrLink } from "@snort/system";
|
||||
import { encodeTLV, EventKind, HexKey, NostrPrefix, tryParseNostrLink } from "@snort/system";
|
||||
|
||||
import { getReactions, unwrap } from "SnortUtils";
|
||||
import { formatShort } from "Number";
|
||||
@ -157,7 +157,7 @@ export default function ProfilePage() {
|
||||
setId(a);
|
||||
});
|
||||
} else {
|
||||
const nav = parseNostrLink(params.id ?? "");
|
||||
const nav = tryParseNostrLink(params.id ?? "");
|
||||
if (nav?.type === NostrPrefix.PublicKey || nav?.type === NostrPrefix.Profile) {
|
||||
// todo: use relays if any for nprofile
|
||||
setId(nav.id);
|
||||
|
@ -2,7 +2,7 @@ import { EventKind, HexKey, NostrPrefix, NostrEvent } from ".";
|
||||
import { HashtagRegex } from "./Const";
|
||||
import { getPublicKey, unixNow } from "./Utils";
|
||||
import { EventExt } from "./EventExt";
|
||||
import { parseNostrLink } from "./NostrLink";
|
||||
import { tryParseNostrLink } from "./NostrLink";
|
||||
|
||||
export class EventBuilder {
|
||||
#kind?: EventKind;
|
||||
@ -90,7 +90,7 @@ export class EventBuilder {
|
||||
|
||||
#replaceMention(match: string) {
|
||||
const npub = match.slice(1);
|
||||
const link = parseNostrLink(npub);
|
||||
const link = tryParseNostrLink(npub);
|
||||
if (link) {
|
||||
if (link.type === NostrPrefix.Profile || link.type === NostrPrefix.PublicKey) {
|
||||
this.tag(["p", link.id]);
|
||||
|
@ -52,6 +52,7 @@ export class RequestBuilder {
|
||||
id: string;
|
||||
#builders: Array<RequestFilterBuilder>;
|
||||
#options?: RequestBuilderOptions;
|
||||
#log = debug("RequestBuilder");
|
||||
|
||||
constructor(id: string) {
|
||||
this.id = id;
|
||||
@ -96,16 +97,13 @@ export class RequestBuilder {
|
||||
*/
|
||||
buildDiff(relays: RelayCache, filters: Array<FlatReqFilter>): Array<BuiltRawReqFilter> {
|
||||
const start = unixNowMs();
|
||||
|
||||
const next = this.#builders.flatMap(f => expandFilter(f.filter))
|
||||
const diff = diffFilters(filters, next);
|
||||
const ts = (unixNowMs() - start);
|
||||
const log = debug("buildDiff");
|
||||
log("%s %d ms", this.id, ts);
|
||||
if (ts > 200) {
|
||||
console.warn(diff, filters);
|
||||
}
|
||||
this.#log("buildDiff %s %d ms", this.id, ts);
|
||||
if (diff.changed) {
|
||||
log(diff);
|
||||
this.#log(diff);
|
||||
return splitAllByWriteRelays(relays, diff.added).map(a => {
|
||||
return {
|
||||
strategy: RequestStrategy.AuthorsRelays,
|
||||
|
@ -71,14 +71,14 @@ export function reqFilterEq(a: FlatReqFilter | ReqFilter, b: FlatReqFilter | Req
|
||||
}
|
||||
|
||||
export function flatFilterEq(a: FlatReqFilter, b: FlatReqFilter): boolean {
|
||||
return a.ids === b.ids
|
||||
&& a.kinds === b.kinds
|
||||
&& a["#e"] === b["#e"]
|
||||
&& a.authors === b.authors
|
||||
&& a.limit === b.limit
|
||||
&& a.since === b.since
|
||||
return a.since === b.since
|
||||
&& a.until === b.until
|
||||
&& a.limit === b.limit
|
||||
&& a.search === b.search
|
||||
&& a.ids === b.ids
|
||||
&& a.kinds === b.kinds
|
||||
&& a.authors === b.authors
|
||||
&& a["#e"] === b["#e"]
|
||||
&& a["#p"] === b["#p"]
|
||||
&& a["#t"] === b["#t"]
|
||||
&& a["#d"] === b["#d"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user