Zap splits
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { EventKind, HexKey, NostrPrefix, NostrEvent, EventSigner, PowMiner } from ".";
|
||||
import { HashtagRegex, MentionNostrEntityRegex } from "./const";
|
||||
import { getPublicKey, unixNow } from "@snort/shared";
|
||||
import { getPublicKey, jitter, unixNow } from "@snort/shared";
|
||||
import { EventExt } from "./event-ext";
|
||||
import { tryParseNostrLink } from "./nostr-link";
|
||||
|
||||
@ -12,6 +12,12 @@ export class EventBuilder {
|
||||
#tags: Array<Array<string>> = [];
|
||||
#pow?: number;
|
||||
#powMiner?: PowMiner;
|
||||
#jitter?: number;
|
||||
|
||||
jitter(n: number) {
|
||||
this.#jitter = n;
|
||||
return this;
|
||||
}
|
||||
|
||||
kind(k: EventKind) {
|
||||
this.#kind = k;
|
||||
@ -73,8 +79,8 @@ export class EventBuilder {
|
||||
pubkey: this.#pubkey ?? "",
|
||||
content: this.#content ?? "",
|
||||
kind: this.#kind,
|
||||
created_at: this.#createdAt ?? unixNow(),
|
||||
tags: this.#tags,
|
||||
created_at: (this.#createdAt ?? unixNow()) + (this.#jitter ? jitter(this.#jitter) : 0),
|
||||
tags: this.#tags.sort((a, b) => a[0].localeCompare(b[0])),
|
||||
} as NostrEvent;
|
||||
ev.id = EventExt.createId(ev);
|
||||
return ev;
|
||||
|
@ -11,6 +11,17 @@ export interface NostrLink {
|
||||
encode(): string;
|
||||
}
|
||||
|
||||
export function linkToEventTag(link: NostrLink) {
|
||||
const relayEntry = link.relays ? [link.relays[0]] : [];
|
||||
if (link.type === NostrPrefix.PublicKey) {
|
||||
return ["p", link.id];
|
||||
} else if (link.type === NostrPrefix.Note || link.type === NostrPrefix.Event) {
|
||||
return ["e", link.id];
|
||||
} else if (link.type === NostrPrefix.Address) {
|
||||
return ["a", `${link.kind}:${link.author}:${link.id}`, ...relayEntry];
|
||||
}
|
||||
}
|
||||
|
||||
export function createNostrLinkToEvent(ev: TaggedNostrEvent | NostrEvent) {
|
||||
const relays = "relays" in ev ? ev.relays : undefined;
|
||||
|
||||
|
@ -64,6 +64,25 @@ export class ProfileLoaderService {
|
||||
}
|
||||
}
|
||||
|
||||
async fetchProfile(key: string) {
|
||||
const existing = this.Cache.get(key);
|
||||
if (existing) {
|
||||
return existing;
|
||||
} else {
|
||||
return await new Promise<MetadataCache>((resolve, reject) => {
|
||||
this.TrackMetadata(key);
|
||||
const release = this.Cache.hook(() => {
|
||||
const existing = this.Cache.getFromCache(key);
|
||||
if (existing) {
|
||||
resolve(existing);
|
||||
release();
|
||||
this.UntrackMetadata(key);
|
||||
}
|
||||
}, key);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async #FetchMetadata() {
|
||||
const missingFromCache = await this.#cache.buffer([...this.#wantsMetadata]);
|
||||
|
||||
|
Reference in New Issue
Block a user