sdk: return store event along with ProfileMetadata.

This commit is contained in:
fiatjaf 2023-10-31 15:22:55 -03:00
parent 711b0844b1
commit 5847335506
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 10 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import (
type ProfileMetadata struct {
pubkey string
event *nostr.Event
Name string `json:"name,omitempty"`
DisplayName string `json:"display_name,omitempty"`
@ -47,6 +48,7 @@ func FetchProfileMetadata(ctx context.Context, pool *nostr.SimplePool, pubkey st
for ie := range ch {
if m, err := ParseMetadata(ie.Event); err == nil {
m.pubkey = pubkey
m.event = ie.Event
return *m
}
}

View File

@ -46,9 +46,14 @@ func (sys System) FetchProfileMetadata(ctx context.Context, pubkey string) Profi
return v
}
ctx, cancel := context.WithTimeout(ctx, time.Second*5)
defer cancel()
res := FetchProfileMetadata(ctx, sys.Pool, pubkey, sys.MetadataRelays...)
ctxRelays, cancel := context.WithTimeout(ctx, time.Second*2)
relays := sys.FetchOutboxRelays(ctxRelays, pubkey)
cancel()
ctx, cancel = context.WithTimeout(ctx, time.Second*3)
res := FetchProfileMetadata(ctx, sys.Pool, pubkey, append(relays, sys.MetadataRelays...)...)
cancel()
sys.MetadataCache.SetWithTTL(pubkey, res, time.Hour*6)
return res
}