summaryrefslogtreecommitdiff
path: root/internal/federation/federatingprotocol.go
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-08-10 13:32:39 +0200
committerLibravatar GitHub <noreply@github.com>2021-08-10 13:32:39 +0200
commit0f2de6394a1c52d47e326bb7d7d129a217ae4f6f (patch)
treee2709bdbbbbcf5e12d6da62b653b67f1789ab1c5 /internal/federation/federatingprotocol.go
parentFrodo swaggins (#126) (diff)
downloadgotosocial-0f2de6394a1c52d47e326bb7d7d129a217ae4f6f.tar.xz
Dereference remote replies (#132)
* decided where to put reply dereferencing * fiddling with dereferencing threads * further adventures * tidy up some stuff * move dereferencing functionality * a bunch of refactoring * go fmt * more refactoring * bleep bloop * docs and linting * start implementing replies collection on gts side * fiddling around * allow dereferencing our replies * lint, fmt
Diffstat (limited to 'internal/federation/federatingprotocol.go')
-rw-r--r--internal/federation/federatingprotocol.go51
1 files changed, 4 insertions, 47 deletions
diff --git a/internal/federation/federatingprotocol.go b/internal/federation/federatingprotocol.go
index 1acdb6cb1..9e21b43bf 100644
--- a/internal/federation/federatingprotocol.go
+++ b/internal/federation/federatingprotocol.go
@@ -31,7 +31,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
@@ -139,7 +138,7 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr
}
// we don't have an entry for this instance yet so dereference it
- i, err = f.DereferenceRemoteInstance(username, &url.URL{
+ i, err = f.GetRemoteInstance(username, &url.URL{
Scheme: publicKeyOwnerURI.Scheme,
Host: publicKeyOwnerURI.Host,
})
@@ -153,51 +152,9 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr
}
}
- requestingAccount := &gtsmodel.Account{}
- if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: publicKeyOwnerURI.String()}}, requestingAccount); err != nil {
- // there's been a proper error so return it
- if _, ok := err.(db.ErrNoEntries); !ok {
- return ctx, false, fmt.Errorf("error getting requesting account with public key id %s: %s", publicKeyOwnerURI.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, false)
- if err != nil {
- return ctx, false, fmt.Errorf("error converting person with public key id %s to account: %s", publicKeyOwnerURI.String(), err)
- }
-
- aID, err := id.NewRandomULID()
- if err != nil {
- return ctx, false, err
- }
- a.ID = aID
-
- if err := f.db.Put(a); err != nil {
- l.Errorf("error inserting dereferenced remote account: %s", err)
- }
-
- requestingAccount = a
-
- // send the newly dereferenced account into the processor channel for further async processing
- 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")
- }
-
- fromFederatorChan <- gtsmodel.FromFederator{
- APObjectType: gtsmodel.ActivityStreamsProfile,
- APActivityType: gtsmodel.ActivityStreamsCreate,
- GTSModel: requestingAccount,
- }
+ requestingAccount, _, err := f.GetRemoteAccount(username, publicKeyOwnerURI, false)
+ if err != nil {
+ return nil, false, fmt.Errorf("couldn't get remote account: %s", err)
}
withRequester := context.WithValue(ctx, util.APRequestingAccount, requestingAccount)