aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage/shared
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/shared
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/shared')
-rw-r--r--roomserver/storage/shared/storage.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go
index c8c34907..7b04641b 100644
--- a/roomserver/storage/shared/storage.go
+++ b/roomserver/storage/shared/storage.go
@@ -2040,6 +2040,74 @@ func (d *Database) QueryAdminEventReports(ctx context.Context, from uint64, limi
return reports, count, nil
}
+func (d *Database) QueryAdminEventReport(ctx context.Context, reportID uint64) (api.QueryAdminEventReportResponse, error) {
+
+ report, err := d.ReportedEventsTable.SelectReportedEvent(ctx, nil, reportID)
+ if err != nil {
+ return api.QueryAdminEventReportResponse{}, err
+ }
+
+ // Get a map from EventStateKeyNID to userID
+ userNIDMap, err := d.EventStateKeys(ctx, []types.EventStateKeyNID{report.ReportingUserNID, report.SenderNID})
+ if err != nil {
+ logrus.WithError(err).Error("unable to map userNIDs to userIDs")
+ return report, err
+ }
+
+ roomIDs, err := d.RoomsTable.BulkSelectRoomIDs(ctx, nil, []types.RoomNID{report.RoomNID})
+ if err != nil {
+ return report, err
+ }
+
+ if len(roomIDs) != 1 {
+ return report, fmt.Errorf("expected one roomID, got %d", len(roomIDs))
+ }
+
+ // TODO: replace this with something more efficient, as it loads the entire state snapshot.
+ stateContent, err := d.GetBulkStateContent(ctx, roomIDs, []gomatrixserverlib.StateKeyTuple{
+ {EventType: spec.MRoomName, StateKey: ""},
+ {EventType: spec.MRoomCanonicalAlias, StateKey: ""},
+ }, false)
+ if err != nil {
+ return report, err
+ }
+
+ eventIDMap, err := d.EventIDs(ctx, []types.EventNID{report.EventNID})
+ if err != nil {
+ logrus.WithError(err).Error("unable to map eventNIDs to eventIDs")
+ return report, err
+ }
+ if len(eventIDMap) != 1 {
+ return report, fmt.Errorf("expected %d eventIDs, got %d", 1, len(eventIDMap))
+ }
+
+ eventJSONs, err := d.EventJSONTable.BulkSelectEventJSON(ctx, nil, []types.EventNID{report.EventNID})
+ if err != nil {
+ return report, err
+ }
+ if len(eventJSONs) != 1 {
+ return report, fmt.Errorf("expected %d eventJSONs, got %d", 1, len(eventJSONs))
+ }
+
+ roomName, canonicalAlias := findRoomNameAndCanonicalAlias(stateContent, roomIDs[0])
+
+ report.Sender = userNIDMap[report.SenderNID]
+ report.UserID = userNIDMap[report.ReportingUserNID]
+ report.RoomID = roomIDs[0]
+ report.RoomName = roomName
+ report.CanonicalAlias = canonicalAlias
+ report.EventID = eventIDMap[report.EventNID]
+ report.EventJSON = eventJSONs[0].EventJSON
+
+ 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) {