From 89795236377c1db1821c7ccbbc48a94562a70995 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sat, 4 Jun 2022 11:08:51 -0700 Subject: made view reported posts less gimped --- db/report.go | 28 ++++++++++++++++++++++------ route/routes/admin.go | 24 +----------------------- route/structs.go | 2 +- views/manage.html | 11 ++++++++++- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/db/report.go b/db/report.go index 958b619..f5569fd 100644 --- a/db/report.go +++ b/db/report.go @@ -5,9 +5,14 @@ import ( "github.com/FChannel0/FChannel-Server/util" ) -type Report struct { +type Reports struct { ID string Count int + Reason []string +} + +type Report struct { + ID string Reason string } @@ -72,10 +77,10 @@ func GetLocalDelete() ([]Removed, error) { return deleted, nil } -func GetLocalReport(board string) ([]Report, error) { - var reported []Report +func GetLocalReport(board string) (map[string]Reports, error) { + var reported = make(map[string]Reports) - query := `select id, count, reason from reported where board=$1` + query := `select id, reason from reported where board=$1` rows, err := config.DB.Query(query, board) if err != nil { @@ -86,11 +91,22 @@ func GetLocalReport(board string) ([]Report, error) { for rows.Next() { var r Report - if err := rows.Scan(&r.ID, &r.Count, &r.Reason); err != nil { + if err := rows.Scan(&r.ID, &r.Reason); err != nil { return reported, util.MakeError(err, "GetLocalReportDB") } - reported = append(reported, r) + if report, has := reported[r.ID]; has { + report.Count += 1 + report.Reason = append(report.Reason, r.Reason) + reported[r.ID] = report + continue + } + + reported[r.ID] = Reports{ + ID: r.ID, + Count: 1, + Reason: []string{r.Reason}, + } } return reported, nil diff --git a/route/routes/admin.go b/route/routes/admin.go index 86e12c6..dfa7313 100644 --- a/route/routes/admin.go +++ b/route/routes/admin.go @@ -226,12 +226,8 @@ func AdminActorIndex(ctx *fiber.Ctx) error { reqActivity.Id = actor.Followers follower, _ := reqActivity.GetCollection() - reqActivity.Id = actor.Id + "/reported" - reported, _ := activitypub.GetActorCollectionReq(reqActivity.Id) - var following []string var followers []string - var reports []db.Report for _, e := range follow.Items { following = append(following, e.Id) @@ -241,28 +237,10 @@ func AdminActorIndex(ctx *fiber.Ctx) error { followers = append(followers, e.Id) } - for _, e := range reported.Items { - var r db.Report - r.Count = int(e.Size) - r.ID = e.Id - r.Reason = e.Content - reports = append(reports, r) - } - - localReports, _ := db.GetLocalReport(actor.Name) - - for _, e := range localReports { - var r db.Report - r.Count = e.Count - r.ID = e.ID - r.Reason = e.Reason - reports = append(reports, r) - } - var data route.AdminPage data.Following = following data.Followers = followers - data.Reported = reports + data.Reported, _ = db.GetLocalReport(actor.Name) data.Domain = config.Domain data.IsLocal, _ = actor.IsLocal() diff --git a/route/structs.go b/route/structs.go index 7b1c2b8..fbfb327 100644 --- a/route/structs.go +++ b/route/structs.go @@ -37,7 +37,7 @@ type AdminPage struct { Boards []webfinger.Board Following []string Followers []string - Reported []db.Report + Reported map[string]db.Reports Domain string IsLocal bool PostBlacklist []util.PostBlacklist diff --git a/views/manage.html b/views/manage.html index af887e3..356e09a 100644 --- a/views/manage.html +++ b/views/manage.html @@ -45,7 +45,16 @@ -- cgit v1.2.3