Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 3665deef authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #6516 from thundernest/fix_dismissing_notifications

Fix notification reappearing shortly after it was dismissed
parents de62a17c 4b5df5ad
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ internal class NewMailNotificationController(
    private val summaryNotificationCreator: SummaryNotificationCreator,
    private val singleMessageNotificationCreator: SingleMessageNotificationCreator
) {
    @Synchronized
    fun restoreNewMailNotifications(accounts: List<Account>) {
        for (account in accounts) {
            val notificationData = newMailNotificationManager.restoreNewMailNotifications(account)
@@ -24,6 +25,7 @@ internal class NewMailNotificationController(
        }
    }

    @Synchronized
    fun addNewMailNotification(account: Account, message: LocalMessage, silent: Boolean) {
        val notificationData = newMailNotificationManager.addNewMailNotification(account, message, silent)

@@ -32,6 +34,7 @@ internal class NewMailNotificationController(
        }
    }

    @Synchronized
    fun removeNewMailNotifications(
        account: Account,
        clearNewMessageState: Boolean,
@@ -48,6 +51,7 @@ internal class NewMailNotificationController(
        }
    }

    @Synchronized
    fun clearNewMailNotifications(account: Account, clearNewMessageState: Boolean) {
        val cancelNotificationIds = newMailNotificationManager.clearNewMailNotifications(account, clearNewMessageState)

+5 −0
Original line number Diff line number Diff line
@@ -15,6 +15,11 @@ internal const val MAX_NUMBER_OF_NEW_MESSAGE_NOTIFICATIONS = 8
internal class NotificationDataStore {
    private val notificationDataMap = mutableMapOf<String, NotificationData>()

    @Synchronized
    fun isAccountInitialized(account: Account): Boolean {
        return notificationDataMap[account.uuid] != null
    }

    @Synchronized
    fun initializeAccount(
        account: Account,
+13 −3
Original line number Diff line number Diff line
@@ -15,14 +15,14 @@ internal class NotificationRepository(

    @Synchronized
    fun restoreNotifications(account: Account): NotificationData? {
        if (notificationDataStore.isAccountInitialized(account)) return null

        val localStore = localStoreProvider.getInstance(account)

        val (activeNotificationMessages, inactiveNotificationMessages) = localStore.notificationMessages.partition {
            it.notificationId != null
        }

        if (activeNotificationMessages.isEmpty()) return null

        val activeNotifications = activeNotificationMessages.map { notificationMessage ->
            val content = notificationContentCreator.createFromMessage(account, notificationMessage.message)
            NotificationHolder(notificationMessage.notificationId!!, notificationMessage.timestamp, content)
@@ -33,11 +33,19 @@ internal class NotificationRepository(
            InactiveNotificationHolder(notificationMessage.timestamp, content)
        }

        return notificationDataStore.initializeAccount(account, activeNotifications, inactiveNotifications)
        val notificationData = notificationDataStore.initializeAccount(
            account,
            activeNotifications,
            inactiveNotifications
        )

        return if (notificationData.activeNotifications.isNotEmpty()) notificationData else null
    }

    @Synchronized
    fun addNotification(account: Account, content: NotificationContent, timestamp: Long): AddNotificationResult? {
        restoreNotifications(account)

        return notificationDataStore.addNotification(account, content, timestamp)?.also { result ->
            persistNotificationDataStoreChanges(
                account = account,
@@ -53,6 +61,8 @@ internal class NotificationRepository(
        clearNewMessageState: Boolean = true,
        selector: (List<MessageReference>) -> List<MessageReference>
    ): RemoveNotificationsResult? {
        restoreNotifications(account)

        return notificationDataStore.removeNotifications(account, selector)?.also { result ->
            persistNotificationDataStoreChanges(
                account = account,