Rename and format and remove duplicate EventType.REDACTION
This commit is contained in:
parent
d1642c928a
commit
ae7e617fdd
@ -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 }
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user