gtsocial-umbx

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

announce.go (2129B)


      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 federatingdb
     19 
     20 import (
     21 	"context"
     22 
     23 	"codeberg.org/gruf/go-logger/v2/level"
     24 	"github.com/superseriousbusiness/activity/streams/vocab"
     25 	"github.com/superseriousbusiness/gotosocial/internal/ap"
     26 	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
     27 	"github.com/superseriousbusiness/gotosocial/internal/log"
     28 	"github.com/superseriousbusiness/gotosocial/internal/messages"
     29 )
     30 
     31 func (f *federatingDB) Announce(ctx context.Context, announce vocab.ActivityStreamsAnnounce) error {
     32 	if log.Level() >= level.DEBUG {
     33 		i, err := marshalItem(announce)
     34 		if err != nil {
     35 			return err
     36 		}
     37 		l := log.WithContext(ctx).
     38 			WithField("announce", i)
     39 		l.Debug("entering Announce")
     40 	}
     41 
     42 	receivingAccount, _, internal := extractFromCtx(ctx)
     43 	if internal {
     44 		return nil // Already processed.
     45 	}
     46 
     47 	boost, isNew, err := f.typeConverter.ASAnnounceToStatus(ctx, announce)
     48 	if err != nil {
     49 		return gtserror.Newf("error converting announce to boost: %w", err)
     50 	}
     51 
     52 	if !isNew {
     53 		// We've already seen this boost;
     54 		// nothing else to do here.
     55 		return nil
     56 	}
     57 
     58 	// This is a new boost. Process side effects asynchronously.
     59 	f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
     60 		APObjectType:     ap.ActivityAnnounce,
     61 		APActivityType:   ap.ActivityCreate,
     62 		GTSModel:         boost,
     63 		ReceivingAccount: receivingAccount,
     64 	})
     65 
     66 	return nil
     67 }