summaryrefslogtreecommitdiff
path: root/internal/processing/workers/federate.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-11-08 14:32:17 +0000
committerLibravatar GitHub <noreply@github.com>2023-11-08 14:32:17 +0000
commite9e5dc5a40926e5320cb131b035c46b1e1b0bd59 (patch)
tree52edc9fa5742f28e1e5223f51cda628ec1c35a24 /internal/processing/workers/federate.go
parent[chore]: Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 (#2338) (diff)
downloadgotosocial-e9e5dc5a40926e5320cb131b035c46b1e1b0bd59.tar.xz
[feature] add support for polls + receiving federated status edits (#2330)
Diffstat (limited to 'internal/processing/workers/federate.go')
-rw-r--r--internal/processing/workers/federate.go59
1 files changed, 40 insertions, 19 deletions
diff --git a/internal/processing/workers/federate.go b/internal/processing/workers/federate.go
index 80b01ca40..44432998d 100644
--- a/internal/processing/workers/federate.go
+++ b/internal/processing/workers/federate.go
@@ -158,26 +158,52 @@ func (f *federate) CreateStatus(ctx context.Context, status *gtsmodel.Status) er
return err
}
- // Convert status to ActivityStreams Statusable implementing type.
+ // Convert status to AS Statusable implementing type.
statusable, err := f.converter.StatusToAS(ctx, status)
if err != nil {
return gtserror.Newf("error converting status to Statusable: %w", err)
}
- // Use ActivityStreams Statusable type as Object of Create.
- create, err := f.converter.WrapStatusableInCreate(statusable, false)
+ // Send a Create activity with Statusable via the Actor's outbox.
+ create := typeutils.WrapStatusableInCreate(statusable, false)
+ if _, err := f.FederatingActor().Send(ctx, outboxIRI, create); err != nil {
+ return gtserror.Newf("error sending Create activity via outbox %s: %w", outboxIRI, err)
+ }
+ return nil
+}
+
+func (f *federate) CreatePollVote(ctx context.Context, poll *gtsmodel.Poll, vote *gtsmodel.PollVote) error {
+ // Extract status from poll.
+ status := poll.Status
+
+ // Do nothing if the status
+ // shouldn't be federated.
+ if !*status.Federated {
+ return nil
+ }
+
+ // Do nothing if this is
+ // a vote in our status.
+ if *status.Local {
+ return nil
+ }
+
+ // Parse the outbox URI of the poll vote author.
+ outboxIRI, err := parseURI(vote.Account.OutboxURI)
if err != nil {
- return gtserror.Newf("error wrapping Statusable in Create: %w", err)
+ return err
}
- // Send the Create via the Actor's outbox.
- if _, err := f.FederatingActor().Send(
- ctx, outboxIRI, create,
- ); err != nil {
- return gtserror.Newf(
- "error sending activity %T via outbox %s: %w",
- create, outboxIRI, err,
- )
+ // Convert votes to AS PollOptionable implementing type.
+ notes, err := f.converter.PollVoteToASOptions(ctx, vote)
+ if err != nil {
+ return gtserror.Newf("error converting to notes: %w", err)
+ }
+
+ // Send a Create activity with PollOptionables via the Actor's outbox.
+ create := typeutils.WrapPollOptionablesInCreate(notes...)
+ if _, err := f.FederatingActor().Send(ctx, outboxIRI, create); err != nil {
+ return gtserror.Newf("error sending Create activity via outbox %s: %w", outboxIRI, err)
}
return nil
@@ -256,13 +282,8 @@ func (f *federate) UpdateStatus(ctx context.Context, status *gtsmodel.Status) er
return gtserror.Newf("error converting status to Statusable: %w", err)
}
- // Use ActivityStreams Statusable type as Object of Update.
- update, err := f.converter.WrapStatusableInUpdate(statusable, false)
- if err != nil {
- return gtserror.Newf("error wrapping Statusable in Update: %w", err)
- }
-
- // Send the Update activity with Statusable via the Actor's outbox.
+ // Send an Update activity with Statusable via the Actor's outbox.
+ update := typeutils.WrapStatusableInUpdate(statusable, false)
if _, err := f.FederatingActor().Send(ctx, outboxIRI, update); err != nil {
return gtserror.Newf("error sending Update activity via outbox %s: %w", outboxIRI, err)
}