@@ -29,10 +29,12 @@ import {
2929 ActionException ,
3030 ActionExceptionKind ,
3131 ActionResult ,
32+ EDStatic ,
3233 Ok ,
3334 SynapseAdminDeleteRoomRequest ,
3435 SynapseAdminGetUserAdminResponse ,
3536 SynapseAdminPostUserDeactivateRequest ,
37+ SynapseReport ,
3638 Value ,
3739 isError ,
3840} from 'matrix-protection-suite' ;
@@ -41,6 +43,15 @@ import {
4143 StringRoomID ,
4244 StringUserID ,
4345} from '@the-draupnir-project/matrix-basic-types' ;
46+ import { Type } from '@sinclair/typebox' ;
47+ import { resultifyBotSDKRequestError } from '../Client/BotSDKBaseClient' ;
48+
49+ const ReportPollResponse = Type . Object ( {
50+ event_reports : Type . Array ( SynapseReport ) ,
51+ next_token : Type . Optional ( Type . Union ( [ Type . Integer ( ) , Type . Null ( ) ] ) ) ,
52+ total : Type . Optional ( Type . Union ( [ Type . Integer ( ) , Type . Null ( ) ] ) ) ,
53+ } ) ;
54+ type ReportPollResponse = EDStatic < typeof ReportPollResponse > ;
4455
4556export class SynapseAdminClient {
4657 constructor (
@@ -144,4 +155,26 @@ export class SynapseAdminClient {
144155 )
145156 ) ;
146157 }
158+
159+ public async getAbuseReports ( {
160+ from,
161+ direction,
162+ limit,
163+ } : { from ?: number ; direction ?: 'f' | 'b' ; limit ?: number } = { } ) : Promise <
164+ ActionResult < ReportPollResponse >
165+ > {
166+ const endpoint = '/_synapse/admin/v1/event_reports' ;
167+ const queryParams = {
168+ ...( from ? { from } : { } ) ,
169+ ...( direction ? { dir : direction } : { } ) ,
170+ ...( limit ? { limit } : { } ) ,
171+ } ;
172+ const response = await this . client
173+ . doRequest ( 'GET' , endpoint , queryParams )
174+ . then ( ( value ) => Ok ( value ) , resultifyBotSDKRequestError ) ;
175+ if ( isError ( response ) ) {
176+ return response ;
177+ }
178+ return Value . Decode ( ReportPollResponse , response . ok ) ;
179+ }
147180}
0 commit comments