diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/BingRuleWatcher.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/BingRuleWatcher.kt index 2e6a1a9a..cf99c205 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/BingRuleWatcher.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/BingRuleWatcher.kt @@ -36,12 +36,15 @@ internal class BingRuleWatcher(monarchy: Monarchy, override val query = Monarchy.Query { EventEntity.types(it, listOf( - EventType.REDACTION, EventType.MESSAGE, EventType.REDACTION, EventType.ENCRYPTED) + EventType.MESSAGE, + EventType.REDACTION, + EventType.ENCRYPTED) ) } override fun processChanges(inserted: List, updated: List, deleted: List) { + // TODO Use const for "global" val rules = defaultPushRuleService.getPushRules("global") inserted.map { it.asDomain() } .filter { it.senderId != sessionParams.credentials.userId } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt index 36b7f720..7db4daa3 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt @@ -33,18 +33,19 @@ internal class DefaultProcessEventForPushTask( private fun fulfilledBingRule(event: Event, rules: List): 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 } diff --git a/vector/src/main/java/im/vector/riotredesign/features/notifications/PushRuleTriggerListener.kt b/vector/src/main/java/im/vector/riotredesign/features/notifications/PushRuleTriggerListener.kt index f3aed6ad..e0fe0fe8 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/notifications/PushRuleTriggerListener.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/notifications/PushRuleTriggerListener.kt @@ -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() } } \ No newline at end of file