mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-18 10:27:30 -06:00
[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)
This commit is contained in:
parent
c59ec6f2a4
commit
3283900b0d
10 changed files with 207 additions and 69 deletions
|
|
@ -20,7 +20,7 @@ package federatingdb
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"codeberg.org/gruf/go-kv"
|
||||
|
|
@ -33,34 +33,27 @@ import (
|
|||
//
|
||||
// The library makes this call only after acquiring a lock first.
|
||||
func (f *federatingDB) Get(ctx context.Context, id *url.URL) (value vocab.Type, err error) {
|
||||
l := log.WithFields(kv.Fields{
|
||||
{"id", id},
|
||||
}...)
|
||||
l := log.WithFields(kv.Fields{{"id", id}}...)
|
||||
l.Debug("entering Get")
|
||||
|
||||
if uris.IsUserPath(id) {
|
||||
switch {
|
||||
case uris.IsUserPath(id):
|
||||
acct, err := f.db.GetAccountByURI(ctx, id.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f.typeConverter.AccountToAS(ctx, acct)
|
||||
}
|
||||
|
||||
if uris.IsStatusesPath(id) {
|
||||
case uris.IsStatusesPath(id):
|
||||
status, err := f.db.GetStatusByURI(ctx, id.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f.typeConverter.StatusToAS(ctx, status)
|
||||
}
|
||||
|
||||
if uris.IsFollowersPath(id) {
|
||||
case uris.IsFollowersPath(id):
|
||||
return f.Followers(ctx, id)
|
||||
}
|
||||
|
||||
if uris.IsFollowingPath(id) {
|
||||
case uris.IsFollowingPath(id):
|
||||
return f.Following(ctx, id)
|
||||
default:
|
||||
return nil, fmt.Errorf("federatingDB: could not Get %s", id.String())
|
||||
}
|
||||
|
||||
return nil, errors.New("could not get")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 := >smodel.Account{}
|
||||
func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (*gtsmodel.Account, error) {
|
||||
var (
|
||||
acct = >smodel.Account{}
|
||||
err error
|
||||
)
|
||||
|
||||
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())
|
||||
}
|
||||
return nil, fmt.Errorf("db error searching for actor with inbox %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 {
|
||||
if err == db.ErrNoEntries {
|
||||
return nil, fmt.Errorf("no actor found that corresponds to outbox %s", iri.String())
|
||||
}
|
||||
return nil, fmt.Errorf("db error searching for actor with outbox %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 {
|
||||
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 uri %s", iri.String())
|
||||
}
|
||||
return nil, fmt.Errorf("db error searching for actor with uri %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.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())
|
||||
}
|
||||
return nil, fmt.Errorf("db error searching for actor with inbox %s", iri.String())
|
||||
}
|
||||
return acct, 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 outbox %s", iri.String())
|
||||
}
|
||||
return nil, fmt.Errorf("db error searching for actor with outbox %s", iri.String())
|
||||
}
|
||||
return acct, 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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue