v0.4.11 - Fixed nasty DM bug

This commit is contained in:
Your Name
2025-10-06 10:06:24 -04:00
parent d5350d7c30
commit f6d13d4318
11 changed files with 1376 additions and 753 deletions

View File

@@ -28,6 +28,7 @@
#include "subscriptions.h" // Subscription structures and functions
#include "embedded_web_content.h" // Embedded web content
#include "api.h" // API for embedded files
#include "dm_admin.h" // DM admin functions including NIP-17
// Forward declarations for logging functions
void log_info(const char* message);
@@ -68,9 +69,6 @@ int nostr_validate_unified_request(const char* json_string, size_t json_length);
int process_admin_event_in_config(cJSON* event, char* error_message, size_t error_size, struct lws* wsi);
int is_authorized_admin_event(cJSON* event, char* error_message, size_t error_size);
// Forward declarations for NIP-17 admin messaging
int process_nip17_admin_message(cJSON* gift_wrap_event, char* error_message, size_t error_size, struct lws* wsi);
// Forward declarations for DM stats command handling
int process_dm_stats_command(cJSON* dm_event, char* error_message, size_t error_size, struct lws* wsi);
@@ -643,9 +641,9 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
log_info("DEBUG NIP17: Detected kind 1059 gift wrap event");
char nip17_error[512] = {0};
int nip17_result = process_nip17_admin_message(event, nip17_error, sizeof(nip17_error), wsi);
cJSON* response_event = process_nip17_admin_message(event, nip17_error, sizeof(nip17_error), wsi);
if (nip17_result != 0) {
if (!response_event) {
log_error("DEBUG NIP17: NIP-17 admin message processing failed");
result = -1;
size_t error_len = strlen(nip17_error);
@@ -659,19 +657,31 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
log_error(debug_nip17_error_msg);
} else {
log_success("DEBUG NIP17: NIP-17 admin message processed successfully");
// Store the gift wrap event in database (unlike kind 23456)
// Store the original gift wrap event in database (unlike kind 23456)
if (store_event(event) != 0) {
log_error("DEBUG NIP17: Failed to store gift wrap event in database");
result = -1;
strncpy(error_message, "error: failed to store gift wrap event", sizeof(error_message) - 1);
cJSON_Delete(response_event);
} else {
log_info("DEBUG NIP17: Gift wrap event stored successfully in database");
// Broadcast gift wrap event to matching persistent subscriptions
int broadcast_count = broadcast_event_to_subscriptions(event);
// Debug: Print response event before broadcasting
char* debug_before_broadcast = cJSON_Print(response_event);
if (debug_before_broadcast) {
log_info("DEBUG EVENT: Before broadcasting response event");
printf(" Response Event: %s\n", debug_before_broadcast);
free(debug_before_broadcast);
}
// Broadcast RESPONSE event to matching persistent subscriptions
int broadcast_count = broadcast_event_to_subscriptions(response_event);
char debug_broadcast_msg[128];
snprintf(debug_broadcast_msg, sizeof(debug_broadcast_msg),
"DEBUG NIP17 BROADCAST: Gift wrap event broadcast to %d subscriptions", broadcast_count);
"DEBUG NIP17 BROADCAST: Response event broadcast to %d subscriptions", broadcast_count);
log_info(debug_broadcast_msg);
// Clean up response event
cJSON_Delete(response_event);
}
}
} else if (event_kind == 14) {