This commit is contained in:
2025-01-03 23:27:03 -05:00
parent c1707d94ef
commit 6188445d03

View File

@@ -550,21 +550,30 @@ function initializeBroadcast() {
async function processBatch(batch, relayUrls, pool) { async function processBatch(batch, relayUrls, pool) {
// First, publish all events in the batch in parallel // First, publish all events in the batch in parallel
const publishPromises = batch.map(async event => { const publishPromises = batch.map(async event => {
try { const relayResults = await Promise.all(relayUrls.map(async relay => {
const published = await pool.publish(relayUrls, event); try {
return { const published = await pool.publish([relay], event);
event, return {
success: true, relay,
published success: true,
}; published
} catch (err) { };
console.error(`Failed to publish event ${event.id}:`, err); } catch (err) {
return { console.error(`Failed to publish event ${event.id} to ${relay}:`, err);
event, return {
success: false, relay,
error: err.message success: false,
}; error: err.message
} };
}
}));
const anySuccess = relayResults.some(r => r.success);
return {
event,
success: anySuccess,
relayResults
};
}); });
const publishResults = await Promise.allSettled(publishPromises); const publishResults = await Promise.allSettled(publishPromises);
@@ -650,7 +659,8 @@ function initializeBroadcast() {
<span class="event-id">${stats.latestVerified.eventId}</span> <span class="event-id">${stats.latestVerified.eventId}</span>
<button class="copy-button" onclick="copyToClipboard('${stats.latestVerified.eventId}', 'latest-copy')">Copy</button> <button class="copy-button" onclick="copyToClipboard('${stats.latestVerified.eventId}', 'latest-copy')">Copy</button>
</p> </p>
<p>✓ Found on ${stats.latestVerified.count} relays</p> <p>✓ Found on ${stats.latestVerified.count} relay(s):</p>
<p class="relay-list">${stats.latestVerified.relays.join('\n')}</p>
</div>`; </div>`;
} }
@@ -716,13 +726,16 @@ function initializeBroadcast() {
results.verified.forEach(verifyGroup => { results.verified.forEach(verifyGroup => {
if (verifyGroup.value) { if (verifyGroup.value) {
const successfulVerifications = verifyGroup.value.filter(v => v.success).length; // Count successful verifications across all relays
stats.verifiedCount += successfulVerifications; const successfulRelays = verifyGroup.value.filter(v => v.success);
stats.verifiedCount += successfulRelays.length;
if (successfulVerifications > 0) { if (successfulRelays.length > 0) {
// Store both the event ID and the specific relays it was found on
stats.latestVerified = { stats.latestVerified = {
eventId: verifyGroup.value[0].eventId, eventId: verifyGroup.value[0].eventId,
count: successfulVerifications count: successfulRelays.length,
relays: successfulRelays.map(v => v.relay)
}; };
} }
} }
@@ -758,6 +771,7 @@ function initializeBroadcast() {
</div>`; </div>`;
} finally { } finally {
startButton.disabled = false; startButton.disabled = false;
pool.close();
} }
}); });
@@ -805,11 +819,31 @@ async function broadcastSingleEvent(event, buttonElement) {
const pool = new NostrTools.SimplePool(); const pool = new NostrTools.SimplePool();
const verificationResults = []; const verificationResults = [];
const publishResults = [];
try { try {
const publishResult = await pool.publish(broadcastRelays, event); // Publish to each relay individually and track results
for (const relay of broadcastRelays) {
try {
const published = await pool.publish([relay], event);
publishResults.push({
relay,
success: true,
published
});
} catch (err) {
console.error(`Failed to publish to ${relay}:`, err);
publishResults.push({
relay,
success: false,
error: err.message
});
}
}
if (publishResult) { const anySuccessfulPublish = publishResults.some(r => r.success);
if (anySuccessfulPublish) {
await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
buttonElement.textContent = 'Verifying...'; buttonElement.textContent = 'Verifying...';
@@ -825,6 +859,7 @@ async function broadcastSingleEvent(event, buttonElement) {
const nostrBandLink = `https://nostr.band/event/${event.id}`; const nostrBandLink = `https://nostr.band/event/${event.id}`;
let message = `Event ID ${event.id} broadcast complete!\n\n`; let message = `Event ID ${event.id} broadcast complete!\n\n`;
message += `Successfully published to ${publishResults.filter(r => r.success).length}/${broadcastRelays.length} relays\n`;
message += `Found on ${foundOn.length} relay(s):\n${foundOn.join('\n')}\n\n`; message += `Found on ${foundOn.length} relay(s):\n${foundOn.join('\n')}\n\n`;
message += `View on nostr.band: ${nostrBandLink}`; message += `View on nostr.band: ${nostrBandLink}`;
@@ -841,7 +876,8 @@ async function broadcastSingleEvent(event, buttonElement) {
// Log detailed results to console for debugging // Log detailed results to console for debugging
console.log('Verification Results:', { console.log('Verification Results:', {
eventId: event.id, eventId: event.id,
results: verificationResults publish: publishResults,
verify: verificationResults
}); });
} else { } else {
alert(`Event ID ${event.id} failed to broadcast to any relays.`); alert(`Event ID ${event.id} failed to broadcast to any relays.`);
@@ -852,6 +888,7 @@ async function broadcastSingleEvent(event, buttonElement) {
} finally { } finally {
buttonElement.disabled = false; buttonElement.disabled = false;
buttonElement.textContent = 'Broadcast'; buttonElement.textContent = 'Broadcast';
pool.close();
} }
} }