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

Commit 2d77c7f7 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

AM: Cancel notifications for updated account

parent 34195b1c
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -23,13 +23,6 @@ class PushNotificationManager @Inject constructor(
    private val notificationRegistry: NotificationRegistry
) {

    /**
     * Generates the notification ID for a push notification.
     */
    private fun notificationId(account: Account, dataType: SyncDataType): Int {
        return account.name.hashCode() + account.type.hashCode() + dataType.hashCode()
    }

    /**
     * Sends a notification to inform the user that a push notification has been received, the
     * sync has been scheduled, but it still has not run.
@@ -67,4 +60,12 @@ class PushNotificationManager @Inject constructor(
            .cancel(notificationId(account, dataType))
    }

    companion object {
        /**
         * Generates the notification ID for a push notification.
         */
        fun notificationId(account: Account, dataType: SyncDataType): Int {
            return account.name.hashCode() + account.type.hashCode() + dataType.hashCode()
        }
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -26,7 +26,10 @@ import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext
import androidx.core.app.NotificationManagerCompat
import androidx.hilt.navigation.compose.hiltViewModel
import at.bitfire.davdroid.push.PushNotificationManager
import at.bitfire.davdroid.sync.SyncDataType
import at.bitfire.davdroid.ui.AppTheme
import at.bitfire.davdroid.ui.account.AccountSettingsActivity
import at.bitfire.davdroid.ui.account.AccountSettingsModel
@@ -78,6 +81,13 @@ fun OAuthHandlerScreen(

            // Sync after authenticated
            AccountHelper.scheduleSyncWithDelay(context)

            // Cancel all notifications for this account
            val notificationManager = NotificationManagerCompat.from(context)
            for (dataType in SyncDataType.entries) {
                val notificationId = PushNotificationManager.notificationId(account, dataType)
                notificationManager.cancel(notificationId)
            }
        } else {
            model.authCodeFailed()
        }