aboutsummaryrefslogtreecommitdiff
path: root/clientapi/routing/admin.go
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2024-03-22 22:32:30 +0100
committerGitHub <noreply@github.com>2024-03-22 22:32:30 +0100
commit79072c3dcdc88b77dd5a49c013a0c62624dd3224 (patch)
treeafba94c5d21fc9d64c8a0391becd21ab682f91cd /clientapi/routing/admin.go
parent1bdf0cc5414a47fbdab9ae76fa7d549349d648ec (diff)
Add `/_synapse/admin/v1/event_reports` endpoint (#3342)
Based on #3340 This adds a `/_synapse/admin/v1/event_reports` endpoint, the same Synapse has. This way existing tools also work with Dendrite. Given this is already getting huge (even though many test lines), splitting this into two PRs. (The next adds "getting one report" and "deleting reports") [skip ci]
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
+}