Use NostrLink everywhere

This commit is contained in:
2023-09-19 09:30:01 +01:00
parent a1cd56292a
commit 9fb6f0dfee
24 changed files with 164 additions and 220 deletions

View File

@ -1,9 +1,9 @@
import debug from "debug";
import { v4 as uuid } from "uuid";
import { appendDedupe, sanitizeRelayUrl, unixNowMs } from "@snort/shared";
import { appendDedupe, sanitizeRelayUrl, unixNowMs, unwrap } from "@snort/shared";
import EventKind from "./event-kind";
import { SystemInterface } from "index";
import { NostrLink, NostrPrefix, SystemInterface } from "index";
import { ReqFilter, u256, HexKey } from "./nostr";
import { RelayCache, splitByWriteRelays, splitFlatByWriteRelays } from "./gossip-model";
@ -229,6 +229,30 @@ export class RequestFilterBuilder {
return this;
}
/**
* Get event from link
*/
link(link: NostrLink) {
if(link.type === NostrPrefix.Address) {
return this.tag("d", [link.id])
.kinds([unwrap(link.kind)])
.authors([unwrap(link.author)]);
} else {
return this.ids([link.id]);
}
}
/**
* Get replies to link with e/a tags
*/
replyToLink(link: NostrLink) {
if(link.type === NostrPrefix.Address) {
return this.tag("a", [`${link.kind}:${link.author}:${link.id}`]);
} else {
return this.tag("e", [link.id]);
}
}
/**
* Build/expand this filter into a set of relay specific queries
*/