@@ -3583,17 +3583,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
35833583 "updateDelayedEvent" ,
35843584 ) ;
35853585 }
3586-
3587- const path = utils . encodeUri ( "/delayed_events/$delayId" , {
3588- $delayId : delayId ,
3589- } ) ;
3590- const data = {
3591- action,
3592- } ;
3593- return await this . http . request ( Method . Post , path , undefined , data , {
3594- ...requestOptions ,
3595- prefix : `${ ClientPrefix . Unstable } /${ UNSTABLE_MSC4140_DELAYED_EVENTS } ` ,
3596- } ) ;
3586+ return await this . updateScheduledDelayedEventWithActionInBody ( delayId , action , requestOptions ) ;
35973587 }
35983588
35993589 /**
@@ -3609,32 +3599,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
36093599 delayId : string ,
36103600 requestOptions : IRequestOpts = { } ,
36113601 ) : Promise < EmptyObject > {
3612- if ( ! ( await this . doesServerSupportUnstableFeature ( UNSTABLE_MSC4140_DELAYED_EVENTS ) ) ) {
3613- throw new UnsupportedDelayedEventsEndpointError (
3614- "Server does not support the delayed events API" ,
3615- "cancelScheduledDelayedEvent" ,
3616- ) ;
3617- }
3618-
3619- try {
3620- const path = utils . encodeUri ( "/delayed_events/$delayId/cancel" , {
3621- $delayId : delayId ,
3622- } ) ;
3623- return await this . http . request ( Method . Post , path , undefined , undefined , {
3624- ...requestOptions ,
3625- prefix : `${ ClientPrefix . Unstable } /${ UNSTABLE_MSC4140_DELAYED_EVENTS } ` ,
3626- } ) ;
3627- } catch ( e ) {
3628- if ( e instanceof MatrixError && e . errcode === "M_UNRECOGNIZED" ) {
3629- return await this . _unstable_updateDelayedEvent (
3630- delayId ,
3631- UpdateDelayedEventAction . Cancel ,
3632- requestOptions ,
3633- ) ;
3634- } else {
3635- throw e ;
3636- }
3637- }
3602+ return this . updateScheduledDelayedEvent ( delayId , UpdateDelayedEventAction . Cancel , requestOptions ) ;
36383603 }
36393604
36403605 /**
@@ -3650,32 +3615,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
36503615 delayId : string ,
36513616 requestOptions : IRequestOpts = { } ,
36523617 ) : Promise < EmptyObject > {
3653- if ( ! ( await this . doesServerSupportUnstableFeature ( UNSTABLE_MSC4140_DELAYED_EVENTS ) ) ) {
3654- throw new UnsupportedDelayedEventsEndpointError (
3655- "Server does not support the delayed events API" ,
3656- "restartScheduledDelayedEvent" ,
3657- ) ;
3658- }
3659-
3660- try {
3661- const path = utils . encodeUri ( "/delayed_events/$delayId/restart" , {
3662- $delayId : delayId ,
3663- } ) ;
3664- return await this . http . request ( Method . Post , path , undefined , undefined , {
3665- ...requestOptions ,
3666- prefix : `${ ClientPrefix . Unstable } /${ UNSTABLE_MSC4140_DELAYED_EVENTS } ` ,
3667- } ) ;
3668- } catch ( e ) {
3669- if ( e instanceof MatrixError && e . errcode === "M_UNRECOGNIZED" ) {
3670- return await this . _unstable_updateDelayedEvent (
3671- delayId ,
3672- UpdateDelayedEventAction . Restart ,
3673- requestOptions ,
3674- ) ;
3675- } else {
3676- throw e ;
3677- }
3678- }
3618+ return this . updateScheduledDelayedEvent ( delayId , UpdateDelayedEventAction . Restart , requestOptions ) ;
36793619 }
36803620
36813621 /**
@@ -3691,31 +3631,57 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
36913631 public async _unstable_sendScheduledDelayedEvent (
36923632 delayId : string ,
36933633 requestOptions : IRequestOpts = { } ,
3634+ ) : Promise < EmptyObject > {
3635+ return this . updateScheduledDelayedEvent ( delayId , UpdateDelayedEventAction . Send , requestOptions ) ;
3636+ }
3637+
3638+ private async updateScheduledDelayedEvent (
3639+ delayId : string ,
3640+ action : UpdateDelayedEventAction ,
3641+ requestOptions : IRequestOpts = { } ,
36943642 ) : Promise < EmptyObject > {
36953643 if ( ! ( await this . doesServerSupportUnstableFeature ( UNSTABLE_MSC4140_DELAYED_EVENTS ) ) ) {
36963644 throw new UnsupportedDelayedEventsEndpointError (
36973645 "Server does not support the delayed events API" ,
3698- "sendScheduledDelayedEvent" ,
3646+ ` ${ action } ScheduledDelayedEvent` ,
36993647 ) ;
37003648 }
37013649
37023650 try {
3703- const path = utils . encodeUri ( "/delayed_events/$delayId/send " , {
3651+ const path = utils . encodeUri ( "/delayed_events/$delayId/$action " , {
37043652 $delayId : delayId ,
3653+ $action : action ,
37053654 } ) ;
37063655 return await this . http . request ( Method . Post , path , undefined , undefined , {
37073656 ...requestOptions ,
37083657 prefix : `${ ClientPrefix . Unstable } /${ UNSTABLE_MSC4140_DELAYED_EVENTS } ` ,
37093658 } ) ;
37103659 } catch ( e ) {
37113660 if ( e instanceof MatrixError && e . errcode === "M_UNRECOGNIZED" ) {
3712- return await this . _unstable_updateDelayedEvent ( delayId , UpdateDelayedEventAction . Send , requestOptions ) ;
3661+ return await this . updateScheduledDelayedEventWithActionInBody ( delayId , action , requestOptions ) ;
37133662 } else {
37143663 throw e ;
37153664 }
37163665 }
37173666 }
37183667
3668+ private async updateScheduledDelayedEventWithActionInBody (
3669+ delayId : string ,
3670+ action : UpdateDelayedEventAction ,
3671+ requestOptions : IRequestOpts = { } ,
3672+ ) : Promise < EmptyObject > {
3673+ const path = utils . encodeUri ( "/delayed_events/$delayId" , {
3674+ $delayId : delayId ,
3675+ } ) ;
3676+ const data = {
3677+ action,
3678+ } ;
3679+ return await this . http . request ( Method . Post , path , undefined , data , {
3680+ ...requestOptions ,
3681+ prefix : `${ ClientPrefix . Unstable } /${ UNSTABLE_MSC4140_DELAYED_EVENTS } ` ,
3682+ } ) ;
3683+ }
3684+
37193685 /**
37203686 * Send a receipt.
37213687 * @param event - The event being acknowledged
0 commit comments