mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Refactor: move Kind to its own file
This commit is contained in:
parent
f745e22a52
commit
558e11a364
5 changed files with 53 additions and 34 deletions
|
@ -20,27 +20,6 @@ import org.matrix.android.sdk.api.session.events.model.Event
|
|||
|
||||
abstract class Condition(val kind: Kind) {
|
||||
|
||||
enum class Kind(val value: String) {
|
||||
EventMatch("event_match"),
|
||||
ContainsDisplayName("contains_display_name"),
|
||||
RoomMemberCount("room_member_count"),
|
||||
SenderNotificationPermission("sender_notification_permission"),
|
||||
Unrecognised("");
|
||||
|
||||
companion object {
|
||||
|
||||
fun fromString(value: String): Kind {
|
||||
return when (value) {
|
||||
"event_match" -> EventMatch
|
||||
"contains_display_name" -> ContainsDisplayName
|
||||
"room_member_count" -> RoomMemberCount
|
||||
"sender_notification_permission" -> SenderNotificationPermission
|
||||
else -> Unrecognised
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun isSatisfied(event: Event, conditionResolver: ConditionResolver): Boolean
|
||||
|
||||
open fun technicalDescription(): String {
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* 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 org.matrix.android.sdk.api.pushrules
|
||||
|
||||
enum class Kind(val value: String) {
|
||||
EventMatch("event_match"),
|
||||
ContainsDisplayName("contains_display_name"),
|
||||
RoomMemberCount("room_member_count"),
|
||||
SenderNotificationPermission("sender_notification_permission"),
|
||||
Unrecognised("");
|
||||
|
||||
companion object {
|
||||
|
||||
fun fromString(value: String): Kind {
|
||||
return when (value) {
|
||||
"event_match" -> EventMatch
|
||||
"contains_display_name" -> ContainsDisplayName
|
||||
"room_member_count" -> RoomMemberCount
|
||||
"sender_notification_permission" -> SenderNotificationPermission
|
||||
else -> Unrecognised
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ import com.squareup.moshi.JsonClass
|
|||
import org.matrix.android.sdk.api.pushrules.Condition
|
||||
import org.matrix.android.sdk.api.pushrules.ContainsDisplayNameCondition
|
||||
import org.matrix.android.sdk.api.pushrules.EventMatchCondition
|
||||
import org.matrix.android.sdk.api.pushrules.Kind
|
||||
import org.matrix.android.sdk.api.pushrules.RoomMemberCountCondition
|
||||
import org.matrix.android.sdk.api.pushrules.SenderNotificationPermissionCondition
|
||||
import timber.log.Timber
|
||||
|
@ -59,8 +60,8 @@ data class PushCondition(
|
|||
) {
|
||||
|
||||
fun asExecutableCondition(): Condition? {
|
||||
return when (Condition.Kind.fromString(kind)) {
|
||||
Condition.Kind.EventMatch -> {
|
||||
return when (Kind.fromString(kind)) {
|
||||
Kind.EventMatch -> {
|
||||
if (key != null && pattern != null) {
|
||||
EventMatchCondition(key, pattern)
|
||||
} else {
|
||||
|
@ -68,10 +69,10 @@ data class PushCondition(
|
|||
null
|
||||
}
|
||||
}
|
||||
Condition.Kind.ContainsDisplayName -> {
|
||||
Kind.ContainsDisplayName -> {
|
||||
ContainsDisplayNameCondition()
|
||||
}
|
||||
Condition.Kind.RoomMemberCount -> {
|
||||
Kind.RoomMemberCount -> {
|
||||
if (iz.isNullOrEmpty()) {
|
||||
Timber.e("Malformed ROOM_MEMBER_COUNT condition")
|
||||
null
|
||||
|
@ -79,7 +80,7 @@ data class PushCondition(
|
|||
RoomMemberCountCondition(iz)
|
||||
}
|
||||
}
|
||||
Condition.Kind.SenderNotificationPermission -> {
|
||||
Kind.SenderNotificationPermission -> {
|
||||
if (key == null) {
|
||||
Timber.e("Malformed Sender Notification Permission condition")
|
||||
null
|
||||
|
@ -87,7 +88,7 @@ data class PushCondition(
|
|||
SenderNotificationPermissionCondition(key)
|
||||
}
|
||||
}
|
||||
Condition.Kind.Unrecognised -> {
|
||||
Kind.Unrecognised -> {
|
||||
Timber.e("Unknown kind $kind")
|
||||
null
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
package org.matrix.android.sdk.internal.database.mapper
|
||||
|
||||
import com.squareup.moshi.Types
|
||||
import org.matrix.android.sdk.api.pushrules.Condition
|
||||
import io.realm.RealmList
|
||||
import org.matrix.android.sdk.api.pushrules.Kind
|
||||
import org.matrix.android.sdk.api.pushrules.rest.PushCondition
|
||||
import org.matrix.android.sdk.api.pushrules.rest.PushRule
|
||||
import org.matrix.android.sdk.internal.database.model.PushRuleEntity
|
||||
import org.matrix.android.sdk.internal.di.MoshiProvider
|
||||
import io.realm.RealmList
|
||||
import timber.log.Timber
|
||||
|
||||
internal object PushRulesMapper {
|
||||
|
@ -39,7 +39,7 @@ internal object PushRulesMapper {
|
|||
enabled = pushrule.enabled,
|
||||
ruleId = pushrule.ruleId,
|
||||
conditions = listOf(
|
||||
PushCondition(Condition.Kind.EventMatch.value, "content.body", pushrule.pattern)
|
||||
PushCondition(Kind.EventMatch.value, "content.body", pushrule.pattern)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ internal object PushRulesMapper {
|
|||
enabled = pushrule.enabled,
|
||||
ruleId = pushrule.ruleId,
|
||||
conditions = listOf(
|
||||
PushCondition(Condition.Kind.EventMatch.value, "room_id", pushrule.ruleId)
|
||||
PushCondition(Kind.EventMatch.value, "room_id", pushrule.ruleId)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ internal object PushRulesMapper {
|
|||
enabled = pushrule.enabled,
|
||||
ruleId = pushrule.ruleId,
|
||||
conditions = listOf(
|
||||
PushCondition(Condition.Kind.EventMatch.value, "user_id", pushrule.ruleId)
|
||||
PushCondition(Kind.EventMatch.value, "user_id", pushrule.ruleId)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
package org.matrix.android.sdk.internal.session.room.notification
|
||||
|
||||
import org.matrix.android.sdk.api.pushrules.Action
|
||||
import org.matrix.android.sdk.api.pushrules.Condition
|
||||
import org.matrix.android.sdk.api.pushrules.Kind
|
||||
import org.matrix.android.sdk.api.pushrules.RuleSetKey
|
||||
import org.matrix.android.sdk.api.pushrules.getActions
|
||||
import org.matrix.android.sdk.api.pushrules.rest.PushCondition
|
||||
|
@ -59,7 +59,7 @@ internal fun RoomNotificationState.toRoomPushRule(roomId: String): RoomPushRule?
|
|||
}
|
||||
else -> {
|
||||
val condition = PushCondition(
|
||||
kind = Condition.Kind.EventMatch.value,
|
||||
kind = Kind.EventMatch.value,
|
||||
key = "room_id",
|
||||
pattern = roomId
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue