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

Unverified Commit e597d012 authored by Rafael Tonholo's avatar Rafael Tonholo
Browse files

feat(notification): add and categorize the application's notification data types

parent a472a5ce
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <!-- TODO: Perform a cleanup removing the other resources from the other modules with the same name once the notification system is consolidated. -->
    <!-- Channel configuration -->
    <string name="notification_channel_push_title">Synchronize (Push)</string>
    <string name="notification_channel_push_description">Displayed while waiting for new messages</string>
    <string name="notification_channel_messages_title">Messages</string>
    <string name="notification_channel_messages_description">Notifications related to messages</string>
    <string name="notification_channel_miscellaneous_title">Miscellaneous</string>
    <string name="notification_channel_miscellaneous_description">Miscellaneous notifications like errors etc.</string>

    <!-- Title of an error notification that is displayed when creating a notification for a new message has failed -->
    <string name="notification_notify_error_title">Notification error</string>
    <!-- Body of an error notification that is displayed when creating a notification for a new message has failed -->
    <string name="notification_notify_error_text">An error has occurred while trying to create a system notification for a new message. The reason is most likely a missing notification sound.\n\nTap to open notification settings.</string>

    <string name="notification_authentication_error_title">Authentication failed</string>
    <string name="notification_authentication_error_text">Authentication failed for %s. Update your server settings.</string>

    <string name="notification_certificate_error_public">Certificate error</string>
    <string name="notification_certificate_error_title">Certificate error for %s</string>
    <string name="notification_certificate_error_text">Check your server settings</string>

    <string name="notification_bg_sync_ticker">Checking mail: %1$s: %2$s</string>
    <string name="notification_bg_sync_title">Checking mail</string>
    <string name="notification_bg_sync_text">%1$s: %2$s</string>
    <string name="notification_bg_send_ticker">Sending mail: %s</string>
    <string name="notification_bg_send_title">Sending mail</string>

    <string name="send_failure_subject">Failed to send some messages</string>

    <plurals name="notification_new_messages_title">
        <item quantity="one">%d new message</item>
        <item quantity="other">%d new messages</item>
    </plurals>
    <string name="notification_additional_messages">+ %1$d more on %2$s</string>

    <string name="push_notification_state_initializing">Initializing…</string>
    <string name="push_notification_state_listening">Waiting for new emails</string>
    <string name="push_notification_state_wait_background_sync">Sleeping until background sync is allowed</string>
    <string name="push_notification_state_wait_network">Sleeping until network is available</string>
    <string name="push_notification_state_alarm_permission_missing">Missing permission to schedule alarms</string>
    <string name="push_notification_info">Tap to learn more.</string>
    <string name="push_notification_grant_alarm_permission">Tap to grant permission.</string>

    <string name="push_info_disable_push_action">Disable Push</string>

</resources>
+31 −0
Original line number Diff line number Diff line
package net.thunderbird.feature.notification

/**
 * Defines the appearance of notifications on the lock screen.
 */
sealed interface LockscreenNotificationAppearance {
    /**
     * No notifications are shown on the lock screen.
     */
    data object None : LockscreenNotificationAppearance

    /**
     * Only the app name is shown on the lock screen for new messages.
     */
    data object AppName : LockscreenNotificationAppearance

    /**
     * All the notification content's is shown on the lock screen.
     */
    data object Public : LockscreenNotificationAppearance

    /**
     * The number of new messages is shown on the lock screen.
     */
    data object MessageCount : LockscreenNotificationAppearance

    /**
     * The names of the senders of new messages are shown on the lock screen.
     */
    data class SenderNames(val senderNames: String) : LockscreenNotificationAppearance
}
+123 −0
Original line number Diff line number Diff line
package net.thunderbird.feature.notification

import net.thunderbird.feature.notification.resources.Res
import net.thunderbird.feature.notification.resources.notification_channel_messages_description
import net.thunderbird.feature.notification.resources.notification_channel_messages_title
import net.thunderbird.feature.notification.resources.notification_channel_miscellaneous_description
import net.thunderbird.feature.notification.resources.notification_channel_miscellaneous_title
import net.thunderbird.feature.notification.resources.notification_channel_push_description
import net.thunderbird.feature.notification.resources.notification_channel_push_title
import org.jetbrains.compose.resources.StringResource

/**
 * Represents the different notification channels used by the application.
 *
 * Each sealed class variant defines a specific type of notification channel with its unique [id].
 *
 * @property id The unique identifier for the notification channel.
 * @property name The user-visible name of the channel.
 * @property description The user-visible description of the channel.
 * @property importance The importance level of the channel.
 */
sealed class NotificationChannel(
    val id: String,
    val name: StringResource,
    val description: StringResource,
    val importance: NotificationChannelImportance,
) {
    /**
     * Represents a notification channel for new messages.
     *
     * @property accountUuid The unique identifier of the account associated with these messages.
     * @property suffix An optional suffix to further differentiate the channel, e.g., for different folder types.
     */
    data class Messages(
        val accountUuid: String,
        val suffix: String,
    ) : NotificationChannel(
        id = "messages_channel_$accountUuid$suffix",
        name = Res.string.notification_channel_messages_title,
        description = Res.string.notification_channel_messages_description,
        importance = NotificationChannelImportance.Default,
    )

    /**
     * Represents a notification channel for miscellaneous notifications.
     *
     * This channel is used for notifications that don't fit into other specific categories.
     * The channel ID is "misc" if no account is specified, or "miscellaneous_channel_[accountUuid]" if an
     * account is provided.
     *
     * @property accountUuid The unique identifier of the account associated with these notifications, if applicable.
     */
    data class Miscellaneous(
        val accountUuid: String? = null,
    ) : NotificationChannel(
        id = if (accountUuid.isNullOrBlank()) {
            "misc"
        } else {
            "miscellaneous_channel_$accountUuid"
        },
        name = Res.string.notification_channel_miscellaneous_title,
        description = Res.string.notification_channel_miscellaneous_description,
        importance = NotificationChannelImportance.Low,
    )

    /**
     * Represents a notification channel for push service messages.
     *
     * This channel is used for notifications related to the background push service,
     * such as connection status or errors.
     */
    data object PushService : NotificationChannel(
        id = "push",
        name = Res.string.notification_channel_push_title,
        description = Res.string.notification_channel_push_description,
        importance = NotificationChannelImportance.Low,
    )
}

/**
 * Represents the importance level of a notification channel.
 *
 * These levels correspond to the Android notification channel importance constants.
 * @see NotificationChannelImportance.None
 * @see NotificationChannelImportance.Min
 * @see NotificationChannelImportance.Low
 * @see NotificationChannelImportance.Default
 * @see NotificationChannelImportance.High
 */
enum class NotificationChannelImportance {
    /**
     * A notification with no importance: does not show in the notification panel.
     */
    None,

    /**
     * Min notification importance: only shows in the notification panel, below the fold.
     *
     * **Android**: This should not be used with `Service.startForeground` since a foreground service is
     * supposed to be something the user cares about so it does not make semantic sense to mark its notification
     * as minimum importance.
     *
     * If you do this as of Android version `Build.VERSION_CODES.O`, the system will show a higher-priority
     * notification about your app running in the background.
     */
    Min,

    /**
     * Low notification importance: Shows in the shade, and potentially in the status bar, but is not
     * audibly intrusive.
     */
    Low,

    /**
     * Default notification importance: shows everywhere, makes noise, but does not visually intrude.
     */
    Default,

    /**
     * Higher notification importance: shows everywhere, makes noise and peeks. May use full screen intents.
     */
    High,
}
+7 −0
Original line number Diff line number Diff line
package net.thunderbird.feature.notification

// TODO: Properly handle notification groups, adding summary, etc.
data class NotificationGroup(
    val key: NotificationGroupKey,
    val summary: String,
)
+13 −0
Original line number Diff line number Diff line
package net.thunderbird.feature.notification

/**
 * Represents a key for a notification group.
 *
 * This class is used to uniquely identify a group of notifications that should be displayed together.
 * For example, all notifications related to a specific account could be grouped together using a
 * NotificationGroupKey.
 *
 * @param value The string value of the notification group key.
 */
@JvmInline
value class NotificationGroupKey(val value: String)
Loading