summaryrefslogtreecommitdiff
path: root/internal/db/bundb/report.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/bundb/report.go')
-rw-r--r--internal/db/bundb/report.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/internal/db/bundb/report.go b/internal/db/bundb/report.go
index 8cc1d8de9..baf11ddb0 100644
--- a/internal/db/bundb/report.go
+++ b/internal/db/bundb/report.go
@@ -25,6 +25,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/state"
"github.com/uptrace/bun"
)
@@ -49,6 +50,73 @@ func (r *reportDB) GetReportByID(ctx context.Context, id string) (*gtsmodel.Repo
)
}
+func (r *reportDB) GetReports(ctx context.Context, resolved *bool, accountID string, targetAccountID string, maxID string, sinceID string, minID string, limit int) ([]*gtsmodel.Report, db.Error) {
+ reportIDs := []string{}
+
+ q := r.conn.
+ NewSelect().
+ TableExpr("? AS ?", bun.Ident("reports"), bun.Ident("report")).
+ Column("report.id").
+ Order("report.id DESC")
+
+ if resolved != nil {
+ i := bun.Ident("report.action_taken_by_account_id")
+ if *resolved {
+ q = q.Where("? IS NOT NULL", i)
+ } else {
+ q = q.Where("? IS NULL", i)
+ }
+ }
+
+ if accountID != "" {
+ q = q.Where("? = ?", bun.Ident("report.account_id"), accountID)
+ }
+
+ if targetAccountID != "" {
+ q = q.Where("? = ?", bun.Ident("report.target_account_id"), targetAccountID)
+ }
+
+ if maxID != "" {
+ q = q.Where("? < ?", bun.Ident("report.id"), maxID)
+ }
+
+ if sinceID != "" {
+ q = q.Where("? > ?", bun.Ident("report.id"), minID)
+ }
+
+ if minID != "" {
+ q = q.Where("? > ?", bun.Ident("report.id"), minID)
+ }
+
+ if limit != 0 {
+ q = q.Limit(limit)
+ }
+
+ if err := q.Scan(ctx, &reportIDs); err != nil {
+ return nil, r.conn.ProcessError(err)
+ }
+
+ // Catch case of no reports early
+ if len(reportIDs) == 0 {
+ return nil, db.ErrNoEntries
+ }
+
+ // Allocate return slice (will be at most len reportIDs)
+ reports := make([]*gtsmodel.Report, 0, len(reportIDs))
+ for _, id := range reportIDs {
+ report, err := r.GetReportByID(ctx, id)
+ if err != nil {
+ log.Errorf("GetReports: error getting report %q: %v", id, err)
+ continue
+ }
+
+ // Append to return slice
+ reports = append(reports, report)
+ }
+
+ return reports, nil
+}
+
func (r *reportDB) getReport(ctx context.Context, lookup string, dbQuery func(*gtsmodel.Report) error, keyParts ...any) (*gtsmodel.Report, db.Error) {
// Fetch report from database cache with loader callback
report, err := r.state.Caches.GTS.Report().Load(lookup, func() (*gtsmodel.Report, error) {