mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] add support for polls + receiving federated status edits (#2330)
This commit is contained in:
@ -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)
|
||||
if err != nil {
|
||||
return gtserror.Newf("error wrapping Statusable in Create: %w", err)
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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,
|
||||
)
|
||||
// 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 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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user