@@ -19,6 +19,7 @@ import {
19
19
EventDirection ,
20
20
IOpenIDCredentials ,
21
21
IOpenIDUpdate ,
22
+ ISendDelayedEventDetails ,
22
23
ISendEventDetails ,
23
24
ITurnServer ,
24
25
IReadEventRelationsResult ,
@@ -33,6 +34,7 @@ import {
33
34
WidgetKind ,
34
35
ISearchUserDirectoryResult ,
35
36
IGetMediaConfigResult ,
37
+ UpdateDelayedEventAction ,
36
38
} from "matrix-widget-api" ;
37
39
import {
38
40
ClientEvent ,
@@ -43,6 +45,7 @@ import {
43
45
Room ,
44
46
Direction ,
45
47
THREAD_RELATION_TYPE ,
48
+ SendDelayedEventResponse ,
46
49
StateEvents ,
47
50
TimelineEvents ,
48
51
} from "matrix-js-sdk/src/matrix" ;
@@ -128,6 +131,8 @@ export class StopGapWidgetDriver extends WidgetDriver {
128
131
this . allowedCapabilities . add ( MatrixCapabilities . AlwaysOnScreen ) ;
129
132
this . allowedCapabilities . add ( MatrixCapabilities . MSC3846TurnServers ) ;
130
133
this . allowedCapabilities . add ( `org.matrix.msc2762.timeline:${ inRoomId } ` ) ;
134
+ this . allowedCapabilities . add ( MatrixCapabilities . MSC4157SendDelayedEvent ) ;
135
+ this . allowedCapabilities . add ( MatrixCapabilities . MSC4157UpdateDelayedEvent ) ;
131
136
132
137
this . allowedCapabilities . add (
133
138
WidgetEventCapability . forRoomEvent ( EventDirection . Send , "org.matrix.rageshake_request" ) . raw ,
@@ -160,7 +165,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
160
165
`_${ clientUserId } _${ clientDeviceId } ` ,
161
166
) . raw ,
162
167
) ;
163
- // MSC3779 version, with no leading underscore
168
+ // Version with no leading underscore, for room versions whose auth rules allow it
164
169
this . allowedCapabilities . add (
165
170
WidgetEventCapability . forStateEvent (
166
171
EventDirection . Send ,
@@ -271,20 +276,20 @@ export class StopGapWidgetDriver extends WidgetDriver {
271
276
public async sendEvent < K extends keyof StateEvents > (
272
277
eventType : K ,
273
278
content : StateEvents [ K ] ,
274
- stateKey ? : string ,
275
- targetRoomId ? : string ,
279
+ stateKey : string | null ,
280
+ targetRoomId : string | null ,
276
281
) : Promise < ISendEventDetails > ;
277
282
public async sendEvent < K extends keyof TimelineEvents > (
278
283
eventType : K ,
279
284
content : TimelineEvents [ K ] ,
280
285
stateKey : null ,
281
- targetRoomId ? : string ,
286
+ targetRoomId : string | null ,
282
287
) : Promise < ISendEventDetails > ;
283
288
public async sendEvent (
284
289
eventType : string ,
285
290
content : IContent ,
286
- stateKey ? : string | null ,
287
- targetRoomId ? : string ,
291
+ stateKey : string | null = null ,
292
+ targetRoomId : string | null = null ,
288
293
) : Promise < ISendEventDetails > {
289
294
const client = MatrixClientPeg . get ( ) ;
290
295
const roomId = targetRoomId || SdkContextClass . instance . roomViewStore . getRoomId ( ) ;
@@ -328,6 +333,94 @@ export class StopGapWidgetDriver extends WidgetDriver {
328
333
return { roomId, eventId : r . event_id } ;
329
334
}
330
335
336
+ /**
337
+ * @experimental Part of MSC4140 & MSC4157
338
+ * @see {@link WidgetDriver#sendDelayedEvent }
339
+ */
340
+ public async sendDelayedEvent < K extends keyof StateEvents > (
341
+ delay : number | null ,
342
+ parentDelayId : string | null ,
343
+ eventType : K ,
344
+ content : StateEvents [ K ] ,
345
+ stateKey : string | null ,
346
+ targetRoomId : string | null ,
347
+ ) : Promise < ISendDelayedEventDetails > ;
348
+ /**
349
+ * @experimental Part of MSC4140 & MSC4157
350
+ */
351
+ public async sendDelayedEvent < K extends keyof TimelineEvents > (
352
+ delay : number | null ,
353
+ parentDelayId : string | null ,
354
+ eventType : K ,
355
+ content : TimelineEvents [ K ] ,
356
+ stateKey : null ,
357
+ targetRoomId : string | null ,
358
+ ) : Promise < ISendDelayedEventDetails > ;
359
+ public async sendDelayedEvent (
360
+ delay : number | null ,
361
+ parentDelayId : string | null ,
362
+ eventType : string ,
363
+ content : IContent ,
364
+ stateKey : string | null = null ,
365
+ targetRoomId : string | null = null ,
366
+ ) : Promise < ISendDelayedEventDetails > {
367
+ const client = MatrixClientPeg . get ( ) ;
368
+ const roomId = targetRoomId || SdkContextClass . instance . roomViewStore . getRoomId ( ) ;
369
+
370
+ if ( ! client || ! roomId ) throw new Error ( "Not in a room or not attached to a client" ) ;
371
+
372
+ let delayOpts ;
373
+ if ( delay !== null ) {
374
+ delayOpts = {
375
+ delay,
376
+ ...( parentDelayId !== null && { parent_delay_id : parentDelayId } ) ,
377
+ } ;
378
+ } else if ( parentDelayId !== null ) {
379
+ delayOpts = {
380
+ parent_delay_id : parentDelayId ,
381
+ } ;
382
+ } else {
383
+ throw new Error ( "Must provide at least one of delay or parentDelayId" ) ;
384
+ }
385
+
386
+ let r : SendDelayedEventResponse | null ;
387
+ if ( stateKey !== null ) {
388
+ // state event
389
+ r = await client . _unstable_sendDelayedStateEvent (
390
+ roomId ,
391
+ delayOpts ,
392
+ eventType as keyof StateEvents ,
393
+ content as StateEvents [ keyof StateEvents ] ,
394
+ stateKey ,
395
+ ) ;
396
+ } else {
397
+ // message event
398
+ r = await client . _unstable_sendDelayedEvent (
399
+ roomId ,
400
+ delayOpts ,
401
+ null ,
402
+ eventType as keyof TimelineEvents ,
403
+ content as TimelineEvents [ keyof TimelineEvents ] ,
404
+ ) ;
405
+ }
406
+
407
+ return {
408
+ roomId,
409
+ delayId : r . delay_id ,
410
+ } ;
411
+ }
412
+
413
+ /**
414
+ * @experimental Part of MSC4140 & MSC4157
415
+ */
416
+ public async updateDelayedEvent ( delayId : string , action : UpdateDelayedEventAction ) : Promise < void > {
417
+ const client = MatrixClientPeg . get ( ) ;
418
+
419
+ if ( ! client ) throw new Error ( "Not in a room or not attached to a client" ) ;
420
+
421
+ await client . _unstable_updateDelayedEvent ( delayId , action ) ;
422
+ }
423
+
331
424
public async sendToDevice (
332
425
eventType : string ,
333
426
encrypted : boolean ,
0 commit comments