Skip to content

Commit 367fcfa

Browse files
authored
Merge pull request #8945 from element-hq/feature/bma/elementCallNotification
Ensure m.call.notify event is not filtered out by push rules.
2 parents 93962d0 + 591ec10 commit 367fcfa

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushrules/RuleIds.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ object RuleIds {
5757
const val RULE_ID_POLL_END = ".m.rule.poll_end"
5858
const val RULE_ID_POLL_END_UNSTABLE = ".org.matrix.msc3930.rule.poll_end"
5959

60+
const val RULE_ID_ELEMENT_CALL_NOTIFY = ".m.call.notify"
61+
const val RULE_ID_ELEMENT_CALL_NOTIFY_UNSTABLE = ".org.matrix.msc4075.call.notify"
62+
6063
// Not documented
6164
const val RULE_ID_FALLBACK = ".m.rule.fallback"
6265

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushrules/DefaultPushRuleService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ internal class DefaultPushRuleService @Inject constructor(
103103
}
104104

105105
return RuleSet(
106-
content = contentRules,
106+
content = contentRules.withElementCallPushRules(),
107107
override = overrideRules,
108108
room = roomRules,
109109
sender = senderRules,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2024 The Matrix.org Foundation C.I.C.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.matrix.android.sdk.internal.session.pushrules
18+
19+
import org.matrix.android.sdk.api.session.pushrules.Action
20+
import org.matrix.android.sdk.api.session.pushrules.RuleIds
21+
import org.matrix.android.sdk.api.session.pushrules.rest.PushCondition
22+
import org.matrix.android.sdk.api.session.pushrules.rest.PushRule
23+
24+
private val localElementCallPushRule = PushRule(
25+
ruleId = RuleIds.RULE_ID_ELEMENT_CALL_NOTIFY,
26+
conditions = listOf(
27+
PushCondition(
28+
kind = "event_match",
29+
key = "type",
30+
pattern = "m.call.notify",
31+
)
32+
),
33+
actions = listOf(
34+
Action.ACTION_NOTIFY,
35+
),
36+
enabled = true,
37+
)
38+
39+
private val localElementCallPushRuleUnstable = PushRule(
40+
ruleId = RuleIds.RULE_ID_ELEMENT_CALL_NOTIFY_UNSTABLE,
41+
conditions = listOf(
42+
PushCondition(
43+
kind = "event_match",
44+
key = "type",
45+
pattern = "org.matrix.msc4075.call.notify",
46+
)
47+
),
48+
actions = listOf(
49+
Action.ACTION_NOTIFY,
50+
),
51+
enabled = true,
52+
)
53+
54+
/**
55+
* Ensure that the element call push rules are present.
56+
*/
57+
fun List<PushRule>.withElementCallPushRules(): List<PushRule> {
58+
val ruleIds = map { it.ruleId }
59+
return buildList {
60+
addAll(this@withElementCallPushRules)
61+
if (!ruleIds.contains(localElementCallPushRule.ruleId)) {
62+
add(localElementCallPushRule)
63+
}
64+
if (!ruleIds.contains(localElementCallPushRuleUnstable.ruleId)) {
65+
add(localElementCallPushRuleUnstable)
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)