gtsocial-umbx

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

boostable.go (2076B)


      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 visibility
     19 
     20 import (
     21 	"context"
     22 
     23 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     24 	"github.com/superseriousbusiness/gotosocial/internal/log"
     25 )
     26 
     27 // StatusBoostable checks if given status is boostable by requester, checking boolean status visibility to requester and ultimately the AP status visibility setting.
     28 func (f *Filter) StatusBoostable(ctx context.Context, requester *gtsmodel.Account, status *gtsmodel.Status) (bool, error) {
     29 	if status.Visibility == gtsmodel.VisibilityDirect {
     30 		log.Trace(ctx, "direct statuses are not boostable")
     31 		return false, nil
     32 	}
     33 
     34 	// Check whether status is visible to requesting account.
     35 	visible, err := f.StatusVisible(ctx, requester, status)
     36 	if err != nil {
     37 		return false, err
     38 	}
     39 
     40 	if !visible {
     41 		log.Trace(ctx, "status not visible to requesting account")
     42 		return false, nil
     43 	}
     44 
     45 	if requester.ID == status.AccountID {
     46 		// Status author can always boost non-directs.
     47 		return true, nil
     48 	}
     49 
     50 	if status.Visibility == gtsmodel.VisibilityFollowersOnly ||
     51 		status.Visibility == gtsmodel.VisibilityMutualsOnly {
     52 		log.Trace(ctx, "unauthored %s status not boostable", status.Visibility)
     53 		return false, nil
     54 	}
     55 
     56 	if !*status.Boostable {
     57 		log.Trace(ctx, "status marked not boostable")
     58 		return false, nil
     59 	}
     60 
     61 	return true, nil
     62 }