From c617377ca468c407edb678e4b1b14a697f3b5f43 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Wed, 28 Mar 2018 19:55:22 -0400 Subject: [PATCH] Delay before notifying --- domain/src/main/java/interactor/ReceiveSms.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/domain/src/main/java/interactor/ReceiveSms.kt b/domain/src/main/java/interactor/ReceiveSms.kt index 04960616..5fbf1a92 100644 --- a/domain/src/main/java/interactor/ReceiveSms.kt +++ b/domain/src/main/java/interactor/ReceiveSms.kt @@ -23,6 +23,7 @@ import io.reactivex.Flowable import manager.NotificationManager import repository.MessageRepository import util.extensions.mapNotNull +import java.util.concurrent.TimeUnit import javax.inject.Inject class ReceiveSms @Inject constructor( @@ -46,6 +47,7 @@ class ReceiveSms @Inject constructor( .mapNotNull { message -> message.conversation } // Map message to conversation .filter { conversation -> !conversation.blocked } // Don't notify for blocked conversations .doOnNext { conversation -> if (conversation.archived) messageRepo.markUnarchived(conversation.id) } // Unarchive conversation if necessary + .delay(1, TimeUnit.SECONDS) // Wait one second before trying to notify, in case the foreground app marks it as read first .doOnNext { conversation -> notificationManager.update(conversation.id) } // Update the notification .flatMap { updateBadge.buildObservable(Unit) } // Update the badge }