more big changes

This commit is contained in:
tsmethurst 2021-08-25 13:36:54 +02:00
commit 4e054233da
71 changed files with 640 additions and 405 deletions

View file

@ -87,7 +87,7 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
a, err := f.db.GetAccountByURI(ctx, id.String())
if err == nil {
// it's an account
l.Debugf("uri is for an account with id: %s", s.ID)
l.Debugf("uri is for an account with id: %s", a.ID)
if err := f.db.DeleteByID(ctx, a.ID, &gtsmodel.Account{}); err != nil {
return fmt.Errorf("DELETE: err deleting account: %s", err)
}

View file

@ -51,13 +51,17 @@ func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (follow
followers = streams.NewActivityStreamsCollection()
items := streams.NewActivityStreamsItemsProperty()
for _, follow := range acctFollowers {
gtsFollower := &gtsmodel.Account{}
if err := f.db.GetByID(ctx, follow.AccountID, gtsFollower); err != nil {
return nil, fmt.Errorf("FOLLOWERS: db error getting account id %s: %s", follow.AccountID, err)
if follow.Account == nil {
followAccount, err := f.db.GetAccountByID(ctx, follow.AccountID)
if err != nil {
return nil, fmt.Errorf("FOLLOWERS: db error getting account id %s: %s", follow.AccountID, err)
}
follow.Account = followAccount
}
uri, err := url.Parse(gtsFollower.URI)
uri, err := url.Parse(follow.Account.URI)
if err != nil {
return nil, fmt.Errorf("FOLLOWERS: error parsing %s as url: %s", gtsFollower.URI, err)
return nil, fmt.Errorf("FOLLOWERS: error parsing %s as url: %s", follow.Account.URI, err)
}
items.AppendIRI(uri)
}

View file

@ -64,13 +64,17 @@ func (f *federatingDB) Following(ctx context.Context, actorIRI *url.URL) (follow
following = streams.NewActivityStreamsCollection()
items := streams.NewActivityStreamsItemsProperty()
for _, follow := range acctFollowing {
gtsFollowing := &gtsmodel.Account{}
if err := f.db.GetByID(ctx, follow.AccountID, gtsFollowing); err != nil {
return nil, fmt.Errorf("FOLLOWING: db error getting account id %s: %s", follow.AccountID, err)
if follow.Account == nil {
followAccount, err := f.db.GetAccountByID(ctx, follow.AccountID)
if err != nil {
return nil, fmt.Errorf("FOLLOWING: db error getting account id %s: %s", follow.AccountID, err)
}
follow.Account = followAccount
}
uri, err := url.Parse(gtsFollowing.URI)
uri, err := url.Parse(follow.Account.URI)
if err != nil {
return nil, fmt.Errorf("FOLLOWING: error parsing %s as url: %s", gtsFollowing.URI, err)
return nil, fmt.Errorf("FOLLOWING: error parsing %s as url: %s", follow.Account.URI, err)
}
items.AppendIRI(uri)
}

View file

@ -152,7 +152,8 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error {
}
updatedAcct.ID = requestingAcct.ID // set this here so the db will update properly instead of trying to PUT this and getting constraint issues
if err := f.db.UpdateByID(ctx, requestingAcct.ID, updatedAcct); err != nil {
updatedAcct, err = f.db.UpdateAccount(ctx, updatedAcct)
if err != nil {
return fmt.Errorf("UPDATE: database error inserting updated account: %s", err)
}