diff options
Diffstat (limited to 'internal/federation/federatingdb')
| -rw-r--r-- | internal/federation/federatingdb/accept.go | 4 | ||||
| -rw-r--r-- | internal/federation/federatingdb/federatingdb_test.go | 8 | ||||
| -rw-r--r-- | internal/federation/federatingdb/get.go | 10 | ||||
| -rw-r--r-- | internal/federation/federatingdb/owns.go | 26 | ||||
| -rw-r--r-- | internal/federation/federatingdb/reject.go | 4 | ||||
| -rw-r--r-- | internal/federation/federatingdb/reject_test.go | 4 | ||||
| -rw-r--r-- | internal/federation/federatingdb/update.go | 3 | ||||
| -rw-r--r-- | internal/federation/federatingdb/util.go | 26 | 
8 files changed, 42 insertions, 43 deletions
diff --git a/internal/federation/federatingdb/accept.go b/internal/federation/federatingdb/accept.go index 8efb29b53..34cdc4fb5 100644 --- a/internal/federation/federatingdb/accept.go +++ b/internal/federation/federatingdb/accept.go @@ -29,7 +29,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/db"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"  	"github.com/superseriousbusiness/gotosocial/internal/messages" -	"github.com/superseriousbusiness/gotosocial/internal/util" +	"github.com/superseriousbusiness/gotosocial/internal/uris"  )  func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsAccept) error { @@ -66,7 +66,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA  		if iter.IsIRI() {  			// we have just the URI of whatever is being accepted, so we need to find out what it is  			acceptedObjectIRI := iter.GetIRI() -			if util.IsFollowPath(acceptedObjectIRI) { +			if uris.IsFollowPath(acceptedObjectIRI) {  				// ACCEPT FOLLOW  				gtsFollowRequest := >smodel.FollowRequest{}  				if err := f.db.GetWhere(ctx, []db.Where{{Key: "uri", Value: acceptedObjectIRI.String()}}, gtsFollowRequest); err != nil { diff --git a/internal/federation/federatingdb/federatingdb_test.go b/internal/federation/federatingdb/federatingdb_test.go index d51e0a825..71cc739c4 100644 --- a/internal/federation/federatingdb/federatingdb_test.go +++ b/internal/federation/federatingdb/federatingdb_test.go @@ -22,12 +22,12 @@ import (  	"context"  	"github.com/stretchr/testify/suite" +	"github.com/superseriousbusiness/gotosocial/internal/ap"  	"github.com/superseriousbusiness/gotosocial/internal/db"  	"github.com/superseriousbusiness/gotosocial/internal/federation/federatingdb"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"  	"github.com/superseriousbusiness/gotosocial/internal/messages"  	"github.com/superseriousbusiness/gotosocial/internal/typeutils" -	"github.com/superseriousbusiness/gotosocial/internal/util"  	"github.com/superseriousbusiness/gotosocial/testrig"  ) @@ -75,8 +75,8 @@ func (suite *FederatingDBTestSuite) TearDownTest() {  func createTestContext(receivingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account, fromFederatorChan chan messages.FromFederator) context.Context {  	ctx := context.Background() -	ctx = context.WithValue(ctx, util.APReceivingAccount, receivingAccount) -	ctx = context.WithValue(ctx, util.APRequestingAccount, requestingAccount) -	ctx = context.WithValue(ctx, util.APFromFederatorChanKey, fromFederatorChan) +	ctx = context.WithValue(ctx, ap.ContextReceivingAccount, receivingAccount) +	ctx = context.WithValue(ctx, ap.ContextRequestingAccount, requestingAccount) +	ctx = context.WithValue(ctx, ap.ContextFromFederatorChan, fromFederatorChan)  	return ctx  } diff --git a/internal/federation/federatingdb/get.go b/internal/federation/federatingdb/get.go index a409b7b91..ac3920c78 100644 --- a/internal/federation/federatingdb/get.go +++ b/internal/federation/federatingdb/get.go @@ -25,7 +25,7 @@ import (  	"github.com/sirupsen/logrus"  	"github.com/superseriousbusiness/activity/streams/vocab" -	"github.com/superseriousbusiness/gotosocial/internal/util" +	"github.com/superseriousbusiness/gotosocial/internal/uris"  )  // Get returns the database entry for the specified id. @@ -40,7 +40,7 @@ func (f *federatingDB) Get(ctx context.Context, id *url.URL) (value vocab.Type,  	)  	l.Debug("entering Get") -	if util.IsUserPath(id) { +	if uris.IsUserPath(id) {  		acct, err := f.db.GetAccountByURI(ctx, id.String())  		if err != nil {  			return nil, err @@ -48,7 +48,7 @@ func (f *federatingDB) Get(ctx context.Context, id *url.URL) (value vocab.Type,  		return f.typeConverter.AccountToAS(ctx, acct)  	} -	if util.IsStatusesPath(id) { +	if uris.IsStatusesPath(id) {  		status, err := f.db.GetStatusByURI(ctx, id.String())  		if err != nil {  			return nil, err @@ -56,11 +56,11 @@ func (f *federatingDB) Get(ctx context.Context, id *url.URL) (value vocab.Type,  		return f.typeConverter.StatusToAS(ctx, status)  	} -	if util.IsFollowersPath(id) { +	if uris.IsFollowersPath(id) {  		return f.Followers(ctx, id)  	} -	if util.IsFollowingPath(id) { +	if uris.IsFollowingPath(id) {  		return f.Following(ctx, id)  	} diff --git a/internal/federation/federatingdb/owns.go b/internal/federation/federatingdb/owns.go index 2603c9aa2..15e3dea0a 100644 --- a/internal/federation/federatingdb/owns.go +++ b/internal/federation/federatingdb/owns.go @@ -28,7 +28,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/config"  	"github.com/superseriousbusiness/gotosocial/internal/db"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" -	"github.com/superseriousbusiness/gotosocial/internal/util" +	"github.com/superseriousbusiness/gotosocial/internal/uris"  )  // Owns returns true if the IRI belongs to this instance, and if @@ -52,8 +52,8 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {  	// apparently it belongs to this host, so what *is* it?  	// check if it's a status, eg /users/example_username/statuses/SOME_UUID_OF_A_STATUS -	if util.IsStatusesPath(id) { -		_, uid, err := util.ParseStatusesPath(id) +	if uris.IsStatusesPath(id) { +		_, uid, err := uris.ParseStatusesPath(id)  		if err != nil {  			return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)  		} @@ -69,8 +69,8 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {  		return status.Local, nil  	} -	if util.IsUserPath(id) { -		username, err := util.ParseUserPath(id) +	if uris.IsUserPath(id) { +		username, err := uris.ParseUserPath(id)  		if err != nil {  			return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)  		} @@ -86,8 +86,8 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {  		return true, nil  	} -	if util.IsFollowersPath(id) { -		username, err := util.ParseFollowersPath(id) +	if uris.IsFollowersPath(id) { +		username, err := uris.ParseFollowersPath(id)  		if err != nil {  			return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)  		} @@ -103,8 +103,8 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {  		return true, nil  	} -	if util.IsFollowingPath(id) { -		username, err := util.ParseFollowingPath(id) +	if uris.IsFollowingPath(id) { +		username, err := uris.ParseFollowingPath(id)  		if err != nil {  			return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)  		} @@ -120,8 +120,8 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {  		return true, nil  	} -	if util.IsLikePath(id) { -		username, likeID, err := util.ParseLikedPath(id) +	if uris.IsLikePath(id) { +		username, likeID, err := uris.ParseLikedPath(id)  		if err != nil {  			return false, fmt.Errorf("error parsing like path for url %s: %s", id.String(), err)  		} @@ -145,8 +145,8 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {  		return true, nil  	} -	if util.IsBlockPath(id) { -		username, blockID, err := util.ParseBlockPath(id) +	if uris.IsBlockPath(id) { +		username, blockID, err := uris.ParseBlockPath(id)  		if err != nil {  			return false, fmt.Errorf("error parsing block path for url %s: %s", id.String(), err)  		} diff --git a/internal/federation/federatingdb/reject.go b/internal/federation/federatingdb/reject.go index 15d4a87ae..2ecdc829e 100644 --- a/internal/federation/federatingdb/reject.go +++ b/internal/federation/federatingdb/reject.go @@ -28,7 +28,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/ap"  	"github.com/superseriousbusiness/gotosocial/internal/db"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" -	"github.com/superseriousbusiness/gotosocial/internal/util" +	"github.com/superseriousbusiness/gotosocial/internal/uris"  )  func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsReject) error { @@ -65,7 +65,7 @@ func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsR  		if iter.IsIRI() {  			// we have just the URI of whatever is being rejected, so we need to find out what it is  			rejectedObjectIRI := iter.GetIRI() -			if util.IsFollowPath(rejectedObjectIRI) { +			if uris.IsFollowPath(rejectedObjectIRI) {  				// REJECT FOLLOW  				gtsFollowRequest := >smodel.FollowRequest{}  				if err := f.db.GetWhere(ctx, []db.Where{{Key: "uri", Value: rejectedObjectIRI.String()}}, gtsFollowRequest); err != nil { diff --git a/internal/federation/federatingdb/reject_test.go b/internal/federation/federatingdb/reject_test.go index 9930d83d2..700330c1f 100644 --- a/internal/federation/federatingdb/reject_test.go +++ b/internal/federation/federatingdb/reject_test.go @@ -27,7 +27,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/db"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"  	"github.com/superseriousbusiness/gotosocial/internal/messages" -	"github.com/superseriousbusiness/gotosocial/internal/util" +	"github.com/superseriousbusiness/gotosocial/internal/uris"  	"github.com/superseriousbusiness/gotosocial/testrig"  ) @@ -48,7 +48,7 @@ func (suite *RejectTestSuite) TestRejectFollowRequest() {  		ID:              "01FJ1S8DX3STJJ6CEYPMZ1M0R3",  		CreatedAt:       time.Now(),  		UpdatedAt:       time.Now(), -		URI:             util.GenerateURIForFollow(followingAccount.Username, "01FJ1S8DX3STJJ6CEYPMZ1M0R3"), +		URI:             uris.GenerateURIForFollow(followingAccount.Username, "01FJ1S8DX3STJJ6CEYPMZ1M0R3"),  		AccountID:       followingAccount.ID,  		TargetAccountID: followedAccount.ID,  	} diff --git a/internal/federation/federatingdb/update.go b/internal/federation/federatingdb/update.go index 1d56b931f..e95e128cd 100644 --- a/internal/federation/federatingdb/update.go +++ b/internal/federation/federatingdb/update.go @@ -30,7 +30,6 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/config"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"  	"github.com/superseriousbusiness/gotosocial/internal/messages" -	"github.com/superseriousbusiness/gotosocial/internal/util"  )  // Update sets an existing entry to the database based on the value's @@ -66,7 +65,7 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error {  		return nil  	} -	requestingAcctI := ctx.Value(util.APRequestingAccount) +	requestingAcctI := ctx.Value(ap.ContextRequestingAccount)  	if requestingAcctI == nil {  		l.Error("UPDATE: requesting account wasn't set on context")  	} diff --git a/internal/federation/federatingdb/util.go b/internal/federation/federatingdb/util.go index afa09e39d..56512e0af 100644 --- a/internal/federation/federatingdb/util.go +++ b/internal/federation/federatingdb/util.go @@ -35,7 +35,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"  	"github.com/superseriousbusiness/gotosocial/internal/id"  	"github.com/superseriousbusiness/gotosocial/internal/messages" -	"github.com/superseriousbusiness/gotosocial/internal/util" +	"github.com/superseriousbusiness/gotosocial/internal/uris"  )  func sameActor(activityActor vocab.ActivityStreamsActorProperty, followActor vocab.ActivityStreamsActorProperty) bool { @@ -106,7 +106,7 @@ func (f *federatingDB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL,  						if err != nil {  							return nil, err  						} -						return url.Parse(util.GenerateURIForFollow(actorAccount.Username, newID)) +						return url.Parse(uris.GenerateURIForFollow(actorAccount.Username, newID))  					}  				}  			} @@ -241,7 +241,7 @@ func (f *federatingDB) ActorForInbox(ctx context.Context, inboxIRI *url.URL) (ac  func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (account *gtsmodel.Account, err error) {  	acct := >smodel.Account{} -	if util.IsInboxPath(iri) { +	if uris.IsInboxPath(iri) {  		if err := f.db.GetWhere(ctx, []db.Where{{Key: "inbox_uri", Value: iri.String()}}, acct); err != nil {  			if err == db.ErrNoEntries {  				return nil, fmt.Errorf("no actor found that corresponds to inbox %s", iri.String()) @@ -251,7 +251,7 @@ func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (acco  		return acct, nil  	} -	if util.IsOutboxPath(iri) { +	if uris.IsOutboxPath(iri) {  		if err := f.db.GetWhere(ctx, []db.Where{{Key: "outbox_uri", Value: iri.String()}}, acct); err != nil {  			if err == db.ErrNoEntries {  				return nil, fmt.Errorf("no actor found that corresponds to outbox %s", iri.String()) @@ -261,7 +261,7 @@ func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (acco  		return acct, nil  	} -	if util.IsUserPath(iri) { +	if uris.IsUserPath(iri) {  		if err := f.db.GetWhere(ctx, []db.Where{{Key: "uri", Value: iri.String()}}, acct); err != nil {  			if err == db.ErrNoEntries {  				return nil, fmt.Errorf("no actor found that corresponds to uri %s", iri.String()) @@ -271,7 +271,7 @@ func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (acco  		return acct, nil  	} -	if util.IsFollowersPath(iri) { +	if uris.IsFollowersPath(iri) {  		if err := f.db.GetWhere(ctx, []db.Where{{Key: "followers_uri", Value: iri.String()}}, acct); err != nil {  			if err == db.ErrNoEntries {  				return nil, fmt.Errorf("no actor found that corresponds to followers_uri %s", iri.String()) @@ -281,7 +281,7 @@ func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (acco  		return acct, nil  	} -	if util.IsFollowingPath(iri) { +	if uris.IsFollowingPath(iri) {  		if err := f.db.GetWhere(ctx, []db.Where{{Key: "following_uri", Value: iri.String()}}, acct); err != nil {  			if err == db.ErrNoEntries {  				return nil, fmt.Errorf("no actor found that corresponds to following_uri %s", iri.String()) @@ -311,30 +311,30 @@ func (f *federatingDB) collectIRIs(ctx context.Context, iris []*url.URL) (vocab.  //   - A channel that messages for the processor can be placed into.  // If a value is not present, nil will be returned for it. It's up to the caller to check this and respond appropriately.  func extractFromCtx(ctx context.Context) (receivingAccount, requestingAccount *gtsmodel.Account, fromFederatorChan chan messages.FromFederator) { -	receivingAccountI := ctx.Value(util.APReceivingAccount) +	receivingAccountI := ctx.Value(ap.ContextReceivingAccount)  	if receivingAccountI != nil {  		var ok bool  		receivingAccount, ok = receivingAccountI.(*gtsmodel.Account)  		if !ok { -			logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to *gtsmodel.Account", util.APReceivingAccount) +			logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to *gtsmodel.Account", ap.ContextReceivingAccount)  		}  	} -	requestingAcctI := ctx.Value(util.APRequestingAccount) +	requestingAcctI := ctx.Value(ap.ContextRequestingAccount)  	if requestingAcctI != nil {  		var ok bool  		requestingAccount, ok = requestingAcctI.(*gtsmodel.Account)  		if !ok { -			logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to *gtsmodel.Account", util.APRequestingAccount) +			logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to *gtsmodel.Account", ap.ContextRequestingAccount)  		}  	} -	fromFederatorChanI := ctx.Value(util.APFromFederatorChanKey) +	fromFederatorChanI := ctx.Value(ap.ContextFromFederatorChan)  	if fromFederatorChanI != nil {  		var ok bool  		fromFederatorChan, ok = fromFederatorChanI.(chan messages.FromFederator)  		if !ok { -			logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to chan messages.FromFederator", util.APFromFederatorChanKey) +			logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to chan messages.FromFederator", ap.ContextFromFederatorChan)  		}  	}  | 
