diff options
author | 2024-10-11 15:22:05 +0200 | |
---|---|---|
committer | 2024-10-11 15:22:05 +0200 | |
commit | 77d755e330d41e681097b0606088281c255c18e0 (patch) | |
tree | d0fe9d092b87481230ab95a2d0e1fd08decb5d8d /internal/typeutils/internaltoas.go | |
parent | [bugfix] Check interaction policies properly on incoming Likes (#3416) (diff) | |
download | gotosocial-77d755e330d41e681097b0606088281c255c18e0.tar.xz |
[chore] Don't cc Accept of likes to followers (#3417)v0.17.0-rc4
Diffstat (limited to 'internal/typeutils/internaltoas.go')
-rw-r--r-- | internal/typeutils/internaltoas.go | 90 |
1 files changed, 66 insertions, 24 deletions
diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go index d9d18e1c7..cfc790bd4 100644 --- a/internal/typeutils/internaltoas.go +++ b/internal/typeutils/internaltoas.go @@ -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) @@ -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 } @@ -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) @@ -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 } |