PushRule: add beforeRuleId and afterRuleId parameter when creating a rule

This commit is contained in:
Benoit Marty 2020-06-24 17:51:32 +02:00
parent 2d6ae3f494
commit c3bdc6127c
6 changed files with 46 additions and 14 deletions

View File

@ -29,13 +29,25 @@ interface PushRuleService {
fun getPushRules(scope: String = RuleScope.GLOBAL): RuleSet
fun updatePushRuleEnableStatus(kind: RuleKind, pushRule: PushRule, enabled: Boolean, callback: MatrixCallback<Unit>): Cancelable
fun updatePushRuleEnableStatus(kind: RuleKind,
pushRule: PushRule,
enabled: Boolean,
callback: MatrixCallback<Unit>): Cancelable
fun addPushRule(kind: RuleKind, pushRule: PushRule, callback: MatrixCallback<Unit>): Cancelable
fun addPushRule(kind: RuleKind,
pushRule: PushRule,
beforeRuleId: String?,
afterRuleId: String?,
callback: MatrixCallback<Unit>): Cancelable
fun updatePushRuleActions(kind: RuleKind, oldPushRule: PushRule, newPushRule: PushRule, callback: MatrixCallback<Unit>): Cancelable
fun updatePushRuleActions(kind: RuleKind,
oldPushRule: PushRule,
newPushRule: PushRule,
callback: MatrixCallback<Unit>): Cancelable
fun removePushRule(kind: RuleKind, pushRule: PushRule, callback: MatrixCallback<Unit>): Cancelable
fun removePushRule(kind: RuleKind,
pushRule: PushRule,
callback: MatrixCallback<Unit>): Cancelable
fun addPushRuleListener(listener: PushRuleListener)

View File

@ -31,7 +31,7 @@ internal data class GetPushRulesResponse(
val global: RuleSet,
/**
* Device specific rules, apply only to current device
* Device specific rules, apply only to current device. Not used anymore
*/
@Json(name = "device")
val device: RuleSet? = null

View File

@ -111,9 +111,13 @@ internal class DefaultPushRuleService @Inject constructor(
.executeBy(taskExecutor)
}
override fun addPushRule(kind: RuleKind, pushRule: PushRule, callback: MatrixCallback<Unit>): Cancelable {
override fun addPushRule(kind: RuleKind,
pushRule: PushRule,
beforeRuleId: String?,
afterRuleId: String?,
callback: MatrixCallback<Unit>): Cancelable {
return addPushRuleTask
.configureWith(AddPushRuleTask.Params(kind, pushRule)) {
.configureWith(AddPushRuleTask.Params(kind, pushRule, beforeRuleId, afterRuleId)) {
this.callback = callback
}
.executeBy(taskExecutor)

View File

@ -25,7 +25,9 @@ import javax.inject.Inject
internal interface AddPushRuleTask : Task<AddPushRuleTask.Params, Unit> {
data class Params(
val kind: RuleKind,
val pushRule: PushRule
val pushRule: PushRule,
val beforeRuleId: String?,
val afterRuleId: String?
)
}
@ -36,7 +38,13 @@ internal class DefaultAddPushRuleTask @Inject constructor(
override suspend fun execute(params: AddPushRuleTask.Params) {
return executeRequest(eventBus) {
apiCall = pushRulesApi.addRule(params.kind.value, params.pushRule.ruleId, params.pushRule)
apiCall = pushRulesApi.addRule(
kind = params.kind.value,
ruleId = params.pushRule.ruleId,
beforeRuleId = params.beforeRuleId,
afterRuleId = params.afterRuleId,
rule = params.pushRule
)
}
}
}

View File

@ -24,6 +24,7 @@ import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Query
/**
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#push-rules-api
@ -74,15 +75,22 @@ internal interface PushRulesApi {
: Call<Unit>
/**
* Add the ruleID enable status
* 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.
*
* @param kind the notification kind (sender, room...)
* @param ruleId the ruleId.
* @param rule the rule to add.
* @param kind the notification kind (sender, room...)
* @param ruleId the ruleId.
* @param beforeRuleId Use 'before' with a rule_id as its value to make the new rule the next-most important rule with
* respect to the given user defined rule. It is not possible to add a rule relative to a predefined server rule.
* @param afterRuleId This makes the new rule the next-less important rule relative to the given user defined rule. It
* is not possible to add a rule relative to a predefined server rule.
* @param rule the rule to add. Note: only a subset of PushRule is documented: actions, condition, pattern. We should create a dedicated model
*/
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}")
fun addRule(@Path("kind") kind: String,
@Path("ruleId") ruleId: String,
@Query("before") beforeRuleId: String?,
@Query("after") afterRuleId: String?,
@Body rule: PushRule)
: Call<Unit>
}

View File

@ -48,7 +48,7 @@ internal class DefaultSetRoomNotificationStateTask @Inject constructor(private v
}
val newRoomPushRule = params.roomNotificationState.toRoomPushRule(params.roomId)
if (newRoomPushRule != null) {
addPushRuleTask.execute(AddPushRuleTask.Params(newRoomPushRule.kind, newRoomPushRule.rule))
addPushRuleTask.execute(AddPushRuleTask.Params(newRoomPushRule.kind, newRoomPushRule.rule, null, null))
}
}
}