diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/NotificationsManager.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/NotificationsManager.kt index 803829294..cfbcb6c4b 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/NotificationsManager.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/NotificationsManager.kt @@ -6,9 +6,11 @@ import com.habitrpg.android.habitica.data.ApiClient import com.habitrpg.android.habitica.models.tasks.Task import com.habitrpg.common.habitica.models.Notification import kotlinx.coroutines.MainScope +import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.filterNotNull +import kotlinx.coroutines.flow.receiveAsFlow import java.lang.ref.WeakReference import java.util.Date @@ -29,8 +31,8 @@ class MainNotificationsManager: NotificationsManager { private var lastNotificationHandling: Date? = null val _notifications = MutableStateFlow?>(null) - val _displaynotificationEvents = MutableStateFlow(null) - override val displayNotificationEvents: Flow = _displaynotificationEvents.filterNotNull() + val _displaynotificationEvents = Channel() + override val displayNotificationEvents: Flow = _displaynotificationEvents.receiveAsFlow().filterNotNull() init { this.seenNotifications = HashMap() @@ -99,12 +101,11 @@ class MainNotificationsManager: NotificationsManager { Notification.Type.ACHIEVEMENT_GENERIC.type -> true Notification.Type.ACHIEVEMENT_ONBOARDING_COMPLETE.type -> true Notification.Type.LOGIN_INCENTIVE.type -> true + Notification.Type.NEW_MYSTERY_ITEMS.type -> true else -> false } if (notificationDisplayed) { - _displaynotificationEvents.value = it - this.seenNotifications[it.id] = true readNotification(it) } } @@ -114,6 +115,8 @@ class MainNotificationsManager: NotificationsManager { private fun readNotification(notification: Notification) { MainScope().launchCatching { + _displaynotificationEvents.send(notification) + seenNotifications[notification.id] = true apiClient?.get()?.readNotification(notification.id) } }