fix: first find metadata on purplepag relay and then try other relays
All checks were successful
Release / build_and_release (push) Successful in 41s

This commit is contained in:
Sabir Hassan 2024-03-19 14:23:34 +05:00
parent 962b2bcea6
commit 6981bef65a

View File

@ -20,10 +20,6 @@ export class MetadataController {
} }
public findMetadata = async (hexKey: string) => { public findMetadata = async (hexKey: string) => {
const mostPopularRelays = import.meta.env.VITE_MOST_POPULAR_RELAYS
const hardcodedPopularRelays = (mostPopularRelays || '').split(' ')
const relays = [...hardcodedPopularRelays, this.specialMetadataRelay]
const eventFilter: Filter = { const eventFilter: Filter = {
kinds: [kinds.Metadata], kinds: [kinds.Metadata],
authors: [hexKey] authors: [hexKey]
@ -31,6 +27,25 @@ export class MetadataController {
const pool = new SimplePool() const pool = new SimplePool()
const metadataEvent = await pool
.get([this.specialMetadataRelay], eventFilter)
.catch((err) => {
console.error(err)
return null
})
if (
metadataEvent &&
validateEvent(metadataEvent) &&
verifyEvent(metadataEvent)
) {
return metadataEvent
}
const mostPopularRelays = import.meta.env.VITE_MOST_POPULAR_RELAYS
const hardcodedPopularRelays = (mostPopularRelays || '').split(' ')
const relays = [...hardcodedPopularRelays]
const events = await pool.querySync(relays, eventFilter).catch((err) => { const events = await pool.querySync(relays, eventFilter).catch((err) => {
console.error(err) console.error(err)
return null return null
@ -67,7 +82,7 @@ export class MetadataController {
if (event.sig.length < 1) { if (event.sig.length < 1) {
const timestamp = Math.floor(Date.now() / 1000) const timestamp = Math.floor(Date.now() / 1000)
// Metadata event to publish to the nquiz relay // Metadata event to publish to the wss://purplepag.es relay
const newMetadataEvent: Event = { const newMetadataEvent: Event = {
...event, ...event,
created_at: timestamp created_at: timestamp