event: renew relay connection before publishing if necessary.

This commit is contained in:
fiatjaf 2025-09-07 18:56:51 -03:00
parent 9251702460
commit ecb7f8f195
1 changed files with 8 additions and 1 deletions

View File

@ -403,13 +403,20 @@ func publishFlow(ctx context.Context, c *cli.Command, kr nostr.Signer, evt nostr
} }
} else { } else {
// normal dumb flow // normal dumb flow
for _, relay := range relays { for i, relay := range relays {
publish: publish:
cleanUrl, _ := strings.CutPrefix(relay.URL, "wss://") cleanUrl, _ := strings.CutPrefix(relay.URL, "wss://")
log("publishing to %s... ", color.CyanString(cleanUrl)) log("publishing to %s... ", color.CyanString(cleanUrl))
ctx, cancel := context.WithTimeout(ctx, 10*time.Second) ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel() defer cancel()
if !relay.IsConnected() {
if new_, err := sys.Pool.EnsureRelay(relay.URL); err == nil {
relays[i] = new_
relay = new_
}
}
err := relay.Publish(ctx, evt) err := relay.Publish(ctx, evt)
if err == nil { if err == nil {
// published fine // published fine