summaryrefslogtreecommitdiff
path: root/internal/federation/dereferencing
diff options
context:
space:
mode:
Diffstat (limited to 'internal/federation/dereferencing')
-rw-r--r--internal/federation/dereferencing/account.go30
-rw-r--r--internal/federation/dereferencing/error.go14
-rw-r--r--internal/federation/dereferencing/status.go75
3 files changed, 4 insertions, 115 deletions
diff --git a/internal/federation/dereferencing/account.go b/internal/federation/dereferencing/account.go
index 0ce35b0e4..4795db733 100644
--- a/internal/federation/dereferencing/account.go
+++ b/internal/federation/dereferencing/account.go
@@ -357,39 +357,13 @@ func (d *deref) enrichAccount(ctx context.Context, requestUser string, uri *url.
// dereferenceAccountable calls remoteAccountID with a GET request, and tries to parse whatever
// it finds as something that an account model can be constructed out of.
-//
-// Will work for Person, Application, or Service models.
func (d *deref) dereferenceAccountable(ctx context.Context, transport transport.Transport, remoteAccountID *url.URL) (ap.Accountable, error) {
b, err := transport.Dereference(ctx, remoteAccountID)
if err != nil {
- return nil, fmt.Errorf("DereferenceAccountable: error deferencing %s: %w", remoteAccountID.String(), err)
- }
-
- m := make(map[string]interface{})
- if err := json.Unmarshal(b, &m); err != nil {
- return nil, fmt.Errorf("DereferenceAccountable: error unmarshalling bytes into json: %w", err)
- }
-
- t, err := streams.ToType(ctx, m)
- if err != nil {
- return nil, fmt.Errorf("DereferenceAccountable: error resolving json into ap vocab type: %w", err)
- }
-
- //nolint:forcetypeassert
- switch t.GetTypeName() {
- case ap.ActorApplication:
- return t.(vocab.ActivityStreamsApplication), nil
- case ap.ActorGroup:
- return t.(vocab.ActivityStreamsGroup), nil
- case ap.ActorOrganization:
- return t.(vocab.ActivityStreamsOrganization), nil
- case ap.ActorPerson:
- return t.(vocab.ActivityStreamsPerson), nil
- case ap.ActorService:
- return t.(vocab.ActivityStreamsService), nil
+ return nil, fmt.Errorf("dereferenceAccountable: error deferencing %s: %w", remoteAccountID.String(), err)
}
- return nil, newErrWrongType(fmt.Errorf("DereferenceAccountable: type name %s not supported as Accountable", t.GetTypeName()))
+ return ap.ResolveAccountable(ctx, b)
}
func (d *deref) fetchRemoteAccountAvatar(ctx context.Context, tsport transport.Transport, avatarURL string, accountID string) (string, error) {
diff --git a/internal/federation/dereferencing/error.go b/internal/federation/dereferencing/error.go
index f2fae63ac..769150cef 100644
--- a/internal/federation/dereferencing/error.go
+++ b/internal/federation/dereferencing/error.go
@@ -66,20 +66,6 @@ func newErrTransportError(err error) error {
return &ErrTransportError{wrapped: err}
}
-// ErrWrongType indicates that an unexpected type was returned from a remote call;
-// for example, we were served a Person when we were looking for a statusable.
-type ErrWrongType struct {
- wrapped error
-}
-
-func (err *ErrWrongType) Error() string {
- return fmt.Sprintf("wrong received type: %v", err.wrapped)
-}
-
-func newErrWrongType(err error) error {
- return &ErrWrongType{wrapped: err}
-}
-
// ErrOther denotes some other kind of weird error, perhaps from a malformed json
// or some other weird crapola.
type ErrOther struct {
diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go
index 8e202d585..fe07be23a 100644
--- a/internal/federation/dereferencing/status.go
+++ b/internal/federation/dereferencing/status.go
@@ -19,14 +19,11 @@ package dereferencing
import (
"context"
- "encoding/json"
"errors"
"fmt"
"net/url"
"strings"
- "github.com/superseriousbusiness/activity/streams"
- "github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@@ -161,78 +158,10 @@ func (d *deref) dereferenceStatusable(ctx context.Context, tsport transport.Tran
b, err := tsport.Dereference(ctx, remoteStatusID)
if err != nil {
- return nil, fmt.Errorf("DereferenceStatusable: error deferencing %s: %s", remoteStatusID.String(), err)
+ return nil, fmt.Errorf("dereferenceStatusable: error deferencing %s: %w", remoteStatusID.String(), err)
}
- m := make(map[string]interface{})
- if err := json.Unmarshal(b, &m); err != nil {
- return nil, fmt.Errorf("DereferenceStatusable: error unmarshalling bytes into json: %s", err)
- }
-
- t, err := streams.ToType(ctx, m)
- if err != nil {
- return nil, fmt.Errorf("DereferenceStatusable: error resolving json into ap vocab type: %s", err)
- }
-
- // Article, Document, Image, Video, Note, Page, Event, Place, Mention, Profile
- switch t.GetTypeName() {
- case ap.ObjectArticle:
- p, ok := t.(vocab.ActivityStreamsArticle)
- if !ok {
- return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsArticle")
- }
- return p, nil
- case ap.ObjectDocument:
- p, ok := t.(vocab.ActivityStreamsDocument)
- if !ok {
- return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsDocument")
- }
- return p, nil
- case ap.ObjectImage:
- p, ok := t.(vocab.ActivityStreamsImage)
- if !ok {
- return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsImage")
- }
- return p, nil
- case ap.ObjectVideo:
- p, ok := t.(vocab.ActivityStreamsVideo)
- if !ok {
- return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsVideo")
- }
- return p, nil
- case ap.ObjectNote:
- p, ok := t.(vocab.ActivityStreamsNote)
- if !ok {
- return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsNote")
- }
- return p, nil
- case ap.ObjectPage:
- p, ok := t.(vocab.ActivityStreamsPage)
- if !ok {
- return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsPage")
- }
- return p, nil
- case ap.ObjectEvent:
- p, ok := t.(vocab.ActivityStreamsEvent)
- if !ok {
- return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsEvent")
- }
- return p, nil
- case ap.ObjectPlace:
- p, ok := t.(vocab.ActivityStreamsPlace)
- if !ok {
- return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsPlace")
- }
- return p, nil
- case ap.ObjectProfile:
- p, ok := t.(vocab.ActivityStreamsProfile)
- if !ok {
- return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsProfile")
- }
- return p, nil
- }
-
- return nil, newErrWrongType(fmt.Errorf("DereferenceStatusable: type name %s not supported as Statusable", t.GetTypeName()))
+ return ap.ResolveStatusable(ctx, b)
}
// populateStatusFields fetches all the information we temporarily pinned to an incoming