A locally focused bluesky appview
1package views
2
3import (
4 "fmt"
5
6 "github.com/bluesky-social/indigo/api/bsky"
7 "github.com/bluesky-social/indigo/lex/util"
8 "github.com/whyrusleeping/konbini/hydration"
9)
10
11// ProfileViewBasic builds a basic profile view (app.bsky.actor.defs#profileViewBasic)
12func ProfileViewBasic(actor *hydration.ActorInfo) *bsky.ActorDefs_ProfileViewBasic {
13 view := &bsky.ActorDefs_ProfileViewBasic{
14 Did: actor.DID,
15 Handle: actor.Handle,
16 }
17
18 if actor.Profile != nil {
19 if actor.Profile.DisplayName != nil && *actor.Profile.DisplayName != "" {
20 view.DisplayName = actor.Profile.DisplayName
21 }
22 if actor.Profile.Avatar != nil {
23 avatarURL := formatBlobRef(actor.DID, actor.Profile.Avatar)
24 if avatarURL != "" {
25 view.Avatar = &avatarURL
26 }
27 }
28 }
29
30 return view
31}
32
33// ProfileView builds a profile view (app.bsky.actor.defs#profileView)
34func ProfileView(actor *hydration.ActorInfo) *bsky.ActorDefs_ProfileView {
35 view := &bsky.ActorDefs_ProfileView{
36 Did: actor.DID,
37 Handle: actor.Handle,
38 }
39
40 if actor.Profile != nil {
41 if actor.Profile.DisplayName != nil && *actor.Profile.DisplayName != "" {
42 view.DisplayName = actor.Profile.DisplayName
43 }
44 if actor.Profile.Description != nil && *actor.Profile.Description != "" {
45 view.Description = actor.Profile.Description
46 }
47 if actor.Profile.Avatar != nil {
48 avatarURL := formatBlobRef(actor.DID, actor.Profile.Avatar)
49 if avatarURL != "" {
50 view.Avatar = &avatarURL
51 }
52 }
53 // Note: CreatedAt is typically set on the profile record itself
54 }
55
56 return view
57}
58
59// ProfileViewDetailed builds a detailed profile view (app.bsky.actor.defs#profileViewDetailed)
60func ProfileViewDetailed(actor *hydration.ActorInfoDetailed) *bsky.ActorDefs_ProfileViewDetailed {
61 view := &bsky.ActorDefs_ProfileViewDetailed{
62 Did: actor.DID,
63 Handle: actor.Handle,
64 }
65
66 if actor.Profile != nil {
67 if actor.Profile.DisplayName != nil && *actor.Profile.DisplayName != "" {
68 view.DisplayName = actor.Profile.DisplayName
69 }
70 if actor.Profile.Description != nil && *actor.Profile.Description != "" {
71 view.Description = actor.Profile.Description
72 }
73 if actor.Profile.Avatar != nil {
74 avatarURL := formatBlobRef(actor.DID, actor.Profile.Avatar)
75 if avatarURL != "" {
76 view.Avatar = &avatarURL
77 }
78 }
79 if actor.Profile.Banner != nil {
80 bannerURL := formatBlobRef(actor.DID, actor.Profile.Banner)
81 if bannerURL != "" {
82 view.Banner = &bannerURL
83 }
84 }
85 }
86
87 // Add counts
88 view.FollowersCount = &actor.FollowerCount
89 view.FollowsCount = &actor.FollowCount
90 view.PostsCount = &actor.PostCount
91
92 return view
93}
94
95func formatBlobRef(did string, blob *util.LexBlob) string {
96 return fmt.Sprintf("https://cdn.bsky.app/img/avatar_thumbnail/plain/%s/%s@jpeg", did, blob.Ref.String())
97}