diff --git a/src/app/components/SpaceMenuNavItems.svelte b/src/app/components/SpaceMenuNavItems.svelte index e120f20a..6765e955 100644 --- a/src/app/components/SpaceMenuNavItems.svelte +++ b/src/app/components/SpaceMenuNavItems.svelte @@ -1,5 +1,6 @@ diff --git a/src/app/content.ts b/src/app/content.ts index 39194ad5..90fca8ca 100644 --- a/src/app/content.ts +++ b/src/app/content.ts @@ -6,6 +6,7 @@ import { DIRECT_MESSAGE_FILE, EVENT_TIME, GENERIC_REPOST, + PINBOARD, POLL, REACTION, REPORT, @@ -40,7 +41,7 @@ if (ENABLE_ZAPS) { REACTION_KINDS.push(ZAP_RECEIPT) } -export const CONTENT_KINDS = [ZAP_GOAL, EVENT_TIME, THREAD, CLASSIFIED, POLL] +export const CONTENT_KINDS = [ZAP_GOAL, EVENT_TIME, THREAD, CLASSIFIED, POLL, PINBOARD] export const DM_KINDS = [DIRECT_MESSAGE, DIRECT_MESSAGE_FILE] diff --git a/src/app/storage.ts b/src/app/storage.ts index c94ec31d..be3d0e01 100644 --- a/src/app/storage.ts +++ b/src/app/storage.ts @@ -250,7 +250,8 @@ class Storage { } private syncEvents = () => { - const table = this.db.table("events") + const eventsTable = this.db.table("events") + const trackerTable = this.db.table("tracker") return on( this.app.repository, @@ -273,11 +274,26 @@ class Storage { } if (add.length > 0) { - await table.bulkPut(add) + // The ingest policy tracks an event before publishing it, so by the time the + // repository reports it, its provenance is already in the tracker — persist the + // two together so an event is never saved without the relays it came from. + const items: TrackerItem[] = [] + + for (const {id} of add) { + const relays = Array.from(this.app.tracker.getRelays(id)) + + if (relays.length > 0) { + items.push({id, relays}) + } + } + + await eventsTable.bulkPut(add) + await trackerTable.bulkPut(items) } if (remove.size > 0) { - await table.bulkDelete(remove) + await eventsTable.bulkDelete(remove) + await trackerTable.bulkDelete(remove) } }), ) @@ -312,6 +328,9 @@ class Storage { for (const id of ids) { const event = this.app.repository.getEvent(id) + // A brand-new event is tracked before it's published, so it isn't queryable here — + // syncEvents persists its provenance along with the event itself. This pass only + // records additional relays for events we already have. if (!event || !shouldPersistEvent(event)) continue const relays = Array.from(this.app.tracker.getRelays(id))