summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltoas.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-01-27 14:48:11 +0100
committerLibravatar GitHub <noreply@github.com>2023-01-27 14:48:11 +0100
commit3283900b0d0b98e5ca956f61ce09ab373cf0cbe8 (patch)
treef7dc654ea2d510e0c02d63d8a174908f1e25c680 /internal/typeutils/internaltoas.go
parent[docs] Add Flag documentation to federation docs (#1393) (diff)
downloadgotosocial-3283900b0d0b98e5ca956f61ce09ab373cf0cbe8.tar.xz
[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)
Diffstat (limited to 'internal/typeutils/internaltoas.go')
-rw-r--r--internal/typeutils/internaltoas.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go
index bf4dc7e18..2ae58b317 100644
--- a/internal/typeutils/internaltoas.go
+++ b/internal/typeutils/internaltoas.go
@@ -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
+}