summaryrefslogtreecommitdiff
path: root/internal/typeutils/internal.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-12-01 15:27:15 +0100
committerLibravatar GitHub <noreply@github.com>2023-12-01 15:27:15 +0100
commit0e2c34219112db3a6b7801530a946fd5b1bbb111 (patch)
tree6a5557373dbfc9edc80de941b13e870a8af32881 /internal/typeutils/internal.go
parent[bugfix] in fedi API CreateStatus(), handle case of data-race and return earl... (diff)
downloadgotosocial-0e2c34219112db3a6b7801530a946fd5b1bbb111.tar.xz
[bugfix/chore] `Announce` reliability updates (#2405)v0.13.0-rc1
* [bugfix/chore] `Announce` updates * test update * fix tests * TestParseAnnounce * update comments * don't lock/unlock, change function signature * naming stuff * don't check domain block twice * UnwrapIfBoost * beep boop
Diffstat (limited to 'internal/typeutils/internal.go')
-rw-r--r--internal/typeutils/internal.go122
1 files changed, 59 insertions, 63 deletions
diff --git a/internal/typeutils/internal.go b/internal/typeutils/internal.go
index 1824a4421..095e2b121 100644
--- a/internal/typeutils/internal.go
+++ b/internal/typeutils/internal.go
@@ -19,90 +19,86 @@ package typeutils
import (
"context"
- "time"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/uris"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
-// FollowRequestToFollow just converts a follow request into a follow, that's it! No bells and whistles.
-func (c *Converter) FollowRequestToFollow(ctx context.Context, f *gtsmodel.FollowRequest) *gtsmodel.Follow {
- showReblogs := *f.ShowReblogs
- notify := *f.Notify
+// FollowRequestToFollow just converts a follow request
+// into a follow, that's it! No bells and whistles.
+func (c *Converter) FollowRequestToFollow(
+ ctx context.Context,
+ fr *gtsmodel.FollowRequest,
+) *gtsmodel.Follow {
return &gtsmodel.Follow{
- ID: f.ID,
- CreatedAt: f.CreatedAt,
- UpdatedAt: f.UpdatedAt,
- AccountID: f.AccountID,
- TargetAccountID: f.TargetAccountID,
- ShowReblogs: &showReblogs,
- URI: f.URI,
- Notify: &notify,
+ ID: fr.ID,
+ CreatedAt: fr.CreatedAt,
+ UpdatedAt: fr.UpdatedAt,
+ AccountID: fr.AccountID,
+ TargetAccountID: fr.TargetAccountID,
+ ShowReblogs: util.Ptr(*fr.ShowReblogs),
+ URI: fr.URI,
+ Notify: util.Ptr(*fr.Notify),
}
}
-// StatusToBoost wraps the given status into a boosting status.
-func (c *Converter) StatusToBoost(ctx context.Context, s *gtsmodel.Status, boostingAccount *gtsmodel.Account) (*gtsmodel.Status, error) {
- // the wrapper won't use the same ID as the boosted status so we generate some new UUIDs
- accountURIs := uris.GenerateURIsForAccount(boostingAccount.Username)
- boostWrapperStatusID := id.NewULID()
- boostWrapperStatusURI := accountURIs.StatusesURI + "/" + boostWrapperStatusID
- boostWrapperStatusURL := accountURIs.StatusesURL + "/" + boostWrapperStatusID
+// StatusToBoost wraps the target status into a
+// boost wrapper status owned by the requester.
+func (c *Converter) StatusToBoost(
+ ctx context.Context,
+ target *gtsmodel.Status,
+ booster *gtsmodel.Account,
+ applicationID string,
+) (*gtsmodel.Status, error) {
+ // The boost won't use the same IDs as the
+ // target so we need to generate new ones.
+ boostID := id.NewULID()
+ accountURIs := uris.GenerateURIsForAccount(booster.Username)
- local := true
- if boostingAccount.Domain != "" {
- local = false
- }
-
- sensitive := *s.Sensitive
- federated := *s.Federated
- boostable := *s.Boostable
- replyable := *s.Replyable
- likeable := *s.Likeable
+ boost := &gtsmodel.Status{
+ ID: boostID,
+ URI: accountURIs.StatusesURI + "/" + boostID,
+ URL: accountURIs.StatusesURL + "/" + boostID,
- boostWrapperStatus := &gtsmodel.Status{
- ID: boostWrapperStatusID,
- URI: boostWrapperStatusURI,
- URL: boostWrapperStatusURL,
+ // Inherit some fields from the booster account.
+ Local: util.Ptr(booster.IsLocal()),
+ AccountID: booster.ID,
+ Account: booster,
+ AccountURI: booster.URI,
+ CreatedWithApplicationID: applicationID,
- // the boosted status is not created now, but the boost certainly is
- CreatedAt: time.Now(),
- UpdatedAt: time.Now(),
- Local: &local,
- AccountID: boostingAccount.ID,
- AccountURI: boostingAccount.URI,
-
- // replies can be boosted, but boosts are never replies
+ // Replies can be boosted, but
+ // boosts are never replies.
InReplyToID: "",
InReplyToAccountID: "",
- // these will all be wrapped in the boosted status so set them empty here
+ // These will all be wrapped in the
+ // boosted status so set them empty.
AttachmentIDs: []string{},
TagIDs: []string{},
MentionIDs: []string{},
EmojiIDs: []string{},
- // the below fields will be taken from the target status
- Content: s.Content,
- ContentWarning: s.ContentWarning,
- ActivityStreamsType: s.ActivityStreamsType,
- Sensitive: &sensitive,
- Language: s.Language,
- Text: s.Text,
- BoostOfID: s.ID,
- BoostOfAccountID: s.AccountID,
- Visibility: s.Visibility,
- Federated: &federated,
- Boostable: &boostable,
- Replyable: &replyable,
- Likeable: &likeable,
-
- // attach these here for convenience -- the boosted status/account won't go in the DB
- // but they're needed in the processor and for the frontend. Since we have them, we can
- // attach them so we don't need to fetch them again later (save some DB calls)
- BoostOf: s,
+ // Remaining fields all
+ // taken from boosted status.
+ Content: target.Content,
+ ContentWarning: target.ContentWarning,
+ ActivityStreamsType: target.ActivityStreamsType,
+ Sensitive: util.Ptr(*target.Sensitive),
+ Language: target.Language,
+ Text: target.Text,
+ BoostOfID: target.ID,
+ BoostOf: target,
+ BoostOfAccountID: target.AccountID,
+ BoostOfAccount: target.Account,
+ Visibility: target.Visibility,
+ Federated: util.Ptr(*target.Federated),
+ Boostable: util.Ptr(*target.Boostable),
+ Replyable: util.Ptr(*target.Replyable),
+ Likeable: util.Ptr(*target.Likeable),
}
- return boostWrapperStatus, nil
+ return boost, nil
}