diff options
author | 2023-08-09 19:14:33 +0200 | |
---|---|---|
committer | 2023-08-09 19:14:33 +0200 | |
commit | 9770d54237bea828cab7e50aec7dff452c203138 (patch) | |
tree | 59c444a02e81925bab47d3656a489a8c7087d530 /internal/db/bundb/report.go | |
parent | [bugfix] Fix incorrect per-loop variable capture (#2092) (diff) | |
download | gotosocial-9770d54237bea828cab7e50aec7dff452c203138.tar.xz |
[feature] List replies policy, refactor async workers (#2087)
* Add/update some DB functions.
* move async workers into subprocessor
* rename FromFederator -> FromFediAPI
* update home timeline check to include check for current status first before moving to parent status
* change streamMap to pointer to mollify linter
* update followtoas func signature
* fix merge
* remove errant debug log
* don't use separate errs.Combine() check to wrap errs
* wrap parts of workers functionality in sub-structs
* populate report using new db funcs
* embed federator (tiny bit tidier)
* flesh out error msg, add continue(!)
* fix other error messages to be more specific
* better, nicer
* give parseURI util function a bit more util
* missing headers
* use pointers for subprocessors
Diffstat (limited to 'internal/db/bundb/report.go')
-rw-r--r-- | internal/db/bundb/report.go | 71 |
1 files changed, 53 insertions, 18 deletions
diff --git a/internal/db/bundb/report.go b/internal/db/bundb/report.go index 3a1e18789..eaeac4860 100644 --- a/internal/db/bundb/report.go +++ b/internal/db/bundb/report.go @@ -20,11 +20,11 @@ package bundb import ( "context" "errors" - "fmt" "time" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtscontext" + "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/state" @@ -135,35 +135,70 @@ func (r *reportDB) getReport(ctx context.Context, lookup string, dbQuery func(*g return nil, err } - // Set the report author account - report.Account, err = r.state.DB.GetAccountByID(ctx, report.AccountID) - if err != nil { - return nil, fmt.Errorf("error getting report account: %w", err) + if gtscontext.Barebones(ctx) { + // Only a barebones model was requested. + return report, nil } - // Set the report target account - report.TargetAccount, err = r.state.DB.GetAccountByID(ctx, report.TargetAccountID) - if err != nil { - return nil, fmt.Errorf("error getting report target account: %w", err) + if err := r.state.DB.PopulateReport(ctx, report); err != nil { + return nil, err } - if len(report.StatusIDs) > 0 { - // Fetch reported statuses - report.Statuses, err = r.state.DB.GetStatusesByIDs(ctx, report.StatusIDs) + return report, nil +} + +func (r *reportDB) PopulateReport(ctx context.Context, report *gtsmodel.Report) error { + var ( + err error + errs = gtserror.NewMultiError(4) + ) + + if report.Account == nil { + // Report account is not set, fetch from the database. + report.Account, err = r.state.DB.GetAccountByID( + gtscontext.SetBarebones(ctx), + report.AccountID, + ) if err != nil { - return nil, fmt.Errorf("error getting status mentions: %w", err) + errs.Appendf("error populating report account: %w", err) } } - if report.ActionTakenByAccountID != "" { - // Set the report action taken by account - report.ActionTakenByAccount, err = r.state.DB.GetAccountByID(ctx, report.ActionTakenByAccountID) + if report.TargetAccount == nil { + // Report target account is not set, fetch from the database. + report.TargetAccount, err = r.state.DB.GetAccountByID( + gtscontext.SetBarebones(ctx), + report.TargetAccountID, + ) if err != nil { - return nil, fmt.Errorf("error getting report action taken by account: %w", err) + errs.Appendf("error populating report target account: %w", err) } } - return report, nil + if l := len(report.StatusIDs); l > 0 && l != len(report.Statuses) { + // Report target statuses not set, fetch from the database. + report.Statuses, err = r.state.DB.GetStatusesByIDs( + gtscontext.SetBarebones(ctx), + report.StatusIDs, + ) + if err != nil { + errs.Appendf("error populating report statuses: %w", err) + } + } + + if report.ActionTakenByAccountID != "" && + report.ActionTakenByAccount == nil { + // Report action account is not set, fetch from the database. + report.ActionTakenByAccount, err = r.state.DB.GetAccountByID( + gtscontext.SetBarebones(ctx), + report.ActionTakenByAccountID, + ) + if err != nil { + errs.Appendf("error populating report action taken by account: %w", err) + } + } + + return errs.Combine() } func (r *reportDB) PutReport(ctx context.Context, report *gtsmodel.Report) error { |