clarify sdk update and cleanup typos

This commit is contained in:
David Langley 2021-07-20 11:24:17 +01:00
parent da993b5b58
commit 608a1d3f8f
7 changed files with 59 additions and 51 deletions

1
changelog.d/3681.removal Normal file
View File

@ -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).

View File

@ -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>?)
suspend fun removePushRule(kind: RuleKind, pushRule: PushRule)

View File

@ -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
@ -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()
}
/**

View File

@ -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 }
@ -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
})
}
@ -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)
}
}
@ -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)
}
}
}

View File

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

View File

@ -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)
}

View File

@ -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()
@ -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)
}
}