fix: merge conflicts

This commit is contained in:
complex 2025-04-08 16:19:47 +02:00
parent 38e9301510
commit 01e164c119

@ -77,7 +77,7 @@ export async function publishToRelay(event: NostrEvent, relayUrl: string): Promi
const relayPool = new nostrTools.SimplePool();
// Set a timeout for the publish operation
const timeout = setTimeout(() => {
relayPool.close([relayUrl]);
reject(new Error(`Timed out connecting to relay: ${relayUrl}`));
@ -129,27 +129,13 @@ export async function publishToRelay(event: NostrEvent, relayUrl: string): Promi
try {
// Use the WebSocket API directly
<<<<<<< HEAD
ws = new WebSocket(relayUrl);
// eslint-disable-next-line no-undef
wsTimeout = setTimeout(() => {
if (ws) {
try {
ws.close();
} catch {
// Ignore errors when closing WebSocket
}
=======
const ws = new WebSocket(relayUrl);
const wsTimeout = setTimeout(() => {
try {
ws.close();
} catch {
// Ignore errors when closing WebSocket
>>>>>>> main
}
reject(new Error("WebSocket connection timed out"));
}, 10000);
@ -167,13 +153,7 @@ export async function publishToRelay(event: NostrEvent, relayUrl: string): Promi
if (typeof msg.data === 'string' && msg.data.startsWith('["OK"')) {
responseHandled = true;
<<<<<<< HEAD
// eslint-disable-next-line no-undef
if (wsTimeout) clearTimeout(wsTimeout);
=======
clearTimeout(wsTimeout);
>>>>>>> main
resolve(`Event published successfully via WebSocket`);
try {
ws?.close();
@ -182,13 +162,7 @@ export async function publishToRelay(event: NostrEvent, relayUrl: string): Promi
}
} else if (typeof msg.data === 'string' && (msg.data.includes('invalid') || msg.data.includes('error'))) {
responseHandled = true;
<<<<<<< HEAD
// eslint-disable-next-line no-undef
if (wsTimeout) clearTimeout(wsTimeout);
=======
clearTimeout(wsTimeout);
>>>>>>> main
reject(new Error(`Relay rejected event: ${msg.data}`));
try {
ws?.close();
@ -204,19 +178,8 @@ export async function publishToRelay(event: NostrEvent, relayUrl: string): Promi
}
responseHandled = true;
<<<<<<< HEAD
// eslint-disable-next-line no-undef
if (wsTimeout) clearTimeout(wsTimeout);
// Create a more meaningful error message
const errorMessage = 'WebSocket connection failed';
reject(new Error(`WebSocket error: ${errorMessage}`));
=======
clearTimeout(wsTimeout);
reject(new Error(`WebSocket error: ${String(error)}`));
>>>>>>> main
reject(new Error('WebSocket connection failed'));
try {
ws?.close();
} catch {
@ -225,13 +188,7 @@ export async function publishToRelay(event: NostrEvent, relayUrl: string): Promi
};
ws.onclose = (): void => {
<<<<<<< HEAD
// eslint-disable-next-line no-undef
if (wsTimeout) clearTimeout(wsTimeout);
=======
clearTimeout(wsTimeout);
>>>>>>> main
};
} catch (wsError) {
// If WebSocket fails, try the regular method
@ -243,7 +200,7 @@ export async function publishToRelay(event: NostrEvent, relayUrl: string): Promi
// Use Promise.all to wait for all promises to resolve
Promise.all(publishPromises)
.then((relayResults: string[]) => {
clearTimeout(timeout);
relayPool.close([relayUrl]);
if (relayResults && relayResults.length > 0) {
@ -253,7 +210,7 @@ export async function publishToRelay(event: NostrEvent, relayUrl: string): Promi
}
})
.catch((error: Error) => {
clearTimeout(timeout);
relayPool.close([relayUrl]);
reject(new Error(`Failed to publish event: ${error.message}`));