aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage/sqlite3/reported_events_table.go
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2024-03-22 22:54:29 +0100
committerGitHub <noreply@github.com>2024-03-22 21:54:29 +0000
commitad0a7d09e89fe18c9e2b08f23f5817a5231c6074 (patch)
tree01ae155c112ac01dce299724790a9db8d999994d /roomserver/storage/sqlite3/reported_events_table.go
parent81f73c9f8df6dd3078a93b6ca978ecbb9c95df16 (diff)
Add getting/deleting single event report (#3344)
Based on https://github.com/matrix-org/dendrite/pull/3342 Adds `GET /_synapse/admin/v1/event_reports/{reportID}` and `DELETE /_synapse/admin/v1/event_reports/{reportID}`
Diffstat (limited to 'roomserver/storage/sqlite3/reported_events_table.go')
-rw-r--r--roomserver/storage/sqlite3/reported_events_table.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/roomserver/storage/sqlite3/reported_events_table.go b/roomserver/storage/sqlite3/reported_events_table.go
index 65584f4c..b72cb068 100644
--- a/roomserver/storage/sqlite3/reported_events_table.go
+++ b/roomserver/storage/sqlite3/reported_events_table.go
@@ -74,10 +74,20 @@ LIMIT $3
OFFSET $4
`
+const selectReportedEventSQL = `
+SELECT id, room_nid, event_nid, reporting_user_nid, event_sender_nid, reason, score, received_ts
+FROM roomserver_reported_events
+WHERE id = $1
+`
+
+const deleteReportedEventSQL = `DELETE FROM roomserver_reported_events WHERE id = $1`
+
type reportedEventsStatements struct {
insertReportedEventsStmt *sql.Stmt
selectReportedEventsDescStmt *sql.Stmt
selectReportedEventsAscStmt *sql.Stmt
+ selectReportedEventStmt *sql.Stmt
+ deleteReportedEventStmt *sql.Stmt
}
func CreateReportedEventsTable(db *sql.DB) error {
@@ -92,6 +102,8 @@ func PrepareReportedEventsTable(db *sql.DB) (tables.ReportedEvents, error) {
{&s.insertReportedEventsStmt, insertReportedEventSQL},
{&s.selectReportedEventsDescStmt, selectReportedEventsDescSQL},
{&s.selectReportedEventsAscStmt, selectReportedEventsAscSQL},
+ {&s.selectReportedEventStmt, selectReportedEventSQL},
+ {&s.deleteReportedEventStmt, deleteReportedEventSQL},
}.Prepare(db)
}
@@ -178,3 +190,32 @@ func (r *reportedEventsStatements) SelectReportedEvents(
return result, count, rows.Err()
}
+
+func (r *reportedEventsStatements) SelectReportedEvent(
+ ctx context.Context,
+ txn *sql.Tx,
+ reportID uint64,
+) (api.QueryAdminEventReportResponse, error) {
+ stmt := sqlutil.TxStmt(txn, r.selectReportedEventStmt)
+
+ var row api.QueryAdminEventReportResponse
+ if err := stmt.QueryRowContext(ctx, reportID).Scan(
+ &row.ID,
+ &row.RoomNID,
+ &row.EventNID,
+ &row.ReportingUserNID,
+ &row.SenderNID,
+ &row.Reason,
+ &row.Score,
+ &row.ReceivedTS,
+ ); err != nil {
+ return api.QueryAdminEventReportResponse{}, err
+ }
+ return row, nil
+}
+
+func (r *reportedEventsStatements) DeleteReportedEvent(ctx context.Context, txn *sql.Tx, reportID uint64) error {
+ stmt := sqlutil.TxStmt(txn, r.deleteReportedEventStmt)
+ _, err := stmt.ExecContext(ctx, reportID)
+ return err
+}