diff --git a/packages/app/src/context.ts b/packages/app/src/context.ts index ca9bd9a..4cd5aa7 100644 --- a/packages/app/src/context.ts +++ b/packages/app/src/context.ts @@ -1,7 +1,7 @@ import {partition} from "@welshman/lib" import {defaultOptimizeSubscriptions, getDefaultNetContext as originalGetDefaultNetContext} from "@welshman/net" import type {Subscription, RelaysAndFilters, NetContext} from "@welshman/net" -import {WRAP, unionFilters} from "@welshman/util" +import {WRAP, isEphemeralKind, isDVMKind, unionFilters} from "@welshman/util" import type {TrustedEvent, StampedEvent} from "@welshman/util" import {tracker, repository} from './core' import {makeRouter, getFilterSelections} from './router' @@ -22,6 +22,8 @@ export const getDefaultNetContext = (overrides: Partial = {}) => ({ ...originalGetDefaultNetContext(), signEvent: (event: StampedEvent) => signer.get()?.sign(event), onEvent: (url: string, event: TrustedEvent) => { + if (isEphemeralKind(event.kind) || isDVMKind(event.kind)) return + tracker.track(event.id, url) repository.publish(event) diff --git a/packages/net/src/Subscribe.ts b/packages/net/src/Subscribe.ts index e0ee69a..bba887c 100644 --- a/packages/net/src/Subscribe.ts +++ b/packages/net/src/Subscribe.ts @@ -139,7 +139,7 @@ export const optimizeSubscriptions = (subs: Subscription[]) => { const closedSubs = new Set() const eosedSubs = new Set() const sentSubs = new Set() - const mergedSubs = [] + const mergedSubs: Subscription[] = [] for (const {relays, filters} of ctx.net.optimizeSubscriptions(group)) { const mergedSub = makeSubscription({ diff --git a/packages/util/src/Kinds.ts b/packages/util/src/Kinds.ts index 910d115..1d3d2c5 100644 --- a/packages/util/src/Kinds.ts +++ b/packages/util/src/Kinds.ts @@ -1,4 +1,5 @@ import {kinds} from 'nostr-tools' +import {between} from '@welshman/lib' export const isRegularKind = kinds.isRegularKind export const isEphemeralKind = kinds.isEphemeralKind @@ -6,6 +7,7 @@ export const isPlainReplaceableKind = kinds.isReplaceableKind export const isParameterizedReplaceableKind = kinds.isParameterizedReplaceableKind export const isReplaceableKind = (kind: number) => isPlainReplaceableKind(kind) || isParameterizedReplaceableKind(kind) +export const isDVMKind = (kind: number) => between([4999, 7001], kind) export const PROFILE = 0 export const NOTE = 1 diff --git a/packages/util/src/Relay.ts b/packages/util/src/Relay.ts index 95e0ad6..fc37bae 100644 --- a/packages/util/src/Relay.ts +++ b/packages/util/src/Relay.ts @@ -13,6 +13,7 @@ export const BOGUS_RELAY_URL = "bogus://welshman.relay" export type RelayProfile = { url: string icon?: string + banner?: string name?: string pubkey?: string contact?: string @@ -21,6 +22,7 @@ export type RelayProfile = { description?: string supported_nips?: number[] limitation?: { + min_pow_difficulty?: number payment_required?: boolean auth_required?: boolean } diff --git a/packages/util/src/Tags.ts b/packages/util/src/Tags.ts index b3f5bd8..60439bc 100644 --- a/packages/util/src/Tags.ts +++ b/packages/util/src/Tags.ts @@ -1,6 +1,6 @@ import type {OmitStatics} from '@welshman/lib' -import {Fluent, uniqBy, mapVals, nth, nthEq, ensurePlural} from '@welshman/lib' -import {isRelayUrl, normalizeRelayUrl} from './Relay' +import {Fluent, uniq, uniqBy, mapVals, nth, nthEq, ensurePlural} from '@welshman/lib' +import {isRelayUrl, isShareableRelayUrl, normalizeRelayUrl} from './Relay' import {Address, isContextAddress} from './Address' import {GROUP, COMMUNITY} from './Kinds' @@ -262,4 +262,7 @@ export const getAncestorTags = (tags: string[][]) => { export const getAncestorTagValues = (tags: string[][]) => mapVals(tags => tags.map(nth(1)), getAncestorTags(tags)) +export const getRelayHints = (tags: string[][]) => + uniq(tags.flatMap(t => t.slice(2).filter(isShareableRelayUrl))) + export const uniqTags = (tags: string[][]) => uniqBy(t => t.join(":"), tags)