mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] Process Reject
of interaction via fedi API, put rejected statuses in the "sin bin" 😈 (#3271)
* [feature] Process `Reject` of interaction via fedi API, put rejected statuses in the "sin bin" * update test * move nil check back to `rejectStatusIRI`
This commit is contained in:
@ -37,69 +37,90 @@ import (
|
||||
// util provides util functions used by both
|
||||
// the fromClientAPI and fromFediAPI functions.
|
||||
type utils struct {
|
||||
state *state.State
|
||||
media *media.Processor
|
||||
account *account.Processor
|
||||
surface *Surface
|
||||
state *state.State
|
||||
media *media.Processor
|
||||
account *account.Processor
|
||||
surface *Surface
|
||||
converter *typeutils.Converter
|
||||
}
|
||||
|
||||
// wipeStatus encapsulates common logic
|
||||
// used to totally delete a status + all
|
||||
// its attachments, notifications, boosts,
|
||||
// and timeline entries.
|
||||
// wipeStatus encapsulates common logic used to
|
||||
// totally delete a status + all its attachments,
|
||||
// notifications, boosts, and timeline entries.
|
||||
//
|
||||
// If deleteAttachments is true, then any status
|
||||
// attachments will also be deleted, else they
|
||||
// will just be detached.
|
||||
//
|
||||
// If copyToSinBin is true, then a version of the
|
||||
// status will be put in the `sin_bin_statuses`
|
||||
// table prior to deletion.
|
||||
func (u *utils) wipeStatus(
|
||||
ctx context.Context,
|
||||
statusToDelete *gtsmodel.Status,
|
||||
status *gtsmodel.Status,
|
||||
deleteAttachments bool,
|
||||
copyToSinBin bool,
|
||||
) error {
|
||||
var errs gtserror.MultiError
|
||||
|
||||
if copyToSinBin {
|
||||
// Copy this status to the sin bin before we delete it.
|
||||
sbStatus, err := u.converter.StatusToSinBinStatus(ctx, status)
|
||||
if err != nil {
|
||||
errs.Appendf("error converting status to sinBinStatus: %w", err)
|
||||
} else {
|
||||
if err := u.state.DB.PutSinBinStatus(ctx, sbStatus); err != nil {
|
||||
errs.Appendf("db error storing sinBinStatus: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Either delete all attachments for this status,
|
||||
// or simply unattach + clean them separately later.
|
||||
// or simply detach + clean them separately later.
|
||||
//
|
||||
// Reason to unattach rather than delete is that
|
||||
// the poster might want to reattach them to another
|
||||
// status immediately (in case of delete + redraft)
|
||||
// Reason to detach rather than delete is that
|
||||
// the author might want to reattach them to another
|
||||
// status immediately (in case of delete + redraft).
|
||||
if deleteAttachments {
|
||||
// todo:u.state.DB.DeleteAttachmentsForStatus
|
||||
for _, id := range statusToDelete.AttachmentIDs {
|
||||
for _, id := range status.AttachmentIDs {
|
||||
if err := u.media.Delete(ctx, id); err != nil {
|
||||
errs.Appendf("error deleting media: %w", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// todo:u.state.DB.UnattachAttachmentsForStatus
|
||||
for _, id := range statusToDelete.AttachmentIDs {
|
||||
if _, err := u.media.Unattach(ctx, statusToDelete.Account, id); err != nil {
|
||||
for _, id := range status.AttachmentIDs {
|
||||
if _, err := u.media.Unattach(ctx, status.Account, id); err != nil {
|
||||
errs.Appendf("error unattaching media: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// delete all mention entries generated by this status
|
||||
// Delete all mentions generated by this status.
|
||||
// todo:u.state.DB.DeleteMentionsForStatus
|
||||
for _, id := range statusToDelete.MentionIDs {
|
||||
for _, id := range status.MentionIDs {
|
||||
if err := u.state.DB.DeleteMentionByID(ctx, id); err != nil {
|
||||
errs.Appendf("error deleting status mention: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// delete all notification entries generated by this status
|
||||
if err := u.state.DB.DeleteNotificationsForStatus(ctx, statusToDelete.ID); err != nil {
|
||||
// Delete all notifications generated by this status.
|
||||
if err := u.state.DB.DeleteNotificationsForStatus(ctx, status.ID); err != nil {
|
||||
errs.Appendf("error deleting status notifications: %w", err)
|
||||
}
|
||||
|
||||
// delete all bookmarks that point to this status
|
||||
if err := u.state.DB.DeleteStatusBookmarksForStatus(ctx, statusToDelete.ID); err != nil {
|
||||
// Delete all bookmarks of this status.
|
||||
if err := u.state.DB.DeleteStatusBookmarksForStatus(ctx, status.ID); err != nil {
|
||||
errs.Appendf("error deleting status bookmarks: %w", err)
|
||||
}
|
||||
|
||||
// delete all faves of this status
|
||||
if err := u.state.DB.DeleteStatusFavesForStatus(ctx, statusToDelete.ID); err != nil {
|
||||
// Delete all faves of this status.
|
||||
if err := u.state.DB.DeleteStatusFavesForStatus(ctx, status.ID); err != nil {
|
||||
errs.Appendf("error deleting status faves: %w", err)
|
||||
}
|
||||
|
||||
if pollID := statusToDelete.PollID; pollID != "" {
|
||||
if pollID := status.PollID; pollID != "" {
|
||||
// Delete this poll by ID from the database.
|
||||
if err := u.state.DB.DeletePollByID(ctx, pollID); err != nil {
|
||||
errs.Appendf("error deleting status poll: %w", err)
|
||||
@ -114,38 +135,42 @@ func (u *utils) wipeStatus(
|
||||
_ = u.state.Workers.Scheduler.Cancel(pollID)
|
||||
}
|
||||
|
||||
// delete all boosts for this status + remove them from timelines
|
||||
// Get all boost of this status so that we can
|
||||
// delete those boosts + remove them from timelines.
|
||||
boosts, err := u.state.DB.GetStatusBoosts(
|
||||
// we MUST set a barebones context here,
|
||||
// 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)
|
||||
status.ID)
|
||||
if err != nil {
|
||||
errs.Appendf("error fetching status boosts: %w", err)
|
||||
}
|
||||
|
||||
for _, boost := range boosts {
|
||||
if err := u.surface.deleteStatusFromTimelines(ctx, boost.ID); err != nil {
|
||||
errs.Appendf("error deleting boost from timelines: %w", err)
|
||||
}
|
||||
// Delete the boost itself.
|
||||
if err := u.state.DB.DeleteStatusByID(ctx, boost.ID); err != nil {
|
||||
errs.Appendf("error deleting boost: %w", err)
|
||||
}
|
||||
|
||||
// Remove the boost from any and all timelines.
|
||||
if err := u.surface.deleteStatusFromTimelines(ctx, boost.ID); err != nil {
|
||||
errs.Appendf("error deleting boost from timelines: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// delete this status from any and all timelines
|
||||
if err := u.surface.deleteStatusFromTimelines(ctx, statusToDelete.ID); err != nil {
|
||||
// Delete the status itself from any and all timelines.
|
||||
if err := u.surface.deleteStatusFromTimelines(ctx, status.ID); err != nil {
|
||||
errs.Appendf("error deleting status from timelines: %w", err)
|
||||
}
|
||||
|
||||
// delete this status from any conversations that it's part of
|
||||
if err := u.state.DB.DeleteStatusFromConversations(ctx, statusToDelete.ID); err != nil {
|
||||
// Delete this status from any conversations it's part of.
|
||||
if err := u.state.DB.DeleteStatusFromConversations(ctx, status.ID); err != nil {
|
||||
errs.Appendf("error deleting status from conversations: %w", err)
|
||||
}
|
||||
|
||||
// finally, delete the status itself
|
||||
if err := u.state.DB.DeleteStatusByID(ctx, statusToDelete.ID); err != nil {
|
||||
// Finally delete the status itself.
|
||||
if err := u.state.DB.DeleteStatusByID(ctx, status.ID); err != nil {
|
||||
errs.Appendf("error deleting status: %w", err)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user