forked from GitHub-Mirror/riotX-android
Notification: Fix TestAccountSettings test
This commit is contained in:
parent
2625e11508
commit
134c2fcd42
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package im.vector.matrix.android.api.pushrules
|
package im.vector.matrix.android.api.pushrules
|
||||||
|
|
||||||
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
import im.vector.matrix.android.api.pushrules.rest.PushRule
|
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.session.events.model.Event
|
||||||
|
|
||||||
@ -30,6 +31,8 @@ interface PushRuleService {
|
|||||||
|
|
||||||
//TODO update rule
|
//TODO update rule
|
||||||
|
|
||||||
|
fun updatePushRuleEnableStatus(kind: String, pushRule: PushRule, enabled: Boolean, callback: MatrixCallback<Unit>)
|
||||||
|
|
||||||
fun addPushRuleListener(listener: PushRuleListener)
|
fun addPushRuleListener(listener: PushRuleListener)
|
||||||
|
|
||||||
fun removePushRuleListener(listener: PushRuleListener)
|
fun removePushRuleListener(listener: PushRuleListener)
|
||||||
|
@ -16,5 +16,32 @@
|
|||||||
|
|
||||||
package im.vector.matrix.android.api.pushrules
|
package im.vector.matrix.android.api.pushrules
|
||||||
|
|
||||||
enum class RuleIds {
|
/**
|
||||||
}
|
* Known rule ids
|
||||||
|
*
|
||||||
|
* Ref: https://matrix.org/docs/spec/client_server/latest#predefined-rules
|
||||||
|
*/
|
||||||
|
object RuleIds {
|
||||||
|
// Default Override Rules
|
||||||
|
const val RULE_ID_DISABLE_ALL = ".m.rule.master"
|
||||||
|
const val RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS = ".m.rule.suppress_notices"
|
||||||
|
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_CONTAIN_DISPLAY_NAME = ".m.rule.contains_display_name"
|
||||||
|
|
||||||
|
const val RULE_ID_TOMBSTONE = ".m.rule.tombstone"
|
||||||
|
const val RULE_ID_ROOM_NOTIF = ".m.rule.roomnotif"
|
||||||
|
|
||||||
|
// Default Content Rules
|
||||||
|
const val RULE_ID_CONTAIN_USER_NAME = ".m.rule.contains_user_name"
|
||||||
|
|
||||||
|
// 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_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"
|
||||||
|
|
||||||
|
// Not documented
|
||||||
|
const val RULE_ID_FALLBACK = ".m.rule.fallback"
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@ import io.realm.annotations.Index
|
|||||||
internal open class PushRulesEntity(
|
internal open class PushRulesEntity(
|
||||||
@Index var userId: String = "",
|
@Index var userId: String = "",
|
||||||
var scope: String = "",
|
var scope: String = "",
|
||||||
|
// "content", etc.
|
||||||
var rulesetKey: String = "",
|
var rulesetKey: String = "",
|
||||||
var pushRules: RealmList<PushRuleEntity> = RealmList()
|
var pushRules: RealmList<PushRuleEntity> = RealmList()
|
||||||
) : RealmObject() {
|
) : RealmObject() {
|
||||||
|
@ -507,6 +507,10 @@ internal class DefaultSession(override val sessionParams: SessionParams) : Sessi
|
|||||||
return pushRuleService.getPushRules(scope)
|
return pushRuleService.getPushRules(scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun updatePushRuleEnableStatus(kind: String, pushRule: PushRule, enabled: Boolean, callback: MatrixCallback<Unit>) {
|
||||||
|
pushRuleService.updatePushRuleEnableStatus(kind, pushRule, enabled, callback)
|
||||||
|
}
|
||||||
|
|
||||||
override fun fetchPushRules(scope: String) {
|
override fun fetchPushRules(scope: String) {
|
||||||
pushRuleService.fetchPushRules(scope)
|
pushRuleService.fetchPushRules(scope)
|
||||||
}
|
}
|
||||||
|
@ -180,13 +180,17 @@ internal class SessionModule(private val sessionParams: SessionParams) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scope(DefaultSession.SCOPE) {
|
scope(DefaultSession.SCOPE) {
|
||||||
DefaultPushRuleService(get(), get(), get(), get())
|
DefaultPushRuleService(get(), get(), get(), get(), get())
|
||||||
}
|
}
|
||||||
|
|
||||||
scope(DefaultSession.SCOPE) {
|
scope(DefaultSession.SCOPE) {
|
||||||
DefaultGetPushRulesTask(get()) as GetPushRulesTask
|
DefaultGetPushRulesTask(get()) as GetPushRulesTask
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope(DefaultSession.SCOPE) {
|
||||||
|
DefaultUpdatePushRuleEnableStatusTask(get()) as UpdatePushRuleEnableStatusTask
|
||||||
|
}
|
||||||
|
|
||||||
scope(DefaultSession.SCOPE) {
|
scope(DefaultSession.SCOPE) {
|
||||||
DefaultProcessEventForPushTask(get()) as ProcessEventForPushTask
|
DefaultProcessEventForPushTask(get()) as ProcessEventForPushTask
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import im.vector.matrix.android.internal.database.model.PushRulesEntity
|
|||||||
import im.vector.matrix.android.internal.database.model.PusherEntityFields
|
import im.vector.matrix.android.internal.database.model.PusherEntityFields
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
import im.vector.matrix.android.internal.session.pushers.GetPushRulesTask
|
import im.vector.matrix.android.internal.session.pushers.GetPushRulesTask
|
||||||
|
import im.vector.matrix.android.internal.session.pushers.UpdatePushRuleEnableStatusTask
|
||||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
import im.vector.matrix.android.internal.task.configureWith
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@ -36,6 +37,7 @@ import timber.log.Timber
|
|||||||
internal class DefaultPushRuleService(
|
internal class DefaultPushRuleService(
|
||||||
private val sessionParams: SessionParams,
|
private val sessionParams: SessionParams,
|
||||||
private val pushRulesTask: GetPushRulesTask,
|
private val pushRulesTask: GetPushRulesTask,
|
||||||
|
private val updatePushRuleEnableStatusTask: UpdatePushRuleEnableStatusTask,
|
||||||
private val taskExecutor: TaskExecutor,
|
private val taskExecutor: TaskExecutor,
|
||||||
private val monarchy: Monarchy
|
private val monarchy: Monarchy
|
||||||
) : PushRuleService {
|
) : PushRuleService {
|
||||||
@ -95,8 +97,6 @@ internal class DefaultPushRuleService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
realm.insertOrUpdate(underrides)
|
realm.insertOrUpdate(underrides)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -111,6 +111,7 @@ internal class DefaultPushRuleService(
|
|||||||
var senderRules: List<PushRule> = emptyList()
|
var senderRules: List<PushRule> = emptyList()
|
||||||
var underrideRules: List<PushRule> = emptyList()
|
var underrideRules: List<PushRule> = emptyList()
|
||||||
|
|
||||||
|
// TODO Create const for ruleSetKey
|
||||||
monarchy.doWithRealm { realm ->
|
monarchy.doWithRealm { realm ->
|
||||||
PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "content").findFirst()?.let { re ->
|
PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "content").findFirst()?.let { re ->
|
||||||
contentRules = re.pushRules.map { PushRulesMapper.mapContentRule(it) }
|
contentRules = re.pushRules.map { PushRulesMapper.mapContentRule(it) }
|
||||||
@ -132,6 +133,14 @@ internal class DefaultPushRuleService(
|
|||||||
return contentRules + overrideRules + roomRules + senderRules + underrideRules
|
return contentRules + overrideRules + roomRules + senderRules + underrideRules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun updatePushRuleEnableStatus(kind: String, pushRule: PushRule, enabled: Boolean, callback: MatrixCallback<Unit>) {
|
||||||
|
updatePushRuleEnableStatusTask
|
||||||
|
.configureWith(UpdatePushRuleEnableStatusTask.Params(kind, pushRule, enabled))
|
||||||
|
// TODO Fetch the rules
|
||||||
|
.dispatchTo(callback)
|
||||||
|
.executeBy(taskExecutor)
|
||||||
|
}
|
||||||
|
|
||||||
override fun removePushRuleListener(listener: PushRuleService.PushRuleListener) {
|
override fun removePushRuleListener(listener: PushRuleService.PushRuleListener) {
|
||||||
listeners.remove(listener)
|
listeners.remove(listener)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.internal.session.pushers
|
||||||
|
|
||||||
|
import arrow.core.Try
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
internal interface UpdatePushRuleEnableStatusTask : Task<UpdatePushRuleEnableStatusTask.Params, Unit> {
|
||||||
|
data class Params(val kind: String,
|
||||||
|
val pushRule: PushRule,
|
||||||
|
val enabled: Boolean)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class DefaultUpdatePushRuleEnableStatusTask(private val pushRulesApi: PushRulesApi) : UpdatePushRuleEnableStatusTask {
|
||||||
|
|
||||||
|
override suspend fun execute(params: UpdatePushRuleEnableStatusTask.Params): Try<Unit> {
|
||||||
|
return executeRequest {
|
||||||
|
apiCall = pushRulesApi.updateEnableRuleStatus(params.kind, params.pushRule.ruleId, params.enabled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,15 +16,11 @@
|
|||||||
package im.vector.riotredesign.push.fcm
|
package im.vector.riotredesign.push.fcm
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import im.vector.fragments.troubleshoot.TestAccountSettings
|
|
||||||
import im.vector.matrix.android.api.session.Session
|
import im.vector.matrix.android.api.session.Session
|
||||||
|
import im.vector.riotredesign.features.settings.troubleshoot.*
|
||||||
import im.vector.riotredesign.push.fcm.troubleshoot.TestFirebaseToken
|
import im.vector.riotredesign.push.fcm.troubleshoot.TestFirebaseToken
|
||||||
import im.vector.riotredesign.push.fcm.troubleshoot.TestPlayServices
|
import im.vector.riotredesign.push.fcm.troubleshoot.TestPlayServices
|
||||||
import im.vector.riotredesign.push.fcm.troubleshoot.TestTokenRegistration
|
import im.vector.riotredesign.push.fcm.troubleshoot.TestTokenRegistration
|
||||||
import im.vector.riotredesign.features.settings.troubleshoot.NotificationTroubleshootTestManager
|
|
||||||
import im.vector.riotredesign.features.settings.troubleshoot.TestBingRulesSettings
|
|
||||||
import im.vector.riotredesign.features.settings.troubleshoot.TestDeviceSettings
|
|
||||||
import im.vector.riotredesign.features.settings.troubleshoot.TestSystemSettings
|
|
||||||
|
|
||||||
class NotificationTroubleshootTestManagerFactory {
|
class NotificationTroubleshootTestManagerFactory {
|
||||||
|
|
||||||
|
@ -13,24 +13,26 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package im.vector.fragments.troubleshoot
|
package im.vector.riotredesign.features.settings.troubleshoot
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
|
import im.vector.matrix.android.api.pushrules.RuleIds
|
||||||
import im.vector.matrix.android.api.session.Session
|
import im.vector.matrix.android.api.session.Session
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
import im.vector.riotredesign.features.settings.troubleshoot.TroubleshootTest
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that the main pushRule (RULE_ID_DISABLE_ALL) is correctly setup
|
* Check that the main pushRule (RULE_ID_DISABLE_ALL) is correctly setup
|
||||||
*/
|
*/
|
||||||
class TestAccountSettings(val fragment: Fragment, val session: Session) : TroubleshootTest(R.string.settings_troubleshoot_test_account_settings_title) {
|
class TestAccountSettings(val fragment: Fragment, val session: Session)
|
||||||
|
: TroubleshootTest(R.string.settings_troubleshoot_test_account_settings_title) {
|
||||||
|
|
||||||
override fun perform() {
|
override fun perform() {
|
||||||
/*
|
val defaultRule = session.getPushRules()
|
||||||
TODO
|
.find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL }
|
||||||
val defaultRule = session?.dataHandler?.bingRulesManager?.pushRules()?.findDefaultRule(BingRule.RULE_ID_DISABLE_ALL)
|
|
||||||
if (defaultRule != null) {
|
if (defaultRule != null) {
|
||||||
if (!defaultRule.isEnabled) {
|
if (!defaultRule.enabled) {
|
||||||
description = fragment.getString(R.string.settings_troubleshoot_test_account_settings_success)
|
description = fragment.getString(R.string.settings_troubleshoot_test_account_settings_success)
|
||||||
quickFix = null
|
quickFix = null
|
||||||
status = TestStatus.SUCCESS
|
status = TestStatus.SUCCESS
|
||||||
@ -39,14 +41,16 @@ class TestAccountSettings(val fragment: Fragment, val session: Session) : Troubl
|
|||||||
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_account_settings_quickfix) {
|
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_account_settings_quickfix) {
|
||||||
override fun doFix() {
|
override fun doFix() {
|
||||||
if (manager?.diagStatus == TestStatus.RUNNING) return //wait before all is finished
|
if (manager?.diagStatus == TestStatus.RUNNING) return //wait before all is finished
|
||||||
session?.dataHandler?.bingRulesManager?.updateEnableRuleStatus(defaultRule, !defaultRule.isEnabled,
|
|
||||||
object : BingRulesManager.onBingRuleUpdateListener {
|
|
||||||
|
|
||||||
override fun onBingRuleUpdateSuccess() {
|
// TODO Use constant for kind
|
||||||
|
session.updatePushRuleEnableStatus("override", defaultRule, !defaultRule.enabled,
|
||||||
|
object : MatrixCallback<Unit> {
|
||||||
|
|
||||||
|
override fun onSuccess(data: Unit) {
|
||||||
manager?.retry()
|
manager?.retry()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBingRuleUpdateFailure(errorMessage: String) {
|
override fun onFailure(failure: Throwable) {
|
||||||
manager?.retry()
|
manager?.retry()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -58,8 +62,5 @@ class TestAccountSettings(val fragment: Fragment, val session: Session) : Troubl
|
|||||||
//should not happen?
|
//should not happen?
|
||||||
status = TestStatus.FAILED
|
status = TestStatus.FAILED
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
status = TestStatus.FAILED
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user