fix: improve findUserRelays method in metadata controller

This commit is contained in:
daniyal 2024-09-11 22:25:55 +05:00
parent 7a1d0bbfb0
commit 53d47fcb80

View File

@ -121,10 +121,10 @@ export class MetadataController {
public findUserRelays = async ( public findUserRelays = async (
hexKey: string, hexKey: string,
userRelaysType: UserRelaysType = UserRelaysType.Both userRelaysType: UserRelaysType = UserRelaysType.Both
) => { ): Promise<string[]> => {
log(true, LogType.Info, ` Finding user's relays`, hexKey, userRelaysType) log(true, LogType.Info, ` Finding user's relays`, hexKey, userRelaysType)
const ndkRelayListPromise = await getRelayListForUser(hexKey, this.ndk) const ndkRelayListPromise = getRelayListForUser(hexKey, this.ndk)
// Use Promise.race to either get the NDKRelayList instance or handle the timeout // Use Promise.race to either get the NDKRelayList instance or handle the timeout
return await Promise.race([ return await Promise.race([
@ -132,11 +132,12 @@ export class MetadataController {
timeout() // Custom timeout function that rejects after a specified time timeout() // Custom timeout function that rejects after a specified time
]) ])
.then((ndkRelayList) => { .then((ndkRelayList) => {
return ndkRelayList[userRelaysType] if (ndkRelayList) return ndkRelayList[userRelaysType]
return [] // Return an empty array if ndkRelayList is undefined
}) })
.catch((err) => { .catch((err) => {
log(true, LogType.Error, err) log(true, LogType.Error, err)
return [] as string[] // Return an empty array if an error occurs return [] // Return an empty array if an error occurs
}) })
} }