fix(chat): send Archipelago(Tor) group messages concurrently so 'sending' clears fast (#32)

sendArchMessage looped over every federation node sequentially (await
sendMessageToPeer per node), so the spinner stayed up until the slowest/offline
node's Tor request finished — long after online peers had received the message.
Send to all peers concurrently (Promise.allSettled); the spinner now clears
after the slowest single delivery, not the sum.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
archipelago 2026-06-16 09:42:51 -04:00
parent 9a518db7b8
commit ef2991a117

View File

@ -183,16 +183,24 @@ async function sendArchMessage() {
selfOnion = tor.tor_address selfOnion = tor.tor_address
} catch { /* non-fatal */ } } catch { /* non-fatal */ }
const msg = messageText.value.trim() const msg = messageText.value.trim()
let sent = 0 const targets = nodes.nodes
for (const node of nodes.nodes) { .map((node) => node.onion || node.did)
const nodeOnion = node.onion || node.did // Skip sending to ourselves (would create a duplicate received message).
// Skip sending to ourselves (would create duplicate received message) .filter(
if (selfOnion && (nodeOnion === selfOnion || nodeOnion === selfOnion.replace('.onion', '') || selfOnion === nodeOnion + '.onion')) continue (nodeOnion) =>
try { !(selfOnion &&
await rpcClient.sendMessageToPeer(nodeOnion, msg) (nodeOnion === selfOnion ||
sent++ nodeOnion === selfOnion.replace('.onion', '') ||
} catch { /* some peers may be offline */ } selfOnion === nodeOnion + '.onion'))
} )
// Send to all peers CONCURRENTLY so the spinner clears after the slowest
// single delivery (one Tor round-trip) rather than the sum of all of them
// previously a slow or offline node kept the "sending" spinner up long after
// the online peers had already received the message.
const results = await Promise.allSettled(
targets.map((nodeOnion) => rpcClient.sendMessageToPeer(nodeOnion, msg))
)
const sent = results.filter((r) => r.status === 'fulfilled').length
try { try {
await rpcClient.call({ method: 'node-store-sent', params: { message: msg } }) await rpcClient.call({ method: 'node-store-sent', params: { message: msg } })
} catch { /* non-fatal */ } } catch { /* non-fatal */ }