aboutsummaryrefslogtreecommitdiff
path: root/backend/fetchers/app.bsky.actor.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/fetchers/app.bsky.actor.go')
-rw-r--r--backend/fetchers/app.bsky.actor.go43
1 files changed, 15 insertions, 28 deletions
diff --git a/backend/fetchers/app.bsky.actor.go b/backend/fetchers/app.bsky.actor.go
index 45ced77..e07f5be 100644
--- a/backend/fetchers/app.bsky.actor.go
+++ b/backend/fetchers/app.bsky.actor.go
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"llostre/backend/general"
+ "llostre/backend/notes"
"log/slog"
"net"
"net/http"
@@ -129,7 +130,7 @@ func FetchHandleAndPDS(did string) (string, string, error) {
return handle, pds, nil
}
-func FetchProfile(logger *slog.Logger, did, pdsURL, slingshotURL string, cache *Cache) (*general.Profile, error) {
+func FetchAppBskyActorProfile(logger *slog.Logger, did, pdsURL, slingshotURL string, cache *Cache) (*notes.Author, error) {
// construct profile record URI
uri := fmt.Sprintf("at://%s/app.bsky.actor.profile/self", did)
@@ -139,7 +140,7 @@ func FetchProfile(logger *slog.Logger, did, pdsURL, slingshotURL string, cache *
if err != nil {
logger.Warn("slingshot profile fetch failed", "did", did, "error", err)
} else {
- return parseProfile(did, rawRecord, cache)
+ return parseAppBskyActorProfile(did, rawRecord, cache)
}
}
@@ -149,47 +150,33 @@ func FetchProfile(logger *slog.Logger, did, pdsURL, slingshotURL string, cache *
return nil, err
}
- return parseProfile(did, rawRecord, cache)
+ return parseAppBskyActorProfile(did, rawRecord, cache)
}
-func FetchProfiles(logger *slog.Logger, dids []string, pdsURL, slingshotURL string, cache *Cache) map[string]general.Profile {
- profiles := make(map[string]general.Profile)
+func FetchAppBskyActorProfiles(logger *slog.Logger, dids []string, pdsURL, slingshotURL string, cache *Cache) map[string]notes.Author {
+ authors := make(map[string]notes.Author)
for _, did := range dids {
- profile, err := FetchProfile(logger, did, pdsURL, slingshotURL, cache)
+ author, err := FetchAppBskyActorProfile(logger, did, pdsURL, slingshotURL, cache)
if err == nil {
- profiles[did] = *profile
+ authors[did] = *author
}
}
- return profiles
+ return authors
}
-func parseProfile(did string, rawRecord *general.RawRecord, cache *Cache) (*general.Profile, error) {
- var profileData general.ProfileRecord
- if err := json.Unmarshal(rawRecord.Value, &profileData); err != nil {
+func parseAppBskyActorProfile(did string, rawRecord *general.RawRecord, cache *Cache) (*notes.Author, error) {
+ var profile notes.AppBskyActorProfileRecord
+ if err := json.Unmarshal(rawRecord.Value, &profile); err != nil {
return nil, err
}
- var avatarURL, bannerURL string
- if profileData.Avatar != nil {
- avatarURL = fmt.Sprintf("https://cdn.bsky.app/img/avatar/plain/%s/%s@jpeg", did, profileData.Avatar.Ref.Link)
- }
- if profileData.Banner != nil {
- bannerURL = fmt.Sprintf("https://cdn.bsky.app/img/banner/plain/%s/%s@jpeg", did, profileData.Banner.Ref.Link)
- }
-
handle, err := FetchHandle(did)
if err != nil {
handle = "handle.invalid"
}
- profile := &general.Profile{
- Handle: handle,
- DisplayName: profileData.DisplayName,
- AvatarURL: avatarURL,
- BannerURL: bannerURL,
- Pronouns: profileData.Pronouns,
- }
+ author, err := notes.AuthorFromAppBskyActorProfileRecord(profile, did, handle)
- cache.SetProfile(did, profile)
- return profile, nil
+ cache.SetAuthor(did, author)
+ return author, nil
}