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> { override val query = Monarchy.Query<EventEntity> {


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

View File

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


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


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



View File

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


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




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


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


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


} }