aboutsummaryrefslogtreecommitdiff
path: root/views/actor.go
blob: 36f1f0c287fd4f555f3b7aae4b00ca3dd5f3adae (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package views

import (
	"git.capotej.com/capotej/communique/urls"
	"github.com/go-fed/activity/streams"
)

func RenderActor(name, domain, pem, mediaType, summary string) (map[string]interface{}, error) {
	inbox, err := urls.UrlInbox(name, domain)
	if err != nil {
		return nil, err
	}

	inboxProp := streams.NewActivityStreamsInboxProperty()
	inboxProp.SetIRI(inbox)

	outbox, err := urls.UrlOutbox(name, domain)
	if err != nil {
		return nil, err
	}

	outboxProp := streams.NewActivityStreamsOutboxProperty()
	outboxProp.SetIRI(outbox)

	actorUrl, err := urls.UrlProfile(name, domain)
	if err != nil {
		return nil, err
	}

	actorUrlKey, err := urls.UrlProfileKey(name, domain)
	if err != nil {
		return nil, err
	}

	actorAvatarUrl, err := urls.UrlActorAvatar(name, domain)
	if err != nil {
		return nil, err
	}

	followingUrl, err := urls.UrlFollowing(name, domain)
	if err != nil {
		return nil, err
	}

	followersUrl, err := urls.UrlFollowers(name, domain)
	if err != nil {
		return nil, err
	}

	p := streams.NewActivityStreamsService()
	idProp := streams.NewJSONLDIdProperty()
	idProp.Set(actorUrl)
	p.SetJSONLDId(idProp)
	p.SetActivityStreamsInbox(inboxProp)
	p.SetActivityStreamsOutbox(outboxProp)

	if mediaType != "" {
		image := streams.NewActivityStreamsImage()
		mediaTypeProp := streams.NewActivityStreamsMediaTypeProperty()
		mediaTypeProp.Set(mediaType)
		image.SetActivityStreamsMediaType(mediaTypeProp)
		urlProp := streams.NewActivityStreamsUrlProperty()
		urlProp.AppendIRI(actorAvatarUrl)
		image.SetActivityStreamsUrl(urlProp)

		iconProp := streams.NewActivityStreamsIconProperty()
		iconProp.AppendActivityStreamsImage(image)
		p.SetActivityStreamsIcon(iconProp)
	}

	nameProp := streams.NewActivityStreamsNameProperty()
	nameProp.AppendXMLSchemaString(name)
	p.SetActivityStreamsName(nameProp)

	usernameProp := streams.NewActivityStreamsPreferredUsernameProperty()
	usernameProp.SetXMLSchemaString(name)
	p.SetActivityStreamsPreferredUsername(usernameProp)

	actorUrlProp := streams.NewActivityStreamsUrlProperty()
	actorUrlProp.AppendIRI(actorUrl)
	p.SetActivityStreamsUrl(actorUrlProp)

	summaryProp := streams.NewActivityStreamsSummaryProperty()
	if summary != "" {
		summaryProp.AppendXMLSchemaString(summary)
	} else {
		summaryProp.AppendXMLSchemaString("an activitypub bot on communique (https://git.capotej.com/capotej/communique)")
	}
	p.SetActivityStreamsSummary(summaryProp)

	followersProp := streams.NewActivityStreamsFollowersProperty()
	followersProp.SetIRI(followersUrl)
	p.SetActivityStreamsFollowers(followersProp)

	followingProp := streams.NewActivityStreamsFollowingProperty()
	followingProp.SetIRI(followingUrl)
	p.SetActivityStreamsFollowing(followingProp)

	pemProp := streams.NewW3IDSecurityV1PublicKeyPemProperty()
	pemProp.Set(pem)

	ownerProp := streams.NewW3IDSecurityV1OwnerProperty()
	ownerProp.Set(actorUrl)

	pubkeyId := streams.NewJSONLDIdProperty()
	pubkeyId.Set(actorUrlKey)

	pubKey := streams.NewW3IDSecurityV1PublicKey()
	pubKey.SetW3IDSecurityV1PublicKeyPem(pemProp)
	pubKey.SetW3IDSecurityV1Owner(ownerProp)
	pubKey.SetJSONLDId(pubkeyId)

	pubKeyProp := streams.NewW3IDSecurityV1PublicKeyProperty()
	pubKeyProp.AppendW3IDSecurityV1PublicKey(pubKey)
	p.SetW3IDSecurityV1PublicKey(pubKeyProp)

	return streams.Serialize(p)
}