@@ -13,6 +13,7 @@ import {
1313 type MatrixClient ,
1414 ClientEvent ,
1515 RoomStateEvent ,
16+ type ReceivedToDeviceMessage ,
1617} from "matrix-js-sdk/src/matrix" ;
1718import { KnownMembership } from "matrix-js-sdk/src/types" ;
1819import {
@@ -360,7 +361,7 @@ export class StopGapWidget extends EventEmitter {
360361 this . client . on ( ClientEvent . Event , this . onEvent ) ;
361362 this . client . on ( MatrixEventEvent . Decrypted , this . onEventDecrypted ) ;
362363 this . client . on ( RoomStateEvent . Events , this . onStateUpdate ) ;
363- this . client . on ( ClientEvent . ToDeviceEvent , this . onToDeviceEvent ) ;
364+ this . client . on ( ClientEvent . ReceivedToDeviceMessage , this . onToDeviceMessage ) ;
364365
365366 this . messaging . on (
366367 `action:${ WidgetApiFromWidgetAction . UpdateAlwaysOnScreen } ` ,
@@ -493,7 +494,7 @@ export class StopGapWidget extends EventEmitter {
493494 this . client . off ( ClientEvent . Event , this . onEvent ) ;
494495 this . client . off ( MatrixEventEvent . Decrypted , this . onEventDecrypted ) ;
495496 this . client . off ( RoomStateEvent . Events , this . onStateUpdate ) ;
496- this . client . off ( ClientEvent . ToDeviceEvent , this . onToDeviceEvent ) ;
497+ this . client . off ( ClientEvent . ReceivedToDeviceMessage , this . onToDeviceMessage ) ;
497498 }
498499
499500 private onEvent = ( ev : MatrixEvent ) : void => {
@@ -513,10 +514,10 @@ export class StopGapWidget extends EventEmitter {
513514 } ) ;
514515 } ;
515516
516- private onToDeviceEvent = async ( ev : MatrixEvent ) : Promise < void > => {
517- await this . client . decryptEventIfNeeded ( ev ) ;
518- if ( ev . isDecryptionFailure ( ) ) return ;
519- await this . messaging ?. feedToDevice ( ev . getEffectiveEvent ( ) as IRoomEvent , ev . isEncrypted ( ) ) ;
517+ private onToDeviceMessage = async ( payload : ReceivedToDeviceMessage ) : Promise < void > => {
518+ const { message , encryptionInfo } = payload ;
519+ // TODO: Update the widget API to use a proper IToDeviceMessage instead of a IRoomEvent
520+ await this . messaging ?. feedToDevice ( message as IRoomEvent , encryptionInfo != null ) ;
520521 } ;
521522
522523 /**
0 commit comments