Rename and format and remove duplicate EventType.REDACTION

This commit is contained in:
Benoit Marty 2019-06-26 14:35:00 +02:00 committed by Benoit Marty
parent d1642c928a
commit ae7e617fdd
3 changed files with 24 additions and 20 deletions

View File

@ -36,12 +36,15 @@ internal class BingRuleWatcher(monarchy: Monarchy,
override val query = Monarchy.Query<EventEntity> {

EventEntity.types(it, listOf(
EventType.REDACTION, EventType.MESSAGE, EventType.REDACTION, EventType.ENCRYPTED)
EventType.MESSAGE,
EventType.REDACTION,
EventType.ENCRYPTED)
)

}

override fun processChanges(inserted: List<EventEntity>, updated: List<EventEntity>, deleted: List<EventEntity>) {
// TODO Use const for "global"
val rules = defaultPushRuleService.getPushRules("global")
inserted.map { it.asDomain() }
.filter { it.senderId != sessionParams.credentials.userId }

View File

@ -33,18 +33,19 @@ internal class DefaultProcessEventForPushTask(

private fun fulfilledBingRule(event: Event, rules: List<PushRule>): PushRule? {
val conditionResolver = DefaultConditionResolver(event)
rules.filter { it.enabled }.forEach { rule ->
val isFullfilled = rule.conditions?.map {
it.asExecutableCondition()?.isSatisfied(conditionResolver) ?: false
}?.fold(true/*A rule with no conditions always matches*/, { acc, next ->
//All conditions must hold true for an event in order to apply the action for the event.
acc && next
}) ?: false
rules.filter { it.enabled }
.forEach { rule ->
val isFullfilled = rule.conditions?.map {
it.asExecutableCondition()?.isSatisfied(conditionResolver) ?: false
}?.fold(true/*A rule with no conditions always matches*/, { acc, next ->
//All conditions must hold true for an event in order to apply the action for the event.
acc && next
}) ?: false

if (isFullfilled) {
return rule
}
}
if (isFullfilled) {
return rule
}
}
return null
}


View File

@ -25,7 +25,7 @@ import timber.log.Timber

class PushRuleTriggerListener(
private val resolver: NotifiableEventResolver,
private val drawerManager: NotificationDrawerManager
private val notificationDrawerManager: NotificationDrawerManager
) : PushRuleService.PushRuleListener {


@ -39,14 +39,14 @@ class PushRuleTriggerListener(
}
val notificationAction = NotificationAction.extractFrom(actions)
if (notificationAction.shouldNotify) {
val resolveEvent = resolver.resolveEvent(event, session!!)
if (resolveEvent == null) {
val notifiableEvent = resolver.resolveEvent(event, session!!)
if (notifiableEvent == null) {
Timber.v("## Failed to resolve event")
//TODO
} else {
resolveEvent.noisy = !notificationAction.soundName.isNullOrBlank()
Timber.v("New event to notify $resolveEvent tweaks:$notificationAction")
drawerManager.onNotifiableEventReceived(resolveEvent)
notifiableEvent.noisy = !notificationAction.soundName.isNullOrBlank()
Timber.v("New event to notify $notifiableEvent tweaks:$notificationAction")
notificationDrawerManager.onNotifiableEventReceived(notifiableEvent)
}
} else {
Timber.v("Matched push rule is set to not notify")
@ -54,7 +54,7 @@ class PushRuleTriggerListener(
}

override fun batchFinish() {
drawerManager.refreshNotificationDrawer()
notificationDrawerManager.refreshNotificationDrawer()
}

fun startWithSession(session: Session) {
@ -68,7 +68,7 @@ class PushRuleTriggerListener(
fun stop() {
session?.removePushRuleListener(this)
session = null
drawerManager.clearAllEvents()
notificationDrawerManager.clearAllEvents()
}

}