From e04b187702acb0c9908237a35b3a9857e2167b3f Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 4 Oct 2021 15:24:19 +0200 Subject: 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 --- internal/federation/federatingdb/undo.go | 34 +++++++++++++------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'internal/federation/federatingdb/undo.go') diff --git a/internal/federation/federatingdb/undo.go b/internal/federation/federatingdb/undo.go index 481c2d787..9fcb6ce1a 100644 --- a/internal/federation/federatingdb/undo.go +++ b/internal/federation/federatingdb/undo.go @@ -20,48 +20,42 @@ 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" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/util" ) func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo) error { l := f.log.WithFields( logrus.Fields{ - "func": "Undo", - "asType": undo.GetTypeName(), + "func": "Undo", }, ) - m, err := streams.Serialize(undo) - if err != nil { - return err + + if l.Level >= logrus.DebugLevel { + i, err := marshalItem(undo) + if err != nil { + return err + } + l = l.WithField("undo", i) + l.Debug("entering Undo") } - b, err := json.Marshal(m) + + targetAcct, fromFederatorChan, err := extractFromCtx(ctx) if err != nil { return err } - l.Debugf("received UNDO 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("UNDO: target account was set on context but couldn't be parsed") - return nil - } undoObject := undo.GetActivityStreamsObject() if undoObject == nil { -- cgit v1.2.3