summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/account/delete.go2
-rw-r--r--internal/processing/fromcommon.go47
-rw-r--r--internal/processing/status/boost.go47
-rw-r--r--internal/processing/status/fave.go2
4 files changed, 44 insertions, 54 deletions
diff --git a/internal/processing/account/delete.go b/internal/processing/account/delete.go
index a613ba485..dd5957531 100644
--- a/internal/processing/account/delete.go
+++ b/internal/processing/account/delete.go
@@ -330,7 +330,7 @@ statusLoop:
})
// Look for any boosts of this status in DB.
- boosts, err := p.state.DB.GetStatusReblogs(ctx, status)
+ boosts, err := p.state.DB.GetStatusBoosts(ctx, status.ID)
if err != nil && !errors.Is(err, db.ErrNoEntries) {
return gtserror.Newf("error fetching status reblogs for %s: %w", status.ID, err)
}
diff --git a/internal/processing/fromcommon.go b/internal/processing/fromcommon.go
index 030ff506c..07895b6ba 100644
--- a/internal/processing/fromcommon.go
+++ b/internal/processing/fromcommon.go
@@ -380,6 +380,8 @@ func (p *Processor) notify(
// wipeStatus contains common logic used to totally delete a status
// + all its attachments, notifications, boosts, and timeline entries.
func (p *Processor) wipeStatus(ctx context.Context, statusToDelete *gtsmodel.Status, deleteAttachments bool) error {
+ var errs gtserror.MultiError
+
// either delete all attachments for this status, or simply
// unattach all attachments for this status, so they'll be
// cleaned later by a separate process; reason to unattach rather
@@ -389,14 +391,14 @@ func (p *Processor) wipeStatus(ctx context.Context, statusToDelete *gtsmodel.Sta
// todo: p.state.DB.DeleteAttachmentsForStatus
for _, a := range statusToDelete.AttachmentIDs {
if err := p.media.Delete(ctx, a); err != nil {
- return err
+ errs.Appendf("error deleting media: %w", err)
}
}
} else {
// todo: p.state.DB.UnattachAttachmentsForStatus
for _, a := range statusToDelete.AttachmentIDs {
if _, err := p.media.Unattach(ctx, statusToDelete.Account, a); err != nil {
- return err
+ errs.Appendf("error unattaching media: %w", err)
}
}
}
@@ -405,44 +407,55 @@ func (p *Processor) wipeStatus(ctx context.Context, statusToDelete *gtsmodel.Sta
// todo: p.state.DB.DeleteMentionsForStatus
for _, id := range statusToDelete.MentionIDs {
if err := p.state.DB.DeleteMentionByID(ctx, id); err != nil {
- return err
+ errs.Appendf("error deleting status mention: %w", err)
}
}
// delete all notification entries generated by this status
if err := p.state.DB.DeleteNotificationsForStatus(ctx, statusToDelete.ID); err != nil {
- return err
+ errs.Appendf("error deleting status notifications: %w", err)
}
// delete all bookmarks that point to this status
if err := p.state.DB.DeleteStatusBookmarksForStatus(ctx, statusToDelete.ID); err != nil {
- return err
+ errs.Appendf("error deleting status bookmarks: %w", err)
}
// delete all faves of this status
if err := p.state.DB.DeleteStatusFavesForStatus(ctx, statusToDelete.ID); err != nil {
- return err
+ errs.Appendf("error deleting status faves: %w", err)
}
// delete all boosts for this status + remove them from timelines
- if boosts, err := p.state.DB.GetStatusReblogs(ctx, statusToDelete); err == nil {
- for _, b := range boosts {
- if err := p.deleteStatusFromTimelines(ctx, b.ID); err != nil {
- return err
- }
- if err := p.state.DB.DeleteStatusByID(ctx, b.ID); err != nil {
- return err
- }
+ boosts, err := p.state.DB.GetStatusBoosts(
+ // we MUST set a barebones context here,
+ // as depending on where it came from the
+ // original BoostOf may already be gone.
+ gtscontext.SetBarebones(ctx),
+ statusToDelete.ID)
+ if err != nil {
+ errs.Appendf("error fetching status boosts: %w", err)
+ }
+ for _, b := range boosts {
+ if err := p.deleteStatusFromTimelines(ctx, b.ID); err != nil {
+ errs.Appendf("error deleting boost from timelines: %w", err)
+ }
+ if err := p.state.DB.DeleteStatusByID(ctx, b.ID); err != nil {
+ errs.Appendf("error deleting boost: %w", err)
}
}
// delete this status from any and all timelines
if err := p.deleteStatusFromTimelines(ctx, statusToDelete.ID); err != nil {
- return err
+ errs.Appendf("error deleting status from timelines: %w", err)
+ }
+
+ // finally, delete the status itself
+ if err := p.state.DB.DeleteStatusByID(ctx, statusToDelete.ID); err != nil {
+ errs.Appendf("error deleting status: %w", err)
}
- // delete the status itself
- return p.state.DB.DeleteStatusByID(ctx, statusToDelete.ID)
+ return errs.Combine()
}
// deleteStatusFromTimelines completely removes the given status from all timelines.
diff --git a/internal/processing/status/boost.go b/internal/processing/status/boost.go
index e5d38d9d2..eccd81886 100644
--- a/internal/processing/status/boost.go
+++ b/internal/processing/status/boost.go
@@ -106,47 +106,24 @@ func (p *Processor) BoostRemove(ctx context.Context, requestingAccount *gtsmodel
return nil, gtserror.NewErrorNotFound(errors.New("status is not visible"))
}
- // check if we actually have a boost for this status
- var toUnboost bool
-
- gtsBoost := &gtsmodel.Status{}
- where := []db.Where{
- {
- Key: "boost_of_id",
- Value: targetStatusID,
- },
- {
- Key: "account_id",
- Value: requestingAccount.ID,
- },
- }
- err = p.state.DB.GetWhere(ctx, where, gtsBoost)
- if err == nil {
- // we have a boost
- toUnboost = true
- }
-
+ // Check whether the requesting account has boosted the given status ID.
+ boost, err := p.state.DB.GetStatusBoost(ctx, targetStatusID, requestingAccount.ID)
if err != nil {
- // something went wrong in the db finding the boost
- 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
- toUnboost = false
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("error checking status boost %s: %w", targetStatusID, err))
}
- if toUnboost {
+ if boost != nil {
// pin some stuff onto the boost while we have it out of the db
- gtsBoost.Account = requestingAccount
- gtsBoost.BoostOf = targetStatus
- gtsBoost.BoostOfAccount = targetStatus.Account
- gtsBoost.BoostOf.Account = targetStatus.Account
+ boost.Account = requestingAccount
+ boost.BoostOf = targetStatus
+ boost.BoostOfAccount = targetStatus.Account
+ boost.BoostOf.Account = targetStatus.Account
// send it back to the processor for async processing
p.state.Workers.EnqueueClientAPI(ctx, messages.FromClientAPI{
APObjectType: ap.ActivityAnnounce,
APActivityType: ap.ActivityUndo,
- GTSModel: gtsBoost,
+ GTSModel: boost,
OriginAccount: requestingAccount,
TargetAccount: targetStatus.Account,
})
@@ -189,15 +166,15 @@ func (p *Processor) StatusBoostedBy(ctx context.Context, requestingAccount *gtsm
return nil, gtserror.NewErrorNotFound(err)
}
- statusReblogs, err := p.state.DB.GetStatusReblogs(ctx, targetStatus)
+ statusBoosts, err := p.state.DB.GetStatusBoosts(ctx, targetStatus.ID)
if err != nil {
err = fmt.Errorf("BoostedBy: error seeing who boosted status: %s", err)
return nil, gtserror.NewErrorNotFound(err)
}
// filter account IDs so the user doesn't see accounts they blocked or which blocked them
- accountIDs := make([]string, 0, len(statusReblogs))
- for _, s := range statusReblogs {
+ accountIDs := make([]string, 0, len(statusBoosts))
+ for _, s := range statusBoosts {
blocked, err := p.state.DB.IsEitherBlocked(ctx, requestingAccount.ID, s.AccountID)
if err != nil {
err = fmt.Errorf("BoostedBy: error checking blocks: %s", err)
diff --git a/internal/processing/status/fave.go b/internal/processing/status/fave.go
index 77d3f67e9..9da243312 100644
--- a/internal/processing/status/fave.go
+++ b/internal/processing/status/fave.go
@@ -112,7 +112,7 @@ func (p *Processor) FavedBy(ctx context.Context, requestingAccount *gtsmodel.Acc
return nil, errWithCode
}
- statusFaves, err := p.state.DB.GetStatusFavesForStatus(ctx, targetStatus.ID)
+ statusFaves, err := p.state.DB.GetStatusFaves(ctx, targetStatus.ID)
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("FavedBy: error seeing who faved status: %s", err))
}