Create enum for Push rules. Also add some TODOs

This commit is contained in:
Benoit Marty 2019-09-20 11:20:51 +02:00
parent acd7a709de
commit 03f8120b7d
20 changed files with 209 additions and 89 deletions

View File

@ -25,14 +25,14 @@ interface PushRuleService {
/**
* Fetch the push rules from the server
*/
fun fetchPushRules(scope: String = "global")
fun fetchPushRules(scope: String = RuleScope.GLOBAL)
//TODO get push rule set
fun getPushRules(scope: String = "global"): List<PushRule>
fun getPushRules(scope: String = RuleScope.GLOBAL): List<PushRule>
//TODO update rule
fun updatePushRuleEnableStatus(kind: String, pushRule: PushRule, enabled: Boolean, callback: MatrixCallback<Unit>): Cancelable
fun updatePushRuleEnableStatus(kind: RuleKind, pushRule: PushRule, enabled: Boolean, callback: MatrixCallback<Unit>): Cancelable
fun addPushRuleListener(listener: PushRuleListener)

View File

@ -37,7 +37,7 @@ object RuleIds {
// Default Underride Rules
const val RULE_ID_CALL = ".m.rule.call"
const val RULE_ID_one_to_one_encrypted_room = ".m.rule.encrypted_room_one_to_one"
const val RULE_ID_ONE_TO_ONE_ENCRYPTED_ROOM = ".m.rule.encrypted_room_one_to_one"
const val RULE_ID_ONE_TO_ONE_ROOM = ".m.rule.room_one_to_one"
const val RULE_ID_ALL_OTHER_MESSAGES_ROOMS = ".m.rule.message"
const val RULE_ID_ENCRYPTED = ".m.rule.encrypted"

View File

@ -15,12 +15,6 @@
*/
package im.vector.matrix.android.api.pushrules
enum class RulesetKey(val value: String) {
CONTENT("content"),
OVERRIDE("override"),
ROOM("room"),
SENDER("sender"),
UNDERRIDE("underride"),
UNKNOWN("")
}
object RuleScope {
const val GLOBAL = "global"
}

View File

@ -0,0 +1,33 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.matrix.android.api.pushrules
/**
* Ref: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushrules
*/
enum class RuleSetKey(val value: String) {
CONTENT("content"),
OVERRIDE("override"),
ROOM("room"),
SENDER("sender"),
UNDERRIDE("underride")
}
/**
* Ref: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushrules-scope-kind-ruleid
*/
typealias RuleKind = RuleSetKey

View File

@ -71,7 +71,7 @@ data class PushCondition(
this.key?.let { SenderNotificationPermissionCondition(it) }
}
Condition.Kind.UNRECOGNIZE -> {
Timber.e("Unknwon kind $kind")
Timber.e("Unknown kind $kind")
null
}
}

View File

@ -15,17 +15,27 @@
*/
package im.vector.matrix.android.internal.database.model
import im.vector.matrix.android.api.pushrules.RuleKind
import io.realm.RealmList
import io.realm.RealmObject
import io.realm.annotations.Index
internal open class PushRulesEntity(
// TODO Remove userId
@Index var userId: String = "",
var scope: String = "",
// "content", etc.
var rulesetKey: String = "",
var pushRules: RealmList<PushRuleEntity> = RealmList()
) : RealmObject() {
private var kindStr: String = RuleKind.CONTENT.name
var kind: RuleKind
get() {
return RuleKind.valueOf(kindStr)
}
set(value) {
kindStr = value.name
}
companion object
}

View File

@ -29,6 +29,7 @@ import io.realm.annotations.Index
// at im.vector.matrix.android.internal.session.pushers.AddHttpPusherWorker$doWork$$inlined$fold$lambda$2.execute(AddHttpPusherWorker.kt:70)
// at io.realm.Realm.executeTransaction(Realm.java:1493)
internal open class PusherEntity(
// TODO Remove userId
@Index var userId: String = "",
var pushKey: String = "",
var kind: String? = null,

View File

@ -15,6 +15,7 @@
*/
package im.vector.matrix.android.internal.database.query
import im.vector.matrix.android.api.pushrules.RuleKind
import im.vector.matrix.android.internal.database.model.PushRulesEntity
import im.vector.matrix.android.internal.database.model.PushRulesEntityFields
import im.vector.matrix.android.internal.database.model.PusherEntity
@ -38,9 +39,9 @@ internal fun PusherEntity.Companion.where(realm: Realm,
internal fun PushRulesEntity.Companion.where(realm: Realm,
userId: String,
scope: String,
ruleSetKey: String): RealmQuery<PushRulesEntity> {
kind: RuleKind): RealmQuery<PushRulesEntity> {
return realm.where<PushRulesEntity>()
.equalTo(PushRulesEntityFields.USER_ID, userId)
.equalTo(PushRulesEntityFields.SCOPE, scope)
.equalTo(PushRulesEntityFields.RULESET_KEY, ruleSetKey)
.equalTo(PushRulesEntityFields.KIND_STR, kind.name)
}

View File

@ -19,6 +19,8 @@ import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.pushrules.Action
import im.vector.matrix.android.api.pushrules.PushRuleService
import im.vector.matrix.android.api.pushrules.RuleKind
import im.vector.matrix.android.api.pushrules.RuleSetKey
import im.vector.matrix.android.api.pushrules.rest.PushRule
import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.util.Cancelable
@ -53,36 +55,46 @@ internal class DefaultPushRuleService @Inject constructor(
}
override fun getPushRules(scope: String): List<PushRule> {
var contentRules: List<PushRule> = emptyList()
var overrideRules: List<PushRule> = emptyList()
var roomRules: List<PushRule> = emptyList()
var senderRules: List<PushRule> = emptyList()
var underrideRules: List<PushRule> = emptyList()
// TODO Create const for ruleSetKey
monarchy.doWithRealm { realm ->
PushRulesEntity.where(realm, userId, scope, "content").findFirst()?.let { re ->
contentRules = re.pushRules.map { PushRulesMapper.mapContentRule(it) }
}
PushRulesEntity.where(realm, userId, scope, "override").findFirst()?.let { re ->
overrideRules = re.pushRules.map { PushRulesMapper.map(it) }
}
PushRulesEntity.where(realm, userId, scope, "room").findFirst()?.let { re ->
roomRules = re.pushRules.map { PushRulesMapper.mapRoomRule(it) }
}
PushRulesEntity.where(realm, userId, scope, "sender").findFirst()?.let { re ->
senderRules = re.pushRules.map { PushRulesMapper.mapSenderRule(it) }
}
PushRulesEntity.where(realm, userId, scope, "underride").findFirst()?.let { re ->
underrideRules = re.pushRules.map { PushRulesMapper.map(it) }
}
// FIXME PushRulesEntity are not always created here...
// FIWME Get the push rules from the sync
PushRulesEntity.where(realm, userId, scope, RuleSetKey.CONTENT)
.findFirst()
?.let { pushRulesEntity ->
contentRules = pushRulesEntity.pushRules.map { PushRulesMapper.mapContentRule(it) }
}
PushRulesEntity.where(realm, userId, scope, RuleSetKey.OVERRIDE)
.findFirst()
?.let { pushRulesEntity ->
overrideRules = pushRulesEntity.pushRules.map { PushRulesMapper.map(it) }
}
PushRulesEntity.where(realm, userId, scope, RuleSetKey.ROOM)
.findFirst()
?.let { pushRulesEntity ->
roomRules = pushRulesEntity.pushRules.map { PushRulesMapper.mapRoomRule(it) }
}
PushRulesEntity.where(realm, userId, scope, RuleSetKey.SENDER)
.findFirst()
?.let { pushRulesEntity ->
senderRules = pushRulesEntity.pushRules.map { PushRulesMapper.mapSenderRule(it) }
}
PushRulesEntity.where(realm, userId, scope, RuleSetKey.UNDERRIDE)
.findFirst()
?.let { pushRulesEntity ->
underrideRules = pushRulesEntity.pushRules.map { PushRulesMapper.map(it) }
}
}
return contentRules + overrideRules + roomRules + senderRules + underrideRules
}
override fun updatePushRuleEnableStatus(kind: String, pushRule: PushRule, enabled: Boolean, callback: MatrixCallback<Unit>): Cancelable {
override fun updatePushRuleEnableStatus(kind: RuleKind, pushRule: PushRule, enabled: Boolean, callback: MatrixCallback<Unit>): Cancelable {
return updatePushRuleEnableStatusTask
.configureWith(UpdatePushRuleEnableStatusTask.Params(kind, pushRule, enabled)) {
this.callback = callback

View File

@ -102,6 +102,7 @@ internal class DefaultProcessEventForPushTask @Inject constructor(
}
private fun fulfilledBingRule(event: Event, rules: List<PushRule>): PushRule? {
// TODO This should be injected
val conditionResolver = DefaultConditionResolver(event, roomService, userId)
rules.filter { it.enabled }.forEach { rule ->
val isFullfilled = rule.conditions?.map {

View File

@ -21,6 +21,7 @@ import im.vector.matrix.android.api.session.room.RoomService
import im.vector.matrix.android.internal.di.UserId
import timber.log.Timber
// TODO Inject constructor
internal class DefaultConditionResolver(private val event: Event,
private val roomService: RoomService,
@UserId

View File

@ -16,6 +16,7 @@
package im.vector.matrix.android.internal.session.pushers
import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.api.pushrules.RuleSetKey
import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse
import im.vector.matrix.android.internal.database.mapper.PushRulesMapper
import im.vector.matrix.android.internal.database.model.PushRulesEntity
@ -28,12 +29,9 @@ import javax.inject.Inject
internal interface GetPushRulesTask : Task<GetPushRulesTask.Params, Unit> {
data class Params(val scope: String)
}
internal class DefaultGetPushRulesTask @Inject constructor(private val pushRulesApi: PushRulesApi,
private val monarchy: Monarchy,
@UserId
@ -49,17 +47,16 @@ internal class DefaultGetPushRulesTask @Inject constructor(private val pushRules
//TODO
realm.where(PushRulesEntity::class.java)
.equalTo(PusherEntityFields.USER_ID, userId)
.findAll().deleteAllFromRealm()
.findAll()
.deleteAllFromRealm()
val content = PushRulesEntity(userId, scope, "content")
val content = PushRulesEntity(userId, scope).apply { kind = RuleSetKey.CONTENT }
response.global.content?.forEach { rule ->
PushRulesMapper.map(rule).also {
content.pushRules.add(it)
}
content.pushRules.add(PushRulesMapper.map(rule))
}
realm.insertOrUpdate(content)
val override = PushRulesEntity(userId, scope, "override")
val override = PushRulesEntity(userId, scope).apply { kind = RuleSetKey.OVERRIDE }
response.global.override?.forEach { rule ->
PushRulesMapper.map(rule).also {
override.pushRules.add(it)
@ -67,27 +64,21 @@ internal class DefaultGetPushRulesTask @Inject constructor(private val pushRules
}
realm.insertOrUpdate(override)
val rooms = PushRulesEntity(userId, scope, "room")
val rooms = PushRulesEntity(userId, scope).apply { kind = RuleSetKey.ROOM }
response.global.room?.forEach { rule ->
PushRulesMapper.map(rule).also {
rooms.pushRules.add(it)
}
rooms.pushRules.add(PushRulesMapper.map(rule))
}
realm.insertOrUpdate(rooms)
val senders = PushRulesEntity(userId, scope, "sender")
val senders = PushRulesEntity(userId, scope).apply { kind = RuleSetKey.SENDER }
response.global.sender?.forEach { rule ->
PushRulesMapper.map(rule).also {
senders.pushRules.add(it)
}
senders.pushRules.add(PushRulesMapper.map(rule))
}
realm.insertOrUpdate(senders)
val underrides = PushRulesEntity(userId, scope, "underride")
val underrides = PushRulesEntity(userId, scope).apply { kind = RuleSetKey.UNDERRIDE }
response.global.underride?.forEach { rule ->
PushRulesMapper.map(rule).also {
underrides.pushRules.add(it)
}
underrides.pushRules.add(PushRulesMapper.map(rule))
}
realm.insertOrUpdate(underrides)
}

View File

@ -15,6 +15,7 @@
*/
package im.vector.matrix.android.internal.session.pushers
import im.vector.matrix.android.api.pushrules.RuleKind
import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse
import im.vector.matrix.android.api.pushrules.rest.PushRule
import im.vector.matrix.android.internal.network.NetworkConstants
@ -37,7 +38,7 @@ internal interface PushRulesApi {
* @param enable the new enable status
*/
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/enabled")
fun updateEnableRuleStatus(@Path("kind") kind: String,
fun updateEnableRuleStatus(@Path("kind") kind: RuleKind,
@Path("ruleId") ruleId: String,
@Body enable: Boolean?)
: Call<Unit>
@ -51,7 +52,7 @@ internal interface PushRulesApi {
* @param actions the actions
*/
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/actions")
fun updateRuleActions(@Path("kind") kind: String,
fun updateRuleActions(@Path("kind") kind: RuleKind,
@Path("ruleId") ruleId: String,
@Body actions: Any)
: Call<Unit>
@ -64,7 +65,7 @@ internal interface PushRulesApi {
* @param ruleId the ruleId
*/
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}")
fun deleteRule(@Path("kind") kind: String,
fun deleteRule(@Path("kind") kind: RuleKind,
@Path("ruleId") ruleId: String)
: Call<Unit>
@ -76,7 +77,7 @@ internal interface PushRulesApi {
* @param rule the rule to add.
*/
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}")
fun addRule(@Path("kind") kind: String,
fun addRule(@Path("kind") kind: RuleKind,
@Path("ruleId") ruleId: String,
@Body rule: PushRule)
: Call<Unit>

View File

@ -15,6 +15,7 @@
*/
package im.vector.matrix.android.internal.session.pushers
import im.vector.matrix.android.api.pushrules.RuleKind
import im.vector.matrix.android.api.pushrules.rest.PushRule
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
@ -22,7 +23,7 @@ import javax.inject.Inject
internal interface UpdatePushRuleEnableStatusTask : Task<UpdatePushRuleEnableStatusTask.Params, Unit> {
data class Params(val kind: String,
data class Params(val kind: RuleKind,
val pushRule: PushRule,
val enabled: Boolean)
}

View File

@ -18,6 +18,7 @@ package im.vector.matrix.android.internal.session.sync
import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.R
import im.vector.matrix.android.api.pushrules.RuleScope
import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.events.model.toModel
@ -77,11 +78,11 @@ internal class RoomSyncHandler @Inject constructor(private val monarchy: Monarch
private fun checkPushRules(roomsSyncResponse: RoomsSyncResponse) {
Timber.v("[PushRules] --> checkPushRules")
if (tokenStore.getLastToken() == null) {
Timber.v("[PushRules] <-- No push tule check on initial sync")
Timber.v("[PushRules] <-- No push rule check on initial sync")
return
} //nothing on initial sync
val rules = pushRuleService.getPushRules("global")
val rules = pushRuleService.getPushRules(RuleScope.GLOBAL)
processForPushTask.configureWith(ProcessEventForPushTask.Params(roomsSyncResponse, rules))
.executeBy(taskExecutor)
Timber.v("[PushRules] <-- Push task scheduled")

View File

@ -24,14 +24,13 @@ import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.events.model.toContent
import im.vector.matrix.android.api.session.room.Room
import im.vector.matrix.android.api.session.room.RoomService
import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary
import im.vector.matrix.android.api.session.room.model.Membership
import im.vector.matrix.android.api.session.room.model.RoomMember
import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.matrix.android.api.session.room.model.*
import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams
import im.vector.matrix.android.api.session.room.model.message.MessageTextContent
import im.vector.matrix.android.api.session.room.send.UserDraft
import im.vector.matrix.android.api.session.room.timeline.Timeline
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
import im.vector.matrix.android.api.session.room.timeline.TimelineSettings
import im.vector.matrix.android.api.util.Cancelable
import org.junit.Assert
import org.junit.Test
@ -164,10 +163,29 @@ class PushrulesConditionTest {
}
@Test
fun test_notice_condition() {
val conditionEqual = EventMatchCondition("content.msgtype", "m.notice")
Event(
type = "m.room.message",
eventId = "mx0",
content = MessageTextContent("m.notice", "A").toContent(),
originServerTs = 0,
roomId = "2joined").also {
Assert.assertTrue("Notice", conditionEqual.isSatisfied(it))
}
}
class MockRoomService() : RoomService {
override fun createRoom(createRoomParams: CreateRoomParams, callback: MatrixCallback<String>) {
override fun createRoom(createRoomParams: CreateRoomParams, callback: MatrixCallback<String>): Cancelable {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun joinRoom(roomId: String, viaServers: List<String>, callback: MatrixCallback<Unit>): Cancelable {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getRoom(roomId: String): Room? {
@ -184,6 +202,53 @@ class PushrulesConditionTest {
}
class MockRoom(override val roomId: String, val _numberOfJoinedMembers: Int) : Room {
override fun resendTextMessage(localEcho: TimelineEvent): Cancelable? {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun resendMediaMessage(localEcho: TimelineEvent): Cancelable? {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun deleteFailedEcho(localEcho: TimelineEvent) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun clearSendingQueue() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun resendAllFailedMessages() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun saveDraft(draft: UserDraft) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun deleteDraft() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getDraftsLive(): LiveData<List<UserDraft>> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getEventReadReceiptsLive(eventId: String): LiveData<List<ReadReceipt>> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getStateEvent(eventType: String): Event? {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun editReply(replyToEdit: TimelineEvent, originalTimelineEvent: TimelineEvent, newBodyText: String, compatibilityBodyText: String): Cancelable {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun fetchEditHistory(eventId: String, callback: MatrixCallback<List<Event>>) {
}
override fun liveTimeLineEvent(eventId: String): LiveData<TimelineEvent> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@ -201,7 +266,7 @@ class PushrulesConditionTest {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun createTimeline(eventId: String?, allowedTypes: List<String>?): Timeline {
override fun createTimeline(eventId: String?, settings: TimelineSettings): Timeline {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@ -245,7 +310,7 @@ class PushrulesConditionTest {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun loadRoomMembersIfNeeded(): Cancelable {
override fun loadRoomMembersIfNeeded(matrixCallback: MatrixCallback<Unit>): Cancelable {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@ -257,15 +322,15 @@ class PushrulesConditionTest {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun invite(userId: String, callback: MatrixCallback<Unit>) {
override fun invite(userId: String, callback: MatrixCallback<Unit>): Cancelable {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun join(callback: MatrixCallback<Unit>) {
override fun join(viaServers: List<String>, callback: MatrixCallback<Unit>): Cancelable {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun leave(callback: MatrixCallback<Unit>) {
override fun leave(callback: MatrixCallback<Unit>): Cancelable {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

View File

@ -32,6 +32,9 @@ fun Session.configureAndStart(pushRuleTriggerListener: PushRuleTriggerListener)
startSync(isAtLeastStarted)
refreshPushers()
pushRuleTriggerListener.startWithSession(this)
// TODO After a clear cache, this is not done.
// TODO Push rule should be parsed from the sync
fetchPushRules()
// TODO P1 From HomeActivity

View File

@ -28,6 +28,7 @@ data class NotificationAction(
var highlight = false
var sound: String? = null
ruleActions.forEach {
// TODO When
if (it.type == Action.Type.NOTIFY) shouldNotify = true
if (it.type == Action.Type.DONT_NOTIFY) shouldNotify = false
if (it.type == Action.Type.SET_TWEAK) {

View File

@ -21,6 +21,7 @@ import androidx.preference.Preference
import androidx.preference.SwitchPreference
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.pushrules.RuleIds
import im.vector.matrix.android.api.pushrules.RuleKind
import im.vector.riotx.R
import im.vector.riotx.core.di.ActiveSessionHolder
import im.vector.riotx.core.di.ScreenComponent
@ -45,12 +46,13 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment(
.find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL }
if (mRuleMaster == null) {
// The home server does not support RULE_ID_DISABLE_ALL, so hide the preference
pref.isVisible = false
return
}
val areNotifEnabledAtAccountLevelt = !mRuleMaster.enabled
(pref as SwitchPreference).isChecked = areNotifEnabledAtAccountLevelt
val areNotifEnabledAtAccountLevel = !mRuleMaster.enabled
(pref as SwitchPreference).isChecked = areNotifEnabledAtAccountLevel
}
}
@ -114,19 +116,21 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment(
.find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL }
?.let {
//Trick, we must enable this room to disable notifications
pushRuleService.updatePushRuleEnableStatus("override", it, !switchPref.isChecked,
object : MatrixCallback<Unit> {
pushRuleService.updatePushRuleEnableStatus(RuleKind.OVERRIDE,
it,
!switchPref.isChecked,
object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {
pushRuleService.fetchPushRules()
}
override fun onSuccess(data: Unit) {
pushRuleService.fetchPushRules()
}
override fun onFailure(failure: Throwable) {
//revert the check box
switchPref.isChecked = !switchPref.isChecked
Toast.makeText(activity, R.string.unknown_error, Toast.LENGTH_SHORT).show()
}
})
override fun onFailure(failure: Throwable) {
//revert the check box
switchPref.isChecked = !switchPref.isChecked
Toast.makeText(activity, R.string.unknown_error, Toast.LENGTH_SHORT).show()
}
})
}
}

View File

@ -17,6 +17,7 @@ package im.vector.riotx.features.settings.troubleshoot
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.pushrules.RuleIds
import im.vector.matrix.android.api.pushrules.RuleKind
import im.vector.riotx.R
import im.vector.riotx.core.di.ActiveSessionHolder
import im.vector.riotx.core.resources.StringProvider
@ -45,8 +46,7 @@ class TestAccountSettings @Inject constructor(private val stringProvider: String
override fun doFix() {
if (manager?.diagStatus == TestStatus.RUNNING) return //wait before all is finished
// TODO Use constant for kind
session.updatePushRuleEnableStatus("override", defaultRule, !defaultRule.enabled,
session.updatePushRuleEnableStatus(RuleKind.OVERRIDE, defaultRule, !defaultRule.enabled,
object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {