@@ -52,7 +52,16 @@ import {
52
52
type GroupCallEventHandlerEventHandlerMap ,
53
53
} from "./webrtc/groupCallEventHandler.ts" ;
54
54
import * as utils from "./utils.ts" ;
55
- import { deepCompare , defer , noUnsafeEventProps , type QueryDict , replaceParam , safeSet , sleep } from "./utils.ts" ;
55
+ import {
56
+ deepCompare ,
57
+ defer ,
58
+ MapWithDefault ,
59
+ noUnsafeEventProps ,
60
+ type QueryDict ,
61
+ replaceParam ,
62
+ safeSet ,
63
+ sleep ,
64
+ } from "./utils.ts" ;
56
65
import { Direction , EventTimeline } from "./models/event-timeline.ts" ;
57
66
import { type IActionsObject , PushProcessor } from "./pushprocessor.ts" ;
58
67
import { AutoDiscovery , type AutoDiscoveryAction } from "./autodiscovery.ts" ;
@@ -7948,7 +7957,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
7948
7957
* @param eventType - The type of event to send
7949
7958
* @param devices - The list of devices to send the event to.
7950
7959
* @param payload - The payload to send. This will be encrypted.
7951
- * @returns Promise which resolves once queued there is no error feedback when sending fails.
7960
+ * @returns Promise which resolves once send there. Can be rejected with an error if sending fails
7961
+ * Sending will retry automatically but there is a Max retries limit.
7952
7962
*/
7953
7963
public async encryptAndSendToDevice (
7954
7964
eventType : string ,
@@ -7960,9 +7970,20 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
7960
7970
}
7961
7971
const batch = await this . cryptoBackend . encryptToDeviceMessages ( eventType , devices , payload ) ;
7962
7972
7963
- // TODO The batch mechanism removes all possibility to get error feedbacks..
7964
- // We might want instead to do the API call directly and pass the errors back.
7965
- await this . queueToDevice ( batch ) ;
7973
+ const contentMap : MapWithDefault < string , Map < string , ToDevicePayload > > = new MapWithDefault ( ( ) => new Map ( ) ) ;
7974
+ for ( const item of batch . batch ) {
7975
+ contentMap . getOrCreate ( item . userId ) . set ( item . deviceId , item . payload ) ;
7976
+ }
7977
+
7978
+ return new Promise < void > ( ( resolve , reject ) => {
7979
+ this . queueToDevice ( batch , ( result ) => {
7980
+ if ( result === undefined ) {
7981
+ resolve ;
7982
+ } else if ( result ) {
7983
+ reject ( result ) ;
7984
+ }
7985
+ } ) ;
7986
+ } ) ;
7966
7987
}
7967
7988
7968
7989
/**
@@ -7971,9 +7992,11 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
7971
7992
* batches for sending and stored in the store so they can be retried
7972
7993
* later if they fail to send. Retries will happen automatically.
7973
7994
* @param batch - The to-device messages to send
7995
+ * @param sendCallback - Optional callback to call when the batch is sent
7996
+ * @returns Promise which resolves once the batch is queued.
7974
7997
*/
7975
- public queueToDevice ( batch : ToDeviceBatch ) : Promise < void > {
7976
- return this . toDeviceMessageQueue . queueBatch ( batch ) ;
7998
+ public queueToDevice ( batch : ToDeviceBatch , sendCallback ?: ( result : Error | undefined ) => void ) : Promise < void > {
7999
+ return this . toDeviceMessageQueue . queueBatch ( batch , sendCallback ) ;
7977
8000
}
7978
8001
7979
8002
/**
0 commit comments