Add support for resolving Application actors and fix error handling with failed resolution. Fixes #1710
This commit is contained in:
@@ -78,6 +78,25 @@ func MakeActorFromService(service vocab.ActivityStreamsService) ActivityPubActor
|
||||
return apActor
|
||||
}
|
||||
|
||||
// MakeActorFromApplication takes a full ActivityPub application and returns
|
||||
// our internal representation of an actor.
|
||||
func MakeActorFromApplication(application vocab.ActivityStreamsApplication) ActivityPubActor {
|
||||
apActor := ActivityPubActor{
|
||||
ActorIri: application.GetJSONLDId().Get(),
|
||||
Inbox: application.GetActivityStreamsInbox().GetIRI(),
|
||||
Name: application.GetActivityStreamsName().Begin().GetXMLSchemaString(),
|
||||
Username: application.GetActivityStreamsPreferredUsername().GetXMLSchemaString(),
|
||||
FullUsername: GetFullUsernameFromApplication(application),
|
||||
W3IDSecurityV1PublicKey: application.GetW3IDSecurityV1PublicKey(),
|
||||
}
|
||||
|
||||
if application.GetActivityStreamsIcon() != nil && application.GetActivityStreamsIcon().Len() > 0 && application.GetActivityStreamsIcon().At(0).GetActivityStreamsImage() != nil {
|
||||
apActor.Image = application.GetActivityStreamsIcon().At(0).GetActivityStreamsImage().GetActivityStreamsUrl().Begin().GetIRI()
|
||||
}
|
||||
|
||||
return apActor
|
||||
}
|
||||
|
||||
// MakeActorPropertyWithID will return an actor property filled with the provided IRI.
|
||||
func MakeActorPropertyWithID(idIRI *url.URL) vocab.ActivityStreamsActorProperty {
|
||||
actor := streams.NewActivityStreamsActorProperty()
|
||||
@@ -238,6 +257,15 @@ func GetFullUsernameFromService(person vocab.ActivityStreamsService) string {
|
||||
return fullUsername
|
||||
}
|
||||
|
||||
// GetFullUsernameFromApplication will return the user@host.tld formatted user given a service object.
|
||||
func GetFullUsernameFromApplication(person vocab.ActivityStreamsApplication) string {
|
||||
hostname := person.GetJSONLDId().GetIRI().Hostname()
|
||||
username := person.GetActivityStreamsPreferredUsername().GetXMLSchemaString()
|
||||
fullUsername := fmt.Sprintf("%s@%s", username, hostname)
|
||||
|
||||
return fullUsername
|
||||
}
|
||||
|
||||
func addMetadataLinkToProfile(profile vocab.ActivityStreamsService, name string, url string) {
|
||||
attachments := profile.GetActivityStreamsAttachment()
|
||||
if attachments == nil {
|
||||
|
||||
Reference in New Issue
Block a user