diff options
Diffstat (limited to 'internal/processing/status')
-rw-r--r-- | internal/processing/status/boost.go | 33 | ||||
-rw-r--r-- | internal/processing/status/boostedby.go | 35 | ||||
-rw-r--r-- | internal/processing/status/context.go | 43 | ||||
-rw-r--r-- | internal/processing/status/create.go | 18 | ||||
-rw-r--r-- | internal/processing/status/delete.go | 34 | ||||
-rw-r--r-- | internal/processing/status/fave.go | 53 | ||||
-rw-r--r-- | internal/processing/status/favedby.go | 31 | ||||
-rw-r--r-- | internal/processing/status/get.go | 31 | ||||
-rw-r--r-- | internal/processing/status/unboost.go | 39 | ||||
-rw-r--r-- | internal/processing/status/unfave.go | 31 | ||||
-rw-r--r-- | internal/processing/status/util.go | 28 | ||||
-rw-r--r-- | internal/processing/status/util_test.go | 28 |
12 files changed, 150 insertions, 254 deletions
diff --git a/internal/processing/status/boost.go b/internal/processing/status/boost.go index 93d0f19de..d7a62beb1 100644 --- a/internal/processing/status/boost.go +++ b/internal/processing/status/boost.go @@ -9,31 +9,22 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (p *processor) Boost(account *gtsmodel.Account, application *gtsmodel.Application, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { - l := p.log.WithField("func", "StatusBoost") - - l.Tracef("going to search for target status %s", targetStatusID) - targetStatus := >smodel.Status{} - if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { +func (p *processor) Boost(requestingAccount *gtsmodel.Account, application *gtsmodel.Application, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { + targetStatus, err := p.db.GetStatusByID(targetStatusID) + if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err)) } - - l.Tracef("going to search for target account %s", targetStatus.AccountID) - targetAccount := >smodel.Account{} - if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err)) + if targetStatus.Account == nil { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("no status owner for status %s", targetStatusID)) } - l.Trace("going to see if status is visible") - visible, err := p.filter.StatusVisible(targetStatus, account) + visible, err := p.filter.StatusVisible(targetStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } - if !visible { return nil, gtserror.NewErrorNotFound(errors.New("status is not visible")) } - if targetStatus.VisibilityAdvanced != nil { if !targetStatus.VisibilityAdvanced.Boostable { return nil, gtserror.NewErrorForbidden(errors.New("status is not boostable")) @@ -41,16 +32,16 @@ func (p *processor) Boost(account *gtsmodel.Account, application *gtsmodel.Appli } // it's visible! it's boostable! so let's boost the FUCK out of it - boostWrapperStatus, err := p.tc.StatusToBoost(targetStatus, account) + boostWrapperStatus, err := p.tc.StatusToBoost(targetStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorInternalError(err) } boostWrapperStatus.CreatedWithApplicationID = application.ID - boostWrapperStatus.GTSBoostedAccount = targetAccount + boostWrapperStatus.BoostOfAccount = targetStatus.Account // put the boost in the database - if err := p.db.Put(boostWrapperStatus); err != nil { + if err := p.db.PutStatus(boostWrapperStatus); err != nil { return nil, gtserror.NewErrorInternalError(err) } @@ -59,12 +50,12 @@ func (p *processor) Boost(account *gtsmodel.Account, application *gtsmodel.Appli APObjectType: gtsmodel.ActivityStreamsAnnounce, APActivityType: gtsmodel.ActivityStreamsCreate, GTSModel: boostWrapperStatus, - OriginAccount: account, - TargetAccount: targetAccount, + OriginAccount: requestingAccount, + TargetAccount: targetStatus.Account, } // return the frontend representation of the new status to the submitter - mastoStatus, err := p.tc.StatusToMasto(boostWrapperStatus, account) + mastoStatus, err := p.tc.StatusToMasto(boostWrapperStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err)) } diff --git a/internal/processing/status/boostedby.go b/internal/processing/status/boostedby.go index b352178e3..1bde6b5ae 100644 --- a/internal/processing/status/boostedby.go +++ b/internal/processing/status/boostedby.go @@ -9,46 +9,37 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (p *processor) BoostedBy(account *gtsmodel.Account, targetStatusID string) ([]*apimodel.Account, gtserror.WithCode) { - l := p.log.WithField("func", "StatusBoostedBy") - - l.Tracef("going to search for target status %s", targetStatusID) - targetStatus := >smodel.Status{} - if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error fetching status %s: %s", targetStatusID, err)) +func (p *processor) BoostedBy(requestingAccount *gtsmodel.Account, targetStatusID string) ([]*apimodel.Account, gtserror.WithCode) { + targetStatus, err := p.db.GetStatusByID(targetStatusID) + if err != nil { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err)) } - - l.Tracef("going to search for target account %s", targetStatus.AccountID) - targetAccount := >smodel.Account{} - if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error fetching target account %s: %s", targetStatus.AccountID, err)) + if targetStatus.Account == nil { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("no status owner for status %s", targetStatusID)) } - l.Trace("going to see if status is visible") - visible, err := p.filter.StatusVisible(targetStatus, account) + visible, err := p.filter.StatusVisible(targetStatus, requestingAccount) if err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error seeing if status %s is visible: %s", targetStatus.ID, err)) + return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } - if !visible { - return nil, gtserror.NewErrorNotFound(errors.New("StatusBoostedBy: status is not visible")) + return nil, gtserror.NewErrorNotFound(errors.New("status is not visible")) } - // get ALL accounts that faved a status -- doesn't take account of blocks and mutes and stuff - favingAccounts, err := p.db.WhoBoostedStatus(targetStatus) + statusReblogs, err := p.db.GetStatusReblogs(targetStatus) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error seeing who boosted status: %s", err)) } // filter the list so the user doesn't see accounts they blocked or which blocked them filteredAccounts := []*gtsmodel.Account{} - for _, acc := range favingAccounts { - blocked, err := p.db.Blocked(account.ID, acc.ID) + for _, s := range statusReblogs { + blocked, err := p.db.IsBlocked(requestingAccount.ID, s.AccountID, true) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error checking blocks: %s", err)) } if !blocked { - filteredAccounts = append(filteredAccounts, acc) + filteredAccounts = append(filteredAccounts, s.Account) } } diff --git a/internal/processing/status/context.go b/internal/processing/status/context.go index 32c528296..43002545e 100644 --- a/internal/processing/status/context.go +++ b/internal/processing/status/context.go @@ -1,46 +1,45 @@ package status import ( + "errors" "fmt" "sort" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" - "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (p *processor) Context(account *gtsmodel.Account, targetStatusID string) (*apimodel.Context, gtserror.WithCode) { - - context := &apimodel.Context{ - Ancestors: []apimodel.Status{}, - Descendants: []apimodel.Status{}, +func (p *processor) Context(requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Context, gtserror.WithCode) { + targetStatus, err := p.db.GetStatusByID(targetStatusID) + if err != nil { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err)) } - - targetStatus := >smodel.Status{} - if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { - if _, ok := err.(db.ErrNoEntries); ok { - return nil, gtserror.NewErrorNotFound(err) - } - return nil, gtserror.NewErrorInternalError(err) + if targetStatus.Account == nil { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("no status owner for status %s", targetStatusID)) } - visible, err := p.filter.StatusVisible(targetStatus, account) + visible, err := p.filter.StatusVisible(targetStatus, requestingAccount) if err != nil { - return nil, gtserror.NewErrorNotFound(err) + return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } if !visible { - return nil, gtserror.NewErrorForbidden(fmt.Errorf("account with id %s does not have permission to view status %s", account.ID, targetStatusID)) + return nil, gtserror.NewErrorNotFound(errors.New("status is not visible")) + } + + context := &apimodel.Context{ + Ancestors: []apimodel.Status{}, + Descendants: []apimodel.Status{}, } - parents, err := p.db.StatusParents(targetStatus, false) + parents, err := p.db.GetStatusParents(targetStatus, false) if err != nil { return nil, gtserror.NewErrorInternalError(err) } for _, status := range parents { - if v, err := p.filter.StatusVisible(status, account); err == nil && v { - mastoStatus, err := p.tc.StatusToMasto(status, account) + if v, err := p.filter.StatusVisible(status, requestingAccount); err == nil && v { + mastoStatus, err := p.tc.StatusToMasto(status, requestingAccount) if err == nil { context.Ancestors = append(context.Ancestors, *mastoStatus) } @@ -51,14 +50,14 @@ func (p *processor) Context(account *gtsmodel.Account, targetStatusID string) (* return context.Ancestors[i].ID < context.Ancestors[j].ID }) - children, err := p.db.StatusChildren(targetStatus, false, "") + children, err := p.db.GetStatusChildren(targetStatus, false, "") if err != nil { return nil, gtserror.NewErrorInternalError(err) } for _, status := range children { - if v, err := p.filter.StatusVisible(status, account); err == nil && v { - mastoStatus, err := p.tc.StatusToMasto(status, account) + if v, err := p.filter.StatusVisible(status, requestingAccount); err == nil && v { + mastoStatus, err := p.tc.StatusToMasto(status, requestingAccount) if err == nil { context.Descendants = append(context.Descendants, *mastoStatus) } diff --git a/internal/processing/status/create.go b/internal/processing/status/create.go index 0e99b5f4a..fc112ed8b 100644 --- a/internal/processing/status/create.go +++ b/internal/processing/status/create.go @@ -38,27 +38,22 @@ func (p *processor) Create(account *gtsmodel.Account, application *gtsmodel.Appl Text: form.Status, } - // check if replyToID is ok if err := p.ProcessReplyToID(form, account.ID, newStatus); err != nil { return nil, gtserror.NewErrorInternalError(err) } - // check if mediaIDs are ok if err := p.ProcessMediaIDs(form, account.ID, newStatus); err != nil { return nil, gtserror.NewErrorInternalError(err) } - // check if visibility settings are ok if err := p.ProcessVisibility(form, account.Privacy, newStatus); err != nil { return nil, gtserror.NewErrorInternalError(err) } - // handle language settings if err := p.ProcessLanguage(form, account.Language, newStatus); err != nil { return nil, gtserror.NewErrorInternalError(err) } - // handle mentions if err := p.ProcessMentions(form, account.ID, newStatus); err != nil { return nil, gtserror.NewErrorInternalError(err) } @@ -75,20 +70,11 @@ func (p *processor) Create(account *gtsmodel.Account, application *gtsmodel.Appl return nil, gtserror.NewErrorInternalError(err) } - // put the new status in the database, generating an ID for it in the process - if err := p.db.Put(newStatus); err != nil { + // put the new status in the database + if err := p.db.PutStatus(newStatus); err != nil { return nil, gtserror.NewErrorInternalError(err) } - // change the status ID of the media attachments to the new status - for _, a := range newStatus.GTSMediaAttachments { - a.StatusID = newStatus.ID - a.UpdatedAt = time.Now() - if err := p.db.UpdateByID(a.ID, a); err != nil { - return nil, gtserror.NewErrorInternalError(err) - } - } - // send it back to the processor for async processing p.fromClientAPI <- gtsmodel.FromClientAPI{ APObjectType: gtsmodel.ActivityStreamsNote, diff --git a/internal/processing/status/delete.go b/internal/processing/status/delete.go index 259038dee..4c5dfd744 100644 --- a/internal/processing/status/delete.go +++ b/internal/processing/status/delete.go @@ -5,36 +5,24 @@ import ( "fmt" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" - "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (p *processor) Delete(account *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { - l := p.log.WithField("func", "StatusDelete") - l.Tracef("going to search for target status %s", targetStatusID) - targetStatus := >smodel.Status{} - if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { - if _, ok := err.(db.ErrNoEntries); !ok { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err)) - } - // status is already gone - return nil, nil +func (p *processor) Delete(requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { + targetStatus, err := p.db.GetStatusByID(targetStatusID) + if err != nil { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err)) } - - if targetStatus.AccountID != account.ID { - return nil, gtserror.NewErrorForbidden(errors.New("status doesn't belong to requesting account")) + if targetStatus.Account == nil { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("no status owner for status %s", targetStatusID)) } - var boostOfStatus *gtsmodel.Status - if targetStatus.BoostOfID != "" { - boostOfStatus = >smodel.Status{} - if err := p.db.GetByID(targetStatus.BoostOfID, boostOfStatus); err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching boosted status %s: %s", targetStatus.BoostOfID, err)) - } + if targetStatus.AccountID != requestingAccount.ID { + return nil, gtserror.NewErrorForbidden(errors.New("status doesn't belong to requesting account")) } - mastoStatus, err := p.tc.StatusToMasto(targetStatus, account) + mastoStatus, err := p.tc.StatusToMasto(targetStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err)) } @@ -48,8 +36,8 @@ func (p *processor) Delete(account *gtsmodel.Account, targetStatusID string) (*a APObjectType: gtsmodel.ActivityStreamsNote, APActivityType: gtsmodel.ActivityStreamsDelete, GTSModel: targetStatus, - OriginAccount: account, - TargetAccount: account, + OriginAccount: requestingAccount, + TargetAccount: requestingAccount, } return mastoStatus, nil diff --git a/internal/processing/status/fave.go b/internal/processing/status/fave.go index 0dfee6233..7ba8c8fe8 100644 --- a/internal/processing/status/fave.go +++ b/internal/processing/status/fave.go @@ -12,39 +12,22 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/util" ) -func (p *processor) Fave(account *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { - l := p.log.WithField("func", "StatusFave") - l.Tracef("going to search for target status %s", targetStatusID) - targetStatus := >smodel.Status{} - if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { +func (p *processor) Fave(requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { + targetStatus, err := p.db.GetStatusByID(targetStatusID) + if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err)) } - - l.Tracef("going to search for target account %s", targetStatus.AccountID) - targetAccount := >smodel.Account{} - if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err)) + if targetStatus.Account == nil { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("no status owner for status %s", targetStatusID)) } - var boostOfStatus *gtsmodel.Status - if targetStatus.BoostOfID != "" { - boostOfStatus = >smodel.Status{} - if err := p.db.GetByID(targetStatus.BoostOfID, boostOfStatus); err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching boosted status %s: %s", targetStatus.BoostOfID, err)) - } - } - - l.Trace("going to see if status is visible") - visible, err := p.filter.StatusVisible(targetStatus, account) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that + visible, err := p.filter.StatusVisible(targetStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } - if !visible { return nil, gtserror.NewErrorNotFound(errors.New("status is not visible")) } - - // is the status faveable? if targetStatus.VisibilityAdvanced != nil { if !targetStatus.VisibilityAdvanced.Likeable { return nil, gtserror.NewErrorForbidden(errors.New("status is not faveable")) @@ -54,7 +37,7 @@ func (p *processor) Fave(account *gtsmodel.Account, targetStatusID string) (*api // first check if the status is already faved, if so we don't need to do anything newFave := true gtsFave := >smodel.StatusFave{} - if err := p.db.GetWhere([]db.Where{{Key: "status_id", Value: targetStatus.ID}, {Key: "account_id", Value: account.ID}}, gtsFave); err == nil { + if err := p.db.GetWhere([]db.Where{{Key: "status_id", Value: targetStatus.ID}, {Key: "account_id", Value: requestingAccount.ID}}, gtsFave); err == nil { // we already have a fave for this status newFave = false } @@ -67,14 +50,14 @@ func (p *processor) Fave(account *gtsmodel.Account, targetStatusID string) (*api // we need to create a new fave in the database gtsFave := >smodel.StatusFave{ - ID: thisFaveID, - AccountID: account.ID, - TargetAccountID: targetAccount.ID, - StatusID: targetStatus.ID, - URI: util.GenerateURIForLike(account.Username, p.config.Protocol, p.config.Host, thisFaveID), - GTSStatus: targetStatus, - GTSTargetAccount: targetAccount, - GTSFavingAccount: account, + ID: thisFaveID, + AccountID: requestingAccount.ID, + Account: requestingAccount, + TargetAccountID: targetStatus.AccountID, + TargetAccount: targetStatus.Account, + StatusID: targetStatus.ID, + Status: targetStatus, + URI: util.GenerateURIForLike(requestingAccount.Username, p.config.Protocol, p.config.Host, thisFaveID), } if err := p.db.Put(gtsFave); err != nil { @@ -86,13 +69,13 @@ func (p *processor) Fave(account *gtsmodel.Account, targetStatusID string) (*api APObjectType: gtsmodel.ActivityStreamsLike, APActivityType: gtsmodel.ActivityStreamsCreate, GTSModel: gtsFave, - OriginAccount: account, - TargetAccount: targetAccount, + OriginAccount: requestingAccount, + TargetAccount: targetStatus.Account, } } // return the mastodon representation of the target status - mastoStatus, err := p.tc.StatusToMasto(targetStatus, account) + mastoStatus, err := p.tc.StatusToMasto(targetStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err)) } diff --git a/internal/processing/status/favedby.go b/internal/processing/status/favedby.go index 5194cc258..dffe6bba9 100644 --- a/internal/processing/status/favedby.go +++ b/internal/processing/status/favedby.go @@ -9,51 +9,40 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (p *processor) FavedBy(account *gtsmodel.Account, targetStatusID string) ([]*apimodel.Account, gtserror.WithCode) { - l := p.log.WithField("func", "StatusFavedBy") - - l.Tracef("going to search for target status %s", targetStatusID) - targetStatus := >smodel.Status{} - if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { +func (p *processor) FavedBy(requestingAccount *gtsmodel.Account, targetStatusID string) ([]*apimodel.Account, gtserror.WithCode) { + targetStatus, err := p.db.GetStatusByID(targetStatusID) + if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err)) } - - l.Tracef("going to search for target account %s", targetStatus.AccountID) - targetAccount := >smodel.Account{} - if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err)) + if targetStatus.Account == nil { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("no status owner for status %s", targetStatusID)) } - l.Trace("going to see if status is visible") - visible, err := p.filter.StatusVisible(targetStatus, account) + visible, err := p.filter.StatusVisible(targetStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } - if !visible { return nil, gtserror.NewErrorNotFound(errors.New("status is not visible")) } - // get ALL accounts that faved a status -- doesn't take account of blocks and mutes and stuff - favingAccounts, err := p.db.WhoFavedStatus(targetStatus) + statusFaves, err := p.db.GetStatusFaves(targetStatus) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing who faved status: %s", err)) } // filter the list so the user doesn't see accounts they blocked or which blocked them filteredAccounts := []*gtsmodel.Account{} - for _, acc := range favingAccounts { - blocked, err := p.db.Blocked(account.ID, acc.ID) + for _, fave := range statusFaves { + blocked, err := p.db.IsBlocked(requestingAccount.ID, fave.AccountID, true) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error checking blocks: %s", err)) } if !blocked { - filteredAccounts = append(filteredAccounts, acc) + filteredAccounts = append(filteredAccounts, fave.Account) } } - // TODO: filter other things here? suspended? muted? silenced? - // now we can return the masto representation of those accounts mastoAccounts := []*apimodel.Account{} for _, acc := range filteredAccounts { diff --git a/internal/processing/status/get.go b/internal/processing/status/get.go index 9a70185b0..9d403b901 100644 --- a/internal/processing/status/get.go +++ b/internal/processing/status/get.go @@ -9,44 +9,27 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (p *processor) Get(account *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { - l := p.log.WithField("func", "StatusGet") - - l.Tracef("going to search for target status %s", targetStatusID) - targetStatus := >smodel.Status{} - if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { +func (p *processor) Get(requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { + targetStatus, err := p.db.GetStatusByID(targetStatusID) + if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err)) } - - l.Tracef("going to search for target account %s", targetStatus.AccountID) - targetAccount := >smodel.Account{} - if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err)) + if targetStatus.Account == nil { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("no status owner for status %s", targetStatusID)) } - l.Trace("going to see if status is visible") - visible, err := p.filter.StatusVisible(targetStatus, account) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that + visible, err := p.filter.StatusVisible(targetStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } - if !visible { return nil, gtserror.NewErrorNotFound(errors.New("status is not visible")) } - var boostOfStatus *gtsmodel.Status - if targetStatus.BoostOfID != "" { - boostOfStatus = >smodel.Status{} - if err := p.db.GetByID(targetStatus.BoostOfID, boostOfStatus); err != nil { - return nil, gtserror.NewErrorInternalError(fmt.Errorf("error fetching boosted status %s: %s", targetStatus.BoostOfID, err)) - } - } - - mastoStatus, err := p.tc.StatusToMasto(targetStatus, account) + mastoStatus, err := p.tc.StatusToMasto(targetStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err)) } return mastoStatus, nil - } diff --git a/internal/processing/status/unboost.go b/internal/processing/status/unboost.go index 2a1394695..254cfe11f 100644 --- a/internal/processing/status/unboost.go +++ b/internal/processing/status/unboost.go @@ -10,27 +10,19 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (p *processor) Unboost(account *gtsmodel.Account, application *gtsmodel.Application, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { - l := p.log.WithField("func", "Unboost") - - l.Tracef("going to search for target status %s", targetStatusID) - targetStatus := >smodel.Status{} - if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { +func (p *processor) Unboost(requestingAccount *gtsmodel.Account, application *gtsmodel.Application, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { + targetStatus, err := p.db.GetStatusByID(targetStatusID) + if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err)) } - - l.Tracef("going to search for target account %s", targetStatus.AccountID) - targetAccount := >smodel.Account{} - if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err)) + if targetStatus.Account == nil { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("no status owner for status %s", targetStatusID)) } - l.Trace("going to see if status is visible") - visible, err := p.filter.StatusVisible(targetStatus, account) + visible, err := p.filter.StatusVisible(targetStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } - if !visible { return nil, gtserror.NewErrorNotFound(errors.New("status is not visible")) } @@ -46,7 +38,7 @@ func (p *processor) Unboost(account *gtsmodel.Account, application *gtsmodel.App }, { Key: "account_id", - Value: account.ID, + Value: requestingAccount.ID, }, } err = p.db.GetWhere(where, gtsBoost) @@ -57,7 +49,7 @@ func (p *processor) Unboost(account *gtsmodel.Account, application *gtsmodel.App if err != nil { // something went wrong in the db finding the boost - if _, ok := err.(db.ErrNoEntries); !ok { + if err != db.ErrNoEntries { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error fetching existing boost from database: %s", err)) } // we just don't have a boost @@ -71,22 +63,23 @@ func (p *processor) Unboost(account *gtsmodel.Account, application *gtsmodel.App } // pin some stuff onto the boost while we have it out of the db - gtsBoost.GTSBoostedStatus = targetStatus - gtsBoost.GTSBoostedStatus.GTSAuthorAccount = targetAccount - gtsBoost.GTSBoostedAccount = targetAccount - gtsBoost.GTSAuthorAccount = account + gtsBoost.Account = requestingAccount + + gtsBoost.BoostOf = targetStatus + gtsBoost.BoostOfAccount = targetStatus.Account + gtsBoost.BoostOf.Account = targetStatus.Account // send it back to the processor for async processing p.fromClientAPI <- gtsmodel.FromClientAPI{ APObjectType: gtsmodel.ActivityStreamsAnnounce, APActivityType: gtsmodel.ActivityStreamsUndo, GTSModel: gtsBoost, - OriginAccount: account, - TargetAccount: targetAccount, + OriginAccount: requestingAccount, + TargetAccount: targetStatus.Account, } } - mastoStatus, err := p.tc.StatusToMasto(targetStatus, account) + mastoStatus, err := p.tc.StatusToMasto(targetStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err)) } diff --git a/internal/processing/status/unfave.go b/internal/processing/status/unfave.go index b51daacb9..d6e5320db 100644 --- a/internal/processing/status/unfave.go +++ b/internal/processing/status/unfave.go @@ -10,26 +10,19 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (p *processor) Unfave(account *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { - l := p.log.WithField("func", "StatusUnfave") - l.Tracef("going to search for target status %s", targetStatusID) - targetStatus := >smodel.Status{} - if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { +func (p *processor) Unfave(requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { + targetStatus, err := p.db.GetStatusByID(targetStatusID) + if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err)) } - - l.Tracef("going to search for target account %s", targetStatus.AccountID) - targetAccount := >smodel.Account{} - if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err)) + if targetStatus.Account == nil { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("no status owner for status %s", targetStatusID)) } - l.Trace("going to see if status is visible") - visible, err := p.filter.StatusVisible(targetStatus, account) + visible, err := p.filter.StatusVisible(targetStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } - if !visible { return nil, gtserror.NewErrorNotFound(errors.New("status is not visible")) } @@ -38,14 +31,14 @@ func (p *processor) Unfave(account *gtsmodel.Account, targetStatusID string) (*a var toUnfave bool gtsFave := >smodel.StatusFave{} - err = p.db.GetWhere([]db.Where{{Key: "status_id", Value: targetStatus.ID}, {Key: "account_id", Value: account.ID}}, gtsFave) + err = p.db.GetWhere([]db.Where{{Key: "status_id", Value: targetStatus.ID}, {Key: "account_id", Value: requestingAccount.ID}}, gtsFave) if err == nil { // we have a fave toUnfave = true } if err != nil { // something went wrong in the db finding the fave - if _, ok := err.(db.ErrNoEntries); !ok { + if err != db.ErrNoEntries { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error fetching existing fave from database: %s", err)) } // we just don't have a fave @@ -54,7 +47,7 @@ func (p *processor) Unfave(account *gtsmodel.Account, targetStatusID string) (*a if toUnfave { // we had a fave, so take some action to get rid of it - if err := p.db.DeleteWhere([]db.Where{{Key: "status_id", Value: targetStatus.ID}, {Key: "account_id", Value: account.ID}}, gtsFave); err != nil { + if err := p.db.DeleteWhere([]db.Where{{Key: "status_id", Value: targetStatus.ID}, {Key: "account_id", Value: requestingAccount.ID}}, gtsFave); err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error unfaveing status: %s", err)) } @@ -63,12 +56,12 @@ func (p *processor) Unfave(account *gtsmodel.Account, targetStatusID string) (*a APObjectType: gtsmodel.ActivityStreamsLike, APActivityType: gtsmodel.ActivityStreamsUndo, GTSModel: gtsFave, - OriginAccount: account, - TargetAccount: targetAccount, + OriginAccount: requestingAccount, + TargetAccount: targetStatus.Account, } } - mastoStatus, err := p.tc.StatusToMasto(targetStatus, account) + mastoStatus, err := p.tc.StatusToMasto(targetStatus, requestingAccount) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err)) } diff --git a/internal/processing/status/util.go b/internal/processing/status/util.go index 3be53591b..025607f4a 100644 --- a/internal/processing/status/util.go +++ b/internal/processing/status/util.go @@ -99,7 +99,7 @@ func (p *processor) ProcessReplyToID(form *apimodel.AdvancedStatusCreateForm, th repliedAccount := >smodel.Account{} // check replied status exists + is replyable if err := p.db.GetByID(form.InReplyToID, repliedStatus); err != nil { - if _, ok := err.(db.ErrNoEntries); ok { + if err == db.ErrNoEntries { return fmt.Errorf("status with id %s not replyable because it doesn't exist", form.InReplyToID) } return fmt.Errorf("status with id %s not replyable: %s", form.InReplyToID, err) @@ -113,14 +113,14 @@ func (p *processor) ProcessReplyToID(form *apimodel.AdvancedStatusCreateForm, th // check replied account is known to us if err := p.db.GetByID(repliedStatus.AccountID, repliedAccount); err != nil { - if _, ok := err.(db.ErrNoEntries); ok { + if err == db.ErrNoEntries { return fmt.Errorf("status with id %s not replyable because account id %s is not known", form.InReplyToID, repliedStatus.AccountID) } return fmt.Errorf("status with id %s not replyable: %s", form.InReplyToID, err) } // check if a block exists - if blocked, err := p.db.Blocked(thisAccountID, repliedAccount.ID); err != nil { - if _, ok := err.(db.ErrNoEntries); !ok { + if blocked, err := p.db.IsBlocked(thisAccountID, repliedAccount.ID, true); err != nil { + if err != db.ErrNoEntries { return fmt.Errorf("status with id %s not replyable: %s", form.InReplyToID, err) } } else if blocked { @@ -156,8 +156,8 @@ func (p *processor) ProcessMediaIDs(form *apimodel.AdvancedStatusCreateForm, thi gtsMediaAttachments = append(gtsMediaAttachments, a) attachments = append(attachments, a.ID) } - status.GTSMediaAttachments = gtsMediaAttachments - status.Attachments = attachments + status.Attachments = gtsMediaAttachments + status.AttachmentIDs = attachments return nil } @@ -192,9 +192,9 @@ func (p *processor) ProcessMentions(form *apimodel.AdvancedStatusCreateForm, acc menchies = append(menchies, menchie.ID) } // add full populated gts menchies to the status for passing them around conveniently - status.GTSMentions = gtsMenchies + status.Mentions = gtsMenchies // add just the ids of the mentioned accounts to the status for putting in the db - status.Mentions = menchies + status.MentionIDs = menchies return nil } @@ -211,9 +211,9 @@ func (p *processor) ProcessTags(form *apimodel.AdvancedStatusCreateForm, account tags = append(tags, tag.ID) } // add full populated gts tags to the status for passing them around conveniently - status.GTSTags = gtsTags + status.Tags = gtsTags // add just the ids of the used tags to the status for putting in the db - status.Tags = tags + status.TagIDs = tags return nil } @@ -227,9 +227,9 @@ func (p *processor) ProcessEmojis(form *apimodel.AdvancedStatusCreateForm, accou emojis = append(emojis, e.ID) } // add full populated gts emojis to the status for passing them around conveniently - status.GTSEmojis = gtsEmojis + status.Emojis = gtsEmojis // add just the ids of the used emojis to the status for putting in the db - status.Emojis = emojis + status.EmojiIDs = emojis return nil } @@ -252,9 +252,9 @@ func (p *processor) ProcessContent(form *apimodel.AdvancedStatusCreateForm, acco var formatted string switch form.Format { case apimodel.StatusFormatPlain: - formatted = p.formatter.FromPlain(content, status.GTSMentions, status.GTSTags) + formatted = p.formatter.FromPlain(content, status.Mentions, status.Tags) case apimodel.StatusFormatMarkdown: - formatted = p.formatter.FromMarkdown(content, status.GTSMentions, status.GTSTags) + formatted = p.formatter.FromMarkdown(content, status.Mentions, status.Tags) default: return fmt.Errorf("format %s not recognised as a valid status format", form.Format) } diff --git a/internal/processing/status/util_test.go b/internal/processing/status/util_test.go index 4bf508848..9c282eb52 100644 --- a/internal/processing/status/util_test.go +++ b/internal/processing/status/util_test.go @@ -91,19 +91,19 @@ func (suite *UtilTestSuite) TestProcessMentions1() { err := suite.status.ProcessMentions(form, creatingAccount.ID, status) assert.NoError(suite.T(), err) - assert.Len(suite.T(), status.GTSMentions, 1) - newMention := status.GTSMentions[0] + assert.Len(suite.T(), status.Mentions, 1) + newMention := status.Mentions[0] assert.Equal(suite.T(), mentionedAccount.ID, newMention.TargetAccountID) assert.Equal(suite.T(), creatingAccount.ID, newMention.OriginAccountID) assert.Equal(suite.T(), creatingAccount.URI, newMention.OriginAccountURI) assert.Equal(suite.T(), status.ID, newMention.StatusID) assert.Equal(suite.T(), fmt.Sprintf("@%s@%s", mentionedAccount.Username, mentionedAccount.Domain), newMention.NameString) - assert.Equal(suite.T(), mentionedAccount.URI, newMention.MentionedAccountURI) - assert.Equal(suite.T(), mentionedAccount.URL, newMention.MentionedAccountURL) - assert.NotNil(suite.T(), newMention.GTSAccount) + assert.Equal(suite.T(), mentionedAccount.URI, newMention.TargetAccountURI) + assert.Equal(suite.T(), mentionedAccount.URL, newMention.TargetAccountURL) + assert.NotNil(suite.T(), newMention.OriginAccount) - assert.Len(suite.T(), status.Mentions, 1) - assert.Equal(suite.T(), newMention.ID, status.Mentions[0]) + assert.Len(suite.T(), status.MentionIDs, 1) + assert.Equal(suite.T(), newMention.ID, status.MentionIDs[0]) } func (suite *UtilTestSuite) TestProcessContentFull1() { @@ -232,19 +232,19 @@ func (suite *UtilTestSuite) TestProcessMentions2() { err := suite.status.ProcessMentions(form, creatingAccount.ID, status) assert.NoError(suite.T(), err) - assert.Len(suite.T(), status.GTSMentions, 1) - newMention := status.GTSMentions[0] + assert.Len(suite.T(), status.Mentions, 1) + newMention := status.Mentions[0] assert.Equal(suite.T(), mentionedAccount.ID, newMention.TargetAccountID) assert.Equal(suite.T(), creatingAccount.ID, newMention.OriginAccountID) assert.Equal(suite.T(), creatingAccount.URI, newMention.OriginAccountURI) assert.Equal(suite.T(), status.ID, newMention.StatusID) assert.Equal(suite.T(), fmt.Sprintf("@%s@%s", mentionedAccount.Username, mentionedAccount.Domain), newMention.NameString) - assert.Equal(suite.T(), mentionedAccount.URI, newMention.MentionedAccountURI) - assert.Equal(suite.T(), mentionedAccount.URL, newMention.MentionedAccountURL) - assert.NotNil(suite.T(), newMention.GTSAccount) + assert.Equal(suite.T(), mentionedAccount.URI, newMention.TargetAccountURI) + assert.Equal(suite.T(), mentionedAccount.URL, newMention.TargetAccountURL) + assert.NotNil(suite.T(), newMention.OriginAccount) - assert.Len(suite.T(), status.Mentions, 1) - assert.Equal(suite.T(), newMention.ID, status.Mentions[0]) + assert.Len(suite.T(), status.MentionIDs, 1) + assert.Equal(suite.T(), newMention.ID, status.MentionIDs[0]) } func (suite *UtilTestSuite) TestProcessContentFull2() { |