diff options
Diffstat (limited to 'internal/federation')
-rw-r--r-- | internal/federation/federating_db.go | 32 | ||||
-rw-r--r-- | internal/federation/federatingprotocol.go | 50 | ||||
-rw-r--r-- | internal/federation/federator.go | 4 | ||||
-rw-r--r-- | internal/federation/util.go | 3 |
4 files changed, 36 insertions, 53 deletions
diff --git a/internal/federation/federating_db.go b/internal/federation/federating_db.go index 4ea0412e7..f72c5e636 100644 --- a/internal/federation/federating_db.go +++ b/internal/federation/federating_db.go @@ -364,7 +364,7 @@ func (f *federatingDB) Get(c context.Context, id *url.URL) (value vocab.Type, er // // Under certain conditions and network activities, Create may be called // multiple times for the same ActivityStreams object. -func (f *federatingDB) Create(c context.Context, asType vocab.Type) error { +func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error { l := f.log.WithFields( logrus.Fields{ "func": "Create", @@ -373,6 +373,24 @@ func (f *federatingDB) Create(c context.Context, asType vocab.Type) error { ) l.Debugf("received CREATE asType %+v", asType) + targetAcctI := ctx.Value(util.APAccount) + if targetAcctI == nil { + l.Error("target account wasn't set on context") + } + targetAcct, ok := targetAcctI.(*gtsmodel.Account) + if !ok { + l.Error("target account was set on context but couldn't be parsed") + } + + fromFederatorChanI := ctx.Value(util.APFromFederatorChanKey) + if fromFederatorChanI == nil { + l.Error("from federator channel wasn't set on context") + } + fromFederatorChan, ok := fromFederatorChanI.(chan gtsmodel.FromFederator) + if !ok { + l.Error("from federator channel was set on context but couldn't be parsed") + } + switch gtsmodel.ActivityStreamsActivity(asType.GetTypeName()) { case gtsmodel.ActivityStreamsCreate: create, ok := asType.(vocab.ActivityStreamsCreate) @@ -391,6 +409,12 @@ func (f *federatingDB) Create(c context.Context, asType vocab.Type) error { if err := f.db.Put(status); err != nil { return fmt.Errorf("database error inserting status: %s", err) } + + fromFederatorChan <- gtsmodel.FromFederator{ + APObjectType: gtsmodel.ActivityStreamsNote, + APActivityType: gtsmodel.ActivityStreamsCreate, + GTSModel: status, + } } } case gtsmodel.ActivityStreamsFollow: @@ -407,6 +431,12 @@ func (f *federatingDB) Create(c context.Context, asType vocab.Type) error { if err := f.db.Put(followRequest); err != nil { return fmt.Errorf("database error inserting follow request: %s", err) } + + if !targetAcct.Locked { + if err := f.db.AcceptFollowRequest(followRequest.AccountID, followRequest.TargetAccountID); err != nil { + return fmt.Errorf("database error accepting follow request: %s", err) + } + } } return nil } diff --git a/internal/federation/federatingprotocol.go b/internal/federation/federatingprotocol.go index 0d2a8d9dd..d8f6eb839 100644 --- a/internal/federation/federatingprotocol.go +++ b/internal/federation/federatingprotocol.go @@ -71,49 +71,7 @@ func (f *federator) PostInboxRequestBodyHook(ctx context.Context, r *http.Reques l.Debug(err) return nil, err } - - // derefence the actor of the activity already - // var requestingActorIRI *url.URL - // actorProp := activity.GetActivityStreamsActor() - // if actorProp != nil { - // for i := actorProp.Begin(); i != actorProp.End(); i = i.Next() { - // if i.IsIRI() { - // requestingActorIRI = i.GetIRI() - // break - // } - // } - // } - // if requestingActorIRI != nil { - - // requestedAccountI := ctx.Value(util.APAccount) - // requestedAccount, ok := requestedAccountI.(*gtsmodel.Account) - // if !ok { - // return nil, errors.New("requested account was not set on request context") - // } - - // requestingActor := >smodel.Account{} - // if err := f.db.GetWhere("uri", requestingActorIRI.String(), requestingActor); err != nil { - // // there's been a proper error so return it - // if _, ok := err.(db.ErrNoEntries); !ok { - // return nil, fmt.Errorf("error getting requesting actor with id %s: %s", requestingActorIRI.String(), err) - // } - - // // we don't know this account (yet) so let's dereference it right now - // person, err := f.DereferenceRemoteAccount(requestedAccount.Username, publicKeyOwnerURI) - // if err != nil { - // return ctx, false, fmt.Errorf("error dereferencing account with public key id %s: %s", publicKeyOwnerURI.String(), err) - // } - - // a, err := f.typeConverter.ASRepresentationToAccount(person) - // if err != nil { - // return ctx, false, fmt.Errorf("error converting person with public key id %s to account: %s", publicKeyOwnerURI.String(), err) - // } - // requestingAccount = a - // } - // } - // set the activity on the context for use later on - return context.WithValue(ctx, util.APActivity, activity), nil } @@ -285,14 +243,6 @@ func (f *federator) FederatingCallbacks(ctx context.Context) (wrapped pub.Federa } wrapped = pub.FederatingWrappedCallbacks{ - // Follow handles additional side effects for the Follow ActivityStreams - // type, specific to the application using go-fed. - // - // The wrapping function can have one of several default behaviors, - // depending on the value of the OnFollow setting. - Follow: func(context.Context, vocab.ActivityStreamsFollow) error { - return nil - }, // OnFollow determines what action to take for this particular callback // if a Follow Activity is handled. OnFollow: onFollow, diff --git a/internal/federation/federator.go b/internal/federation/federator.go index 4fe0369b9..a3b1386e4 100644 --- a/internal/federation/federator.go +++ b/internal/federation/federator.go @@ -42,7 +42,9 @@ type Federator interface { DereferenceRemoteAccount(username string, remoteAccountID *url.URL) (typeutils.Accountable, error) // GetTransportForUser returns a new transport initialized with the key credentials belonging to the given username. // This can be used for making signed http requests. - GetTransportForUser(username string) (pub.Transport, error) + // + // If username is an empty string, our instance user's credentials will be used instead. + GetTransportForUser(username string) (transport.Transport, error) pub.CommonBehavior pub.FederatingProtocol } diff --git a/internal/federation/util.go b/internal/federation/util.go index d76ce853d..14ceaeb1d 100644 --- a/internal/federation/util.go +++ b/internal/federation/util.go @@ -33,6 +33,7 @@ import ( "github.com/go-fed/activity/streams/vocab" "github.com/go-fed/httpsig" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/transport" "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) @@ -221,7 +222,7 @@ func (f *federator) DereferenceRemoteAccount(username string, remoteAccountID *u return nil, fmt.Errorf("type name %s not supported", t.GetTypeName()) } -func (f *federator) GetTransportForUser(username string) (pub.Transport, error) { +func (f *federator) GetTransportForUser(username string) (transport.Transport, error) { // We need an account to use to create a transport for dereferecing the signature. // If a username has been given, we can fetch the account with that username and use it. // Otherwise, we can take the instance account and use those credentials to make the request. |