gtsocial-umbx

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

announce.go (3101B)


      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 dereferencing
     19 
     20 import (
     21 	"context"
     22 	"errors"
     23 	"fmt"
     24 	"net/url"
     25 
     26 	"github.com/superseriousbusiness/gotosocial/internal/config"
     27 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     28 )
     29 
     30 func (d *deref) DereferenceAnnounce(ctx context.Context, announce *gtsmodel.Status, requestingUsername string) error {
     31 	if announce.BoostOf == nil {
     32 		// we can't do anything unfortunately
     33 		return errors.New("DereferenceAnnounce: no URI to dereference")
     34 	}
     35 
     36 	// Parse the boosted status' URI
     37 	boostedURI, err := url.Parse(announce.BoostOf.URI)
     38 	if err != nil {
     39 		return fmt.Errorf("DereferenceAnnounce: couldn't parse boosted status URI %s: %s", announce.BoostOf.URI, err)
     40 	}
     41 
     42 	// Check whether the originating status is from a blocked host
     43 	if blocked, err := d.state.DB.IsDomainBlocked(ctx, boostedURI.Host); blocked || err != nil {
     44 		return fmt.Errorf("DereferenceAnnounce: domain %s is blocked", boostedURI.Host)
     45 	}
     46 
     47 	var boostedStatus *gtsmodel.Status
     48 
     49 	if boostedURI.Host == config.GetHost() {
     50 		// This is a local status, fetch from the database
     51 		status, err := d.state.DB.GetStatusByURI(ctx, boostedURI.String())
     52 		if err != nil {
     53 			return fmt.Errorf("DereferenceAnnounce: error fetching local status %q: %v", announce.BoostOf.URI, err)
     54 		}
     55 
     56 		// Set boosted status
     57 		boostedStatus = status
     58 	} else {
     59 		// This is a boost of a remote status, we need to dereference it.
     60 		status, _, err := d.GetStatusByURI(ctx, requestingUsername, boostedURI)
     61 		if err != nil {
     62 			return fmt.Errorf("DereferenceAnnounce: error dereferencing remote status with id %s: %s", announce.BoostOf.URI, err)
     63 		}
     64 
     65 		// Set boosted status
     66 		boostedStatus = status
     67 	}
     68 
     69 	announce.Content = boostedStatus.Content
     70 	announce.ContentWarning = boostedStatus.ContentWarning
     71 	announce.ActivityStreamsType = boostedStatus.ActivityStreamsType
     72 	announce.Sensitive = boostedStatus.Sensitive
     73 	announce.Language = boostedStatus.Language
     74 	announce.Text = boostedStatus.Text
     75 	announce.BoostOfID = boostedStatus.ID
     76 	announce.BoostOfAccountID = boostedStatus.AccountID
     77 	announce.Visibility = boostedStatus.Visibility
     78 	announce.Federated = boostedStatus.Federated
     79 	announce.Boostable = boostedStatus.Boostable
     80 	announce.Replyable = boostedStatus.Replyable
     81 	announce.Likeable = boostedStatus.Likeable
     82 	announce.BoostOf = boostedStatus
     83 
     84 	return nil
     85 }