feat: client tag
feat: attach relays to link for event
This commit is contained in:
parent
edc59fbf79
commit
d16df8086a
@ -3,6 +3,7 @@ import "@szhsin/react-menu/dist/index.css";
|
||||
import "@/assets/fonts/inter.css";
|
||||
|
||||
import { unixNow, unixNowMs } from "@snort/shared";
|
||||
import { EventBuilder } from "@snort/system";
|
||||
import { SnortContext } from "@snort/system-react";
|
||||
import { StrictMode } from "react";
|
||||
import * as ReactDOM from "react-dom/client";
|
||||
@ -47,6 +48,7 @@ import { Day } from "./Utils/Const";
|
||||
import { LoginStore } from "./Utils/Login";
|
||||
|
||||
async function initSite() {
|
||||
EventBuilder.ClientTag = ["snort", __SNORT_VERSION__];
|
||||
storeRefCode();
|
||||
if (hasWasm) {
|
||||
await wasmInit(WasmPath);
|
||||
|
@ -5,6 +5,11 @@ import { EventExt } from "./event-ext";
|
||||
import { NostrLink, tryParseNostrLink } from "./nostr-link";
|
||||
|
||||
export class EventBuilder {
|
||||
/**
|
||||
* Client tag to attach to all events
|
||||
*/
|
||||
static ClientTag: Array<string> | undefined = ["client", "snort_system"];
|
||||
|
||||
#kind?: EventKind;
|
||||
#content?: string;
|
||||
#createdAt?: number;
|
||||
@ -101,6 +106,9 @@ export class EventBuilder {
|
||||
created_at: (this.#createdAt ?? unixNow()) - (this.#jitter ? Math.floor(jitter(this.#jitter)) : 0),
|
||||
tags: this.#tags.sort((a, b) => a[0].localeCompare(b[0])),
|
||||
} as NostrEvent;
|
||||
if (EventBuilder.ClientTag && EventBuilder.ClientTag[0] === "client" && EventBuilder.ClientTag.length > 1) {
|
||||
ev.tags.push(EventBuilder.ClientTag);
|
||||
}
|
||||
ev.id = EventExt.createId(ev);
|
||||
return ev;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { bech32ToHex, hexToBech32, isHex, removeUndefined, unwrap, Bech32Regex } from "@snort/shared";
|
||||
import { bech32ToHex, hexToBech32, isHex, removeUndefined, unwrap, Bech32Regex, sanitizeRelayUrl, appendDedupe } from "@snort/shared";
|
||||
import { decodeTLV, encodeTLV, EventExt, EventKind, NostrEvent, NostrPrefix, TaggedNostrEvent, TLVEntryType } from ".";
|
||||
import { findTag } from "./utils";
|
||||
|
||||
@ -11,7 +11,7 @@ export interface ToNostrEventTag {
|
||||
}
|
||||
|
||||
export class NostrHashtagLink implements ToNostrEventTag {
|
||||
constructor(readonly tag: string) {}
|
||||
constructor(readonly tag: string) { }
|
||||
|
||||
equals(other: ToNostrEventTag): boolean {
|
||||
const otherTag = other.toEventTag();
|
||||
@ -24,7 +24,7 @@ export class NostrHashtagLink implements ToNostrEventTag {
|
||||
}
|
||||
|
||||
export class UnknownTag implements ToNostrEventTag {
|
||||
constructor(readonly value: Array<string>) {}
|
||||
constructor(readonly value: Array<string>) { }
|
||||
|
||||
equals(other: ToNostrEventTag): boolean {
|
||||
const otherTag = other.toEventTag();
|
||||
@ -226,8 +226,13 @@ export class NostrLink implements ToNostrEventTag {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an event link from an existing nostr event
|
||||
*/
|
||||
static fromEvent(ev: TaggedNostrEvent | NostrEvent) {
|
||||
const relays = "relays" in ev ? ev.relays : undefined;
|
||||
let relays = "relays" in ev ? ev.relays : undefined;
|
||||
const eventRelays = removeUndefined(ev.tags.filter(a => a[0] === "relays" || a[0] === "relay" || a[0] === "r").map(a => sanitizeRelayUrl(a[1])));
|
||||
relays = appendDedupe(relays, eventRelays);
|
||||
|
||||
if (ev.kind >= 30_000 && ev.kind < 40_000) {
|
||||
const dTag = unwrap(findTag(ev, "d"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user