diff --git a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationsModule.kt b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationsModule.kt index 24a55bf..e70350b 100644 --- a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationsModule.kt +++ b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationsModule.kt @@ -28,6 +28,7 @@ class NotificationsModule( fun syncService() = syncService fun credentialProvider() = credentialsStore fun firebasePushTokenUseCase() = firebasePushTokenUseCase + fun roomStore() = roomStore fun notificationsUseCase() = NotificationsUseCase( roomStore, NotificationRenderer(notificationManager(), NotificationFactory(iconLoader, context, intentFactory)), diff --git a/features/notifications/src/main/kotlin/app/dapk/st/notifications/PushAndroidService.kt b/features/notifications/src/main/kotlin/app/dapk/st/notifications/PushAndroidService.kt index 8fc6945..9f6bf55 100644 --- a/features/notifications/src/main/kotlin/app/dapk/st/notifications/PushAndroidService.kt +++ b/features/notifications/src/main/kotlin/app/dapk/st/notifications/PushAndroidService.kt @@ -56,11 +56,8 @@ class PushAndroidService : FirebaseMessagingService() { private suspend fun doSync(roomId: RoomId?, eventId: EventId?) { when (roomId) { null -> { - log(PUSH, "empty push payload - triggering a sync if not running") - withTimeoutOrNull(60_000) { - log(PUSH, "got empty event, forcing a sync") - module.syncService().startSyncing().first() - } ?: log(PUSH, "timed out waiting for sync") + log(PUSH, "empty push payload - keeping sync alive until unread changes") + waitForUnreadChange(60_000) ?: log(PUSH, "timed out waiting for sync") } else -> { log(PUSH, "push with eventId payload - keeping sync alive until the event shows up in the sync response") @@ -82,4 +79,12 @@ class PushAndroidService : FirebaseMessagingService() { } } + private suspend fun waitForUnreadChange(timeout: Long): String? { + return withTimeoutOrNull(timeout) { + combine(module.syncService().startSyncing(), module.roomStore().observeUnread()) { _, unread -> unread } + .first() + "ignored" + } + } + }