Enhance delete event functionality and UI updates

- Improved logging in handle-delete.go for admin and owner checks during delete operations.
- Updated handle-event.go to ensure delete events are saved before processing, with enhanced error handling.
- Added fetchDeleteEventsByTarget function in nostr.js to retrieve delete events targeting specific event IDs.
- Modified App.svelte to include delete event verification and improved event sorting by creation timestamp.
- Enhanced UI to display delete event information and added loading indicators for event refresh actions.
This commit is contained in:
2025-10-10 21:23:36 +01:00
parent 67a74980f9
commit 40f3cb6f6e
5 changed files with 306 additions and 81 deletions

View File

@@ -302,7 +302,7 @@ export async function fetchEvents(filters, options = {}) {
}
}
// Fetch all events with timestamp-based pagination using NDK
// Fetch all events with timestamp-based pagination using NDK (including delete events)
export async function fetchAllEvents(options = {}) {
const {
limit = 100,
@@ -317,6 +317,8 @@ export async function fetchAllEvents(options = {}) {
if (until) filters.until = until;
if (authors) filters.authors = authors;
// Don't specify kinds filter - this will include all events including delete events (kind 5)
const events = await fetchEvents(filters, {
limit: limit,
timeout: 30000
@@ -409,6 +411,41 @@ export async function fetchEventById(eventId, options = {}) {
}
}
// Fetch delete events that target a specific event ID using Nostr
export async function fetchDeleteEventsByTarget(eventId, options = {}) {
const {
timeout = 10000
} = options;
console.log(`Fetching delete events for target: ${eventId}`);
try {
const ndk = nostrClient.getNDK();
const filters = {
kinds: [5], // Kind 5 is deletion
'#e': [eventId] // e-tag referencing the target event
};
console.log('Fetching delete events via NDK with filters:', filters);
// Use NDK's fetchEvents method
const events = await ndk.fetchEvents(filters, {
timeout
});
console.log(`Fetched ${events.size} delete events via NDK`);
// Convert NDK events to raw events
const rawEvents = Array.from(events).map(event => event.rawEvent());
return rawEvents;
} catch (error) {
console.error("Failed to fetch delete events via NDK:", error);
throw error;
}
}
// Initialize client connection
export async function initializeNostrClient() {