mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-29 06:28:45 +03:00
Refactor: Remove duplicated declaration for RuleIds
This commit is contained in:
parent
aca8fd7f3d
commit
0d9885a1e0
5 changed files with 24 additions and 39 deletions
|
@ -45,4 +45,6 @@ object RuleIds {
|
||||||
|
|
||||||
// Not documented
|
// Not documented
|
||||||
const val RULE_ID_FALLBACK = ".m.rule.fallback"
|
const val RULE_ID_FALLBACK = ".m.rule.fallback"
|
||||||
|
|
||||||
|
const val RULE_ID_REACTION = ".m.rule.reaction"
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,25 +136,6 @@ data class PushRule(
|
||||||
fun shouldNotNotify() = actions.contains(ACTION_DONT_NOTIFY)
|
fun shouldNotNotify() = actions.contains(ACTION_DONT_NOTIFY)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/* ==========================================================================================
|
|
||||||
* Rule id
|
|
||||||
* ========================================================================================== */
|
|
||||||
|
|
||||||
const val RULE_ID_DISABLE_ALL = ".m.rule.master"
|
|
||||||
const val RULE_ID_CONTAIN_USER_NAME = ".m.rule.contains_user_name"
|
|
||||||
const val RULE_ID_CONTAIN_DISPLAY_NAME = ".m.rule.contains_display_name"
|
|
||||||
const val RULE_ID_ONE_TO_ONE_ROOM = ".m.rule.room_one_to_one"
|
|
||||||
const val RULE_ID_INVITE_ME = ".m.rule.invite_for_me"
|
|
||||||
const val RULE_ID_PEOPLE_JOIN_LEAVE = ".m.rule.member_event"
|
|
||||||
const val RULE_ID_CALL = ".m.rule.call"
|
|
||||||
const val RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS = ".m.rule.suppress_notices"
|
|
||||||
const val RULE_ID_ALL_OTHER_MESSAGES_ROOMS = ".m.rule.message"
|
|
||||||
const val RULE_ID_AT_ROOMS = ".m.rule.roomnotif"
|
|
||||||
const val RULE_ID_TOMBSTONE = ".m.rule.tombstone"
|
|
||||||
const val RULE_ID_E2E_ONE_TO_ONE_ROOM = ".m.rule.encrypted_room_one_to_one"
|
|
||||||
const val RULE_ID_E2E_GROUP = ".m.rule.encrypted"
|
|
||||||
const val RULE_ID_REACTION = ".m.rule.reaction"
|
|
||||||
const val RULE_ID_FALLBACK = ".m.rule.fallback"
|
|
||||||
|
|
||||||
/* ==========================================================================================
|
/* ==========================================================================================
|
||||||
* Actions
|
* Actions
|
||||||
|
|
|
@ -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.pushrules.RuleIds
|
||||||
import org.matrix.android.sdk.api.pushrules.RuleSetKey
|
import org.matrix.android.sdk.api.pushrules.RuleSetKey
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +52,7 @@ data class RuleSet(
|
||||||
var result: PushRuleAndKind? = null
|
var result: PushRuleAndKind? = null
|
||||||
// sanity check
|
// sanity check
|
||||||
if (null != ruleId) {
|
if (null != ruleId) {
|
||||||
if (PushRule.RULE_ID_CONTAIN_USER_NAME == ruleId) {
|
if (RuleIds.RULE_ID_CONTAIN_USER_NAME == ruleId) {
|
||||||
result = findRule(content, ruleId)?.let { PushRuleAndKind(it, RuleSetKey.CONTENT) }
|
result = findRule(content, ruleId)?.let { PushRuleAndKind(it, RuleSetKey.CONTENT) }
|
||||||
} else {
|
} else {
|
||||||
// assume that the ruleId is unique.
|
// assume that the ruleId is unique.
|
||||||
|
|
|
@ -23,6 +23,7 @@ import android.widget.RadioGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.preference.PreferenceViewHolder
|
import androidx.preference.PreferenceViewHolder
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
|
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||||
import org.matrix.android.sdk.api.pushrules.RuleSetKey
|
import org.matrix.android.sdk.api.pushrules.RuleSetKey
|
||||||
import org.matrix.android.sdk.api.pushrules.rest.PushRule
|
import org.matrix.android.sdk.api.pushrules.rest.PushRule
|
||||||
import org.matrix.android.sdk.api.pushrules.rest.PushRuleAndKind
|
import org.matrix.android.sdk.api.pushrules.rest.PushRuleAndKind
|
||||||
|
@ -52,7 +53,7 @@ class PushRulePreference : VectorPreference {
|
||||||
get() {
|
get() {
|
||||||
val safeRule = ruleAndKind?.pushRule ?: return NOTIFICATION_OFF_INDEX
|
val safeRule = ruleAndKind?.pushRule ?: return NOTIFICATION_OFF_INDEX
|
||||||
|
|
||||||
if (safeRule.ruleId == PushRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS) {
|
if (safeRule.ruleId == RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS) {
|
||||||
if (safeRule.shouldNotNotify()) {
|
if (safeRule.shouldNotNotify()) {
|
||||||
return if (safeRule.enabled) {
|
return if (safeRule.enabled) {
|
||||||
NOTIFICATION_OFF_INDEX
|
NOTIFICATION_OFF_INDEX
|
||||||
|
@ -109,7 +110,7 @@ class PushRulePreference : VectorPreference {
|
||||||
val safeKind = ruleAndKind?.kind ?: return null
|
val safeKind = ruleAndKind?.kind ?: return null
|
||||||
|
|
||||||
return if (index != ruleStatusIndex) {
|
return if (index != ruleStatusIndex) {
|
||||||
if (safeRule.ruleId == PushRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS) {
|
if (safeRule.ruleId == RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS) {
|
||||||
when (index) {
|
when (index) {
|
||||||
NOTIFICATION_OFF_INDEX -> {
|
NOTIFICATION_OFF_INDEX -> {
|
||||||
safeRule.copy(enabled = true)
|
safeRule.copy(enabled = true)
|
||||||
|
@ -129,7 +130,7 @@ class PushRulePreference : VectorPreference {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (NOTIFICATION_OFF_INDEX == index) {
|
if (NOTIFICATION_OFF_INDEX == index) {
|
||||||
if (safeKind == RuleSetKey.UNDERRIDE || safeRule.ruleId == PushRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS) {
|
if (safeKind == RuleSetKey.UNDERRIDE || safeRule.ruleId == RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS) {
|
||||||
safeRule.setNotify(false)
|
safeRule.setNotify(false)
|
||||||
} else {
|
} else {
|
||||||
safeRule.copy(enabled = false)
|
safeRule.copy(enabled = false)
|
||||||
|
@ -138,12 +139,12 @@ class PushRulePreference : VectorPreference {
|
||||||
val newRule = safeRule.copy(enabled = true)
|
val newRule = safeRule.copy(enabled = true)
|
||||||
.setNotify(true)
|
.setNotify(true)
|
||||||
.setHighlight(safeKind != RuleSetKey.UNDERRIDE
|
.setHighlight(safeKind != RuleSetKey.UNDERRIDE
|
||||||
&& safeRule.ruleId != PushRule.RULE_ID_INVITE_ME
|
&& safeRule.ruleId != RuleIds.RULE_ID_INVITE_ME
|
||||||
&& NOTIFICATION_NOISY_INDEX == index)
|
&& NOTIFICATION_NOISY_INDEX == index)
|
||||||
|
|
||||||
if (NOTIFICATION_NOISY_INDEX == index) {
|
if (NOTIFICATION_NOISY_INDEX == index) {
|
||||||
newRule.setNotificationSound(
|
newRule.setNotificationSound(
|
||||||
if (safeRule.ruleId == PushRule.RULE_ID_CALL) {
|
if (safeRule.ruleId == RuleIds.RULE_ID_CALL) {
|
||||||
PushRule.ACTION_VALUE_RING
|
PushRule.ACTION_VALUE_RING
|
||||||
} else {
|
} else {
|
||||||
PushRule.ACTION_VALUE_DEFAULT
|
PushRule.ACTION_VALUE_DEFAULT
|
||||||
|
|
|
@ -16,13 +16,13 @@
|
||||||
package im.vector.app.features.settings
|
package im.vector.app.features.settings
|
||||||
|
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import org.matrix.android.sdk.api.MatrixCallback
|
|
||||||
import org.matrix.android.sdk.api.pushrules.rest.PushRule
|
|
||||||
import org.matrix.android.sdk.api.pushrules.rest.PushRuleAndKind
|
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.preference.PushRulePreference
|
import im.vector.app.core.preference.PushRulePreference
|
||||||
import im.vector.app.core.preference.VectorPreference
|
import im.vector.app.core.preference.VectorPreference
|
||||||
import im.vector.app.core.utils.toast
|
import im.vector.app.core.utils.toast
|
||||||
|
import org.matrix.android.sdk.api.MatrixCallback
|
||||||
|
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||||
|
import org.matrix.android.sdk.api.pushrules.rest.PushRuleAndKind
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
|
class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
|
||||||
|
@ -92,17 +92,17 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
|
||||||
companion object {
|
companion object {
|
||||||
// preference name <-> rule Id
|
// preference name <-> rule Id
|
||||||
private val prefKeyToPushRuleId = mapOf(
|
private val prefKeyToPushRuleId = mapOf(
|
||||||
"SETTINGS_PUSH_RULE_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY" to PushRule.RULE_ID_CONTAIN_DISPLAY_NAME,
|
"SETTINGS_PUSH_RULE_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY" to RuleIds.RULE_ID_CONTAIN_DISPLAY_NAME,
|
||||||
"SETTINGS_PUSH_RULE_CONTAINING_MY_USER_NAME_PREFERENCE_KEY" to PushRule.RULE_ID_CONTAIN_USER_NAME,
|
"SETTINGS_PUSH_RULE_CONTAINING_MY_USER_NAME_PREFERENCE_KEY" to RuleIds.RULE_ID_CONTAIN_USER_NAME,
|
||||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY" to PushRule.RULE_ID_ONE_TO_ONE_ROOM,
|
"SETTINGS_PUSH_RULE_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY" to RuleIds.RULE_ID_ONE_TO_ONE_ROOM,
|
||||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY" to PushRule.RULE_ID_ALL_OTHER_MESSAGES_ROOMS,
|
"SETTINGS_PUSH_RULE_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY" to RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS,
|
||||||
"SETTINGS_PUSH_RULE_INVITED_TO_ROOM_PREFERENCE_KEY" to PushRule.RULE_ID_INVITE_ME,
|
"SETTINGS_PUSH_RULE_INVITED_TO_ROOM_PREFERENCE_KEY" to RuleIds.RULE_ID_INVITE_ME,
|
||||||
"SETTINGS_PUSH_RULE_CALL_INVITATIONS_PREFERENCE_KEY" to PushRule.RULE_ID_CALL,
|
"SETTINGS_PUSH_RULE_CALL_INVITATIONS_PREFERENCE_KEY" to RuleIds.RULE_ID_CALL,
|
||||||
"SETTINGS_PUSH_RULE_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY" to PushRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS,
|
"SETTINGS_PUSH_RULE_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY" to RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS,
|
||||||
"SETTINGS_PUSH_RULE_MESSAGES_CONTAINING_AT_ROOM_PREFERENCE_KEY" to PushRule.RULE_ID_AT_ROOMS,
|
"SETTINGS_PUSH_RULE_MESSAGES_CONTAINING_AT_ROOM_PREFERENCE_KEY" to RuleIds.RULE_ID_ROOM_NOTIF,
|
||||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_ONE_ONE_CHAT_PREFERENCE_KEY" to PushRule.RULE_ID_E2E_ONE_TO_ONE_ROOM,
|
"SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_ONE_ONE_CHAT_PREFERENCE_KEY" to RuleIds.RULE_ID_ONE_TO_ONE_ENCRYPTED_ROOM,
|
||||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_GROUP_CHAT_PREFERENCE_KEY" to PushRule.RULE_ID_E2E_GROUP,
|
"SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_GROUP_CHAT_PREFERENCE_KEY" to RuleIds.RULE_ID_ENCRYPTED,
|
||||||
"SETTINGS_PUSH_RULE_ROOMS_UPGRADED_KEY" to PushRule.RULE_ID_TOMBSTONE
|
"SETTINGS_PUSH_RULE_ROOMS_UPGRADED_KEY" to RuleIds.RULE_ID_TOMBSTONE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue