[feature] Federate reports to remote instance as Flag (if desired) (#1386)

* reports federate out, we did it lxds

* fix optional line start (should be optional slash)
This commit is contained in:
tobi
2023-01-27 14:48:11 +01:00
committed by GitHub
parent c59ec6f2a4
commit 3283900b0d
10 changed files with 207 additions and 69 deletions

View File

@@ -1295,3 +1295,53 @@ func (c *converter) OutboxToASCollection(ctx context.Context, outboxID string) (
return collection, nil
}
func (c *converter) ReportToASFlag(ctx context.Context, r *gtsmodel.Report) (vocab.ActivityStreamsFlag, error) {
flag := streams.NewActivityStreamsFlag()
flagIDProp := streams.NewJSONLDIdProperty()
idURI, err := url.Parse(r.URI)
if err != nil {
return nil, fmt.Errorf("error parsing url %s: %w", r.URI, err)
}
flagIDProp.SetIRI(idURI)
flag.SetJSONLDId(flagIDProp)
// for privacy, set the actor as the INSTANCE ACTOR,
// not as the actor who created the report
instanceAccount, err := c.db.GetInstanceAccount(ctx, "")
if err != nil {
return nil, fmt.Errorf("error getting instance account: %w", err)
}
instanceAccountIRI, err := url.Parse(instanceAccount.URI)
if err != nil {
return nil, fmt.Errorf("error parsing url %s: %w", instanceAccount.URI, err)
}
flagActorProp := streams.NewActivityStreamsActorProperty()
flagActorProp.AppendIRI(instanceAccountIRI)
flag.SetActivityStreamsActor(flagActorProp)
// content should be the comment submitted when the report was created
contentProp := streams.NewActivityStreamsContentProperty()
contentProp.AppendXMLSchemaString(r.Comment)
flag.SetActivityStreamsContent(contentProp)
// set at least the target account uri as the object of the flag
objectProp := streams.NewActivityStreamsObjectProperty()
targetAccountURI, err := url.Parse(r.TargetAccount.URI)
if err != nil {
return nil, fmt.Errorf("error parsing url %s: %w", r.TargetAccount.URI, err)
}
objectProp.AppendIRI(targetAccountURI)
// also set status URIs if they were provided with the report
for _, s := range r.Statuses {
statusURI, err := url.Parse(s.URI)
if err != nil {
return nil, fmt.Errorf("error parsing url %s: %w", s.URI, err)
}
objectProp.AppendIRI(statusURI)
}
flag.SetActivityStreamsObject(objectProp)
return flag, nil
}