gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

delete.go (2402B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package status
     19 
     20 import (
     21 	"context"
     22 	"errors"
     23 	"fmt"
     24 
     25 	"github.com/superseriousbusiness/gotosocial/internal/ap"
     26 	apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
     27 	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
     28 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     29 	"github.com/superseriousbusiness/gotosocial/internal/messages"
     30 )
     31 
     32 // Delete processes the delete of a given status, returning the deleted status if the delete goes through.
     33 func (p *Processor) Delete(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) {
     34 	targetStatus, err := p.state.DB.GetStatusByID(ctx, targetStatusID)
     35 	if err != nil {
     36 		return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err))
     37 	}
     38 
     39 	if targetStatus.Account == nil {
     40 		return nil, gtserror.NewErrorNotFound(fmt.Errorf("no status owner for status %s", targetStatusID))
     41 	}
     42 
     43 	if targetStatus.AccountID != requestingAccount.ID {
     44 		return nil, gtserror.NewErrorForbidden(errors.New("status doesn't belong to requesting account"))
     45 	}
     46 
     47 	// Parse the status to API model BEFORE deleting it.
     48 	apiStatus, errWithCode := p.apiStatus(ctx, targetStatus, requestingAccount)
     49 	if errWithCode != nil {
     50 		return nil, errWithCode
     51 	}
     52 
     53 	// Process delete side effects.
     54 	p.state.Workers.EnqueueClientAPI(ctx, messages.FromClientAPI{
     55 		APObjectType:   ap.ObjectNote,
     56 		APActivityType: ap.ActivityDelete,
     57 		GTSModel:       targetStatus,
     58 		OriginAccount:  requestingAccount,
     59 		TargetAccount:  requestingAccount,
     60 	})
     61 
     62 	return apiStatus, nil
     63 }