package views import ( "fmt" "git.capotej.com/capotej/communique/urls" "github.com/go-fed/activity/streams" ) func RenderActor(name, domain, pem 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 } 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) nameProp := streams.NewActivityStreamsNameProperty() nameProp.AppendXMLSchemaString(name) p.SetActivityStreamsName(nameProp) usernameProp := streams.NewActivityStreamsPreferredUsernameProperty() usernameProp.SetXMLSchemaString(name) p.SetActivityStreamsPreferredUsername(usernameProp) urlProp := streams.NewActivityStreamsUrlProperty() urlProp.AppendIRI(actorUrl) p.SetActivityStreamsUrl(urlProp) summaryProp := streams.NewActivityStreamsSummaryProperty() summaryProp.AppendXMLSchemaString(fmt.Sprintf("profile for %s", name)) 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) }