Repository: louislam/uptime-kuma
File: server/notification-providers/nostr.js (JavaScript)

Code before:
        }

        // Publish events to each relay
        const relays = notification.relays.split("\n");
        let successfulRelays = 0;

        // Connect to each relay
        for (const relayUrl of relays) {
            const relay = relayInit(relayUrl);
            try {
                await relay.connect();
                successfulRelays++;

                // Publish events
                for (const event of events) {
                    relay.publish(event);
                }
            } catch (error) {
                continue;
            } finally {
                relay.close();
            }
        }

        // Report success or failure
        if (successfulRelays == 0) {
            throw Error("Failed to connect to any relays.");
        }
        return `${successfulRelays}/${relays.length} relays connected.`;
    }

    async getPrivateKey(sender) {
        try {
            const senderDecodeResult = await nip19.decode(sender);
            const { data } = senderDecodeResult;
            return data;
        } catch (error) {
            throw new Error(`Failed to get private key: ${error.message}`);
        }
    }

    async getPublicKeys(recipients) {
        const recipientsList = recipients.split("\n");
        const publicKeys = [];
        for (const recipient of recipientsList) {
            try {
                const recipientDecodeResult = await nip19.decode(recipient);
                const { type, data } = recipientDecodeResult;
                if (type === "npub") {
                    publicKeys.push(data);
                } else {

Review comment (suggestion):
```suggestion
        if (successfulRelays === 0) {
```

Code after:
            events.push(event);
        }

        // Publish events to each relay
        const relays = notification.relays.split("\n");
        let successfulRelays = 0;

        // Connect to each relay
        for (const relayUrl of relays) {
            const relay = relayInit(relayUrl);
            try {
                await relay.connect();
                successfulRelays++;

                // Publish events
                for (const event of events) {
                    relay.publish(event);
                }
            } catch (error) {
                continue;
            } finally {
                relay.close();
            }
        }

        // Report success or failure
        if (successfulRelays === 0) {
            throw Error("Failed to connect to any relays.");
        }
        return `${successfulRelays}/${relays.length} relays connected.`;
    }

    async getPrivateKey(sender) {
        try {
            const senderDecodeResult = await nip19.decode(sender);
            const { data } = senderDecodeResult;
            return data;
        } catch (error) {
            throw new Error(`Failed to get private key: ${error.message}`);
        }
    }

    async getPublicKeys(recipients) {
        const recipientsList = recipients.split("\n");
        const publicKeys = [];
        for (const recipient of recipientsList) {
            try {
                const recipientDecodeResult = await nip19.decode(recipient);
                const { type, data } = recipientDecodeResult;
                if (type === "npub") {
                    publicKeys.push(data);