Skip to content

Commit

Permalink
[chore] Don't cc Accept of likes to followers (#3417)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmethurst authored Oct 11, 2024
1 parent 1c895f3 commit 77d755e
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 25 deletions.
90 changes: 66 additions & 24 deletions internal/typeutils/internaltoas.go
Original file line number Diff line number Diff line change
Expand Up @@ -1988,16 +1988,6 @@ func (c *Converter) InteractionReqToASAccept(
return nil, gtserror.Newf("invalid interacting account uri: %w", err)
}

publicIRI, err := url.Parse(pub.PublicActivityPubIRI)
if err != nil {
return nil, gtserror.Newf("invalid public uri: %w", err)
}

followersIRI, err := url.Parse(req.TargetAccount.FollowersURI)
if err != nil {
return nil, gtserror.Newf("invalid followers uri: %w", err)
}

// Set id to the URI of
// interaction request.
ap.SetJSONLDId(accept, acceptID)
Expand All @@ -2013,8 +2003,39 @@ func (c *Converter) InteractionReqToASAccept(
// of interaction URI.
ap.AppendTo(accept, toIRI)

// Cc to the actor's followers, and to Public.
ap.AppendCc(accept, publicIRI, followersIRI)
// Whether or not we cc this Accept to
// followers and public depends on the
// type of interaction it Accepts.

var cc bool
switch req.InteractionType {

case gtsmodel.InteractionLike:
// Accept of Like doesn't get cc'd
// because it's not that important.

case gtsmodel.InteractionReply:
// Accept of reply gets cc'd.
cc = true

case gtsmodel.InteractionAnnounce:
// Accept of announce gets cc'd.
cc = true
}

if cc {
publicIRI, err := url.Parse(pub.PublicActivityPubIRI)
if err != nil {
return nil, gtserror.Newf("invalid public uri: %w", err)
}

followersIRI, err := url.Parse(req.TargetAccount.FollowersURI)
if err != nil {
return nil, gtserror.Newf("invalid followers uri: %w", err)
}

ap.AppendCc(accept, publicIRI, followersIRI)
}

return accept, nil
}
Expand Down Expand Up @@ -2047,16 +2068,6 @@ func (c *Converter) InteractionReqToASReject(
return nil, gtserror.Newf("invalid interacting account uri: %w", err)
}

publicIRI, err := url.Parse(pub.PublicActivityPubIRI)
if err != nil {
return nil, gtserror.Newf("invalid public uri: %w", err)
}

followersIRI, err := url.Parse(req.TargetAccount.FollowersURI)
if err != nil {
return nil, gtserror.Newf("invalid followers uri: %w", err)
}

// Set id to the URI of
// interaction request.
ap.SetJSONLDId(reject, rejectID)
Expand All @@ -2072,8 +2083,39 @@ func (c *Converter) InteractionReqToASReject(
// of interaction URI.
ap.AppendTo(reject, toIRI)

// Cc to the actor's followers, and to Public.
ap.AppendCc(reject, publicIRI, followersIRI)
// Whether or not we cc this Reject to
// followers and public depends on the
// type of interaction it Rejects.

var cc bool
switch req.InteractionType {

case gtsmodel.InteractionLike:
// Reject of Like doesn't get cc'd
// because it's not that important.

case gtsmodel.InteractionReply:
// Reject of reply gets cc'd.
cc = true

case gtsmodel.InteractionAnnounce:
// Reject of announce gets cc'd.
cc = true
}

if cc {
publicIRI, err := url.Parse(pub.PublicActivityPubIRI)
if err != nil {
return nil, gtserror.Newf("invalid public uri: %w", err)
}

followersIRI, err := url.Parse(req.TargetAccount.FollowersURI)
if err != nil {
return nil, gtserror.Newf("invalid followers uri: %w", err)
}

ap.AppendCc(reject, publicIRI, followersIRI)
}

return reject, nil
}
47 changes: 46 additions & 1 deletion internal/typeutils/internaltoas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ func (suite *InternalToASTestSuite) TestPollVoteToASCreate() {
}`, string(bytes))
}

func (suite *InternalToASTestSuite) TestInteractionReqToASAccept() {
func (suite *InternalToASTestSuite) TestInteractionReqToASAcceptAnnounce() {
acceptingAccount := suite.testAccounts["local_account_1"]
interactingAccount := suite.testAccounts["remote_account_1"]

Expand Down Expand Up @@ -1192,6 +1192,51 @@ func (suite *InternalToASTestSuite) TestInteractionReqToASAccept() {
}`, string(b))
}

func (suite *InternalToASTestSuite) TestInteractionReqToASAcceptLike() {
acceptingAccount := suite.testAccounts["local_account_1"]
interactingAccount := suite.testAccounts["remote_account_1"]

req := &gtsmodel.InteractionRequest{
ID: "01J1AKMZ8JE5NW0ZSFTRC1JJNE",
CreatedAt: testrig.TimeMustParse("2022-06-09T13:12:00Z"),
TargetAccountID: acceptingAccount.ID,
TargetAccount: acceptingAccount,
InteractingAccountID: interactingAccount.ID,
InteractingAccount: interactingAccount,
InteractionURI: "https://fossbros-anonymous.io/users/foss_satan/statuses/01J1AKRRHQ6MDDQHV0TP716T2K",
InteractionType: gtsmodel.InteractionLike,
URI: "http://localhost:8080/users/the_mighty_zork/accepts/01J1AKMZ8JE5NW0ZSFTRC1JJNE",
AcceptedAt: testrig.TimeMustParse("2022-06-09T13:12:00Z"),
}

accept, err := suite.typeconverter.InteractionReqToASAccept(
context.Background(),
req,
)
if err != nil {
suite.FailNow(err.Error())
}

i, err := ap.Serialize(accept)
if err != nil {
suite.FailNow(err.Error())
}

b, err := json.MarshalIndent(i, "", " ")
if err != nil {
suite.FailNow(err.Error())
}

suite.Equal(`{
"@context": "https://www.w3.org/ns/activitystreams",
"actor": "http://localhost:8080/users/the_mighty_zork",
"id": "http://localhost:8080/users/the_mighty_zork/accepts/01J1AKMZ8JE5NW0ZSFTRC1JJNE",
"object": "https://fossbros-anonymous.io/users/foss_satan/statuses/01J1AKRRHQ6MDDQHV0TP716T2K",
"to": "http://fossbros-anonymous.io/users/foss_satan",
"type": "Accept"
}`, string(b))
}

func TestInternalToASTestSuite(t *testing.T) {
suite.Run(t, new(InternalToASTestSuite))
}

0 comments on commit 77d755e

Please sign in to comment.