mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-17 04:20:00 +03:00
extracting notifiable event creation to its own function
This commit is contained in:
parent
588958c807
commit
77e0b22982
1 changed files with 14 additions and 11 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue