Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Changing Account Settings > Notifications > Advanced Notifications on android causes discrepancies with web #3681

Merged
merged 8 commits into from
Jul 27, 2021
1 change: 1 addition & 0 deletions changelog.d/3681.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
updatePushRuleActions signature has been updated to more explicitly enabled/disable the rule and update the actions. It's behaviour has also been changed to match the web with the enable/disable requests being sent on every invocation and actions sent when needed(not null).
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ interface PushRuleService {

suspend fun addPushRule(kind: RuleKind, pushRule: PushRule)

/**
* Enables/Disables a push rule and updates the actions if necessary
* @param enable Enables/Disables the rule
* @param actions Actions to update if not null
*/

suspend fun updatePushRuleActions(kind: RuleKind, ruleId: String, enable: Boolean, actions: List<Action>?)
bmarty marked this conversation as resolved.
Show resolved Hide resolved

suspend fun removePushRule(kind: RuleKind, pushRule: PushRule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.matrix.android.sdk.api.pushrules.rest

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.pushrules.Action
import org.matrix.android.sdk.api.pushrules.getActions
import org.matrix.android.sdk.api.pushrules.toJson
Expand Down Expand Up @@ -104,7 +105,7 @@ data class PushRule(
* Get the highlight status. As spec mentions assume false if no tweak present.
*/
fun getHighlight(): Boolean {
return (getActions().firstOrNull { it is Action.Highlight } as? Action.Highlight)?.highlight ?: false
return (getActions().firstOrNull { it is Action.Highlight } as? Action.Highlight)?.highlight.orFalse()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you did not take my whole suggestion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As sorry, read it too quickly

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PushRulePreference : VectorPreference {
enum class NotificationIndex(val index: Int) {
OFF(0),
SILENT(1),
NOISEY(2);
NOISY(2);

companion object {
fun fromInt(index: Int) = values().first { it.index == index }
Expand Down Expand Up @@ -67,8 +67,8 @@ class PushRulePreference : VectorPreference {
private fun refreshSummary() {
summary = context.getString(when (index) {
NotificationIndex.OFF -> R.string.notification_off
NotificationIndex.SILENT -> R.string.notification_silent
NotificationIndex.NOISEY, null -> R.string.notification_noisy
NotificationIndex.SILENT -> R.string.notification_silent
NotificationIndex.NOISY, null -> R.string.notification_noisy
})
}

Expand All @@ -86,10 +86,10 @@ class PushRulePreference : VectorPreference {
NotificationIndex.OFF -> {
radioGroup?.check(R.id.bingPreferenceRadioBingRuleOff)
}
NotificationIndex.SILENT -> {
NotificationIndex.SILENT -> {
radioGroup?.check(R.id.bingPreferenceRadioBingRuleSilent)
}
NotificationIndex.NOISEY -> {
NotificationIndex.NOISY -> {
radioGroup?.check(R.id.bingPreferenceRadioBingRuleNoisy)
}
}
Expand All @@ -103,7 +103,7 @@ class PushRulePreference : VectorPreference {
onPreferenceChangeListener?.onPreferenceChange(this, NotificationIndex.SILENT)
}
R.id.bingPreferenceRadioBingRuleNoisy -> {
onPreferenceChangeListener?.onPreferenceChange(this, NotificationIndex.NOISEY)
onPreferenceChangeListener?.onPreferenceChange(this, NotificationIndex.NOISY)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,73 +19,73 @@ package im.vector.app.features.settings.notifications
import im.vector.app.core.preference.PushRulePreference
import org.matrix.android.sdk.api.pushrules.RuleIds

fun getStandardAction(ruleId: String, index: PushRulePreference.NotificationIndex): StandardAction? {
fun getStandardAction(ruleId: String, index: PushRulePreference.NotificationIndex): StandardActions? {
return when (ruleId) {
RuleIds.RULE_ID_CONTAIN_DISPLAY_NAME ->
when (index) {
PushRulePreference.NotificationIndex.OFF -> StandardAction.Disabled
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.HighlightDefaultSound
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
PushRulePreference.NotificationIndex.NOISY -> StandardActions.HighlightDefaultSound
}
RuleIds.RULE_ID_CONTAIN_USER_NAME ->
when (index) {
PushRulePreference.NotificationIndex.OFF -> StandardAction.Disabled
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.HighlightDefaultSound
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
PushRulePreference.NotificationIndex.NOISY -> StandardActions.HighlightDefaultSound
}
RuleIds.RULE_ID_ROOM_NOTIF ->
when (index) {
PushRulePreference.NotificationIndex.OFF -> StandardAction.Disabled
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.Highlight
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
PushRulePreference.NotificationIndex.NOISY -> StandardActions.Highlight
}
RuleIds.RULE_ID_ONE_TO_ONE_ROOM ->
when (index) {
PushRulePreference.NotificationIndex.OFF -> StandardAction.DontNotify
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyDefaultSound
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
}
RuleIds.RULE_ID_ONE_TO_ONE_ENCRYPTED_ROOM ->
when (index) {
PushRulePreference.NotificationIndex.OFF -> StandardAction.DontNotify
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyDefaultSound
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
}
RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS ->
when (index) {
PushRulePreference.NotificationIndex.OFF -> StandardAction.DontNotify
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyDefaultSound
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
}
RuleIds.RULE_ID_ENCRYPTED ->
when (index) {
PushRulePreference.NotificationIndex.OFF -> StandardAction.DontNotify
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyDefaultSound
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
}
RuleIds.RULE_ID_INVITE_ME ->
when (index) {
PushRulePreference.NotificationIndex.OFF -> StandardAction.Disabled
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyDefaultSound
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
}
RuleIds.RULE_ID_CALL ->
when (index) {
PushRulePreference.NotificationIndex.OFF -> StandardAction.Disabled
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyRingSound
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyRingSound
}
RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS ->
when (index) {
PushRulePreference.NotificationIndex.OFF -> StandardAction.DontNotify
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Disabled
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyDefaultSound
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Disabled
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
}
RuleIds.RULE_ID_TOMBSTONE ->
when (index) {
PushRulePreference.NotificationIndex.OFF -> StandardAction.Disabled
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.Highlight
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
PushRulePreference.NotificationIndex.NOISY -> StandardActions.Highlight
}
else -> null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package im.vector.app.features.settings.notifications

import org.matrix.android.sdk.api.pushrules.Action

sealed class StandardAction(
sealed class StandardActions(
val actions: List<Action>?
) {
object Notify : StandardAction(actions = listOf(Action.Notify))
object NotifyDefaultSound : StandardAction(actions = listOf(Action.Notify, Action.Sound()))
object NotifyRingSound : StandardAction(actions = listOf(Action.Notify, Action.Sound(sound = Action.ACTION_OBJECT_VALUE_VALUE_RING)))
object Highlight : StandardAction(actions = listOf(Action.Notify, Action.Highlight(highlight = true)))
object HighlightDefaultSound : StandardAction(actions = listOf(Action.Notify, Action.Highlight(highlight = true), Action.Sound()))
object DontNotify : StandardAction(actions = listOf(Action.DoNotNotify))
object Disabled : StandardAction(actions = null)
object Notify : StandardActions(actions = listOf(Action.Notify))
object NotifyDefaultSound : StandardActions(actions = listOf(Action.Notify, Action.Sound()))
object NotifyRingSound : StandardActions(actions = listOf(Action.Notify, Action.Sound(sound = Action.ACTION_OBJECT_VALUE_VALUE_RING)))
object Highlight : StandardActions(actions = listOf(Action.Notify, Action.Highlight(highlight = true)))
object HighlightDefaultSound : StandardActions(actions = listOf(Action.Notify, Action.Highlight(highlight = true), Action.Sound()))
object DontNotify : StandardActions(actions = listOf(Action.DoNotNotify))
object Disabled : StandardActions(actions = null)
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
val newIndex = newValue as NotificationIndex
val standardAction = getStandardAction(ruleAndKind.pushRule.ruleId, newIndex)
if (standardAction != null) {
val enabled = standardAction != StandardAction.Disabled
val enabled = standardAction != StandardActions.Disabled
val newActions = standardAction.actions
displayLoadingView()

Expand Down Expand Up @@ -93,7 +93,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
val standardAction = getStandardAction(rule.ruleId, it) ?: return@firstOrNull false
val indexActions = standardAction.actions ?: listOf()
// Check if the input rule matches a rule generated from the static rule definitions
val targetRule = rule.copy(enabled = standardAction != StandardAction.Disabled, actions = indexActions.toJson())
val targetRule = rule.copy(enabled = standardAction != StandardActions.Disabled, actions = indexActions.toJson())
ruleMatches(rule, targetRule)
}
}
Expand Down