Skip to content

Commit 710d21f

Browse files
authored
Implement MSC3987: Push actions clean-up (#8530)
1 parent ce80d7f commit 710d21f

File tree

8 files changed

+11
-15
lines changed

8 files changed

+11
-15
lines changed

changelog.d/8503.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MSC3987 implementation: the 'dont_notify' action for a push_rule is now deprecated and replaced by an empty action list.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import timber.log.Timber
2020

2121
sealed class Action {
2222
object Notify : Action()
23-
object DoNotNotify : Action()
2423
data class Sound(val sound: String = ACTION_OBJECT_VALUE_VALUE_DEFAULT) : Action()
2524
data class Highlight(val highlight: Boolean) : Action()
2625

@@ -72,7 +71,6 @@ fun List<Action>.toJson(): List<Any> {
7271
return map { action ->
7372
when (action) {
7473
is Action.Notify -> Action.ACTION_NOTIFY
75-
is Action.DoNotNotify -> Action.ACTION_DONT_NOTIFY
7674
is Action.Sound -> {
7775
mapOf(
7876
Action.ACTION_OBJECT_SET_TWEAK_KEY to Action.ACTION_OBJECT_SET_TWEAK_VALUE_SOUND,
@@ -95,7 +93,7 @@ fun PushRule.getActions(): List<Action> {
9593
actions.forEach { actionStrOrObj ->
9694
when (actionStrOrObj) {
9795
Action.ACTION_NOTIFY -> Action.Notify
98-
Action.ACTION_DONT_NOTIFY -> Action.DoNotNotify
96+
Action.ACTION_DONT_NOTIFY -> return@forEach
9997
is Map<*, *> -> {
10098
when (actionStrOrObj[Action.ACTION_OBJECT_SET_TWEAK_KEY]) {
10199
Action.ACTION_OBJECT_SET_TWEAK_VALUE_SOUND -> {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ data class PushRule(
121121

122122
if (notify) {
123123
mutableActions.add(Action.ACTION_NOTIFY)
124-
} else {
125-
mutableActions.add(Action.ACTION_DONT_NOTIFY)
126124
}
127125

128126
return copy(actions = mutableActions)
@@ -140,5 +138,5 @@ data class PushRule(
140138
*
141139
* @return true if the rule should not play sound
142140
*/
143-
fun shouldNotNotify() = actions.contains(Action.ACTION_DONT_NOTIFY)
141+
fun shouldNotNotify() = actions.isEmpty() || actions.contains(Action.ACTION_DONT_NOTIFY)
144142
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/notification/RoomPushRuleMapper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal fun RoomNotificationState.toRoomPushRule(roomId: String): RoomPushRule?
6363
pattern = roomId
6464
)
6565
val rule = PushRule(
66-
actions = listOf(Action.DoNotNotify).toJson(),
66+
actions = emptyList<Action>().toJson(),
6767
enabled = true,
6868
ruleId = roomId,
6969
conditions = listOf(condition)
@@ -81,7 +81,7 @@ internal fun RoomNotificationState.toRoomPushRule(roomId: String): RoomPushRule?
8181
internal fun RoomPushRule.toRoomNotificationState(): RoomNotificationState {
8282
return if (rule.enabled) {
8383
val actions = rule.getActions()
84-
if (actions.contains(Action.DoNotNotify)) {
84+
if (actions.isEmpty()) {
8585
if (kind == RuleSetKey.OVERRIDE) {
8686
RoomNotificationState.MUTE
8787
} else {

vector/src/main/java/im/vector/app/features/notifications/NotificationAction.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ fun List<Action>.toNotificationAction(): NotificationAction {
3030
forEach { action ->
3131
when (action) {
3232
is Action.Notify -> shouldNotify = true
33-
is Action.DoNotNotify -> shouldNotify = false
3433
is Action.Highlight -> highlight = action.highlight
3534
is Action.Sound -> sound = action.sound
3635
}

vector/src/main/java/im/vector/app/features/settings/notifications/StandardActions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ sealed class StandardActions(
2626
object NotifyRingSound : StandardActions(actions = listOf(Action.Notify, Action.Sound(sound = Action.ACTION_OBJECT_VALUE_VALUE_RING)))
2727
object Highlight : StandardActions(actions = listOf(Action.Notify, Action.Highlight(highlight = true)))
2828
object HighlightDefaultSound : StandardActions(actions = listOf(Action.Notify, Action.Highlight(highlight = true), Action.Sound()))
29-
object DontNotify : StandardActions(actions = listOf(Action.DoNotNotify))
29+
object DontNotify : StandardActions(actions = emptyList())
3030
object Disabled : StandardActions(actions = null)
3131
}

vector/src/test/java/im/vector/app/features/settings/notifications/usecase/GetPushRulesOnInvalidStateUseCaseTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ internal class GetPushRulesOnInvalidStateUseCaseTest {
4848
fun `given a list of push rules with children not matching their parent when execute then returns the list of not matching rules`() {
4949
// Given
5050
val firstActions = listOf(Action.Notify)
51-
val secondActions = listOf(Action.DoNotNotify)
51+
val secondActions = emptyList<Action>()
5252
givenARuleList(
5353
listOf(
5454
// first set of related rules
5555
givenARuleId(RuleIds.RULE_ID_ONE_TO_ONE_ROOM, true, firstActions),
56-
givenARuleId(RuleIds.RULE_ID_POLL_START_ONE_TO_ONE, true, listOf(Action.DoNotNotify)), // diff
56+
givenARuleId(RuleIds.RULE_ID_POLL_START_ONE_TO_ONE, true, emptyList()), // diff
5757
givenARuleId(RuleIds.RULE_ID_POLL_START_ONE_TO_ONE_UNSTABLE, true, emptyList()), // diff
5858
givenARuleId(RuleIds.RULE_ID_POLL_END_ONE_TO_ONE, false, listOf(Action.Notify)), // diff
5959
givenARuleId(RuleIds.RULE_ID_POLL_END_ONE_TO_ONE_UNSTABLE, true, listOf(Action.Notify)),
6060
// second set of related rules
6161
givenARuleId(RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS, false, secondActions),
6262
givenARuleId(RuleIds.RULE_ID_POLL_START, true, listOf(Action.Notify)), // diff
63-
givenARuleId(RuleIds.RULE_ID_POLL_START_UNSTABLE, false, listOf(Action.DoNotNotify)),
63+
givenARuleId(RuleIds.RULE_ID_POLL_START_UNSTABLE, false, emptyList()),
6464
givenARuleId(RuleIds.RULE_ID_POLL_END, false, listOf(Action.Notify)), // diff
6565
givenARuleId(RuleIds.RULE_ID_POLL_END_UNSTABLE, true, listOf()), // diff
6666
// Another rule

vector/src/test/java/im/vector/app/features/settings/notifications/usecase/UpdatePushRulesIfNeededUseCaseTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ internal class UpdatePushRulesIfNeededUseCaseTest {
5454
val firstParentActions = listOf(Action.Notify)
5555
val firstParent = givenARuleId(RuleIds.RULE_ID_ONE_TO_ONE_ROOM, firstParentEnabled, firstParentActions)
5656
val secondParentEnabled = false
57-
val secondParentActions = listOf(Action.DoNotNotify)
57+
val secondParentActions = emptyList<Action>()
5858
val secondParent = givenARuleId(RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS, secondParentEnabled, secondParentActions)
5959
val rulesOnError = listOf(
6060
// first set of related rules
6161
firstParent,
62-
givenARuleId(RuleIds.RULE_ID_POLL_START_ONE_TO_ONE, true, listOf(Action.DoNotNotify)), // diff
62+
givenARuleId(RuleIds.RULE_ID_POLL_START_ONE_TO_ONE, true, emptyList()), // diff
6363
givenARuleId(RuleIds.RULE_ID_POLL_START_ONE_TO_ONE_UNSTABLE, true, emptyList()), // diff
6464
givenARuleId(RuleIds.RULE_ID_POLL_END_ONE_TO_ONE, false, listOf(Action.Notify)), // diff
6565
// second set of related rules

0 commit comments

Comments
 (0)