fixing reading notification on other session not always being taken into account

- the sync wasn't being triggered for long enough, now we're waiting for 60 seconds or until the unread change
This commit is contained in:
Adam Brown 2022-05-21 11:47:42 +01:00
parent 6e2e377e51
commit 7a10ae3232
2 changed files with 11 additions and 5 deletions

View File

@ -28,6 +28,7 @@ class NotificationsModule(
fun syncService() = syncService fun syncService() = syncService
fun credentialProvider() = credentialsStore fun credentialProvider() = credentialsStore
fun firebasePushTokenUseCase() = firebasePushTokenUseCase fun firebasePushTokenUseCase() = firebasePushTokenUseCase
fun roomStore() = roomStore
fun notificationsUseCase() = NotificationsUseCase( fun notificationsUseCase() = NotificationsUseCase(
roomStore, roomStore,
NotificationRenderer(notificationManager(), NotificationFactory(iconLoader, context, intentFactory)), NotificationRenderer(notificationManager(), NotificationFactory(iconLoader, context, intentFactory)),

View File

@ -56,11 +56,8 @@ class PushAndroidService : FirebaseMessagingService() {
private suspend fun doSync(roomId: RoomId?, eventId: EventId?) { private suspend fun doSync(roomId: RoomId?, eventId: EventId?) {
when (roomId) { when (roomId) {
null -> { null -> {
log(PUSH, "empty push payload - triggering a sync if not running") log(PUSH, "empty push payload - keeping sync alive until unread changes")
withTimeoutOrNull(60_000) { waitForUnreadChange(60_000) ?: log(PUSH, "timed out waiting for sync")
log(PUSH, "got empty event, forcing a sync")
module.syncService().startSyncing().first()
} ?: log(PUSH, "timed out waiting for sync")
} }
else -> { else -> {
log(PUSH, "push with eventId payload - keeping sync alive until the event shows up in the sync response") 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"
}
}
} }