aboutsummaryrefslogtreecommitdiff
path: root/backend/notes/app.bsky.actor.go
blob: 00a1ff127c533c6f01214f2526847407404a885c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package notes

import (
	"fmt"
)

type AppBskyActorProfileRecord struct {
	DisplayName string `json:"displayName"`
	Avatar      *struct {
		Ref struct {
			Link string `json:"$link"`
		} `json:"ref"`
	} `json:"avatar,omitempty"`
	Banner *struct {
		Ref struct {
			Link string `json:"$link"`
		} `json:"ref"`
	} `json:"banner,omitempty"`
	Pronouns string `json:"pronouns"`
	Labels   *struct {
		Type   string `json:"$type"`
		Values []struct {
			Val string `json:"val"`
		} `json:"values"`
	} `json:"labels,omitempty"`
}

func AuthorFromAppBskyActorProfileRecord(record AppBskyActorProfileRecord, did, handle, pds string) (*Author, error) {
	var avatarURL, bannerURL string
	if record.Avatar != nil {
		avatarURL = fmt.Sprintf("%s/xrpc/com.atproto.sync.getBlob?did=%s&cid=%s", pds, did, record.Avatar.Ref.Link)
	}
	if record.Banner != nil {
		bannerURL = fmt.Sprintf("%s/xrpc/com.atproto.sync.getBlob?did=%s&cid=%s", pds, did, record.Banner.Ref.Link)
	}

	// check for !no-unauthenticated label
	noUnauth := false
	if record.Labels != nil && record.Labels.Type == "com.atproto.label.defs#selfLabels" {
		for _, label := range record.Labels.Values {
			if label.Val == "!no-unauthenticated" {
				noUnauth = true
			}
		}
	}

	author := &Author{
		PDS:         pds,
		Handle:      handle,
		DisplayName: record.DisplayName,
		AvatarURL:   avatarURL,
		BannerURL:   bannerURL,
		Pronouns:    record.Pronouns,
		NoUnauth:    noUnauth,
	}

	return author, nil
}