summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb
diff options
context:
space:
mode:
Diffstat (limited to 'internal/federation/federatingdb')
-rw-r--r--internal/federation/federatingdb/followers.go14
-rw-r--r--internal/federation/federatingdb/following.go13
-rw-r--r--internal/federation/federatingdb/lock.go7
3 files changed, 30 insertions, 4 deletions
diff --git a/internal/federation/federatingdb/followers.go b/internal/federation/federatingdb/followers.go
index 28f3bb6d1..7cba101dd 100644
--- a/internal/federation/federatingdb/followers.go
+++ b/internal/federation/federatingdb/followers.go
@@ -10,6 +10,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
// Followers obtains the Followers Collection for an actor with the
@@ -28,8 +29,17 @@ func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (follower
l.Debugf("entering FOLLOWERS function with actorIRI %s", actorIRI.String())
acct := &gtsmodel.Account{}
- if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: actorIRI.String()}}, acct); err != nil {
- return nil, fmt.Errorf("db error getting account with uri %s: %s", actorIRI.String(), err)
+
+ if util.IsUserPath(actorIRI) {
+ if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: actorIRI.String()}}, acct); err != nil {
+ return nil, fmt.Errorf("db error getting account with uri %s: %s", actorIRI.String(), err)
+ }
+ } else if util.IsFollowersPath(actorIRI) {
+ if err := f.db.GetWhere([]db.Where{{Key: "followers_uri", Value: actorIRI.String()}}, acct); err != nil {
+ return nil, fmt.Errorf("db error getting account with followers uri %s: %s", actorIRI.String(), err)
+ }
+ } else {
+ return nil, fmt.Errorf("could not parse actor IRI %s as users or followers path", actorIRI.String())
}
acctFollowers := []gtsmodel.Follow{}
diff --git a/internal/federation/federatingdb/following.go b/internal/federation/federatingdb/following.go
index 342250880..f34f252a5 100644
--- a/internal/federation/federatingdb/following.go
+++ b/internal/federation/federatingdb/following.go
@@ -10,6 +10,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
// Following obtains the Following Collection for an actor with the
@@ -28,8 +29,16 @@ func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (followin
l.Debugf("entering FOLLOWING function with actorIRI %s", actorIRI.String())
acct := &gtsmodel.Account{}
- if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: actorIRI.String()}}, acct); err != nil {
- return nil, fmt.Errorf("db error getting account with uri %s: %s", actorIRI.String(), err)
+ if util.IsUserPath(actorIRI) {
+ if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: actorIRI.String()}}, acct); err != nil {
+ return nil, fmt.Errorf("db error getting account with uri %s: %s", actorIRI.String(), err)
+ }
+ } else if util.IsFollowingPath(actorIRI) {
+ if err := f.db.GetWhere([]db.Where{{Key: "following_uri", Value: actorIRI.String()}}, acct); err != nil {
+ return nil, fmt.Errorf("db error getting account with following uri %s: %s", actorIRI.String(), err)
+ }
+ } else {
+ return nil, fmt.Errorf("could not parse actor IRI %s as users or following path", actorIRI.String())
}
acctFollowing := []gtsmodel.Follow{}
diff --git a/internal/federation/federatingdb/lock.go b/internal/federation/federatingdb/lock.go
index 417fd79b2..c9062da89 100644
--- a/internal/federation/federatingdb/lock.go
+++ b/internal/federation/federatingdb/lock.go
@@ -42,6 +42,10 @@ func (f *federatingDB) Lock(c context.Context, id *url.URL) error {
// Strategy: create a new lock, if stored, continue. Otherwise, lock the
// existing mutex.
+ if id == nil {
+ return errors.New("Lock: id was nil")
+ }
+
mu := &sync.Mutex{}
mu.Lock() // Optimistically lock if we do store it.
i, loaded := f.locks.LoadOrStore(id.String(), mu)
@@ -59,6 +63,9 @@ func (f *federatingDB) Lock(c context.Context, id *url.URL) error {
func (f *federatingDB) Unlock(c context.Context, id *url.URL) error {
// Once Go-Fed is done calling Database methods, the relevant `id`
// entries are unlocked.
+ if id == nil {
+ return errors.New("Unlock: id was nil")
+ }
i, ok := f.locks.Load(id.String())
if !ok {