mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 10:55:55 +03:00
clarify sdk update and cleanup typos
This commit is contained in:
parent
da993b5b58
commit
608a1d3f8f
7 changed files with 59 additions and 51 deletions
1
changelog.d/3681.removal
Normal file
1
changelog.d/3681.removal
Normal 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).
|
|
@ -31,6 +31,12 @@ interface PushRuleService {
|
||||||
|
|
||||||
suspend fun addPushRule(kind: RuleKind, pushRule: PushRule)
|
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 updatePushRuleActions(kind: RuleKind, ruleId: String, enable: Boolean, actions: List<Action>?)
|
||||||
|
|
||||||
suspend fun removePushRule(kind: RuleKind, pushRule: PushRule)
|
suspend fun removePushRule(kind: RuleKind, pushRule: PushRule)
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.api.pushrules.rest
|
||||||
|
|
||||||
import com.squareup.moshi.Json
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
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.Action
|
||||||
import org.matrix.android.sdk.api.pushrules.getActions
|
import org.matrix.android.sdk.api.pushrules.getActions
|
||||||
import org.matrix.android.sdk.api.pushrules.toJson
|
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.
|
* Get the highlight status. As spec mentions assume false if no tweak present.
|
||||||
*/
|
*/
|
||||||
fun getHighlight(): Boolean {
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,7 +28,7 @@ class PushRulePreference : VectorPreference {
|
||||||
enum class NotificationIndex(val index: Int) {
|
enum class NotificationIndex(val index: Int) {
|
||||||
OFF(0),
|
OFF(0),
|
||||||
SILENT(1),
|
SILENT(1),
|
||||||
NOISEY(2);
|
NOISY(2);
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun fromInt(index: Int) = values().first { it.index == index }
|
fun fromInt(index: Int) = values().first { it.index == index }
|
||||||
|
@ -67,8 +67,8 @@ class PushRulePreference : VectorPreference {
|
||||||
private fun refreshSummary() {
|
private fun refreshSummary() {
|
||||||
summary = context.getString(when (index) {
|
summary = context.getString(when (index) {
|
||||||
NotificationIndex.OFF -> R.string.notification_off
|
NotificationIndex.OFF -> R.string.notification_off
|
||||||
NotificationIndex.SILENT -> R.string.notification_silent
|
NotificationIndex.SILENT -> R.string.notification_silent
|
||||||
NotificationIndex.NOISEY, null -> R.string.notification_noisy
|
NotificationIndex.NOISY, null -> R.string.notification_noisy
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,10 +86,10 @@ class PushRulePreference : VectorPreference {
|
||||||
NotificationIndex.OFF -> {
|
NotificationIndex.OFF -> {
|
||||||
radioGroup?.check(R.id.bingPreferenceRadioBingRuleOff)
|
radioGroup?.check(R.id.bingPreferenceRadioBingRuleOff)
|
||||||
}
|
}
|
||||||
NotificationIndex.SILENT -> {
|
NotificationIndex.SILENT -> {
|
||||||
radioGroup?.check(R.id.bingPreferenceRadioBingRuleSilent)
|
radioGroup?.check(R.id.bingPreferenceRadioBingRuleSilent)
|
||||||
}
|
}
|
||||||
NotificationIndex.NOISEY -> {
|
NotificationIndex.NOISY -> {
|
||||||
radioGroup?.check(R.id.bingPreferenceRadioBingRuleNoisy)
|
radioGroup?.check(R.id.bingPreferenceRadioBingRuleNoisy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ class PushRulePreference : VectorPreference {
|
||||||
onPreferenceChangeListener?.onPreferenceChange(this, NotificationIndex.SILENT)
|
onPreferenceChangeListener?.onPreferenceChange(this, NotificationIndex.SILENT)
|
||||||
}
|
}
|
||||||
R.id.bingPreferenceRadioBingRuleNoisy -> {
|
R.id.bingPreferenceRadioBingRuleNoisy -> {
|
||||||
onPreferenceChangeListener?.onPreferenceChange(this, NotificationIndex.NOISEY)
|
onPreferenceChangeListener?.onPreferenceChange(this, NotificationIndex.NOISY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,73 +19,73 @@ package im.vector.app.features.settings.notifications
|
||||||
import im.vector.app.core.preference.PushRulePreference
|
import im.vector.app.core.preference.PushRulePreference
|
||||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
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) {
|
return when (ruleId) {
|
||||||
RuleIds.RULE_ID_CONTAIN_DISPLAY_NAME ->
|
RuleIds.RULE_ID_CONTAIN_DISPLAY_NAME ->
|
||||||
when (index) {
|
when (index) {
|
||||||
PushRulePreference.NotificationIndex.OFF -> StandardAction.Disabled
|
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
|
||||||
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
|
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||||
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.HighlightDefaultSound
|
PushRulePreference.NotificationIndex.NOISY -> StandardActions.HighlightDefaultSound
|
||||||
}
|
}
|
||||||
RuleIds.RULE_ID_CONTAIN_USER_NAME ->
|
RuleIds.RULE_ID_CONTAIN_USER_NAME ->
|
||||||
when (index) {
|
when (index) {
|
||||||
PushRulePreference.NotificationIndex.OFF -> StandardAction.Disabled
|
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
|
||||||
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
|
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||||
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.HighlightDefaultSound
|
PushRulePreference.NotificationIndex.NOISY -> StandardActions.HighlightDefaultSound
|
||||||
}
|
}
|
||||||
RuleIds.RULE_ID_ROOM_NOTIF ->
|
RuleIds.RULE_ID_ROOM_NOTIF ->
|
||||||
when (index) {
|
when (index) {
|
||||||
PushRulePreference.NotificationIndex.OFF -> StandardAction.Disabled
|
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
|
||||||
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
|
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||||
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.Highlight
|
PushRulePreference.NotificationIndex.NOISY -> StandardActions.Highlight
|
||||||
}
|
}
|
||||||
RuleIds.RULE_ID_ONE_TO_ONE_ROOM ->
|
RuleIds.RULE_ID_ONE_TO_ONE_ROOM ->
|
||||||
when (index) {
|
when (index) {
|
||||||
PushRulePreference.NotificationIndex.OFF -> StandardAction.DontNotify
|
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
|
||||||
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
|
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||||
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyDefaultSound
|
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||||
}
|
}
|
||||||
RuleIds.RULE_ID_ONE_TO_ONE_ENCRYPTED_ROOM ->
|
RuleIds.RULE_ID_ONE_TO_ONE_ENCRYPTED_ROOM ->
|
||||||
when (index) {
|
when (index) {
|
||||||
PushRulePreference.NotificationIndex.OFF -> StandardAction.DontNotify
|
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
|
||||||
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
|
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||||
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyDefaultSound
|
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||||
}
|
}
|
||||||
RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS ->
|
RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS ->
|
||||||
when (index) {
|
when (index) {
|
||||||
PushRulePreference.NotificationIndex.OFF -> StandardAction.DontNotify
|
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
|
||||||
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
|
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||||
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyDefaultSound
|
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||||
}
|
}
|
||||||
RuleIds.RULE_ID_ENCRYPTED ->
|
RuleIds.RULE_ID_ENCRYPTED ->
|
||||||
when (index) {
|
when (index) {
|
||||||
PushRulePreference.NotificationIndex.OFF -> StandardAction.DontNotify
|
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
|
||||||
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
|
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||||
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyDefaultSound
|
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||||
}
|
}
|
||||||
RuleIds.RULE_ID_INVITE_ME ->
|
RuleIds.RULE_ID_INVITE_ME ->
|
||||||
when (index) {
|
when (index) {
|
||||||
PushRulePreference.NotificationIndex.OFF -> StandardAction.Disabled
|
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
|
||||||
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
|
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||||
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyDefaultSound
|
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||||
}
|
}
|
||||||
RuleIds.RULE_ID_CALL ->
|
RuleIds.RULE_ID_CALL ->
|
||||||
when (index) {
|
when (index) {
|
||||||
PushRulePreference.NotificationIndex.OFF -> StandardAction.Disabled
|
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
|
||||||
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
|
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||||
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyRingSound
|
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyRingSound
|
||||||
}
|
}
|
||||||
RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS ->
|
RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS ->
|
||||||
when (index) {
|
when (index) {
|
||||||
PushRulePreference.NotificationIndex.OFF -> StandardAction.DontNotify
|
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
|
||||||
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Disabled
|
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Disabled
|
||||||
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.NotifyDefaultSound
|
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||||
}
|
}
|
||||||
RuleIds.RULE_ID_TOMBSTONE ->
|
RuleIds.RULE_ID_TOMBSTONE ->
|
||||||
when (index) {
|
when (index) {
|
||||||
PushRulePreference.NotificationIndex.OFF -> StandardAction.Disabled
|
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
|
||||||
PushRulePreference.NotificationIndex.SILENT -> StandardAction.Notify
|
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||||
PushRulePreference.NotificationIndex.NOISEY -> StandardAction.Highlight
|
PushRulePreference.NotificationIndex.NOISY -> StandardActions.Highlight
|
||||||
}
|
}
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,14 @@ package im.vector.app.features.settings.notifications
|
||||||
|
|
||||||
import org.matrix.android.sdk.api.pushrules.Action
|
import org.matrix.android.sdk.api.pushrules.Action
|
||||||
|
|
||||||
sealed class StandardAction(
|
sealed class StandardActions(
|
||||||
val actions: List<Action>?
|
val actions: List<Action>?
|
||||||
) {
|
) {
|
||||||
object Notify : StandardAction(actions = listOf(Action.Notify))
|
object Notify : StandardActions(actions = listOf(Action.Notify))
|
||||||
object NotifyDefaultSound : StandardAction(actions = listOf(Action.Notify, Action.Sound()))
|
object NotifyDefaultSound : StandardActions(actions = listOf(Action.Notify, Action.Sound()))
|
||||||
object NotifyRingSound : StandardAction(actions = listOf(Action.Notify, Action.Sound(sound = Action.ACTION_OBJECT_VALUE_VALUE_RING)))
|
object NotifyRingSound : StandardActions(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 Highlight : StandardActions(actions = listOf(Action.Notify, Action.Highlight(highlight = true)))
|
||||||
object HighlightDefaultSound : StandardAction(actions = listOf(Action.Notify, Action.Highlight(highlight = true), Action.Sound()))
|
object HighlightDefaultSound : StandardActions(actions = listOf(Action.Notify, Action.Highlight(highlight = true), Action.Sound()))
|
||||||
object DontNotify : StandardAction(actions = listOf(Action.DoNotNotify))
|
object DontNotify : StandardActions(actions = listOf(Action.DoNotNotify))
|
||||||
object Disabled : StandardAction(actions = null)
|
object Disabled : StandardActions(actions = null)
|
||||||
}
|
}
|
|
@ -55,7 +55,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
|
||||||
val newIndex = newValue as NotificationIndex
|
val newIndex = newValue as NotificationIndex
|
||||||
val standardAction = getStandardAction(ruleAndKind.pushRule.ruleId, newIndex)
|
val standardAction = getStandardAction(ruleAndKind.pushRule.ruleId, newIndex)
|
||||||
if (standardAction != null) {
|
if (standardAction != null) {
|
||||||
val enabled = standardAction != StandardAction.Disabled
|
val enabled = standardAction != StandardActions.Disabled
|
||||||
val newActions = standardAction.actions
|
val newActions = standardAction.actions
|
||||||
displayLoadingView()
|
displayLoadingView()
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
|
||||||
val standardAction = getStandardAction(rule.ruleId, it) ?: return@firstOrNull false
|
val standardAction = getStandardAction(rule.ruleId, it) ?: return@firstOrNull false
|
||||||
val indexActions = standardAction.actions ?: listOf()
|
val indexActions = standardAction.actions ?: listOf()
|
||||||
// Check if the input rule matches a rule generated from the static rule definitions
|
// 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)
|
ruleMatches(rule, targetRule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue