summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb/util.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-01-27 14:48:11 +0100
committerLibravatar GitHub <noreply@github.com>2023-01-27 14:48:11 +0100
commit3283900b0d0b98e5ca956f61ce09ab373cf0cbe8 (patch)
treef7dc654ea2d510e0c02d63d8a174908f1e25c680 /internal/federation/federatingdb/util.go
parent[docs] Add Flag documentation to federation docs (#1393) (diff)
downloadgotosocial-3283900b0d0b98e5ca956f61ce09ab373cf0cbe8.tar.xz
[feature] Federate reports to remote instance as Flag (if desired) (#1386)
* reports federate out, we did it lxds * fix optional line start (should be optional slash)
Diffstat (limited to 'internal/federation/federatingdb/util.go')
-rw-r--r--internal/federation/federatingdb/util.go52
1 files changed, 24 insertions, 28 deletions
diff --git a/internal/federation/federatingdb/util.go b/internal/federation/federatingdb/util.go
index a1efad3f0..b5a9feab1 100644
--- a/internal/federation/federatingdb/util.go
+++ b/internal/federation/federatingdb/util.go
@@ -229,60 +229,56 @@ func (f *federatingDB) ActorForInbox(ctx context.Context, inboxIRI *url.URL) (ac
}
// getAccountForIRI returns the account that corresponds to or owns the given IRI.
-func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (account *gtsmodel.Account, err error) {
- acct := &gtsmodel.Account{}
+func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (*gtsmodel.Account, error) {
+ var (
+ acct = &gtsmodel.Account{}
+ err error
+ )
- if uris.IsInboxPath(iri) {
- if err := f.db.GetWhere(ctx, []db.Where{{Key: "inbox_uri", Value: iri.String()}}, acct); err != nil {
+ switch {
+ case uris.IsUserPath(iri):
+ if acct, err = f.db.GetAccountByURI(ctx, iri.String()); err != nil {
if err == db.ErrNoEntries {
- return nil, fmt.Errorf("no actor found that corresponds to inbox %s", iri.String())
+ return nil, fmt.Errorf("no actor found that corresponds to uri %s", iri.String())
}
- return nil, fmt.Errorf("db error searching for actor with inbox %s", iri.String())
+ return nil, fmt.Errorf("db error searching for actor with uri %s", iri.String())
}
return acct, nil
- }
-
- if uris.IsOutboxPath(iri) {
- if err := f.db.GetWhere(ctx, []db.Where{{Key: "outbox_uri", Value: iri.String()}}, acct); err != nil {
+ case 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 outbox %s", iri.String())
+ return nil, fmt.Errorf("no actor found that corresponds to inbox %s", iri.String())
}
- return nil, fmt.Errorf("db error searching for actor with outbox %s", iri.String())
+ return nil, fmt.Errorf("db error searching for actor with inbox %s", iri.String())
}
return acct, nil
- }
-
- if uris.IsUserPath(iri) {
- if err := f.db.GetWhere(ctx, []db.Where{{Key: "uri", Value: iri.String()}}, acct); err != nil {
+ case 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 uri %s", iri.String())
+ return nil, fmt.Errorf("no actor found that corresponds to outbox %s", iri.String())
}
- return nil, fmt.Errorf("db error searching for actor with uri %s", iri.String())
+ return nil, fmt.Errorf("db error searching for actor with outbox %s", iri.String())
}
return acct, nil
- }
-
- if uris.IsFollowersPath(iri) {
- if err := f.db.GetWhere(ctx, []db.Where{{Key: "followers_uri", Value: iri.String()}}, acct); err != nil {
+ case 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())
}
return nil, fmt.Errorf("db error searching for actor with followers_uri %s", iri.String())
}
return acct, nil
- }
-
- if uris.IsFollowingPath(iri) {
- if err := f.db.GetWhere(ctx, []db.Where{{Key: "following_uri", Value: iri.String()}}, acct); err != nil {
+ case 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())
}
return nil, fmt.Errorf("db error searching for actor with following_uri %s", iri.String())
}
return acct, nil
+ default:
+ return nil, fmt.Errorf("getActorForIRI: iri %s not recognised", iri)
}
-
- return nil, fmt.Errorf("getActorForIRI: iri %s not recognised", iri)
}
// collectFollows takes a slice of iris and converts them into ActivityStreamsCollection of IRIs.