@@ -21,6 +21,8 @@ import { MatrixEvent } from "./models/event";
21
21
import {
22
22
ConditionKind ,
23
23
IAnnotatedPushRule ,
24
+ ICallStartedCondition ,
25
+ ICallStartedPrefixCondition ,
24
26
IContainsDisplayNameCondition ,
25
27
IEventMatchCondition ,
26
28
IPushRule ,
@@ -92,8 +94,8 @@ const DEFAULT_OVERRIDE_RULES: IPushRule[] = [
92
94
actions : [ ] ,
93
95
} ,
94
96
{
95
- // For homeservers which don't support MSC3401 yet
96
- rule_id : ".org.matrix.msc3401 .rule.room.call" ,
97
+ // For homeservers which don't support MSC3914 yet
98
+ rule_id : ".org.matrix.msc3914 .rule.room.call" ,
97
99
default : true ,
98
100
enabled : true ,
99
101
conditions : [
@@ -102,6 +104,9 @@ const DEFAULT_OVERRIDE_RULES: IPushRule[] = [
102
104
key : "type" ,
103
105
pattern : "org.matrix.msc3401.call" ,
104
106
} ,
107
+ {
108
+ kind : ConditionKind . CallStarted ,
109
+ } ,
105
110
] ,
106
111
actions : [ PushRuleActionName . Notify , { set_tweak : TweakName . Sound , value : "default" } ] ,
107
112
} ,
@@ -269,6 +274,9 @@ export class PushProcessor {
269
274
return this . eventFulfillsRoomMemberCountCondition ( cond , ev ) ;
270
275
case ConditionKind . SenderNotificationPermission :
271
276
return this . eventFulfillsSenderNotifPermCondition ( cond , ev ) ;
277
+ case ConditionKind . CallStarted :
278
+ case ConditionKind . CallStartedPrefix :
279
+ return this . eventFulfillsCallStartedCondition ( cond , ev ) ;
272
280
}
273
281
274
282
// unknown conditions: we previously matched all unknown conditions,
@@ -383,6 +391,22 @@ export class PushProcessor {
383
391
return ! ! val . match ( regex ) ;
384
392
}
385
393
394
+ private eventFulfillsCallStartedCondition (
395
+ _cond : ICallStartedCondition | ICallStartedPrefixCondition ,
396
+ ev : MatrixEvent ,
397
+ ) : boolean {
398
+ // Since servers don't support properly sending push notification
399
+ // about MSC3401 call events, we do the handling ourselves
400
+ return (
401
+ [ "m.ring" , "m.prompt" ] . includes ( ev . getContent ( ) [ "m.intent" ] )
402
+ && ! ( "m.terminated" in ev . getContent ( ) )
403
+ && (
404
+ ( ev . getPrevContent ( ) [ "m.terminated" ] !== ev . getContent ( ) [ "m.terminated" ] )
405
+ || deepCompare ( ev . getPrevContent ( ) , { } )
406
+ )
407
+ ) ;
408
+ }
409
+
386
410
private createCachedRegex ( prefix : string , glob : string , suffix : string ) : RegExp {
387
411
if ( PushProcessor . cachedGlobToRegex [ glob ] ) {
388
412
return PushProcessor . cachedGlobToRegex [ glob ] ;
@@ -438,7 +462,7 @@ export class PushProcessor {
438
462
return { } as IActionsObject ;
439
463
}
440
464
441
- let actionObj = PushProcessor . actionListToActionsObject ( rule . actions ) ;
465
+ const actionObj = PushProcessor . actionListToActionsObject ( rule . actions ) ;
442
466
443
467
// Some actions are implicit in some situations: we add those here
444
468
if ( actionObj . tweaks . highlight === undefined ) {
@@ -447,30 +471,6 @@ export class PushProcessor {
447
471
actionObj . tweaks . highlight = ( rule . kind == PushRuleKind . ContentSpecific ) ;
448
472
}
449
473
450
- actionObj = this . performCustomEventHandling ( ev , actionObj ) ;
451
-
452
- return actionObj ;
453
- }
454
-
455
- /**
456
- * Some events require custom event handling e.g. due to missing server support
457
- */
458
- private performCustomEventHandling ( ev : MatrixEvent , actionObj : IActionsObject ) : IActionsObject {
459
- switch ( ev . getType ( ) ) {
460
- case "m.call" :
461
- case "org.matrix.msc3401.call" :
462
- // Since servers don't support properly sending push notification
463
- // about MSC3401 call events, we do the handling ourselves
464
- if (
465
- ev . getContent ( ) [ "m.intent" ] === "m.room"
466
- || ( "m.terminated" in ev . getContent ( ) )
467
- || ! ( "m.terminated" in ev . getPrevContent ( ) ) && ! deepCompare ( ev . getPrevContent ( ) , { } )
468
- ) {
469
- actionObj . notify = false ;
470
- actionObj . tweaks = { } ;
471
- }
472
- }
473
-
474
474
return actionObj ;
475
475
}
476
476
0 commit comments