Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Add deleting reports
Browse files Browse the repository at this point in the history
  • Loading branch information
S7evinK committed Mar 22, 2024
1 parent fbeaa0f commit fa3671e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions roomserver/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ type ClientRoomserverAPI interface {
) (int64, error)
QueryAdminEventReports(ctx context.Context, from, limit uint64, backwards bool, userID, roomID string) ([]QueryAdminEventReportsResponse, int64, error)
QueryAdminEventReport(ctx context.Context, reportID uint64) (QueryAdminEventReportResponse, error)
PerformAdminDeleteEventReport(ctx context.Context, reportID uint64) error
}

type UserRoomserverAPI interface {
Expand Down
4 changes: 4 additions & 0 deletions roomserver/internal/perform/perform_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,7 @@ func (r *Admin) PerformAdminDownloadState(

return nil
}

func (r *Admin) PerformAdminDeleteEventReport(ctx context.Context, reportID uint64) error {
return r.DB.AdminDeleteEventReport(ctx, reportID)
}
1 change: 1 addition & 0 deletions roomserver/storage/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ type Database interface {
RoomsWithACLs(ctx context.Context) ([]string, error)
QueryAdminEventReports(ctx context.Context, from uint64, limit uint64, backwards bool, userID string, roomID string) ([]api.QueryAdminEventReportsResponse, int64, error)
QueryAdminEventReport(ctx context.Context, reportID uint64) (api.QueryAdminEventReportResponse, error)
AdminDeleteEventReport(ctx context.Context, reportID uint64) error
}

type UserRoomKeys interface {
Expand Down
10 changes: 10 additions & 0 deletions roomserver/storage/postgres/reported_events_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ 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 {
Expand All @@ -101,6 +104,7 @@ func PrepareReportedEventsTable(db *sql.DB) (tables.ReportedEvents, error) {
{&s.selectReportedEventsDescStmt, selectReportedEventsDescSQL},
{&s.selectReportedEventsAscStmt, selectReportedEventsAscSQL},
{&s.selectReportedEventStmt, selectReportedEventSQL},
{&s.deleteReportedEventStmt, deleteReportedEventSQL},
}.Prepare(db)
}

Expand Down Expand Up @@ -209,3 +213,9 @@ func (r *reportedEventsStatements) SelectReportedEvent(
}
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
}
6 changes: 6 additions & 0 deletions roomserver/storage/shared/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,12 @@ func (d *Database) QueryAdminEventReport(ctx context.Context, reportID uint64) (
return report, nil
}

func (d *Database) AdminDeleteEventReport(ctx context.Context, reportID uint64) error {
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
return d.ReportedEventsTable.DeleteReportedEvent(ctx, txn, reportID)
})
}

// findRoomNameAndCanonicalAlias loops over events to find the corresponding room name and canonicalAlias
// for a given roomID.
func findRoomNameAndCanonicalAlias(events []tables.StrippedEvent, roomID string) (name, canonicalAlias string) {
Expand Down
10 changes: 10 additions & 0 deletions roomserver/storage/sqlite3/reported_events_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ 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 {
Expand All @@ -100,6 +103,7 @@ func PrepareReportedEventsTable(db *sql.DB) (tables.ReportedEvents, error) {
{&s.selectReportedEventsDescStmt, selectReportedEventsDescSQL},
{&s.selectReportedEventsAscStmt, selectReportedEventsAscSQL},
{&s.selectReportedEventStmt, selectReportedEventSQL},
{&s.deleteReportedEventStmt, deleteReportedEventSQL},
}.Prepare(db)
}

Expand Down Expand Up @@ -209,3 +213,9 @@ func (r *reportedEventsStatements) SelectReportedEvent(
}
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
}
1 change: 1 addition & 0 deletions roomserver/storage/tables/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ type ReportedEvents interface {
txn *sql.Tx,
reportID uint64,
) (api.QueryAdminEventReportResponse, error)
DeleteReportedEvent(ctx context.Context, txn *sql.Tx, reportID uint64) error
}

type MembershipState int64
Expand Down

0 comments on commit fa3671e

Please sign in to comment.