diff --git a/src/app/views/PublishesConnections.svelte b/src/app/views/PublishesConnections.svelte index a2a0a379..76b2d496 100644 --- a/src/app/views/PublishesConnections.svelte +++ b/src/app/views/PublishesConnections.svelte @@ -1,9 +1,11 @@ -{#if !notices.length && selected.length} +{#if !selected.length} +
+ +
No relay selected.
+
+
+{:else if !notices.length && selected.length}
No notices found for selected relays.
{:else} - {#each notices as notice} - {#if notice.event} - router.at("notes").of(notice.event.id).open()}> -
- {formatTimestamp(notice.event.created_at)} - [Kind {notice.event.kind}] - {#each uniq(Object.entries(get(notice.status)).filter( ([k, v]) => selected.includes(k), )) as [url, status]} + + {#each notices as notice (JSON.stringify(notice))} +
+ {#if notice.event} + {#each uniq(Object.entries(get(notice.status)).filter( ([k, v]) => selected.includes(k), )) as [url, status] (url)} {@const {message, color} = messageAndColorFromStatus(get(notice.status)[url])} -
- to {url}: -
- {message} -
+
router.at("notes").of(notice.event.id).open()}> + {formatTimestamp(notice.event.created_at)} + to {url}: + [Kind {notice.event.kind}] + {message}
{/each} -
- - {:else} - -
- {formatTimestamp(notice.received_at)} - [Notice] -
- {notice.notice} + {:else} +
+ {formatTimestamp(notice.created_at)} + from {notice.url} + [{notice.notice[0]}] + {#each notice.notice.slice(1).filter(n => typeof n == "string") as item} + {item} + {/each}
-
- - {/if} - {/each} + {/if} +
+ {/each} +
{/if} diff --git a/src/engine/state.ts b/src/engine/state.ts index bd5a82a0..af13fff3 100644 --- a/src/engine/state.ts +++ b/src/engine/state.ts @@ -51,8 +51,16 @@ import { uniq, uniqBy, } from "@welshman/lib" -import type {PublishRequest, Target} from "@welshman/net" -import {Executor, AuthMode, Local, Multi, Relays, SubscriptionEvent} from "@welshman/net" +import type {Connection, PublishRequest, Target} from "@welshman/net" +import { + Executor, + AuthMode, + Local, + Multi, + Relays, + SubscriptionEvent, + ConnectionEvent, +} from "@welshman/net" import {Nip01Signer, Nip59} from "@welshman/signer" import {deriveEvents, deriveEventsMapped, throttled, withGetter} from "@welshman/store" import type {EventTemplate, PublishedList, SignedEvent, TrustedEvent} from "@welshman/util" @@ -1023,6 +1031,10 @@ const migrateEvents = (events: TrustedEvent[]) => { ) } +export type SubscriptionNotice = {created_at: number; notice: string[]} + +export const subscriptionNotices = writable>(new Map()) + // Avoid initializing multiple times on hot reload if (!db) { const initialRelays = [ @@ -1052,6 +1064,17 @@ if (!db) { ctx.app.dufflepudUrl = getSetting("dufflepud_url") }) + ctx.net.pool.on("init", (connection: Connection) => { + // if (!connection.url.includes("snort")) return + connection.on(ConnectionEvent.Receive, function (cxn, [verb, ...args]) { + if (verb == "EVENT") return + subscriptionNotices.update($notices => { + pushToMapKey($notices, connection.url, {created_at: now(), notice: [verb, ...args]}) + return $notices + }) + }) + }) + ready = initStorage("coracle", 2, { relays: {keyPath: "url", store: throttled(1000, relays)}, handles: {keyPath: "nip05", store: throttled(1000, handles)},