diff options
author | 2024-11-28 15:37:37 +0000 | |
---|---|---|
committer | 2024-11-28 15:37:37 +0000 | |
commit | d9f67efae512673c826b27daeae404a6051d9817 (patch) | |
tree | fe89c62e3f43eb285d6ed64b2b407986fe1917bb /internal/typeutils/internaltoas.go | |
parent | pulls in the latest exif-terminator version with bugfix and performance optim... (diff) | |
download | gotosocial-d9f67efae512673c826b27daeae404a6051d9817.tar.xz |
send out poll votes as separate create activities given that no other AP servers support multiple objects in a single activity (#3582)
Diffstat (limited to 'internal/typeutils/internaltoas.go')
-rw-r--r-- | internal/typeutils/internaltoas.go | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go index ed8bc1d8d..a81e5d2c0 100644 --- a/internal/typeutils/internaltoas.go +++ b/internal/typeutils/internaltoas.go @@ -1701,10 +1701,14 @@ func (c *Converter) ReportToASFlag(ctx context.Context, r *gtsmodel.Report) (voc // PollVoteToASCreate converts a vote on a poll into a Create // activity, suitable for federation, with each choice in the // vote appended as a Note to the Create's Object field. -func (c *Converter) PollVoteToASCreate( +// +// TODO: as soon as other AP server implementations support +// the use of multiple objects in a single create, update this +// to return just the one create event again. +func (c *Converter) PollVoteToASCreates( ctx context.Context, vote *gtsmodel.PollVote, -) (vocab.ActivityStreamsCreate, error) { +) ([]vocab.ActivityStreamsCreate, error) { if len(vote.Choices) == 0 { panic("no vote.Choices") } @@ -1743,22 +1747,25 @@ func (c *Converter) PollVoteToASCreate( return nil, gtserror.Newf("invalid account uri: %w", err) } - // Allocate Create activity and address 'To' poll author. - create := streams.NewActivityStreamsCreate() - ap.AppendTo(create, pollAuthorIRI) + // Parse each choice to a Note and add it to the list of Creates. + creates := make([]vocab.ActivityStreamsCreate, len(vote.Choices)) + for i, choice := range vote.Choices { + + // Allocate Create activity and address 'To' poll author. + create := streams.NewActivityStreamsCreate() + ap.AppendTo(create, pollAuthorIRI) - // Create ID formatted as: {$voterIRI}/activity#vote/{$statusIRI}. - id := author.URI + "/activity#vote/" + poll.Status.URI - ap.MustSet(ap.SetJSONLDIdStr, ap.WithJSONLDId(create), id) + // Create ID formatted as: {$voterIRI}/activity#vote{$index}/{$statusIRI}. + createID := fmt.Sprintf("%s/activity#vote%d/%s", author.URI, i, poll.Status.URI) + ap.MustSet(ap.SetJSONLDIdStr, ap.WithJSONLDId(create), createID) - // Set Create actor appropriately. - ap.AppendActorIRIs(create, authorIRI) + // Set Create actor appropriately. + ap.AppendActorIRIs(create, authorIRI) - // Set publish time for activity. - ap.SetPublished(create, vote.CreatedAt) + // Set publish time for activity. + ap.SetPublished(create, vote.CreatedAt) - // Parse each choice to a Note and add it to the Create. - for _, choice := range vote.Choices { + // Allocate new note to hold the vote. note := streams.NewActivityStreamsNote() // For AP IRI generate from author URI + poll ID + vote choice. @@ -1775,11 +1782,14 @@ func (c *Converter) PollVoteToASCreate( ap.AppendInReplyTo(note, statusIRI) ap.AppendTo(note, pollAuthorIRI) - // Append this note as Create Object. + // Append this note to the Create Object. appendStatusableToActivity(create, note, false) + + // Set create in slice. + creates[i] = create } - return create, nil + return creates, nil } // populateValuesForProp appends the given PolicyValues |