|
| 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