forked from GitHub-Mirror/riotX-android
Code review and cleanup
This commit is contained in:
@ -1,2 +0,0 @@
|
||||
package im.vector.matrix.android.api.pushrules
|
||||
|
@ -15,16 +15,23 @@
|
||||
*/
|
||||
package im.vector.matrix.android.api.pushrules.rest
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.android.api.pushrules.rest.Ruleset
|
||||
|
||||
/**
|
||||
* All push rulesets for a user.
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class PushrulesResponse(
|
||||
//Global rules, account level applying to all devices
|
||||
data class GetPushRulesResponse(
|
||||
/**
|
||||
* Global rules, account level applying to all devices
|
||||
*/
|
||||
@Json(name = "global")
|
||||
val global: Ruleset,
|
||||
//Device specific rules, apply only to current device
|
||||
|
||||
/**
|
||||
* Device specific rules, apply only to current device
|
||||
*/
|
||||
@Json(name = "device")
|
||||
val device: Ruleset? = null
|
||||
)
|
@ -22,15 +22,26 @@ import timber.log.Timber
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class PushCondition(
|
||||
//Required. The kind of condition to apply.
|
||||
/**
|
||||
* Required. The kind of condition to apply.
|
||||
*/
|
||||
val kind: String,
|
||||
//Required for event_match conditions. The dot- separated field of the event to match.
|
||||
|
||||
/**
|
||||
* Required for event_match conditions. The dot- separated field of the event to match.
|
||||
*/
|
||||
|
||||
val key: String? = null,
|
||||
//Required for event_match conditions.
|
||||
/**
|
||||
*Required for event_match conditions.
|
||||
*/
|
||||
|
||||
val pattern: String? = null,
|
||||
//Required for room_member_count conditions.
|
||||
// A decimal integer optionally prefixed by one of, ==, <, >, >= or <=.
|
||||
// A prefix of < matches rooms where the member count is strictly less than the given number and so forth. If no prefix is present, this parameter defaults to ==.
|
||||
/**
|
||||
* Required for room_member_count conditions.
|
||||
* A decimal integer optionally prefixed by one of, ==, <, >, >= or <=.
|
||||
* A prefix of < matches rooms where the member count is strictly less than the given number and so forth. If no prefix is present, this parameter defaults to ==.
|
||||
*/
|
||||
@Json(name = "is") val iz: String? = null
|
||||
) {
|
||||
|
||||
@ -58,7 +69,7 @@ data class PushCondition(
|
||||
Condition.Kind.sender_notification_permission -> {
|
||||
this.key?.let { SenderNotificationPermissionCondition(it) }
|
||||
}
|
||||
Condition.Kind.UNRECOGNIZE -> {
|
||||
Condition.Kind.UNRECOGNIZE -> {
|
||||
Timber.e("Unknwon kind $kind")
|
||||
null
|
||||
}
|
||||
|
@ -22,17 +22,29 @@ import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class PushRule(
|
||||
//Required. The domainActions to perform when this rule is matched.
|
||||
/**
|
||||
* Required. The actions to perform when this rule is matched.
|
||||
*/
|
||||
val actions: List<Any>,
|
||||
//Required. Whether this is a default rule, or has been set explicitly.
|
||||
/**
|
||||
* Required. Whether this is a default rule, or has been set explicitly.
|
||||
*/
|
||||
val default: Boolean? = false,
|
||||
//Required. Whether the push rule is enabled or not.
|
||||
/**
|
||||
* Required. Whether the push rule is enabled or not.
|
||||
*/
|
||||
val enabled: Boolean,
|
||||
//Required. The ID of this rule.
|
||||
/**
|
||||
* Required. The ID of this rule.
|
||||
*/
|
||||
@Json(name = "rule_id") val ruleId: String,
|
||||
//The conditions that must hold true for an event in order for a rule to be applied to an event
|
||||
/**
|
||||
* The conditions that must hold true for an event in order for a rule to be applied to an event
|
||||
*/
|
||||
val conditions: List<PushCondition>? = null,
|
||||
//The glob-style pattern to match against. Only applicable to content rules.
|
||||
/**
|
||||
* The glob-style pattern to match against. Only applicable to content rules.
|
||||
*/
|
||||
val pattern: String? = null
|
||||
)
|
||||
|
||||
|
@ -32,7 +32,7 @@ data class Pusher(
|
||||
)
|
||||
|
||||
enum class PusherState {
|
||||
UNREGISTRED,
|
||||
UNREGISTERED,
|
||||
REGISTERING,
|
||||
UNREGISTERING,
|
||||
REGISTERED,
|
||||
|
@ -19,7 +19,7 @@ import io.realm.RealmList
|
||||
import io.realm.RealmObject
|
||||
|
||||
internal open class PushRuleEntity(
|
||||
//Required. The domainActions to perform when this rule is matched.
|
||||
//Required. The actions to perform when this rule is matched.
|
||||
var actionsStr: String? = null,
|
||||
//Required. Whether this is a default rule, or has been set explicitly.
|
||||
var default: Boolean = false,
|
||||
|
@ -38,7 +38,7 @@ internal open class PusherEntity(
|
||||
var lang: String? = null,
|
||||
var data: PusherDataEntity? = null
|
||||
) : RealmObject() {
|
||||
private var stateStr: String = PusherState.UNREGISTRED.name
|
||||
private var stateStr: String = PusherState.UNREGISTERED.name
|
||||
|
||||
var state: PusherState
|
||||
get() {
|
||||
@ -46,7 +46,7 @@ internal open class PusherEntity(
|
||||
return PusherState.valueOf(stateStr)
|
||||
} catch (e: Exception) {
|
||||
//can this happen?
|
||||
return PusherState.UNREGISTRED
|
||||
return PusherState.UNREGISTERED
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,15 +15,17 @@
|
||||
*/
|
||||
package im.vector.matrix.android.internal.database.query
|
||||
|
||||
import im.vector.matrix.android.api.pushrules.rest.PushRule
|
||||
import im.vector.matrix.android.internal.database.model.*
|
||||
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
|
||||
import im.vector.matrix.android.internal.database.model.PusherEntityFields
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.where
|
||||
|
||||
internal fun PusherEntity.Companion.where(realm: Realm, userId: String, pushKey: String? = null): RealmQuery<PusherEntity> {
|
||||
internal fun PusherEntity.Companion.where(realm: Realm,
|
||||
userId: String,
|
||||
pushKey: String? = null): RealmQuery<PusherEntity> {
|
||||
return realm.where<PusherEntity>()
|
||||
.equalTo(PusherEntityFields.USER_ID, userId)
|
||||
.apply {
|
||||
@ -33,9 +35,12 @@ internal fun PusherEntity.Companion.where(realm: Realm, userId: String, pushKey:
|
||||
}
|
||||
}
|
||||
|
||||
internal fun PushRulesEntity.Companion.where(realm: Realm, userId: String, scope: String, rulesetKey: String) : RealmQuery<PushRulesEntity> {
|
||||
return realm.where<PushRulesEntity>()
|
||||
.equalTo(PushRulesEntityFields.USER_ID,userId)
|
||||
.equalTo(PushRulesEntityFields.SCOPE,scope)
|
||||
.equalTo(PushRulesEntityFields.RULESET_KEY,rulesetKey)
|
||||
internal fun PushRulesEntity.Companion.where(realm: Realm,
|
||||
userId: String,
|
||||
scope: String,
|
||||
ruleSetKey: String): RealmQuery<PushRulesEntity> {
|
||||
return realm.where<PushRulesEntity>()
|
||||
.equalTo(PushRulesEntityFields.USER_ID, userId)
|
||||
.equalTo(PushRulesEntityFields.SCOPE, scope)
|
||||
.equalTo(PushRulesEntityFields.RULESET_KEY, ruleSetKey)
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ internal class SessionModule(private val sessionParams: SessionParams) {
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
val retrofit: Retrofit = get()
|
||||
retrofit.create(PushrulesApi::class.java)
|
||||
retrofit.create(PushRulesApi::class.java)
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
@ -184,7 +184,7 @@ internal class SessionModule(private val sessionParams: SessionParams) {
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGetPushrulesTask(get()) as GetPushRulesTask
|
||||
DefaultGetPushRulesTask(get()) as GetPushRulesTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
|
@ -20,8 +20,8 @@ import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.pushrules.Action
|
||||
import im.vector.matrix.android.api.pushrules.PushRuleService
|
||||
import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse
|
||||
import im.vector.matrix.android.api.pushrules.rest.PushRule
|
||||
import im.vector.matrix.android.api.pushrules.rest.PushrulesResponse
|
||||
import im.vector.matrix.android.api.session.events.model.Event
|
||||
import im.vector.matrix.android.internal.database.mapper.PushRulesMapper
|
||||
import im.vector.matrix.android.internal.database.model.PushRulesEntity
|
||||
@ -47,8 +47,8 @@ internal class DefaultPushRuleService(
|
||||
override fun fetchPushRules(scope: String) {
|
||||
pushRulesTask
|
||||
.configureWith(Unit)
|
||||
.dispatchTo(object : MatrixCallback<PushrulesResponse> {
|
||||
override fun onSuccess(data: PushrulesResponse) {
|
||||
.dispatchTo(object : MatrixCallback<GetPushRulesResponse> {
|
||||
override fun onSuccess(data: GetPushRulesResponse) {
|
||||
monarchy.runTransactionSync { realm ->
|
||||
//clear existings?
|
||||
//TODO
|
||||
@ -56,7 +56,7 @@ internal class DefaultPushRuleService(
|
||||
.equalTo(PusherEntityFields.USER_ID, sessionParams.credentials.userId)
|
||||
.findAll().deleteAllFromRealm()
|
||||
|
||||
var content = PushRulesEntity(sessionParams.credentials.userId, scope, "content")
|
||||
val content = PushRulesEntity(sessionParams.credentials.userId, scope, "content")
|
||||
data.global.content?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
content.pushRules.add(it)
|
||||
@ -64,7 +64,7 @@ internal class DefaultPushRuleService(
|
||||
}
|
||||
realm.insertOrUpdate(content)
|
||||
|
||||
var override = PushRulesEntity(sessionParams.credentials.userId, scope, "override")
|
||||
val override = PushRulesEntity(sessionParams.credentials.userId, scope, "override")
|
||||
data.global.override?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
override.pushRules.add(it)
|
||||
@ -72,7 +72,7 @@ internal class DefaultPushRuleService(
|
||||
}
|
||||
realm.insertOrUpdate(override)
|
||||
|
||||
var rooms = PushRulesEntity(sessionParams.credentials.userId, scope, "room")
|
||||
val rooms = PushRulesEntity(sessionParams.credentials.userId, scope, "room")
|
||||
data.global.room?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
rooms.pushRules.add(it)
|
||||
@ -80,7 +80,7 @@ internal class DefaultPushRuleService(
|
||||
}
|
||||
realm.insertOrUpdate(rooms)
|
||||
|
||||
var senders = PushRulesEntity(sessionParams.credentials.userId, scope, "sender")
|
||||
val senders = PushRulesEntity(sessionParams.credentials.userId, scope, "sender")
|
||||
data.global.sender?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
senders.pushRules.add(it)
|
||||
@ -88,7 +88,7 @@ internal class DefaultPushRuleService(
|
||||
}
|
||||
realm.insertOrUpdate(senders)
|
||||
|
||||
var underrides = PushRulesEntity(sessionParams.credentials.userId, scope, "underride")
|
||||
val underrides = PushRulesEntity(sessionParams.credentials.userId, scope, "underride")
|
||||
data.global.underride?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
underrides.pushRules.add(it)
|
||||
@ -106,35 +106,24 @@ internal class DefaultPushRuleService(
|
||||
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()
|
||||
|
||||
monarchy.doWithRealm { realm ->
|
||||
PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "content").findFirst()?.let { re ->
|
||||
contentRules = re.pushRules.map { PushRulesMapper.mapContentRule(it) }
|
||||
}
|
||||
}
|
||||
|
||||
var overrideRules: List<PushRule> = emptyList()
|
||||
monarchy.doWithRealm { realm ->
|
||||
PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "override").findFirst()?.let { re ->
|
||||
overrideRules = re.pushRules.map { PushRulesMapper.map(it) }
|
||||
}
|
||||
}
|
||||
|
||||
var roomRules: List<PushRule> = emptyList()
|
||||
monarchy.doWithRealm { realm ->
|
||||
PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "room").findFirst()?.let { re ->
|
||||
roomRules = re.pushRules.map { PushRulesMapper.mapRoomRule(it) }
|
||||
}
|
||||
}
|
||||
|
||||
var senderRules: List<PushRule> = emptyList()
|
||||
monarchy.doWithRealm { realm ->
|
||||
PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "sender").findFirst()?.let { re ->
|
||||
senderRules = re.pushRules.map { PushRulesMapper.mapSenderRule(it) }
|
||||
}
|
||||
}
|
||||
|
||||
var underrideRules: List<PushRule> = emptyList()
|
||||
monarchy.doWithRealm { realm ->
|
||||
PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "underride").findFirst()?.let { re ->
|
||||
underrideRules = re.pushRules.map { PushRulesMapper.map(it) }
|
||||
}
|
||||
@ -184,6 +173,4 @@ internal class DefaultPushRuleService(
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -47,8 +47,8 @@ internal class DefaultPusherService(
|
||||
override fun refreshPushers() {
|
||||
getPusherTask
|
||||
.configureWith(Unit)
|
||||
.dispatchTo(object : MatrixCallback<PushersResponse> {
|
||||
override fun onSuccess(data: PushersResponse) {
|
||||
.dispatchTo(object : MatrixCallback<GetPushersResponse> {
|
||||
override fun onSuccess(data: GetPushersResponse) {
|
||||
monarchy.runTransactionSync { realm ->
|
||||
//clear existings?
|
||||
realm.where(PusherEntity::class.java)
|
||||
@ -66,9 +66,6 @@ internal class DefaultPusherService(
|
||||
.executeBy(taskExecutor)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
override fun addHttpPusher(pushkey: String, appId: String, profileTag: String,
|
||||
lang: String, appDisplayName: String, deviceDisplayName: String,
|
||||
url: String, append: Boolean, withEventIdOnly: Boolean)
|
||||
|
@ -20,6 +20,7 @@ import com.squareup.moshi.JsonClass
|
||||
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
internal class PushersResponse(
|
||||
@Json(name = "pushers") val pushers: List<JsonPusher>? = null
|
||||
internal class GetPushersResponse(
|
||||
@Json(name = "pushers")
|
||||
val pushers: List<JsonPusher>? = null
|
||||
)
|
@ -19,11 +19,11 @@ import arrow.core.Try
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
|
||||
internal interface GetPushersTask : Task<Unit, PushersResponse>
|
||||
internal interface GetPushersTask : Task<Unit, GetPushersResponse>
|
||||
|
||||
internal class DefaultGetPusherTask(private val pushersAPI: PushersAPI) : GetPushersTask {
|
||||
|
||||
override suspend fun execute(params: Unit): Try<PushersResponse> {
|
||||
override suspend fun execute(params: Unit): Try<GetPushersResponse> {
|
||||
return executeRequest {
|
||||
apiCall = pushersAPI.getPushers()
|
||||
}
|
||||
|
@ -16,18 +16,18 @@
|
||||
package im.vector.matrix.android.internal.session.pushers
|
||||
|
||||
import arrow.core.Try
|
||||
import im.vector.matrix.android.api.pushrules.rest.PushrulesResponse
|
||||
import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
|
||||
|
||||
internal interface GetPushRulesTask : Task<Unit, PushrulesResponse>
|
||||
internal interface GetPushRulesTask : Task<Unit, GetPushRulesResponse>
|
||||
|
||||
internal class DefaultGetPushrulesTask(private val pushrulesApi: PushrulesApi) : GetPushRulesTask {
|
||||
internal class DefaultGetPushRulesTask(private val pushRulesApi: PushRulesApi) : GetPushRulesTask {
|
||||
|
||||
override suspend fun execute(params: Unit): Try<PushrulesResponse> {
|
||||
override suspend fun execute(params: Unit): Try<GetPushRulesResponse> {
|
||||
return executeRequest {
|
||||
apiCall = pushrulesApi.getAllRules()
|
||||
apiCall = pushRulesApi.getAllRules()
|
||||
}
|
||||
}
|
||||
}
|
@ -20,14 +20,7 @@ import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.android.internal.di.SerializeNulls
|
||||
|
||||
/**
|
||||
* pushkey string Required. This is a unique identifier for this pusher. See /set for more detail. Max length, 512 bytes.
|
||||
* kind string Required. The kind of pusher. "http" is a pusher that sends HTTP pokes.
|
||||
* app_id string Required. This is a reverse-DNS style identifier for the application. Max length, 64 chars.
|
||||
* app_display_name string Required. A string that will allow the user to identify what application owns this pusher.
|
||||
* device_display_name string Required. A string that will allow the user to identify what device owns this pusher.
|
||||
* profile_tag string This string determines which set of device specific rules this pusher executes.
|
||||
* lang string Required. The preferred language for receiving notifications (e.g. 'en' or 'en-US')
|
||||
* data PusherData Required. A dictionary of information for the pusher implementation itself.
|
||||
* Example:
|
||||
*
|
||||
* <code>
|
||||
* {
|
||||
@ -50,20 +43,61 @@ import im.vector.matrix.android.internal.di.SerializeNulls
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
internal data class JsonPusher(
|
||||
@Json(name = "pushkey") val pushKey: String,
|
||||
@Json(name = "kind") @SerializeNulls val kind: String?,
|
||||
@Json(name = "app_id") val appId: String,
|
||||
@Json(name = "app_display_name") val appDisplayName: String? = null,
|
||||
@Json(name = "device_display_name") val deviceDisplayName: String? = null,
|
||||
@Json(name = "profile_tag") val profileTag: String? = null,
|
||||
@Json(name = "lang") val lang: String? = null,
|
||||
@Json(name = "data") val data: JsonPusherData? = null,
|
||||
/**
|
||||
* Required. This is a unique identifier for this pusher. See /set for more detail. Max length, 512 bytes.
|
||||
*/
|
||||
@Json(name = "pushkey")
|
||||
val pushKey: String,
|
||||
|
||||
/**
|
||||
* Required. The kind of pusher. "http" is a pusher that sends HTTP pokes.
|
||||
*/
|
||||
@SerializeNulls
|
||||
@Json(name = "kind")
|
||||
val kind: String?,
|
||||
|
||||
/**
|
||||
* Required. This is a reverse-DNS style identifier for the application. Max length, 64 chars.
|
||||
*/
|
||||
@Json(name = "app_id")
|
||||
val appId: String,
|
||||
|
||||
/**
|
||||
* Required. A string that will allow the user to identify what application owns this pusher.
|
||||
*/
|
||||
@Json(name = "app_display_name")
|
||||
val appDisplayName: String? = null,
|
||||
|
||||
/**
|
||||
* Required. A string that will allow the user to identify what device owns this pusher.
|
||||
*/
|
||||
@Json(name = "device_display_name")
|
||||
val deviceDisplayName: String? = null,
|
||||
|
||||
/**
|
||||
* This string determines which set of device specific rules this pusher executes.
|
||||
*/
|
||||
@Json(name = "profile_tag")
|
||||
val profileTag: String? = null,
|
||||
|
||||
/**
|
||||
* Required. The preferred language for receiving notifications (e.g. 'en' or 'en-US')
|
||||
*/
|
||||
@Json(name = "lang")
|
||||
val lang: String? = null,
|
||||
|
||||
/**
|
||||
* Required. A dictionary of information for the pusher implementation itself.
|
||||
*/
|
||||
@Json(name = "data")
|
||||
val data: JsonPusherData? = null,
|
||||
|
||||
// Only used to update add Pusher (body of api request)
|
||||
// Used If true, the homeserver should add another pusher with the given pushkey and App ID in addition
|
||||
// to any others with different user IDs.
|
||||
// Otherwise, the homeserver must remove any other pushers with the same App ID and pushkey for different users.
|
||||
// The default is false.
|
||||
@Json(name = "append") val append: Boolean? = false
|
||||
@Json(name = "append")
|
||||
val append: Boolean? = false
|
||||
)
|
||||
|
||||
|
@ -20,8 +20,15 @@ import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
internal data class JsonPusherData(
|
||||
//Required if kind is http. The URL to use to send notifications to.
|
||||
@Json(name = "url") val url: String? = null,
|
||||
//The format to use when sending notifications to the Push Gateway.
|
||||
@Json(name = "format") val format: String? = null
|
||||
/**
|
||||
* Required if kind is http. The URL to use to send notifications to.
|
||||
*/
|
||||
@Json(name = "url")
|
||||
val url: String? = null,
|
||||
|
||||
/**
|
||||
* The format to use when sending notifications to the Push Gateway.
|
||||
*/
|
||||
@Json(name = "format")
|
||||
val format: String? = null
|
||||
)
|
@ -16,18 +16,18 @@
|
||||
package im.vector.matrix.android.internal.session.pushers
|
||||
|
||||
import im.vector.matrix.android.api.pushrules.rest.PushRule
|
||||
import im.vector.matrix.android.api.pushrules.rest.PushrulesResponse
|
||||
import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse
|
||||
import im.vector.matrix.android.internal.network.NetworkConstants
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.*
|
||||
|
||||
|
||||
internal interface PushrulesApi {
|
||||
internal interface PushRulesApi {
|
||||
/**
|
||||
* Get all push rules
|
||||
*/
|
||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/")
|
||||
fun getAllRules(): Call<PushrulesResponse>
|
||||
fun getAllRules(): Call<GetPushRulesResponse>
|
||||
|
||||
/**
|
||||
* Update the ruleID enable status
|
||||
@ -37,28 +37,36 @@ 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, @Path("ruleId") ruleId: String, @Body enable: Boolean?): Call<Unit>
|
||||
fun updateEnableRuleStatus(@Path("kind") kind: String,
|
||||
@Path("ruleId") ruleId: String,
|
||||
@Body enable: Boolean?)
|
||||
: Call<Unit>
|
||||
|
||||
|
||||
/**
|
||||
* Update the ruleID enable status
|
||||
* Update the ruleID action
|
||||
*
|
||||
* @param kind the notification kind (sender, room...)
|
||||
* @param ruleId the ruleId
|
||||
* @param actions the actions
|
||||
*/
|
||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/actions")
|
||||
fun updateRuleActions(@Path("kind") kind: String, @Path("ruleId") ruleId: String, @Body actions: Any): Call<Unit>
|
||||
fun updateRuleActions(@Path("kind") kind: String,
|
||||
@Path("ruleId") ruleId: String,
|
||||
@Body actions: Any)
|
||||
: Call<Unit>
|
||||
|
||||
|
||||
/**
|
||||
* Update the ruleID enable status
|
||||
* Delete a rule
|
||||
*
|
||||
* @param kind the notification kind (sender, room...)
|
||||
* @param ruleId the ruleId
|
||||
*/
|
||||
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}")
|
||||
fun deleteRule(@Path("kind") kind: String, @Path("ruleId") ruleId: String): Call<Unit>
|
||||
fun deleteRule(@Path("kind") kind: String,
|
||||
@Path("ruleId") ruleId: String)
|
||||
: Call<Unit>
|
||||
|
||||
/**
|
||||
* Add the ruleID enable status
|
||||
@ -68,5 +76,8 @@ 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, @Path("ruleId") ruleId: String, @Body rule: PushRule): Call<Unit>
|
||||
fun addRule(@Path("kind") kind: String,
|
||||
@Path("ruleId") ruleId: String,
|
||||
@Body rule: PushRule)
|
||||
: Call<Unit>
|
||||
}
|
@ -27,14 +27,16 @@ internal interface PushersAPI {
|
||||
/**
|
||||
* Get the pushers for this user.
|
||||
*
|
||||
* Ref: https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-thirdparty-protocols
|
||||
* Ref: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers
|
||||
*/
|
||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushers")
|
||||
fun getPushers(): Call<PushersResponse>
|
||||
fun getPushers(): Call<GetPushersResponse>
|
||||
|
||||
/**
|
||||
* This endpoint allows the creation, modification and deletion of pushers for this user ID.
|
||||
* The behaviour of this endpoint varies depending on the values in the JSON body.
|
||||
*
|
||||
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-pushers-set
|
||||
*/
|
||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushers/set")
|
||||
fun setPusher(@Body jsonPusher: JsonPusher): Call<Unit>
|
||||
|
@ -12,7 +12,9 @@ import im.vector.matrix.android.internal.task.Task
|
||||
import im.vector.matrix.android.internal.util.tryTransactionSync
|
||||
|
||||
internal interface RemovePusherTask : Task<RemovePusherTask.Params, Unit> {
|
||||
data class Params(val userId: String, val pushKey: String, val pushAppId: String)
|
||||
data class Params(val userId: String,
|
||||
val pushKey: String,
|
||||
val pushAppId: String)
|
||||
}
|
||||
|
||||
internal class DefaultRemovePusherTask(
|
||||
@ -35,10 +37,11 @@ internal class DefaultRemovePusherTask(
|
||||
}
|
||||
}.flatMap {
|
||||
executeRequest<Unit> {
|
||||
val deleteRequest = JsonPusher(
|
||||
val deleteBody = JsonPusher(
|
||||
pushKey = params.pushKey,
|
||||
appId = params.pushAppId,
|
||||
kind = null, //null deletes the pusher
|
||||
// kind null deletes the pusher
|
||||
kind = null,
|
||||
appDisplayName = it.appDisplayName ?: "",
|
||||
deviceDisplayName = it.deviceDisplayName ?: "",
|
||||
profileTag = it.profileTag ?: "",
|
||||
@ -46,7 +49,7 @@ internal class DefaultRemovePusherTask(
|
||||
data = JsonPusherData(it.data.url, it.data.format),
|
||||
append = false
|
||||
)
|
||||
apiCall = pushersAPI.setPusher(deleteRequest)
|
||||
apiCall = pushersAPI.setPusher(deleteBody)
|
||||
}
|
||||
}.flatMap {
|
||||
monarchy.tryTransactionSync {
|
||||
|
@ -29,7 +29,7 @@ import im.vector.matrix.android.internal.task.Task
|
||||
|
||||
internal interface SyncTask : Task<SyncTask.Params, SyncResponse> {
|
||||
|
||||
data class Params(val token: String?, var timeout: Long = 30_1000L)
|
||||
data class Params(val token: String?, var timeout: Long = 30_000L)
|
||||
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class PushRuleActionsTest {
|
||||
val pushRule = MoshiProvider.providesMoshi().adapter<PushRule>(PushRule::class.java).fromJson(rawPushRule)
|
||||
|
||||
Assert.assertNotNull("Should have parsed the rule", pushRule)
|
||||
Assert.assertNotNull("Failed to parse domainActions", Action.mapFrom(pushRule!!))
|
||||
Assert.assertNotNull("Failed to parse actions", Action.mapFrom(pushRule!!))
|
||||
|
||||
val actions = Action.mapFrom(pushRule)
|
||||
Assert.assertEquals(3, actions!!.size)
|
||||
|
Reference in New Issue
Block a user