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