From 2f2348f459e3b6683284975e63df356e8c821bdc Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Wed, 1 Oct 2025 11:13:09 -0500 Subject: Fetch & display received DMs from relays --- src/routes/(app)/dm/[recipient]/+page.svelte | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/routes') diff --git a/src/routes/(app)/dm/[recipient]/+page.svelte b/src/routes/(app)/dm/[recipient]/+page.svelte index 4f02829d..971c0cd5 100644 --- a/src/routes/(app)/dm/[recipient]/+page.svelte +++ b/src/routes/(app)/dm/[recipient]/+page.svelte @@ -12,8 +12,16 @@ const pool = new SimplePool(); import { PUBLIC_DM_RELAYS } from '$env/static/public'; const DM_RELAYS_LIST = PUBLIC_DM_RELAYS.split(','); + const DM_FETCH_LIMIT = 256; let text = $state(""); + let events = $state([]); + + pool.querySync(DM_RELAYS_LIST, + { kinds: [1059], "#p": [user.pubkey], limit: DM_FETCH_LIMIT }) + .then(wrapped => + Promise.all(wrapped.map(decryptMessage)) + .then(rumours => events = rumours)); const btnCreateMessage = async () => { let event; @@ -28,15 +36,12 @@ await Promise.any(pool.publish(DM_RELAYS_LIST, event)); } - const btnDecryptMessage = async () => { + const decryptMessage = async (event: object): object => { if (window.nostr) { - text = await libnip17.decryptNIP17MessageNIP07(text); + return await libnip17.decryptNIP17MessageNIP07(event); } else { - // TODO get events from relays instead of the text box - const wrapped = JSON.parse(text); const sk = await getPrivateKey(user); - const rumour = toolsnip17.unwrapEvent(wrapped, sk); - text = rumour.content; + return toolsnip17.unwrapEvent(event, sk); } } @@ -56,9 +61,15 @@ >Direct Messages

You are sending nostr messages to {recipient.username}.

+

Received Messages:

+ + - - + -- cgit v1.2.3