summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb/accept.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-10-04 15:24:19 +0200
committerLibravatar GitHub <noreply@github.com>2021-10-04 15:24:19 +0200
commite04b187702acb0c9908237a35b3a9857e2167b3f (patch)
tree29839b8d5bbc28d34aba759a48dd7b005f1444f5 /internal/federation/federatingdb/accept.go
parentFollow request auto approval (#259) (diff)
downloadgotosocial-e04b187702acb0c9908237a35b3a9857e2167b3f.tar.xz
Refactor/tidy (#261)
* tidy up streaming * cut down code duplication * test get followers/following * test streaming processor * fix some test models * add TimeMustParse * fix uri / url typo * make trace logging less verbose * make logging more consistent * disable quote on logging * remove context.Background * remove many extraneous mastodon references * regenerate swagger * don't log query on no rows result * log latency first for easier reading
Diffstat (limited to 'internal/federation/federatingdb/accept.go')
-rw-r--r--internal/federation/federatingdb/accept.go44
1 files changed, 14 insertions, 30 deletions
diff --git a/internal/federation/federatingdb/accept.go b/internal/federation/federatingdb/accept.go
index 477c5e8b9..3bd84849d 100644
--- a/internal/federation/federatingdb/accept.go
+++ b/internal/federation/federatingdb/accept.go
@@ -20,11 +20,9 @@ package federatingdb
import (
"context"
- "encoding/json"
"errors"
"fmt"
- "github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/ap"
@@ -37,43 +35,29 @@ import (
func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsAccept) error {
l := f.log.WithFields(
logrus.Fields{
- "func": "Accept",
- "asType": accept.GetTypeName(),
+ "func": "Accept",
},
)
- m, err := streams.Serialize(accept)
- if err != nil {
- return err
+
+ if l.Level >= logrus.DebugLevel {
+ i, err := marshalItem(accept)
+ if err != nil {
+ return err
+ }
+ l = l.WithField("accept", i)
+ l.Debug("entering Accept")
}
- b, err := json.Marshal(m)
+
+ targetAcct, fromFederatorChan, err := extractFromCtx(ctx)
if err != nil {
return err
}
- l.Debugf("received ACCEPT asType %s", string(b))
-
- targetAcctI := ctx.Value(util.APAccount)
- if targetAcctI == nil {
- // If the target account wasn't set on the context, that means this request didn't pass through the
- // API, but came from inside GtS as the result of another activity on this instance. That being so,
+ if targetAcct == nil || fromFederatorChan == nil {
+ // If the target account or federator channel wasn't set on the context, that means this request didn't pass
+ // through the API, but came from inside GtS as the result of another activity on this instance. That being so,
// we can safely just ignore this activity, since we know we've already processed it elsewhere.
return nil
}
- targetAcct, ok := targetAcctI.(*gtsmodel.Account)
- if !ok {
- l.Error("ACCEPT: target account was set on context but couldn't be parsed")
- return nil
- }
-
- fromFederatorChanI := ctx.Value(util.APFromFederatorChanKey)
- if fromFederatorChanI == nil {
- l.Error("ACCEPT: from federator channel wasn't set on context")
- return nil
- }
- fromFederatorChan, ok := fromFederatorChanI.(chan messages.FromFederator)
- if !ok {
- l.Error("ACCEPT: from federator channel was set on context but couldn't be parsed")
- return nil
- }
acceptObject := accept.GetActivityStreamsObject()
if acceptObject == nil {