mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-18 13:37:30 -06:00
Refactor/tidy (#261)
* tidy up streaming * cut down code duplication * test get followers/following * test streaming processor * fix some test models * add TimeMustParse * fix uri / url typo * make trace logging less verbose * make logging more consistent * disable quote on logging * remove context.Background * remove many extraneous mastodon references * regenerate swagger * don't log query on no rows result * log latency first for easier reading
This commit is contained in:
parent
9ce4234b9f
commit
e04b187702
126 changed files with 1192 additions and 955 deletions
|
|
@ -74,10 +74,10 @@ func (p *processor) Boost(ctx context.Context, requestingAccount *gtsmodel.Accou
|
|||
}
|
||||
|
||||
// return the frontend representation of the new status to the submitter
|
||||
mastoStatus, err := p.tc.StatusToMasto(ctx, boostWrapperStatus, requestingAccount)
|
||||
apiStatus, err := p.tc.StatusToAPIStatus(ctx, boostWrapperStatus, requestingAccount)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err))
|
||||
}
|
||||
|
||||
return mastoStatus, nil
|
||||
return apiStatus, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,15 +64,15 @@ func (p *processor) BoostedBy(ctx context.Context, requestingAccount *gtsmodel.A
|
|||
|
||||
// TODO: filter other things here? suspended? muted? silenced?
|
||||
|
||||
// now we can return the masto representation of those accounts
|
||||
mastoAccounts := []*apimodel.Account{}
|
||||
// now we can return the api representation of those accounts
|
||||
apiAccounts := []*apimodel.Account{}
|
||||
for _, acc := range filteredAccounts {
|
||||
mastoAccount, err := p.tc.AccountToMastoPublic(ctx, acc)
|
||||
apiAccount, err := p.tc.AccountToAPIAccountPublic(ctx, acc)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorNotFound(fmt.Errorf("StatusFavedBy: error converting account to api model: %s", err))
|
||||
}
|
||||
mastoAccounts = append(mastoAccounts, mastoAccount)
|
||||
apiAccounts = append(apiAccounts, apiAccount)
|
||||
}
|
||||
|
||||
return mastoAccounts, nil
|
||||
return apiAccounts, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ func (p *processor) Context(ctx context.Context, requestingAccount *gtsmodel.Acc
|
|||
|
||||
for _, status := range parents {
|
||||
if v, err := p.filter.StatusVisible(ctx, status, requestingAccount); err == nil && v {
|
||||
mastoStatus, err := p.tc.StatusToMasto(ctx, status, requestingAccount)
|
||||
apiStatus, err := p.tc.StatusToAPIStatus(ctx, status, requestingAccount)
|
||||
if err == nil {
|
||||
context.Ancestors = append(context.Ancestors, *mastoStatus)
|
||||
context.Ancestors = append(context.Ancestors, *apiStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -76,9 +76,9 @@ func (p *processor) Context(ctx context.Context, requestingAccount *gtsmodel.Acc
|
|||
|
||||
for _, status := range children {
|
||||
if v, err := p.filter.StatusVisible(ctx, status, requestingAccount); err == nil && v {
|
||||
mastoStatus, err := p.tc.StatusToMasto(ctx, status, requestingAccount)
|
||||
apiStatus, err := p.tc.StatusToAPIStatus(ctx, status, requestingAccount)
|
||||
if err == nil {
|
||||
context.Descendants = append(context.Descendants, *mastoStatus)
|
||||
context.Descendants = append(context.Descendants, *apiStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,10 +105,10 @@ func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, appli
|
|||
}
|
||||
|
||||
// return the frontend representation of the new status to the submitter
|
||||
mastoStatus, err := p.tc.StatusToMasto(ctx, newStatus, account)
|
||||
apiStatus, err := p.tc.StatusToAPIStatus(ctx, newStatus, account)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", newStatus.ID, err))
|
||||
}
|
||||
|
||||
return mastoStatus, nil
|
||||
return apiStatus, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func (p *processor) Delete(ctx context.Context, requestingAccount *gtsmodel.Acco
|
|||
return nil, gtserror.NewErrorForbidden(errors.New("status doesn't belong to requesting account"))
|
||||
}
|
||||
|
||||
mastoStatus, err := p.tc.StatusToMasto(ctx, targetStatus, requestingAccount)
|
||||
apiStatus, err := p.tc.StatusToAPIStatus(ctx, targetStatus, requestingAccount)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err))
|
||||
}
|
||||
|
|
@ -61,5 +61,5 @@ func (p *processor) Delete(ctx context.Context, requestingAccount *gtsmodel.Acco
|
|||
TargetAccount: requestingAccount,
|
||||
}
|
||||
|
||||
return mastoStatus, nil
|
||||
return apiStatus, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,11 +93,11 @@ func (p *processor) Fave(ctx context.Context, requestingAccount *gtsmodel.Accoun
|
|||
}
|
||||
}
|
||||
|
||||
// return the mastodon representation of the target status
|
||||
mastoStatus, err := p.tc.StatusToMasto(ctx, targetStatus, requestingAccount)
|
||||
// return the apidon representation of the target status
|
||||
apiStatus, err := p.tc.StatusToAPIStatus(ctx, targetStatus, requestingAccount)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err))
|
||||
}
|
||||
|
||||
return mastoStatus, nil
|
||||
return apiStatus, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,15 +62,15 @@ func (p *processor) FavedBy(ctx context.Context, requestingAccount *gtsmodel.Acc
|
|||
}
|
||||
}
|
||||
|
||||
// now we can return the masto representation of those accounts
|
||||
mastoAccounts := []*apimodel.Account{}
|
||||
// now we can return the api representation of those accounts
|
||||
apiAccounts := []*apimodel.Account{}
|
||||
for _, acc := range filteredAccounts {
|
||||
mastoAccount, err := p.tc.AccountToMastoPublic(ctx, acc)
|
||||
apiAccount, err := p.tc.AccountToAPIAccountPublic(ctx, acc)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err))
|
||||
}
|
||||
mastoAccounts = append(mastoAccounts, mastoAccount)
|
||||
apiAccounts = append(apiAccounts, apiAccount)
|
||||
}
|
||||
|
||||
return mastoAccounts, nil
|
||||
return apiAccounts, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ func (p *processor) Get(ctx context.Context, requestingAccount *gtsmodel.Account
|
|||
return nil, gtserror.NewErrorNotFound(errors.New("status is not visible"))
|
||||
}
|
||||
|
||||
mastoStatus, err := p.tc.StatusToMasto(ctx, targetStatus, requestingAccount)
|
||||
apiStatus, err := p.tc.StatusToAPIStatus(ctx, targetStatus, requestingAccount)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err))
|
||||
}
|
||||
|
||||
return mastoStatus, nil
|
||||
return apiStatus, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,10 +100,10 @@ func (p *processor) Unboost(ctx context.Context, requestingAccount *gtsmodel.Acc
|
|||
}
|
||||
}
|
||||
|
||||
mastoStatus, err := p.tc.StatusToMasto(ctx, targetStatus, requestingAccount)
|
||||
apiStatus, err := p.tc.StatusToAPIStatus(ctx, targetStatus, requestingAccount)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err))
|
||||
}
|
||||
|
||||
return mastoStatus, nil
|
||||
return apiStatus, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,10 +82,10 @@ func (p *processor) Unfave(ctx context.Context, requestingAccount *gtsmodel.Acco
|
|||
}
|
||||
}
|
||||
|
||||
mastoStatus, err := p.tc.StatusToMasto(ctx, targetStatus, requestingAccount)
|
||||
apiStatus, err := p.tc.StatusToAPIStatus(ctx, targetStatus, requestingAccount)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err))
|
||||
}
|
||||
|
||||
return mastoStatus, nil
|
||||
return apiStatus, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func (p *processor) ProcessVisibility(ctx context.Context, form *apimodel.Advanc
|
|||
// If visibility isn't set on the form, then just take the account default.
|
||||
// If that's also not set, take the default for the whole instance.
|
||||
if form.Visibility != "" {
|
||||
vis = p.tc.MastoVisToVis(form.Visibility)
|
||||
vis = p.tc.APIVisToVis(form.Visibility)
|
||||
} else if accountDefaultVis != "" {
|
||||
vis = accountDefaultVis
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue