aboutsummaryrefslogtreecommitdiff
path: root/db/report.go
diff options
context:
space:
mode:
Diffstat (limited to 'db/report.go')
-rw-r--r--db/report.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/db/report.go b/db/report.go
new file mode 100644
index 0000000..4fcb806
--- /dev/null
+++ b/db/report.go
@@ -0,0 +1,56 @@
+package db
+
+func DeleteReportActivity(id string) error {
+ query := `delete from reported where id=$1`
+
+ _, err := db.Exec(query, id)
+ return err
+}
+
+func ReportActivity(id string, reason string) (bool, error) {
+ if res, err := IsIDLocal(id); err == nil && !res {
+ // TODO: not local error
+ return false, nil
+ } else if err != nil {
+ return false, err
+ }
+
+ actor, err := GetActivityFromDB(id)
+ if err != nil {
+ return false, err
+ }
+
+ query := `select count from reported where id=$1`
+
+ rows, err := db.Query(query, id)
+ if err != nil {
+ return false, err
+ }
+ defer rows.Close()
+
+ var count int
+ for rows.Next() {
+ if err := rows.Scan(&count); err != nil {
+ return false, err
+ }
+ }
+
+ if count < 1 {
+ query = `insert into reported (id, count, board, reason) values ($1, $2, $3, $4)`
+
+ _, err := db.Exec(query, id, 1, actor.Actor.Id, reason)
+ if err != nil {
+ return false, err
+ }
+ } else {
+ count = count + 1
+ query = `update reported set count=$1 where id=$2`
+
+ _, err := db.Exec(query, count, id)
+ if err != nil {
+ return false, err
+ }
+ }
+
+ return true, nil
+}