mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-30 09:06:14 -06:00
more big changes
This commit is contained in:
parent
b9746a30f3
commit
4e054233da
71 changed files with 640 additions and 405 deletions
|
|
@ -177,17 +177,21 @@ selectStatusesLoop:
|
|||
}
|
||||
|
||||
for _, b := range boosts {
|
||||
oa := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, b.AccountID, oa); err == nil {
|
||||
|
||||
l.Debug("putting boost undo in the client api channel")
|
||||
p.fromClientAPI <- gtsmodel.FromClientAPI{
|
||||
APObjectType: gtsmodel.ActivityStreamsAnnounce,
|
||||
APActivityType: gtsmodel.ActivityStreamsUndo,
|
||||
GTSModel: s,
|
||||
OriginAccount: oa,
|
||||
TargetAccount: account,
|
||||
if b.Account == nil {
|
||||
bAccount, err := p.db.GetAccountByID(ctx, b.AccountID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
b.Account = bAccount
|
||||
}
|
||||
|
||||
l.Debug("putting boost undo in the client api channel")
|
||||
p.fromClientAPI <- gtsmodel.FromClientAPI{
|
||||
APObjectType: gtsmodel.ActivityStreamsAnnounce,
|
||||
APActivityType: gtsmodel.ActivityStreamsUndo,
|
||||
GTSModel: s,
|
||||
OriginAccount: b.Account,
|
||||
TargetAccount: account,
|
||||
}
|
||||
|
||||
if err := p.db.DeleteByID(ctx, b.ID, b); err != nil {
|
||||
|
|
@ -267,7 +271,8 @@ selectStatusesLoop:
|
|||
account.SuspendedAt = time.Now()
|
||||
account.SuspensionOrigin = origin
|
||||
|
||||
if err := p.db.UpdateByID(ctx, account.ID, account); err != nil {
|
||||
account, err := p.db.UpdateAccount(ctx, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ import (
|
|||
)
|
||||
|
||||
func (p *processor) Get(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Account, error) {
|
||||
targetAccount := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, targetAccountID, targetAccount); err != nil {
|
||||
targetAccount, err := p.db.GetAccountByID(ctx, targetAccountID)
|
||||
if err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
return nil, errors.New("account not found")
|
||||
}
|
||||
|
|
@ -38,7 +38,6 @@ func (p *processor) Get(ctx context.Context, requestingAccount *gtsmodel.Account
|
|||
}
|
||||
|
||||
var blocked bool
|
||||
var err error
|
||||
if requestingAccount != nil {
|
||||
blocked, err = p.db.IsBlocked(ctx, requestingAccount.ID, targetAccountID, true)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ func (p *processor) FollowRemove(ctx context.Context, requestingAccount *gtsmode
|
|||
}
|
||||
|
||||
// make sure the target account actually exists in our db
|
||||
targetAcct := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, targetAccountID, targetAcct); err != nil {
|
||||
targetAcct, err := p.db.GetAccountByID(ctx, targetAccountID)
|
||||
if err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
return nil, gtserror.NewErrorNotFound(fmt.Errorf("AccountFollowRemove: account %s not found in the db: %s", targetAccountID, err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,8 +117,8 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
|
|||
}
|
||||
|
||||
// fetch the account with all updated values set
|
||||
updatedAccount := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, account.ID, updatedAccount); err != nil {
|
||||
updatedAccount, err := p.db.GetAccountByID(ctx, account.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not fetch updated account %s: %s", account.ID, err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,11 +38,15 @@ func (p *processor) FollowRequestsGet(ctx context.Context, auth *oauth.Auth) ([]
|
|||
|
||||
accts := []apimodel.Account{}
|
||||
for _, fr := range frs {
|
||||
acct := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, fr.AccountID, acct); err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
if fr.Account == nil {
|
||||
frAcct, err := p.db.GetAccountByID(ctx, fr.AccountID)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
fr.Account = frAcct
|
||||
}
|
||||
mastoAcct, err := p.tc.AccountToMastoPublic(ctx, acct)
|
||||
|
||||
mastoAcct, err := p.tc.AccountToMastoPublic(ctx, fr.Account)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
|
@ -57,22 +61,28 @@ func (p *processor) FollowRequestAccept(ctx context.Context, auth *oauth.Auth, a
|
|||
return nil, gtserror.NewErrorNotFound(err)
|
||||
}
|
||||
|
||||
originAccount := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, follow.AccountID, originAccount); err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
if follow.Account == nil {
|
||||
followAccount, err := p.db.GetAccountByID(ctx, follow.AccountID)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
follow.Account = followAccount
|
||||
}
|
||||
|
||||
targetAccount := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, follow.TargetAccountID, targetAccount); err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
if follow.TargetAccount == nil {
|
||||
followTargetAccount, err := p.db.GetAccountByID(ctx, follow.TargetAccountID)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
follow.TargetAccount = followTargetAccount
|
||||
}
|
||||
|
||||
p.fromClientAPI <- gtsmodel.FromClientAPI{
|
||||
APObjectType: gtsmodel.ActivityStreamsFollow,
|
||||
APActivityType: gtsmodel.ActivityStreamsAccept,
|
||||
GTSModel: follow,
|
||||
OriginAccount: originAccount,
|
||||
TargetAccount: targetAccount,
|
||||
OriginAccount: follow.Account,
|
||||
TargetAccount: follow.TargetAccount,
|
||||
}
|
||||
|
||||
gtsR, err := p.db.GetRelationship(ctx, auth.Account.ID, accountID)
|
||||
|
|
|
|||
|
|
@ -238,11 +238,11 @@ func (p *processor) processFromClientAPI(ctx context.Context, clientMsg gtsmodel
|
|||
|
||||
func (p *processor) federateStatus(ctx context.Context, status *gtsmodel.Status) error {
|
||||
if status.Account == nil {
|
||||
a := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, status.AccountID, a); err != nil {
|
||||
statusAccount, err := p.db.GetAccountByID(ctx, status.AccountID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("federateStatus: error fetching status author account: %s", err)
|
||||
}
|
||||
status.Account = a
|
||||
status.Account = statusAccount
|
||||
}
|
||||
|
||||
// do nothing if this isn't our status
|
||||
|
|
@ -266,11 +266,11 @@ func (p *processor) federateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
|
||||
func (p *processor) federateStatusDelete(ctx context.Context, status *gtsmodel.Status) error {
|
||||
if status.Account == nil {
|
||||
a := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, status.AccountID, a); err != nil {
|
||||
return fmt.Errorf("federateStatus: error fetching status author account: %s", err)
|
||||
statusAccount, err := p.db.GetAccountByID(ctx, status.AccountID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("federateStatusDelete: error fetching status author account: %s", err)
|
||||
}
|
||||
status.Account = a
|
||||
status.Account = statusAccount
|
||||
}
|
||||
|
||||
// do nothing if this isn't our status
|
||||
|
|
@ -558,19 +558,19 @@ func (p *processor) federateAccountUpdate(ctx context.Context, updatedAccount *g
|
|||
|
||||
func (p *processor) federateBlock(ctx context.Context, block *gtsmodel.Block) error {
|
||||
if block.Account == nil {
|
||||
a := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, block.AccountID, a); err != nil {
|
||||
blockAccount, err := p.db.GetAccountByID(ctx, block.AccountID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("federateBlock: error getting block account from database: %s", err)
|
||||
}
|
||||
block.Account = a
|
||||
block.Account = blockAccount
|
||||
}
|
||||
|
||||
if block.TargetAccount == nil {
|
||||
a := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, block.TargetAccountID, a); err != nil {
|
||||
blockTargetAccount, err := p.db.GetAccountByID(ctx, block.TargetAccountID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("federateBlock: error getting block target account from database: %s", err)
|
||||
}
|
||||
block.TargetAccount = a
|
||||
block.TargetAccount = blockTargetAccount
|
||||
}
|
||||
|
||||
// if both accounts are local there's nothing to do here
|
||||
|
|
@ -594,19 +594,19 @@ func (p *processor) federateBlock(ctx context.Context, block *gtsmodel.Block) er
|
|||
|
||||
func (p *processor) federateUnblock(ctx context.Context, block *gtsmodel.Block) error {
|
||||
if block.Account == nil {
|
||||
a := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, block.AccountID, a); err != nil {
|
||||
blockAccount, err := p.db.GetAccountByID(ctx, block.AccountID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("federateUnblock: error getting block account from database: %s", err)
|
||||
}
|
||||
block.Account = a
|
||||
block.Account = blockAccount
|
||||
}
|
||||
|
||||
if block.TargetAccount == nil {
|
||||
a := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, block.TargetAccountID, a); err != nil {
|
||||
blockTargetAccount, err := p.db.GetAccountByID(ctx, block.TargetAccountID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("federateUnblock: error getting block target account from database: %s", err)
|
||||
}
|
||||
block.TargetAccount = a
|
||||
block.TargetAccount = blockTargetAccount
|
||||
}
|
||||
|
||||
// if both accounts are local there's nothing to do here
|
||||
|
|
|
|||
|
|
@ -7,12 +7,11 @@ import (
|
|||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
|
||||
func (p *processor) Delete(ctx context.Context, mediaAttachmentID string) gtserror.WithCode {
|
||||
a := >smodel.MediaAttachment{}
|
||||
if err := p.db.GetByID(ctx, mediaAttachmentID, a); err != nil {
|
||||
attachment, err := p.db.GetAttachmentByID(ctx, mediaAttachmentID)
|
||||
if err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
// attachment already gone
|
||||
return nil
|
||||
|
|
@ -24,21 +23,21 @@ func (p *processor) Delete(ctx context.Context, mediaAttachmentID string) gtserr
|
|||
errs := []string{}
|
||||
|
||||
// delete the thumbnail from storage
|
||||
if a.Thumbnail.Path != "" {
|
||||
if err := p.storage.RemoveFileAt(a.Thumbnail.Path); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("remove thumbnail at path %s: %s", a.Thumbnail.Path, err))
|
||||
if attachment.Thumbnail.Path != "" {
|
||||
if err := p.storage.RemoveFileAt(attachment.Thumbnail.Path); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("remove thumbnail at path %s: %s", attachment.Thumbnail.Path, err))
|
||||
}
|
||||
}
|
||||
|
||||
// delete the file from storage
|
||||
if a.File.Path != "" {
|
||||
if err := p.storage.RemoveFileAt(a.File.Path); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("remove file at path %s: %s", a.File.Path, err))
|
||||
if attachment.File.Path != "" {
|
||||
if err := p.storage.RemoveFileAt(attachment.File.Path); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("remove file at path %s: %s", attachment.File.Path, err))
|
||||
}
|
||||
}
|
||||
|
||||
// delete the attachment
|
||||
if err := p.db.DeleteByID(ctx, mediaAttachmentID, a); err != nil {
|
||||
if err := p.db.DeleteByID(ctx, mediaAttachmentID, attachment); err != nil {
|
||||
if err != db.ErrNoEntries {
|
||||
errs = append(errs, fmt.Sprintf("remove attachment: %s", err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ func (p *processor) GetFile(ctx context.Context, account *gtsmodel.Account, form
|
|||
wantedMediaID := spl[0]
|
||||
|
||||
// get the account that owns the media and make sure it's not suspended
|
||||
acct := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, form.AccountID, acct); err != nil {
|
||||
acct, err := p.db.GetAccountByID(ctx, form.AccountID)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorNotFound(fmt.Errorf("account with id %s could not be selected from the db: %s", form.AccountID, err))
|
||||
}
|
||||
if !acct.SuspendedAt.IsZero() {
|
||||
|
|
@ -91,8 +91,8 @@ func (p *processor) GetFile(ctx context.Context, account *gtsmodel.Account, form
|
|||
return nil, gtserror.NewErrorNotFound(fmt.Errorf("media size %s not recognized for emoji", mediaSize))
|
||||
}
|
||||
case media.Attachment, media.Header, media.Avatar:
|
||||
a := >smodel.MediaAttachment{}
|
||||
if err := p.db.GetByID(ctx, wantedMediaID, a); err != nil {
|
||||
a, err := p.db.GetAttachmentByID(ctx, wantedMediaID)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorNotFound(fmt.Errorf("attachment %s could not be taken from the db: %s", wantedMediaID, err))
|
||||
}
|
||||
if a.AccountID != form.AccountID {
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ import (
|
|||
)
|
||||
|
||||
func (p *processor) GetMedia(ctx context.Context, account *gtsmodel.Account, mediaAttachmentID string) (*apimodel.Attachment, gtserror.WithCode) {
|
||||
attachment := >smodel.MediaAttachment{}
|
||||
if err := p.db.GetByID(ctx, mediaAttachmentID, attachment); err != nil {
|
||||
attachment, err := p.db.GetAttachmentByID(ctx, mediaAttachmentID)
|
||||
if err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
// attachment doesn't exist
|
||||
return nil, gtserror.NewErrorNotFound(errors.New("attachment doesn't exist in the db"))
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ import (
|
|||
)
|
||||
|
||||
func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, mediaAttachmentID string, form *apimodel.AttachmentUpdateRequest) (*apimodel.Attachment, gtserror.WithCode) {
|
||||
attachment := >smodel.MediaAttachment{}
|
||||
if err := p.db.GetByID(ctx, mediaAttachmentID, attachment); err != nil {
|
||||
attachment, err := p.db.GetAttachmentByID(ctx, mediaAttachmentID)
|
||||
if err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
// attachment doesn't exist
|
||||
return nil, gtserror.NewErrorNotFound(errors.New("attachment doesn't exist in the db"))
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ func (p *processor) AuthorizeStreamingRequest(ctx context.Context, accessToken s
|
|||
return nil, fmt.Errorf("AuthorizeStreamingRequest: no user found for validated uid %s", uid)
|
||||
}
|
||||
|
||||
acct := >smodel.Account{}
|
||||
if err := p.db.GetByID(ctx, user.AccountID, acct); err != nil || acct == nil {
|
||||
acct, err := p.db.GetAccountByID(ctx, user.AccountID)
|
||||
if err != nil || acct == nil {
|
||||
return nil, fmt.Errorf("AuthorizeStreamingRequest: no account retrieved for user with id %s", uid)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue