mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Hide previously deleted versions on reload
The versions modal now fetches the user's NIP-09 kind-5 delete events (scoped to #k=5128) in parallel with the snapshot query and filters out any snapshot ids that appear in an `e` tag. Otherwise a deleted version would reappear the next time the modal was opened because relays still hold the original 5128 event. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This commit is contained in:
1 parent
23a6eeec9b
commit
577a83e2d1
1 file changed
+40
-11
@@ -97,19 +97,48 @@ export function NsiteVersionsDialog({
|
||||
setError(null);
|
||||
try {
|
||||
const relayClient = nostr.group(relayUrls);
|
||||
const events = await relayClient.query(
|
||||
[{
|
||||
kinds: [NSITE_SNAPSHOT_KIND],
|
||||
authors: [pubkey],
|
||||
'#a': [parentRef],
|
||||
limit: QUERY_LIMIT,
|
||||
}],
|
||||
{ signal: AbortSignal.timeout(QUERY_TIMEOUT_MS) },
|
||||
);
|
||||
const signal = AbortSignal.timeout(QUERY_TIMEOUT_MS);
|
||||
|
||||
// Dedup by event id (relays may return duplicates) and sort newest-first.
|
||||
// Fetch snapshots and the user's NIP-09 delete events in parallel.
|
||||
// The delete query is scoped to kind 5128 (the snapshot kind) so it
|
||||
// returns only deletions relevant to nsite versions.
|
||||
const [snapshotEvents, deleteEvents] = await Promise.all([
|
||||
relayClient.query(
|
||||
[{
|
||||
kinds: [NSITE_SNAPSHOT_KIND],
|
||||
authors: [pubkey],
|
||||
'#a': [parentRef],
|
||||
limit: QUERY_LIMIT,
|
||||
}],
|
||||
{ signal },
|
||||
),
|
||||
relayClient.query(
|
||||
[{
|
||||
kinds: [5],
|
||||
authors: [pubkey],
|
||||
'#k': [String(NSITE_SNAPSHOT_KIND)],
|
||||
limit: QUERY_LIMIT,
|
||||
}],
|
||||
{ signal },
|
||||
).catch(() => []),
|
||||
]);
|
||||
|
||||
// Collect every event id targeted by a delete event authored by this
|
||||
// user (NIP-09 requires author match, which the filter already enforces).
|
||||
const deletedIds = new Set<string>();
|
||||
for (const ev of deleteEvents) {
|
||||
for (const tag of ev.tags) {
|
||||
if (tag[0] === 'e' && tag[1]) deletedIds.add(tag[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Dedup by event id (relays may return duplicates), filter out tombstones,
|
||||
// and sort newest-first.
|
||||
const byId = new Map<string, NostrEvent>();
|
||||
for (const ev of events) byId.set(ev.id, ev);
|
||||
for (const ev of snapshotEvents) {
|
||||
if (deletedIds.has(ev.id)) continue;
|
||||
byId.set(ev.id, ev);
|
||||
}
|
||||
|
||||
const rows: VersionRow[] = Array.from(byId.values())
|
||||
.sort((a, b) => b.created_at - a.created_at)
|
||||
|
||||
Reference in new issue
Block a user