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:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user