summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb/owns.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/federation/federatingdb/owns.go')
-rw-r--r--internal/federation/federatingdb/owns.go66
1 files changed, 44 insertions, 22 deletions
diff --git a/internal/federation/federatingdb/owns.go b/internal/federation/federatingdb/owns.go
index 62cb7a3ea..cc3bb7d5d 100644
--- a/internal/federation/federatingdb/owns.go
+++ b/internal/federation/federatingdb/owns.go
@@ -19,12 +19,14 @@ package federatingdb
import (
"context"
+ "errors"
"fmt"
"net/url"
"codeberg.org/gruf/go-kv"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/gtscontext"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/uris"
@@ -46,6 +48,11 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {
return false, nil
}
+ // todo: refactor the below; make sure we use
+ // proper db functions for everything, and
+ // preferably clean up by calling subfuncs
+ // (like we now do for ownsLike).
+
// 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 uris.IsStatusesPath(id) {
@@ -117,28 +124,7 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {
}
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)
- }
- if _, err := f.state.DB.GetAccountByUsernameDomain(ctx, username, ""); err != nil {
- if err == db.ErrNoEntries {
- // there are no entries for this username
- return false, nil
- }
- // an actual error happened
- return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
- }
- if err := f.state.DB.GetByID(ctx, likeID, &gtsmodel.StatusFave{}); err != nil {
- if err == db.ErrNoEntries {
- // there are no entries
- return false, nil
- }
- // an actual error happened
- return false, fmt.Errorf("database error fetching like with id %s: %s", likeID, err)
- }
- l.Debugf("we own url %s", id.String())
- return true, nil
+ return f.ownsLike(ctx, id)
}
if uris.IsBlockPath(id) {
@@ -168,3 +154,39 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {
return false, fmt.Errorf("could not match activityID: %s", id.String())
}
+
+func (f *federatingDB) ownsLike(ctx context.Context, uri *url.URL) (bool, error) {
+ username, id, err := uris.ParseLikedPath(uri)
+ if err != nil {
+ return false, fmt.Errorf("error parsing Like path for url %s: %w", uri.String(), err)
+ }
+
+ // We're only checking for existence,
+ // so use barebones context.
+ bbCtx := gtscontext.SetBarebones(ctx)
+
+ if _, err := f.state.DB.GetAccountByUsernameDomain(bbCtx, username, ""); err != nil {
+ if errors.Is(err, db.ErrNoEntries) {
+ // No entries for this acct,
+ // we don't own this item.
+ return false, nil
+ }
+
+ // Actual error.
+ return false, fmt.Errorf("database error fetching account with username %s: %w", username, err)
+ }
+
+ if _, err := f.state.DB.GetStatusFaveByID(bbCtx, id); err != nil {
+ if errors.Is(err, db.ErrNoEntries) {
+ // No entries for this ID,
+ // we don't own this item.
+ return false, nil
+ }
+
+ // Actual error.
+ return false, fmt.Errorf("database error fetching status fave with id %s: %w", id, err)
+ }
+
+ log.Tracef(ctx, "we own Like %s", uri.String())
+ return true, nil
+}