mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-12 20:42:25 +02:00
sdk: return store event along with ProfileMetadata.
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
type ProfileMetadata struct {
|
type ProfileMetadata struct {
|
||||||
pubkey string
|
pubkey string
|
||||||
|
event *nostr.Event
|
||||||
|
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
DisplayName string `json:"display_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 {
|
for ie := range ch {
|
||||||
if m, err := ParseMetadata(ie.Event); err == nil {
|
if m, err := ParseMetadata(ie.Event); err == nil {
|
||||||
m.pubkey = pubkey
|
m.pubkey = pubkey
|
||||||
|
m.event = ie.Event
|
||||||
return *m
|
return *m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,14 @@ func (sys System) FetchProfileMetadata(ctx context.Context, pubkey string) Profi
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Second*5)
|
ctxRelays, cancel := context.WithTimeout(ctx, time.Second*2)
|
||||||
defer cancel()
|
relays := sys.FetchOutboxRelays(ctxRelays, pubkey)
|
||||||
res := FetchProfileMetadata(ctx, sys.Pool, pubkey, sys.MetadataRelays...)
|
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)
|
sys.MetadataCache.SetWithTTL(pubkey, res, time.Hour*6)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user