8585import net .thunderbird .core .android .account .LegacyAccountDto ;
8686import net .thunderbird .core .common .exception .MessagingException ;
8787import net .thunderbird .core .featureflag .FeatureFlagProvider ;
88- import net .thunderbird .core .featureflag .FeatureFlagResult .Enabled ;
8988import net .thunderbird .core .featureflag .compat .FeatureFlagProviderCompat ;
9089import net .thunderbird .core .logging .Logger ;
9190import net .thunderbird .core .logging .legacy .Log ;
9291import net .thunderbird .feature .mail .folder .api .OutboxFolderManager ;
9392import net .thunderbird .feature .mail .folder .api .OutboxFolderManagerKt ;
93+ import net .thunderbird .feature .notification .api .NotificationManager ;
9494import net .thunderbird .feature .notification .api .content .AuthenticationErrorNotification ;
9595import net .thunderbird .feature .notification .api .content .NotificationFactoryCoroutineCompat ;
96- import net .thunderbird .feature .notification .api .sender . NotificationSender ;
96+ import net .thunderbird .feature .notification .api .dismisser . compat . NotificationDismisserCompat ;
9797import net .thunderbird .feature .notification .api .sender .compat .NotificationSenderCompat ;
9898import net .thunderbird .feature .search .legacy .LocalMessageSearch ;
9999import org .jetbrains .annotations .NotNull ;
@@ -145,9 +145,9 @@ public class MessagingController implements MessagingControllerRegistry, Messagi
145145 private final ArchiveOperations archiveOperations ;
146146 private final FeatureFlagProvider featureFlagProvider ;
147147 private final Logger syncDebugLogger ;
148- private final NotificationSenderCompat notificationSender ;
149148 private final OutboxFolderManager outboxFolderManager ;
150-
149+ private final NotificationSenderCompat notificationSender ;
150+ private final NotificationDismisserCompat notificationDismisser ;
151151
152152 private volatile boolean stopped = false ;
153153
@@ -171,7 +171,7 @@ public static MessagingController getInstance(Context context) {
171171 List <ControllerExtension > controllerExtensions ,
172172 FeatureFlagProvider featureFlagProvider ,
173173 Logger syncDebugLogger ,
174- NotificationSender notificationSender ,
174+ NotificationManager notificationManager ,
175175 OutboxFolderManager outboxFolderManager
176176 ) {
177177 this .context = context ;
@@ -186,7 +186,8 @@ public static MessagingController getInstance(Context context) {
186186 this .localDeleteOperationDecider = localDeleteOperationDecider ;
187187 this .featureFlagProvider = featureFlagProvider ;
188188 this .syncDebugLogger = syncDebugLogger ;
189- this .notificationSender = new NotificationSenderCompat (notificationSender );
189+ this .notificationSender = new NotificationSenderCompat (notificationManager );
190+ this .notificationDismisser = new NotificationDismisserCompat (notificationManager );
190191 this .outboxFolderManager = outboxFolderManager ;
191192
192193 controllerThread = new Thread (new Runnable () {
@@ -707,32 +708,36 @@ public void handleAuthenticationFailure(LegacyAccountDto account, boolean incomi
707708 migrateAccountToOAuth (account );
708709 }
709710
710- if (FeatureFlagProviderCompat .provide (featureFlagProvider , "display_in_app_notifications" ) ==
711- Enabled .INSTANCE ) {
711+ if (FeatureFlagProviderCompat .provide (featureFlagProvider , "display_in_app_notifications" ).isEnabled ()) {
712712 Log .d ("handleAuthenticationFailure: sending in-app notification" );
713- final AuthenticationErrorNotification notification = NotificationFactoryCoroutineCompat .create (
714- continuation ->
715- AuthenticationErrorNotification .Companion .invoke (
716- account .getUuid (),
717- account .getDisplayName (),
718- account .getAccountNumber (),
719- incoming ,
720- continuation
721- )
722- );
713+ final AuthenticationErrorNotification notification = createAuthenticationErrorNotification (account , incoming );
723714
724715 notificationSender .send (notification , outcome -> {
725716 Log .v ("notificationSender outcome = " + outcome );
726717 });
727718 }
728719
729720 if (FeatureFlagProviderCompat .provide (featureFlagProvider ,
730- "use_notification_sender_for_system_notifications" ) != Enabled . INSTANCE ) {
721+ "use_notification_sender_for_system_notifications" ). isDisabled () ) {
731722 Log .d ("handleAuthenticationFailure: sending system notification via old notification controller" );
732723 notificationController .showAuthenticationErrorNotification (account , incoming );
733724 }
734725 }
735726
727+ private AuthenticationErrorNotification createAuthenticationErrorNotification (
728+ LegacyAccountDto account , boolean incoming ) {
729+ return NotificationFactoryCoroutineCompat .create (
730+ continuation ->
731+ AuthenticationErrorNotification .Companion .invoke (
732+ account .getUuid (),
733+ account .getDisplayName (),
734+ account .getAccountNumber (),
735+ incoming ,
736+ continuation
737+ )
738+ );
739+ }
740+
736741 private void migrateAccountToOAuth (LegacyAccountDto account ) {
737742 account .setIncomingServerSettings (account .getIncomingServerSettings ().newAuthenticationType (AuthType .XOAUTH2 ));
738743 account .setOutgoingServerSettings (account .getOutgoingServerSettings ().newAuthenticationType (AuthType .XOAUTH2 ));
@@ -2599,10 +2604,15 @@ public void checkAuthenticationProblem(LegacyAccountDto account) {
25992604 if (isAuthenticationProblem (account , true )) {
26002605 handleAuthenticationFailure (account , true );
26012606 return ;
2607+ } else {
2608+ clearAuthenticationErrorNotification (account , true );
26022609 }
2610+
26032611 // checking outgoing server configuration
26042612 if (isAuthenticationProblem (account , false )) {
26052613 handleAuthenticationFailure (account , false );
2614+ } else {
2615+ clearAuthenticationErrorNotification (account , false );
26062616 }
26072617 }
26082618
@@ -2614,6 +2624,16 @@ private boolean isAuthenticationProblem(LegacyAccountDto account, boolean incomi
26142624 serverSettings .authenticationType == AuthType .XOAUTH2 && account .getOAuthState () == null ;
26152625 }
26162626
2627+ private void clearAuthenticationErrorNotification (LegacyAccountDto account , boolean incoming ) {
2628+ if (FeatureFlagProviderCompat .provide (featureFlagProvider , "display_in_app_notifications" ).isEnabled ()) {
2629+ final AuthenticationErrorNotification notification = createAuthenticationErrorNotification (
2630+ account , incoming );
2631+ notificationDismisser .dismiss (notification ,outcome -> {
2632+ Log .v ("notificationDismisser outcome = " + outcome );
2633+ });
2634+ }
2635+ }
2636+
26172637 void actOnMessagesGroupedByAccountAndFolder (List <MessageReference > messages , MessageActor actor ) {
26182638 Map <String , Map <Long , List <MessageReference >>> accountMap = groupMessagesByAccountAndFolder (messages );
26192639
@@ -2702,6 +2722,7 @@ public void syncStarted(@NotNull String folderServerId) {
27022722
27032723 @ Override
27042724 public void syncAuthenticationSuccess () {
2725+ clearAuthenticationErrorNotification (account , true );
27052726 notificationController .clearAuthenticationErrorNotification (account , true );
27062727 }
27072728
0 commit comments