Skip to content

Commit a86115b

Browse files
committed
feat(notifications): navigate to edit sever settings when action is UpdateIncomingServerSettings or UpdateOutgoingServerSettings
1 parent 0f3c33f commit a86115b

File tree

9 files changed

+91
-11
lines changed

9 files changed

+91
-11
lines changed

feature/debug-settings/src/main/kotlin/net/thunderbird/feature/debug/settings/notification/DebugNotificationSectionViewModel.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,14 @@ internal class DebugNotificationSectionViewModel(
204204
isIncomingServerError = true,
205205
accountUuid = selectedAccount.uuid,
206206
accountDisplayName = accountDisplay,
207+
accountNumber = 0,
207208
)
208209

209210
CertificateErrorNotification::class -> CertificateErrorNotification(
210211
isIncomingServerError = true,
211212
accountUuid = selectedAccount.uuid,
212213
accountDisplayName = accountDisplay,
214+
accountNumber = 0,
213215
)
214216

215217
FailedToCreateNotification::class -> FailedToCreateNotification(
@@ -218,6 +220,7 @@ internal class DebugNotificationSectionViewModel(
218220
isIncomingServerError = true,
219221
accountUuid = selectedAccount.uuid,
220222
accountDisplayName = accountDisplay,
223+
accountNumber = 0,
221224
),
222225
)
223226

feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/content/AuthenticationErrorNotification.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,22 @@ import org.jetbrains.compose.resources.getString
2121
data class AuthenticationErrorNotification private constructor(
2222
val isIncomingServerError: Boolean,
2323
override val accountUuid: String,
24+
val accountNumber: Int,
2425
override val title: String,
2526
override val contentText: String?,
2627
override val channel: NotificationChannel,
2728
override val icon: NotificationIcon = NotificationIcons.AuthenticationError,
2829
) : AppNotification(), SystemNotification, InAppNotification {
2930
override val severity: NotificationSeverity = NotificationSeverity.Fatal
30-
override val actions: Set<NotificationAction> = setOf(
31-
if (isIncomingServerError) {
32-
NotificationAction.UpdateIncomingServerSettings(accountUuid)
31+
override val actions: Set<NotificationAction> = buildSet {
32+
val action = if (isIncomingServerError) {
33+
NotificationAction.UpdateIncomingServerSettings(accountUuid, accountNumber)
3334
} else {
34-
NotificationAction.UpdateOutgoingServerSettings(accountUuid)
35-
},
36-
)
35+
NotificationAction.UpdateOutgoingServerSettings(accountUuid, accountNumber)
36+
}
37+
add(action)
38+
add(NotificationAction.Tap(override = action))
39+
}
3740
override val inAppNotificationStyle = inAppNotificationStyle { bannerInline() }
3841

3942
override fun asLockscreenNotification(): SystemNotification.LockscreenNotification =
@@ -52,10 +55,12 @@ data class AuthenticationErrorNotification private constructor(
5255
suspend operator fun invoke(
5356
accountUuid: String,
5457
accountDisplayName: String,
58+
accountNumber: Int,
5559
isIncomingServerError: Boolean,
5660
): AuthenticationErrorNotification = AuthenticationErrorNotification(
5761
isIncomingServerError = isIncomingServerError,
5862
accountUuid = accountUuid,
63+
accountNumber = accountNumber,
5964
title = getString(resource = Res.string.notification_authentication_error_title),
6065
contentText = getString(
6166
resource = Res.string.notification_authentication_error_text,

feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/content/CertificateErrorNotification.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.jetbrains.compose.resources.getString
2222
data class CertificateErrorNotification private constructor(
2323
val isIncomingServerError: Boolean,
2424
override val accountUuid: String,
25+
val accountNumber: Int,
2526
override val title: String,
2627
override val contentText: String,
2728
val lockScreenTitle: String,
@@ -31,9 +32,9 @@ data class CertificateErrorNotification private constructor(
3132
override val severity: NotificationSeverity = NotificationSeverity.Fatal
3233
override val actions: Set<NotificationAction> = setOf(
3334
if (isIncomingServerError) {
34-
NotificationAction.UpdateIncomingServerSettings(accountUuid)
35+
NotificationAction.UpdateIncomingServerSettings(accountUuid, accountNumber)
3536
} else {
36-
NotificationAction.UpdateOutgoingServerSettings(accountUuid)
37+
NotificationAction.UpdateOutgoingServerSettings(accountUuid, accountNumber)
3738
},
3839
)
3940

@@ -53,10 +54,12 @@ data class CertificateErrorNotification private constructor(
5354
suspend operator fun invoke(
5455
accountUuid: String,
5556
accountDisplayName: String,
57+
accountNumber: Int,
5658
isIncomingServerError: Boolean,
5759
): CertificateErrorNotification = CertificateErrorNotification(
5860
isIncomingServerError = isIncomingServerError,
5961
accountUuid = accountUuid,
62+
accountNumber = accountNumber,
6063
title = getString(resource = Res.string.notification_certificate_error_title, accountDisplayName),
6164
lockScreenTitle = getString(resource = Res.string.notification_certificate_error_public),
6265
contentText = getString(resource = Res.string.notification_certificate_error_text),

feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/ui/action/NotificationAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ sealed class NotificationAction {
9595
/**
9696
* Action to prompt the user to update server settings, typically when authentication fails.
9797
*/
98-
data class UpdateIncomingServerSettings(val accountUuid: String) : NotificationAction() {
98+
data class UpdateIncomingServerSettings(val accountUuid: String, val accountNumber: Int) : NotificationAction() {
9999
override val icon: NotificationIcon = NotificationActionIcons.UpdateServerSettings
100100
override val titleResource: StringResource = Res.string.notification_action_update_server_settings
101101
}
102102

103103
/**
104104
* Action to prompt the user to update server settings, typically when authentication fails.
105105
*/
106-
data class UpdateOutgoingServerSettings(val accountUuid: String) : NotificationAction() {
106+
data class UpdateOutgoingServerSettings(val accountUuid: String, val accountNumber: Int) : NotificationAction() {
107107
override val icon: NotificationIcon = NotificationActionIcons.UpdateServerSettings
108108
override val titleResource: StringResource = Res.string.notification_action_update_server_settings
109109
}

feature/notification/impl/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ kotlin {
1616
implementation(projects.core.logging.testing)
1717
implementation(projects.feature.notification.testing)
1818
}
19+
androidMain.dependencies {
20+
// should split feature.launcher into api/impl?
21+
implementation(projects.feature.launcher)
22+
}
1923
androidUnitTest.dependencies {
2024
implementation(libs.androidx.test.core)
2125
implementation(libs.mockito.core)

feature/notification/impl/src/androidMain/kotlin/net/thunderbird/feature/notification/impl/inject/NotificationModule.android.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import net.thunderbird.feature.notification.api.receiver.NotificationNotifier
55
import net.thunderbird.feature.notification.impl.intent.action.AlarmPermissionMissingNotificationTapActionIntentCreator
66
import net.thunderbird.feature.notification.impl.intent.action.DefaultNotificationActionIntentCreator
77
import net.thunderbird.feature.notification.impl.intent.action.NotificationActionIntentCreator
8+
import net.thunderbird.feature.notification.impl.intent.action.UpdateServerSettingsNotificationActionIntentCreator
89
import net.thunderbird.feature.notification.impl.receiver.AndroidSystemNotificationNotifier
910
import net.thunderbird.feature.notification.impl.receiver.SystemNotificationNotifier
1011
import net.thunderbird.feature.notification.impl.ui.action.DefaultSystemNotificationActionCreator
@@ -22,6 +23,10 @@ internal actual val platformFeatureNotificationModule: Module = module {
2223
context = androidApplication(),
2324
logger = get(),
2425
),
26+
UpdateServerSettingsNotificationActionIntentCreator(
27+
context = androidApplication(),
28+
logger = get(),
29+
),
2530
// The Default implementation must always be the last.
2631
DefaultNotificationActionIntentCreator(
2732
logger = get(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package net.thunderbird.feature.notification.impl.intent.action
2+
3+
import android.app.PendingIntent
4+
import android.app.PendingIntent.FLAG_UPDATE_CURRENT
5+
import android.content.Context
6+
import androidx.core.app.PendingIntentCompat
7+
import app.k9mail.feature.launcher.FeatureLauncherActivity
8+
import app.k9mail.feature.launcher.FeatureLauncherTarget
9+
import net.thunderbird.core.logging.Logger
10+
import net.thunderbird.feature.notification.api.content.AuthenticationErrorNotification
11+
import net.thunderbird.feature.notification.api.content.Notification
12+
import net.thunderbird.feature.notification.api.ui.action.NotificationAction
13+
14+
private const val TAG = "UpdateServerSettingsNotificationActionIntentCreator"
15+
16+
class UpdateServerSettingsNotificationActionIntentCreator(
17+
private val context: Context,
18+
private val logger: Logger,
19+
) : NotificationActionIntentCreator<AuthenticationErrorNotification, NotificationAction> {
20+
override fun accept(notification: Notification, action: NotificationAction): Boolean =
21+
notification is AuthenticationErrorNotification &&
22+
(
23+
action is NotificationAction.UpdateIncomingServerSettings ||
24+
action is NotificationAction.UpdateOutgoingServerSettings
25+
)
26+
27+
override fun create(
28+
notification: AuthenticationErrorNotification,
29+
action: NotificationAction,
30+
): PendingIntent? {
31+
logger.debug(TAG) { "create() called with: notification = $notification, action = $action" }
32+
val (accountNumber, intent) = when (action) {
33+
is NotificationAction.UpdateIncomingServerSettings -> {
34+
action.accountNumber to FeatureLauncherActivity.getIntent(
35+
context = context,
36+
target = FeatureLauncherTarget.AccountEditIncomingSettings(action.accountUuid),
37+
)
38+
}
39+
40+
is NotificationAction.UpdateOutgoingServerSettings -> {
41+
action.accountNumber to FeatureLauncherActivity.getIntent(
42+
context = context,
43+
target = FeatureLauncherTarget.AccountEditOutgoingSettings(action.accountUuid),
44+
)
45+
}
46+
47+
else -> error("Unsupported action: $action")
48+
}
49+
50+
return PendingIntentCompat.getActivity(
51+
context,
52+
accountNumber,
53+
intent,
54+
FLAG_UPDATE_CURRENT,
55+
false,
56+
)
57+
}
58+
}

feature/notification/impl/src/androidUnitTest/kotlin/net/thunderbird/feature/notification/impl/intent/action/DefaultNotificationActionIntentCreatorTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class DefaultNotificationActionIntentCreatorTest {
4040
NotificationAction.Delete,
4141
NotificationAction.MarkAsSpam,
4242
NotificationAction.Archive,
43-
NotificationAction.UpdateServerSettings,
43+
NotificationAction.UpdateIncomingServerSettings("uuid", 1),
44+
NotificationAction.UpdateOutgoingServerSettings("uuid", 1),
4445
NotificationAction.Retry,
4546
NotificationAction.CustomAction(title = "Custom Action 1"),
4647
NotificationAction.CustomAction(title = "Custom Action 2"),

legacy/core/src/main/java/com/fsck/k9/controller/MessagingController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ public void handleAuthenticationFailure(LegacyAccountDto account, boolean incomi
710710
AuthenticationErrorNotification.Companion.invoke(
711711
account.getUuid(),
712712
account.getDisplayName(),
713+
account.getAccountNumber(),
713714
incoming,
714715
continuation
715716
)

0 commit comments

Comments
 (0)