@@ -26,6 +26,7 @@ import { buildMatrixQaMessageContent } from "./client-message-content.js";
2626import {
2727 MATRIX_QA_E2EE_SYNC_FILTER ,
2828 prepareMatrixQaE2eeStorage ,
29+ runMatrixQaE2eeClientOperation ,
2930 shouldRecordMatrixQaObservedEventUpdate ,
3031 type MatrixQaE2eeActorId ,
3132} from "./e2ee-client-internals.js" ;
@@ -391,6 +392,13 @@ export async function createMatrixQaE2eeScenarioClient(
391392 }
392393 return client . crypto ;
393394 } ;
395+ const runClientOperation = < T > ( label : string , run : ( ) => Promise < T > ) =>
396+ runMatrixQaE2eeClientOperation ( {
397+ label,
398+ run,
399+ stop : ( ) => client . stopWithoutPersist ( ) ,
400+ timeoutMs : params . timeoutMs ,
401+ } ) ;
394402
395403 return {
396404 async acceptVerification ( id ) {
@@ -452,16 +460,17 @@ export async function createMatrixQaE2eeScenarioClient(
452460 return await requireCrypto ( ) . scanVerificationQr ( id , qrDataBase64 ) ;
453461 } ,
454462 async sendTextMessage ( opts ) {
455- return await client . sendMessage (
456- opts . roomId ,
457- buildMatrixQaMessageContent ( opts ) as MessageEventContent ,
463+ return await runClientOperation ( "Matrix E2EE text send" , ( ) =>
464+ client . sendMessage ( opts . roomId , buildMatrixQaMessageContent ( opts ) as MessageEventContent ) ,
458465 ) ;
459466 } ,
460467 async sendNoticeMessage ( opts ) {
461- return await client . sendMessage ( opts . roomId , {
462- ...buildMatrixQaMessageContent ( opts ) ,
463- msgtype : "m.notice" ,
464- } as MessageEventContent ) ;
468+ return await runClientOperation ( "Matrix E2EE notice send" , ( ) =>
469+ client . sendMessage ( opts . roomId , {
470+ ...buildMatrixQaMessageContent ( opts ) ,
471+ msgtype : "m.notice" ,
472+ } as MessageEventContent ) ,
473+ ) ;
465474 } ,
466475 async sendImageMessage ( opts ) {
467476 const encrypted = await requireCrypto ( ) . encryptMedia ( opts . buffer ) ;
@@ -471,19 +480,21 @@ export async function createMatrixQaE2eeScenarioClient(
471480 opts . fileName ,
472481 ) ;
473482 const file : EncryptedFile = { url : contentUri , ...encrypted . file } ;
474- return await client . sendMessage ( opts . roomId , {
475- ...buildMatrixQaMessageContent ( {
476- body : opts . body ,
477- mentionUserIds : opts . mentionUserIds ,
478- } ) ,
479- file,
480- filename : opts . fileName ,
481- info : {
482- mimetype : opts . contentType ,
483- size : opts . buffer . byteLength ,
484- } ,
485- msgtype : "m.image" ,
486- } as MessageEventContent ) ;
483+ return await runClientOperation ( "Matrix E2EE image send" , ( ) =>
484+ client . sendMessage ( opts . roomId , {
485+ ...buildMatrixQaMessageContent ( {
486+ body : opts . body ,
487+ mentionUserIds : opts . mentionUserIds ,
488+ } ) ,
489+ file,
490+ filename : opts . fileName ,
491+ info : {
492+ mimetype : opts . contentType ,
493+ size : opts . buffer . byteLength ,
494+ } ,
495+ msgtype : "m.image" ,
496+ } as MessageEventContent ) ,
497+ ) ;
487498 } ,
488499 async startVerification ( id , method ) {
489500 return await requireCrypto ( ) . startVerification ( id , method ) ;
0 commit comments