From dd51b95f53ed51cd648975d950c20c5c5aef05b0 Mon Sep 17 00:00:00 2001 From: pauliancu97 <32488931+pauliancu97@users.noreply.github.com> Date: Mon, 18 Oct 2021 18:42:51 +0300 Subject: [PATCH] Bug fix bailey notification not dismissed (#1655) * added resources to run project * fixed bug of bailey notification not being dismissed * added examples files back --- .../ui/viewmodels/NotificationsViewModel.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/viewmodels/NotificationsViewModel.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/viewmodels/NotificationsViewModel.kt index 37cbd2372..1696cd616 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/viewmodels/NotificationsViewModel.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/viewmodels/NotificationsViewModel.kt @@ -61,7 +61,7 @@ open class NotificationsViewModel : BaseViewModel() { var notifications = convertInvitationsToNotifications(it) if (it.flags?.newStuff == true) { val notification = Notification() - notification.id = "new-stuff-notification" + notification.id = "custom-new-stuff-notification" notification.type = Notification.Type.NEW_STUFF.type val data = NewStuffData() notification.data = data @@ -179,11 +179,19 @@ open class NotificationsViewModel : BaseViewModel() { * instead of one of the ones coming from server. */ private fun isCustomNotification(notification: Notification): Boolean { - return notification.id.startsWith("custom-") || notification.id == "new-stuff-notification" + return notification.id.startsWith("custom-") } + private fun isCustomNewStuffNotification(notification: Notification) = + notification.id == "custom-new-stuff-notification" + fun dismissNotification(notification: Notification) { if (isCustomNotification(notification)) { + if (isCustomNewStuffNotification(notification)) { + customNotifications.onNext( + customNotifications.value?.filterNot { it.id == notification.id } + ) + } return } @@ -199,6 +207,13 @@ open class NotificationsViewModel : BaseViewModel() { .filter { !actionableNotificationTypes.contains(it.type) } .map { it.id } + val customNewStuffNotification = notifications + .firstOrNull { isCustomNewStuffNotification(it) } + + if (customNewStuffNotification != null) { + dismissNotification(customNewStuffNotification) + } + if (dismissableIds.isEmpty()) { return }