@@ -355,7 +355,7 @@ export class WidgetApi extends EventEmitter {
355355 * the capabilities request has gone through, not when the capabilities are approved/denied.
356356 * Use the WidgetApiToWidgetAction.NotifyCapabilities action to detect changes.
357357 */
358- public updateRequestedCapabilities ( ) : Promise < void > {
358+ public async updateRequestedCapabilities ( ) : Promise < void > {
359359 return this . transport
360360 . send ( WidgetApiFromWidgetAction . MSC2974RenegotiateCapabilities , < IRenegotiateCapabilitiesRequestData > {
361361 capabilities : this . requestedCapabilities ,
@@ -367,7 +367,7 @@ export class WidgetApi extends EventEmitter {
367367 * Tell the client that the content has been loaded.
368368 * @returns {Promise } Resolves when the client acknowledges the request.
369369 */
370- public sendContentLoaded ( ) : Promise < void > {
370+ public async sendContentLoaded ( ) : Promise < void > {
371371 return this . transport . send ( WidgetApiFromWidgetAction . ContentLoaded , < IWidgetApiRequestEmptyData > { } ) . then ( ) ;
372372 }
373373
@@ -376,7 +376,7 @@ export class WidgetApi extends EventEmitter {
376376 * @param {IStickerActionRequestData } sticker The sticker to send.
377377 * @returns {Promise } Resolves when the client acknowledges the request.
378378 */
379- public sendSticker ( sticker : IStickerActionRequestData ) : Promise < void > {
379+ public async sendSticker ( sticker : IStickerActionRequestData ) : Promise < void > {
380380 return this . transport . send ( WidgetApiFromWidgetAction . SendSticker , sticker ) . then ( ) ;
381381 }
382382
@@ -386,12 +386,11 @@ export class WidgetApi extends EventEmitter {
386386 * @returns {Promise<boolean> } Resolve with true if the client was able to fulfill
387387 * the request, resolves to false otherwise. Rejects if an error occurred.
388388 */
389- public setAlwaysOnScreen ( value : boolean ) : Promise < boolean > {
389+ public async setAlwaysOnScreen ( value : boolean ) : Promise < boolean > {
390390 return this . transport
391- . send <
392- IStickyActionRequestData ,
393- IStickyActionResponseData
394- > ( WidgetApiFromWidgetAction . UpdateAlwaysOnScreen , { value } )
391+ . send < IStickyActionRequestData , IStickyActionResponseData > ( WidgetApiFromWidgetAction . UpdateAlwaysOnScreen , {
392+ value,
393+ } )
395394 . then ( ( res ) => res . success ) ;
396395 }
397396
@@ -404,7 +403,7 @@ export class WidgetApi extends EventEmitter {
404403 * @param {WidgetType } type The type of modal widget.
405404 * @returns {Promise<void> } Resolves when the modal widget has been opened.
406405 */
407- public openModalWidget (
406+ public async openModalWidget (
408407 url : string ,
409408 name : string ,
410409 buttons : IModalWidgetOpenRequestDataButton [ ] = [ ] ,
@@ -427,7 +426,7 @@ export class WidgetApi extends EventEmitter {
427426 * @param {IModalWidgetReturnData } data Optional data to close the modal widget with.
428427 * @returns {Promise<void> } Resolves when complete.
429428 */
430- public closeModalWidget ( data : IModalWidgetReturnData = { } ) : Promise < void > {
429+ public async closeModalWidget ( data : IModalWidgetReturnData = { } ) : Promise < void > {
431430 return this . transport . send < IModalWidgetReturnData > ( WidgetApiFromWidgetAction . CloseModalWidget , data ) . then ( ) ;
432431 }
433432
@@ -503,11 +502,18 @@ export class WidgetApi extends EventEmitter {
503502 ) : Promise < ISendToDeviceFromWidgetResponseData > {
504503 return this . transport . send < ISendToDeviceFromWidgetRequestData , ISendToDeviceFromWidgetResponseData > (
505504 WidgetApiFromWidgetAction . SendToDevice ,
506- { type : eventType , encrypted, messages : contentMap } ,
505+ {
506+ type : eventType ,
507+ encrypted,
508+ messages : contentMap ,
509+ } ,
507510 ) ;
508511 }
509512
510- public readRoomAccountData ( eventType : string , roomIds ?: ( string | Symbols . AnyRoom ) [ ] ) : Promise < IRoomAccountData [ ] > {
513+ public async readRoomAccountData (
514+ eventType : string ,
515+ roomIds ?: ( string | Symbols . AnyRoom ) [ ] ,
516+ ) : Promise < IRoomAccountData [ ] > {
511517 const data : IReadEventFromWidgetRequestData = { type : eventType } ;
512518
513519 if ( roomIds ) {
@@ -517,15 +523,14 @@ export class WidgetApi extends EventEmitter {
517523 data . room_ids = roomIds ;
518524 }
519525 }
520- return this . transport
521- . send <
522- IReadRoomAccountDataFromWidgetRequestData ,
523- IReadRoomAccountDataFromWidgetResponseData
524- > ( WidgetApiFromWidgetAction . BeeperReadRoomAccountData , data )
525- . then ( ( r ) => r . events ) ;
526+ const r = await this . transport . send <
527+ IReadRoomAccountDataFromWidgetRequestData ,
528+ IReadRoomAccountDataFromWidgetResponseData
529+ > ( WidgetApiFromWidgetAction . BeeperReadRoomAccountData , data ) ;
530+ return r . events ;
526531 }
527532
528- public readRoomEvents (
533+ public async readRoomEvents (
529534 eventType : string ,
530535 limit ?: number ,
531536 msgtype ?: string ,
@@ -546,12 +551,11 @@ export class WidgetApi extends EventEmitter {
546551 if ( since ) {
547552 data . since = since ;
548553 }
549- return this . transport
550- . send <
551- IReadEventFromWidgetRequestData ,
552- IReadEventFromWidgetResponseData
553- > ( WidgetApiFromWidgetAction . MSC2876ReadEvents , data )
554- . then ( ( r ) => r . events ) ;
554+ const r = await this . transport . send < IReadEventFromWidgetRequestData , IReadEventFromWidgetResponseData > (
555+ WidgetApiFromWidgetAction . MSC2876ReadEvents ,
556+ data ,
557+ ) ;
558+ return r . events ;
555559 }
556560
557561 /**
@@ -605,7 +609,7 @@ export class WidgetApi extends EventEmitter {
605609 ) ;
606610 }
607611
608- public readStateEvents (
612+ public async readStateEvents (
609613 eventType : string ,
610614 limit ?: number ,
611615 stateKey ?: string ,
@@ -625,12 +629,11 @@ export class WidgetApi extends EventEmitter {
625629 data . room_ids = roomIds ;
626630 }
627631 }
628- return this . transport
629- . send <
630- IReadEventFromWidgetRequestData ,
631- IReadEventFromWidgetResponseData
632- > ( WidgetApiFromWidgetAction . MSC2876ReadEvents , data )
633- . then ( ( r ) => r . events ) ;
632+ const r = await this . transport . send < IReadEventFromWidgetRequestData , IReadEventFromWidgetResponseData > (
633+ WidgetApiFromWidgetAction . MSC2876ReadEvents ,
634+ data ,
635+ ) ;
636+ return r . events ;
634637 }
635638
636639 /**
@@ -640,16 +643,17 @@ export class WidgetApi extends EventEmitter {
640643 * @returns {Promise<void> } Resolves when complete.
641644 * @throws Throws if the button cannot be disabled, or the client refuses to disable the button.
642645 */
643- public setModalButtonEnabled ( buttonId : ModalButtonID , isEnabled : boolean ) : Promise < void > {
646+ public async setModalButtonEnabled ( buttonId : ModalButtonID , isEnabled : boolean ) : Promise < void > {
644647 if ( buttonId === BuiltInModalButtonID . Close ) {
645648 throw new Error ( "The close button cannot be disabled" ) ;
646649 }
647- return this . transport
648- . send < ISetModalButtonEnabledActionRequestData > ( WidgetApiFromWidgetAction . SetModalButtonEnabled , {
650+ await this . transport . send < ISetModalButtonEnabledActionRequestData > (
651+ WidgetApiFromWidgetAction . SetModalButtonEnabled ,
652+ {
649653 button : buttonId ,
650654 enabled : isEnabled ,
651- } )
652- . then ( ) ;
655+ } ,
656+ ) ;
653657 }
654658
655659 /**
@@ -660,14 +664,12 @@ export class WidgetApi extends EventEmitter {
660664 * @throws Throws if the URI is invalid or cannot be processed.
661665 * @deprecated This currently relies on an unstable MSC (MSC2931).
662666 */
663- public navigateTo ( uri : string ) : Promise < void > {
667+ public async navigateTo ( uri : string ) : Promise < void > {
664668 if ( ! uri || ! uri . startsWith ( "https://matrix.to/#" ) ) {
665669 throw new Error ( "Invalid matrix.to URI" ) ;
666670 }
667671
668- return this . transport
669- . send < INavigateActionRequestData > ( WidgetApiFromWidgetAction . MSC2931Navigate , { uri } )
670- . then ( ) ;
672+ await this . transport . send < INavigateActionRequestData > ( WidgetApiFromWidgetAction . MSC2931Navigate , { uri } ) ;
671673 }
672674
673675 /**
@@ -681,7 +683,7 @@ export class WidgetApi extends EventEmitter {
681683 const onUpdateTurnServers = async ( ev : CustomEvent < IUpdateTurnServersRequest > ) : Promise < void > => {
682684 ev . preventDefault ( ) ;
683685 setTurnServer ( ev . detail . data ) ;
684- await this . transport . reply < IWidgetApiAcknowledgeResponseData > ( ev . detail , { } ) ;
686+ this . transport . reply < IWidgetApiAcknowledgeResponseData > ( ev . detail , { } ) ;
685687 } ;
686688
687689 // Start listening for updates before we even start watching, to catch
@@ -849,24 +851,22 @@ export class WidgetApi extends EventEmitter {
849851 } ) ;
850852 }
851853
852- public getClientVersions ( ) : Promise < ApiVersion [ ] > {
854+ public async getClientVersions ( ) : Promise < ApiVersion [ ] > {
853855 if ( Array . isArray ( this . cachedClientVersions ) ) {
854856 return Promise . resolve ( this . cachedClientVersions ) ;
855857 }
856858
857- return this . transport
858- . send < IWidgetApiRequestEmptyData , ISupportedVersionsActionResponseData > (
859+ try {
860+ const r = await this . transport . send < IWidgetApiRequestEmptyData , ISupportedVersionsActionResponseData > (
859861 WidgetApiFromWidgetAction . SupportedApiVersions ,
860862 { } ,
861- )
862- . then ( ( r ) => {
863- this . cachedClientVersions = r . supported_versions ;
864- return r . supported_versions ;
865- } )
866- . catch ( ( e ) => {
867- console . warn ( "non-fatal error getting supported client versions: " , e ) ;
868- return [ ] ;
869- } ) ;
863+ ) ;
864+ this . cachedClientVersions = r . supported_versions ;
865+ return r . supported_versions ;
866+ } catch ( e ) {
867+ console . warn ( "non-fatal error getting supported client versions: " , e ) ;
868+ return [ ] ;
869+ }
870870 }
871871
872872 private handleCapabilities ( request : ICapabilitiesActionRequest ) : void | Promise < void > {
0 commit comments