extracting notifiable event creation to its own function

This commit is contained in:
Adam Brown 2021-11-03 12:59:37 +00:00
parent 588958c807
commit 77e0b22982
1 changed files with 14 additions and 11 deletions

View File

@ -34,17 +34,7 @@ class PushRuleTriggerListener @Inject constructor(
override fun onEvents(pushEvents: PushEvents) {
session?.let { session ->
val notifiableEvents = pushEvents.matchedEvents.mapNotNull { (event, pushRule) ->
Timber.v("Push rule match for event ${event.eventId}")
val action = pushRule.getActions().toNotificationAction()
if (action.shouldNotify) {
resolver.resolveEvent(event, session, isNoisy = !action.soundName.isNullOrBlank())
} else {
Timber.v("Matched push rule is set to not notify")
null
}
}
val notifiableEvents = createNotifiableEvents(pushEvents, session)
notificationDrawerManager.updateEvents { queuedEvents ->
notifiableEvents.forEach { notifiableEvent ->
queuedEvents.onNotifiableEventReceived(notifiableEvent)
@ -55,6 +45,19 @@ class PushRuleTriggerListener @Inject constructor(
} ?: Timber.e("Called without active session")
}
private fun createNotifiableEvents(pushEvents: PushEvents, session: Session): List<NotifiableEvent> {
return pushEvents.matchedEvents.mapNotNull { (event, pushRule) ->
Timber.v("Push rule match for event ${event.eventId}")
val action = pushRule.getActions().toNotificationAction()
if (action.shouldNotify) {
resolver.resolveEvent(event, session, isNoisy = !action.soundName.isNullOrBlank())
} else {
Timber.v("Matched push rule is set to not notify")
null
}
}
}
fun startWithSession(session: Session) {
if (this.session != null) {
stop()