From b3c259e164a0c32075d864cb0a89b1f736e629d0 Mon Sep 17 00:00:00 2001 From: okjodom Date: Sun, 24 Nov 2024 20:17:58 +0300 Subject: [PATCH] chore: add relays and logging on relay events --- apps/nostr/src/nostr.service.ts | 19 ++++++++++++++++++- .../src/dto/send-encrypted-nostr-dm.dto.ts | 4 ++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/nostr/src/nostr.service.ts b/apps/nostr/src/nostr.service.ts index ce0ed23..5cc83c1 100644 --- a/apps/nostr/src/nostr.service.ts +++ b/apps/nostr/src/nostr.service.ts @@ -1,6 +1,7 @@ import NDK, { NDKEvent, NDKPrivateKeySigner, + NDKRelay, NDKUser, } from '@nostr-dev-kit/ndk'; import { nip19 } from 'nostr-tools'; @@ -16,6 +17,9 @@ const explicitRelayUrls = [ 'wss://relay.damus.io', 'wss://relay.nostr.bg', 'wss://relay.snort.social', + 'wss://nostr.mom', + 'wss://nos.lol', + 'wss://relay.nostr.bg' ]; @Injectable() @@ -37,6 +41,15 @@ export class NostrService { signer, }); + + this.ndk.pool.on('relay:connect', (relay: NDKRelay) => { + this.logger.log(`Connected to relay: ${relay.url}`); + }); + + this.ndk.pool.on('relay:disconnect', (relay: NDKRelay) => { + this.logger.warn(`Disconnected from relay: ${relay.url}`); + }); + this.connectRelays() .then(() => { this.logger.log('NostrService connected'); @@ -107,7 +120,7 @@ export class NostrService { async sendEncryptedDirectMessage({ message, recipient, - retry, + retry = true, }: SendEncryptedNostrDmDto): Promise { try { if (!this.connected) { @@ -116,6 +129,10 @@ export class NostrService { const receiver = this.parseRecipient(recipient) || this.pubkey; + this.logger.log( + `${this.ndk.pool.connectedRelays().length} relays connected`, + ); + const dm = new NDKEvent(this.ndk, { kind: 4, content: message, diff --git a/libs/common/src/dto/send-encrypted-nostr-dm.dto.ts b/libs/common/src/dto/send-encrypted-nostr-dm.dto.ts index bae4c5b..2d03ca2 100644 --- a/libs/common/src/dto/send-encrypted-nostr-dm.dto.ts +++ b/libs/common/src/dto/send-encrypted-nostr-dm.dto.ts @@ -20,7 +20,7 @@ class NostrRecipientDto implements NostrRecipient { @IsOptional() @IsString() @Type(() => String) - @ApiProperty() + @ApiProperty({ example: '' }) pubkey: string; } @@ -28,7 +28,7 @@ export class SendEncryptedNostrDmDto implements NostrDirectMessageRequest { @IsNotEmpty() @IsString() @Type(() => String) - @ApiProperty() + @ApiProperty({ example: 'hello bitsacco'}) message: string; @IsDefined()