mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[bugfix/chore] Announce
reliability updates (#2405)
* [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
This commit is contained in:
@@ -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 >smodel.Follow{
|
||||
ID: f.ID,
|
||||
CreatedAt: f.CreatedAt,
|
||||
UpdatedAt: f.UpdatedAt,
|
||||
AccountID: f.AccountID,
|
||||
TargetAccountID: f.TargetAccountID,
|
||||
ShowReblogs: &showReblogs,
|
||||
URI: f.URI,
|
||||
Notify: ¬ify,
|
||||
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
|
||||
}
|
||||
boost := >smodel.Status{
|
||||
ID: boostID,
|
||||
URI: accountURIs.StatusesURI + "/" + boostID,
|
||||
URL: accountURIs.StatusesURL + "/" + boostID,
|
||||
|
||||
sensitive := *s.Sensitive
|
||||
federated := *s.Federated
|
||||
boostable := *s.Boostable
|
||||
replyable := *s.Replyable
|
||||
likeable := *s.Likeable
|
||||
// Inherit some fields from the booster account.
|
||||
Local: util.Ptr(booster.IsLocal()),
|
||||
AccountID: booster.ID,
|
||||
Account: booster,
|
||||
AccountURI: booster.URI,
|
||||
CreatedWithApplicationID: applicationID,
|
||||
|
||||
boostWrapperStatus := >smodel.Status{
|
||||
ID: boostWrapperStatusID,
|
||||
URI: boostWrapperStatusURI,
|
||||
URL: boostWrapperStatusURL,
|
||||
|
||||
// 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
|
||||
}
|
||||
|
Reference in New Issue
Block a user