-
Notifications
You must be signed in to change notification settings - Fork 1
/
application_actor.go
151 lines (121 loc) · 5.31 KB
/
application_actor.go
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package models
import (
"github.com/shigde/sfu/internal/activitypub/crypto"
"github.com/shigde/sfu/internal/activitypub/instance"
"github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/activity/streams/vocab"
"golang.org/x/exp/slog"
)
func BuildActivityApplication(actor *Actor, config *instance.FederationConfig) vocab.ActivityStreamsApplication {
actorIRI := actor.GetActorIri()
app := streams.NewActivityStreamsApplication()
nameProperty := streams.NewActivityStreamsNameProperty()
nameProperty.AppendXMLSchemaString(config.ServerName)
app.SetActivityStreamsName(nameProperty)
preferredUsernameProperty := streams.NewActivityStreamsPreferredUsernameProperty()
preferredUsernameProperty.SetXMLSchemaString(actor.PreferredUsername)
app.SetActivityStreamsPreferredUsername(preferredUsernameProperty)
inboxProp := streams.NewActivityStreamsInboxProperty()
inboxProp.SetIRI(actor.GetInboxIri())
app.SetActivityStreamsInbox(inboxProp)
needsFollowApprovalProperty := streams.NewActivityStreamsManuallyApprovesFollowersProperty()
needsFollowApprovalProperty.Set(config.IsPrivate)
app.SetActivityStreamsManuallyApprovesFollowers(needsFollowApprovalProperty)
outboxProp := streams.NewActivityStreamsOutboxProperty()
outboxProp.SetIRI(actor.GetOutboxIri())
app.SetActivityStreamsOutbox(outboxProp)
id := streams.NewJSONLDIdProperty()
id.Set(actorIRI)
app.SetJSONLDId(id)
publicKey := crypto.GetPublicKey(actorIRI, actor.PublicKey)
publicKeyProp := streams.NewW3IDSecurityV1PublicKeyProperty()
publicKeyType := streams.NewW3IDSecurityV1PublicKey()
pubKeyIDProp := streams.NewJSONLDIdProperty()
pubKeyIDProp.Set(publicKey.ID)
publicKeyType.SetJSONLDId(pubKeyIDProp)
ownerProp := streams.NewW3IDSecurityV1OwnerProperty()
ownerProp.SetIRI(publicKey.Owner)
publicKeyType.SetW3IDSecurityV1Owner(ownerProp)
publicKeyPemProp := streams.NewW3IDSecurityV1PublicKeyPemProperty()
publicKeyPemProp.Set(publicKey.PublicKeyPem)
publicKeyType.SetW3IDSecurityV1PublicKeyPem(publicKeyPemProp)
publicKeyProp.AppendW3IDSecurityV1PublicKey(publicKeyType)
app.SetW3IDSecurityV1PublicKey(publicKeyProp)
if config.ServerInitTime.Valid {
publishedDateProp := streams.NewActivityStreamsPublishedProperty()
publishedDateProp.Set(config.ServerInitTime.Time)
app.SetActivityStreamsPublished(publishedDateProp)
} else {
slog.Error("unable to fetch server init time")
}
// Profile properties
// Avatar
//uniquenessString := data.GetLogoUniquenessString()
//userAvatarURLString := data.GetServerURL() + "/logo/external"
//userAvatarURL, err := url.Parse(userAvatarURLString)
//userAvatarURL.RawQuery = "uc=" + uniquenessString
//if err != nil {
// log.Errorln("unable to parse user avatar url", userAvatarURLString, err)
//}
//image := streams.NewActivityStreamsImage()
//imgProp := streams.NewActivityStreamsUrlProperty()
//imgProp.AppendIRI(userAvatarURL)
//image.SetActivityStreamsUrl(imgProp)
//icon := streams.NewActivityStreamsIconProperty()
//icon.AppendActivityStreamsImage(image)
//app.SetActivityStreamsIcon(icon)
// Actor URL
urlProperty := streams.NewActivityStreamsUrlProperty()
urlProperty.AppendIRI(actorIRI)
app.SetActivityStreamsUrl(urlProperty)
// Profile header
//headerImage := streams.NewActivityStreamsImage()
//headerImgPropURL := streams.NewActivityStreamsUrlProperty()
//headerImgPropURL.AppendIRI(userAvatarURL)
//headerImage.SetActivityStreamsUrl(headerImgPropURL)
//headerImageProp := streams.NewActivityStreamsImageProperty()
//headerImageProp.AppendActivityStreamsImage(headerImage)
//app.SetActivityStreamsImage(headerImageProp)
// Profile bio
//summaryProperty := streams.NewActivityStreamsSummaryProperty()
//summaryProperty.AppendXMLSchemaString(config.GetServerSummary())
//app.SetActivityStreamsSummary(summaryProperty)
// Links
//if serverURL := data.GetServerURL(); serverURL != "" {
// addMetadataLinkToProfile(app, "Stream", serverURL)
//}
//for _, link := range data.GetSocialHandles() {
// addMetadataLinkToProfile(app, link.Platform, link.URL)
//}
// Discoverable
discoverableProperty := streams.NewTootDiscoverableProperty()
discoverableProperty.Set(true)
app.SetTootDiscoverable(discoverableProperty)
// Followers
followersProperty := streams.NewActivityStreamsFollowersProperty()
followersURL := *actorIRI
followersURL.Path = actorIRI.Path + "/followers"
followersProperty.SetIRI(&followersURL)
app.SetActivityStreamsFollowers(followersProperty)
// Tags
tagProp := streams.NewActivityStreamsTagProperty()
//for _, tagString := range data.GetServerMetadataTags() {
// hashtag := MakeHashtag(tagString)
// tagProp.AppendTootHashtag(hashtag)
//}
app.SetActivityStreamsTag(tagProp)
// Work around an issue where a single attachment will not serialize
// as an array, so add another item to the mix.
//if len(data.GetSocialHandles()) == 1 {
// addMetadataLinkToProfile(app, "Owncast", "https://owncast.online")
//}
sharedInbox := streams.NewActivityStreamsSharedInboxProperty()
sharedInboxIri := actor.GetSharedInboxIri()
sharedInbox.SetIRI(sharedInboxIri)
endpoints := streams.NewActivityStreamsEndpointsProperty()
sharedInboxEndpoint := streams.NewActivityStreamsEndpoints()
sharedInboxEndpoint.SetActivityStreamsSharedInbox(sharedInbox)
endpoints.AppendActivityStreamsEndpoints(sharedInboxEndpoint)
app.SetActivityStreamsEndpoints(endpoints)
return app
}