From 14e60048a68a65b773e6298c5ce0fb640ce08f46 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 26 Jul 2023 12:54:06 -0500 Subject: [PATCH] loopback: use RelayPool instead of nostr-tools just because it doesn't die so often --- src/deps.ts | 1 - src/loopback.ts | 15 +++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/deps.ts b/src/deps.ts index 52ce68c..1f0bdfe 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -20,7 +20,6 @@ export { nip05, nip19, nip21, - relayInit, verifySignature, } from 'npm:nostr-tools@^1.11.2'; export { findReplyTag } from 'https://gitlab.com/soapbox-pub/mostr/-/raw/c67064aee5ade5e01597c6d23e22e53c628ef0e2/src/nostr/tags.ts'; diff --git a/src/loopback.ts b/src/loopback.ts index bddc66e..e9f13fc 100644 --- a/src/loopback.ts +++ b/src/loopback.ts @@ -1,19 +1,22 @@ import { Conf } from '@/config.ts'; -import { relayInit } from '@/deps.ts'; +import { RelayPool } from '@/deps.ts'; import { trends } from '@/trends.ts'; import { nostrDate, nostrNow } from '@/utils.ts'; import type { Event } from '@/event.ts'; -const relay = relayInit(Conf.relay); -await relay.connect(); +const relay = new RelayPool([Conf.relay]); // This file watches all events on your Ditto relay and triggers // side-effects based on them. This can be used for things like // notifications, trending hashtag tracking, etc. -relay - .sub([{ kinds: [1], since: nostrNow() }]) - .on('event', handleEvent); +relay.subscribe( + [{ kinds: [1], since: nostrNow() }], + [Conf.relay], + handleEvent, + undefined, + undefined, +); /** Handle events through the loopback pipeline. */ function handleEvent(event: Event): void {