aboutsummaryrefslogtreecommitdiff
path: root/clientapi/routing/admin.go
diff options
context:
space:
mode:
Diffstat (limited to 'clientapi/routing/admin.go')
-rw-r--r--clientapi/routing/admin.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/clientapi/routing/admin.go b/clientapi/routing/admin.go
index 51966607..e91e098a 100644
--- a/clientapi/routing/admin.go
+++ b/clientapi/routing/admin.go
@@ -495,3 +495,45 @@ func AdminDownloadState(req *http.Request, device *api.Device, rsAPI roomserverA
JSON: struct{}{},
}
}
+
+// GetEventReports returns reported events for a given user/room.
+func GetEventReports(
+ req *http.Request,
+ rsAPI roomserverAPI.ClientRoomserverAPI,
+ from, limit uint64,
+ backwards bool,
+ userID, roomID string,
+) util.JSONResponse {
+
+ eventReports, count, err := rsAPI.QueryAdminEventReports(req.Context(), from, limit, backwards, userID, roomID)
+ if err != nil {
+ logrus.WithError(err).Error("failed to query event reports")
+ return util.JSONResponse{
+ Code: http.StatusInternalServerError,
+ JSON: spec.InternalServerError{},
+ }
+ }
+
+ resp := map[string]any{
+ "event_reports": eventReports,
+ "total": count,
+ }
+
+ // Add a next_token if there are still reports
+ if int64(from+limit) < count {
+ resp["next_token"] = int(from) + len(eventReports)
+ }
+
+ return util.JSONResponse{
+ Code: http.StatusOK,
+ JSON: resp,
+ }
+}
+
+func parseUint64OrDefault(input string, defaultValue uint64) uint64 {
+ v, err := strconv.ParseUint(input, 10, 64)
+ if err != nil {
+ return defaultValue
+ }
+ return v
+}