more updates

This commit is contained in:
tsmethurst 2021-08-18 12:08:24 +02:00
commit 81ea286254
30 changed files with 290 additions and 251 deletions

View file

@ -29,7 +29,6 @@ import (
"github.com/go-fed/activity/streams/vocab"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/transport"
@ -65,8 +64,8 @@ func (d *deref) GetRemoteAccount(username string, remoteAccountID *url.URL, refr
new := true
// check if we already have the account in our db
maybeAccount := &gtsmodel.Account{}
if err := d.db.GetWhere([]db.Where{{Key: "uri", Value: remoteAccountID.String()}}, maybeAccount); err == nil {
maybeAccount, err := d.db.GetAccountByURI(remoteAccountID.String())
if err == nil {
// we've seen this account before so it's not new
new = false
if !refresh {

View file

@ -109,7 +109,7 @@ func (d *deref) GetRemoteStatus(username string, remoteStatusID *url.URL, refres
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: error populating status fields: %s", err)
}
if err := d.db.Put(gtsStatus); err != nil {
if err := d.db.PutStatus(gtsStatus); err != nil {
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: error putting new status: %s", err)
}
} else {
@ -338,7 +338,10 @@ func (d *deref) populateStatusFields(status *gtsmodel.Status, requestingUsername
}
m.StatusID = status.ID
m.Status = status
m.OriginAccountID = status.Account.ID
m.OriginAccount = status.Account
m.OriginAccountURI = status.Account.URI
targetAccount, _, err := d.GetRemoteAccount(requestingUsername, uri, false)
@ -348,6 +351,7 @@ func (d *deref) populateStatusFields(status *gtsmodel.Status, requestingUsername
// by this point, we know the targetAccount exists in our database with an ID :)
m.TargetAccountID = targetAccount.ID
m.TargetAccount = targetAccount
if err := d.db.Put(m); err != nil {
return fmt.Errorf("error creating mention: %s", err)
}
@ -357,11 +361,12 @@ func (d *deref) populateStatusFields(status *gtsmodel.Status, requestingUsername
// status has replyToURI but we don't have an ID yet for the status it replies to
if status.InReplyToURI != "" && status.InReplyToID == "" {
replyToStatus := &gtsmodel.Status{}
if err := d.db.GetWhere([]db.Where{{Key: "uri", Value: status.InReplyToURI}}, replyToStatus); err == nil {
if replyToStatus, err := d.db.GetStatusByURI(status.InReplyToURI); err == nil {
// we have the status
status.InReplyToID = replyToStatus.ID
status.InReplyTo = replyToStatus
status.InReplyToAccountID = replyToStatus.AccountID
status.InReplyToAccount = replyToStatus.Account
}
}

View file

@ -112,7 +112,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
}
status.ID = statusID
if err := f.db.Put(status); err != nil {
if err := f.db.PutStatus(status); err != nil {
if err == db.ErrAlreadyExists {
// the status already exists in the database, which means we've already handled everything else,
// so we can just return nil here and be done with it.

View file

@ -31,7 +31,8 @@ func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (follower
acct := &gtsmodel.Account{}
if util.IsUserPath(actorIRI) {
if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: actorIRI.String()}}, acct); err != nil {
acct, err = f.db.GetAccountByURI(actorIRI.String())
if err != nil {
return nil, fmt.Errorf("FOLLOWERS: db error getting account with uri %s: %s", actorIRI.String(), err)
}
} else if util.IsFollowersPath(actorIRI) {

View file

@ -43,8 +43,8 @@ func (f *federatingDB) Get(c context.Context, id *url.URL) (value vocab.Type, er
l.Debug("entering GET function")
if util.IsUserPath(id) {
acct := &gtsmodel.Account{}
if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: id.String()}}, acct); err != nil {
acct, err := f.db.GetAccountByURI(id.String())
if err != nil {
return nil, err
}
l.Debug("is user path! returning account")

View file

@ -97,8 +97,8 @@ func (f *federatingDB) NewID(c context.Context, t vocab.Type) (idURL *url.URL, e
for iter := actorProp.Begin(); iter != actorProp.End(); iter = iter.Next() {
// take the IRI of the first actor we can find (there should only be one)
if iter.IsIRI() {
actorAccount := &gtsmodel.Account{}
if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: iter.GetIRI().String()}}, actorAccount); err == nil { // if there's an error here, just use the fallback behavior -- we don't need to return an error here
// if there's an error here, just use the fallback behavior -- we don't need to return an error here
if actorAccount, err := f.db.GetAccountByURI(iter.GetIRI().String()); err == nil {
newID, err := id.NewRandomULID()
if err != nil {
return nil, err

View file

@ -200,8 +200,8 @@ func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, er
return true, nil
}
requestingAccount := &gtsmodel.Account{}
if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: uri.String()}}, requestingAccount); err != nil {
requestingAccount, err := f.db.GetAccountByURI(uri.String())
if err != nil {
if err == db.ErrNoEntries {
// we don't have an entry for this account so it's not blocked
// TODO: allow a different default to be set for this behavior