summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltoas.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-11-27 14:14:28 +0100
committerLibravatar GitHub <noreply@github.com>2023-11-27 13:14:28 +0000
commite4e0a5e3f66f38e17a8abdafbeac251c75323b0e (patch)
tree6dc6211acd78df9fa3b933f19ab3275c187a5106 /internal/typeutils/internaltoas.go
parent[chore]: Bump golang.org/x/net from 0.17.0 to 0.18.0 (#2390) (diff)
downloadgotosocial-e4e0a5e3f66f38e17a8abdafbeac251c75323b0e.tar.xz
[bugfix] Add Actor to outgoing poll vote Create; other fixes (#2384)
Diffstat (limited to 'internal/typeutils/internaltoas.go')
-rw-r--r--internal/typeutils/internaltoas.go37
1 files changed, 29 insertions, 8 deletions
diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go
index ff502296b..0ffad6fc1 100644
--- a/internal/typeutils/internaltoas.go
+++ b/internal/typeutils/internaltoas.go
@@ -1659,7 +1659,17 @@ func (c *Converter) ReportToASFlag(ctx context.Context, r *gtsmodel.Report) (voc
return flag, nil
}
-func (c *Converter) PollVoteToASOptions(ctx context.Context, vote *gtsmodel.PollVote) ([]ap.PollOptionable, error) {
+// 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(
+ ctx context.Context,
+ vote *gtsmodel.PollVote,
+) (vocab.ActivityStreamsCreate, error) {
+ if len(vote.Choices) == 0 {
+ panic("no vote.Choices")
+ }
+
// Ensure the vote is fully populated (this fetches author).
if err := c.state.DB.PopulatePollVote(ctx, vote); err != nil {
return nil, gtserror.Newf("error populating vote from db: %w", err)
@@ -1694,11 +1704,22 @@ func (c *Converter) PollVoteToASOptions(ctx context.Context, vote *gtsmodel.Poll
return nil, gtserror.Newf("invalid account uri: %w", err)
}
- // Preallocate the return slice of notes.
- notes := make([]ap.PollOptionable, len(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)
+
+ // Set Create actor appropriately.
+ ap.AppendActor(create, authorIRI)
+
+ // Set publish time for activity.
+ ap.SetPublished(create, vote.CreatedAt)
- for i, choice := range vote.Choices {
- // Create new note to represent vote.
+ // Parse each choice to a Note and add it to the Create.
+ for _, choice := range vote.Choices {
note := streams.NewActivityStreamsNote()
// For AP IRI generate from author URI + poll ID + vote choice.
@@ -1715,9 +1736,9 @@ func (c *Converter) PollVoteToASOptions(ctx context.Context, vote *gtsmodel.Poll
ap.AppendInReplyTo(note, statusIRI)
ap.AppendTo(note, pollAuthorIRI)
- // Set note in return slice.
- notes[i] = note
+ // Append this note as Create Object.
+ appendStatusableToActivity(create, note, false)
}
- return notes, nil
+ return create, nil
}