Json parsing

This commit is contained in:
Benoit Marty 2020-02-28 14:14:06 +01:00
parent 41b4f412c4
commit 039924436f
4 changed files with 31 additions and 5 deletions

View File

@ -20,6 +20,7 @@ import com.squareup.moshi.JsonClass
/**
* All push rulesets for a user.
* Ref: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushrules
*/
@JsonClass(generateAdapter = true)
internal data class GetPushRulesResponse(
@ -27,11 +28,11 @@ internal data class GetPushRulesResponse(
* Global rules, account level applying to all devices
*/
@Json(name = "global")
val global: Ruleset,
val global: RuleSet,
/**
* Device specific rules, apply only to current device
*/
@Json(name = "device")
val device: Ruleset? = null
val device: RuleSet? = null
)

View File

@ -24,21 +24,27 @@ import im.vector.matrix.android.api.pushrules.RoomMemberCountCondition
import im.vector.matrix.android.api.pushrules.SenderNotificationPermissionCondition
import timber.log.Timber
/**
* Ref: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushrules
*/
@JsonClass(generateAdapter = true)
data class PushCondition(
/**
* Required. The kind of condition to apply.
*/
@Json(name = "kind")
val kind: String,
/**
* Required for event_match conditions. The dot- separated field of the event to match.
*/
@Json(name = "key")
val key: String? = null,
/**
* Required for event_match conditions.
*/
@Json(name = "pattern")
val pattern: String? = null,
/**
@ -47,7 +53,8 @@ data class PushCondition(
* 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
@Json(name = "is")
val iz: String? = null
) {
fun asExecutableCondition(): Condition? {

View File

@ -19,30 +19,39 @@ package im.vector.matrix.android.api.pushrules.rest
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
/**
* Ref: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushrules
*/
@JsonClass(generateAdapter = true)
data class PushRule(
/**
* Required. The actions to perform when this rule is matched.
*/
@Json(name = "actions")
val actions: List<Any>,
/**
* Required. Whether this is a default rule, or has been set explicitly.
*/
@Json(name = "default")
val default: Boolean? = false,
/**
* Required. Whether the push rule is enabled or not.
*/
@Json(name = "enabled")
val enabled: Boolean,
/**
* Required. The ID of this rule.
*/
@Json(name = "rule_id") val ruleId: String,
@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
*/
@Json(name = "conditions")
val conditions: List<PushCondition>? = null,
/**
* The glob-style pattern to match against. Only applicable to content rules.
*/
@Json(name = "pattern")
val pattern: String? = null
)

View File

@ -15,13 +15,22 @@
*/
package im.vector.matrix.android.api.pushrules.rest
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
/**
* Ref: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushrules
*/
@JsonClass(generateAdapter = true)
internal data class Ruleset(
internal data class RuleSet(
@Json(name = "content")
val content: List<PushRule>? = null,
@Json(name = "override")
val override: List<PushRule>? = null,
@Json(name = "room")
val room: List<PushRule>? = null,
@Json(name = "sender")
val sender: List<PushRule>? = null,
@Json(name = "underride")
val underride: List<PushRule>? = null
)