22
33
44import java .io .File ;
5+ import java .util .ArrayList ;
56import java .util .Date ;
67import java .util .HashMap ;
78import java .util .List ;
128129import net .thunderbird .core .featureflag .compat .FeatureFlagProviderCompat ;
129130import net .thunderbird .core .preference .GeneralSettingsManager ;
130131import net .thunderbird .core .ui .theme .manager .ThemeManager ;
132+ import net .thunderbird .feature .notification .api .content .NotificationFactoryCoroutineCompat ;
133+ import net .thunderbird .feature .notification .api .content .SentFolderNotFoundNotification ;
134+ import net .thunderbird .feature .notification .api .sender .NotificationSender ;
135+ import net .thunderbird .feature .notification .api .sender .compat .NotificationSenderCompat ;
131136import net .thunderbird .feature .search .legacy .LocalMessageSearch ;
132137import org .openintents .openpgp .OpenPgpApiManager ;
133138import org .openintents .openpgp .util .OpenPgpIntentStarter ;
134139import net .thunderbird .core .logging .legacy .Log ;
135140import static com .fsck .k9 .activity .compose .AttachmentPresenter .REQUEST_CODE_ATTACHMENT_URI ;
136141import static app .k9mail .core .android .common .camera .CameraCaptureHandler .CAMERA_PERMISSION_REQUEST_CODE ;
137142import static app .k9mail .core .android .common .camera .CameraCaptureHandler .REQUEST_IMAGE_CAPTURE ;
143+ import static net .thunderbird .feature .notification .api .content .SentFolderNotFoundNotificationKt .SentFolderNotFoundNotification ;
138144
139145
140146@ SuppressWarnings ("deprecation" ) // TODO get rid of activity dialogs and indeterminate progress bars
@@ -208,6 +214,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
208214
209215 private final CameraCaptureHandler cameraCaptureHandler = DI .get (CameraCaptureHandler .class );
210216 private final FeatureFlagProvider featureFlagProvider = DI .get (FeatureFlagProvider .class );
217+ private final NotificationSender notificationSender = DI .get (NotificationSender .class );
218+ private final NotificationSenderCompat notificationSenderCompat = new NotificationSenderCompat (notificationSender );
211219
212220 private QuotedMessagePresenter quotedMessagePresenter ;
213221 private MessageLoaderHelper messageLoaderHelper ;
@@ -293,16 +301,7 @@ public void onCreate(Bundle savedInstanceState) {
293301
294302 final Intent intent = getIntent ();
295303
296- String messageReferenceString = intent .getStringExtra (EXTRA_MESSAGE_REFERENCE );
297- relatedMessageReference = MessageReference .parse (messageReferenceString );
298-
299- final String accountUuid = (relatedMessageReference != null ) ?
300- relatedMessageReference .getAccountUuid () :
301- intent .getStringExtra (EXTRA_ACCOUNT );
302-
303- if (accountUuid != null ) {
304- account = preferences .getAccount (accountUuid );
305- }
304+ fetchAccount (intent );
306305
307306 if (account == null ) {
308307 account = preferences .getDefaultAccount ();
@@ -540,10 +539,36 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
540539 }
541540 }
542541
542+ private void fetchAccount (Intent intent ) {
543+ String messageReferenceString = intent .getStringExtra (EXTRA_MESSAGE_REFERENCE );
544+ relatedMessageReference = MessageReference .parse (messageReferenceString );
545+
546+ final String accountUuid = (relatedMessageReference != null ) ?
547+ relatedMessageReference .getAccountUuid () :
548+ intent .getStringExtra (EXTRA_ACCOUNT );
549+
550+ if (accountUuid != null ) {
551+ account = preferences .getAccount (accountUuid );
552+ }
553+ }
554+
543555 @ Override
544556 protected void onResume () {
545557 super .onResume ();
546558 messagingController .addListener (messagingListener );
559+
560+ if (account == null ) {
561+ fetchAccount (getIntent ());
562+ }
563+
564+ if (account != null && account .getSentFolderId () == null ) {
565+ final SentFolderNotFoundNotification notification = NotificationFactoryCoroutineCompat .create (
566+ continuation -> SentFolderNotFoundNotification (account .getUuid (), continuation )
567+ );
568+ notificationSenderCompat .send (notification , outcome -> {
569+ Log .v ("notificationSender outcome = " + outcome );
570+ });
571+ }
547572 }
548573
549574 @ Override
@@ -1748,8 +1773,9 @@ private void initializeInAppNotificationFragment() {
17481773 return ;
17491774 }
17501775
1751- if (account == null ) {
1752- Log .w ("Can't initialize in-app notifications. Account is currently null" );
1776+ final List <LegacyAccountDto > accounts = preferences .getAccounts ();
1777+ if (accounts .isEmpty ()) {
1778+ Log .w ("Can't initialize in-app notifications. No accounts were found." );
17531779 return ;
17541780 }
17551781 final FragmentManager fragmentManager = getSupportFragmentManager ();
@@ -1760,13 +1786,17 @@ private void initializeInAppNotificationFragment() {
17601786 return ;
17611787 }
17621788
1789+ final ArrayList <String > uuids = new ArrayList <>();
1790+ for (LegacyAccountDto legacyAccountDto : accounts ) {
1791+ uuids .add (legacyAccountDto .getUuid ());
1792+ }
17631793 final MessageComposeInAppNotificationFragment inAppNotificationFragment =
1764- MessageComposeInAppNotificationFragment .newInstance (account . getUuid () );
1794+ MessageComposeInAppNotificationFragment .newInstance (uuids );
17651795 fragmentManager
1766- .beginTransaction ()
1767- .add (R .id .message_compose_in_app_notifications_container , inAppNotificationFragment ,
1768- MessageComposeInAppNotificationFragment .FRAGMENT_TAG )
1769- .commit ();
1796+ .beginTransaction ()
1797+ .add (R .id .message_compose_in_app_notifications_container , inAppNotificationFragment ,
1798+ MessageComposeInAppNotificationFragment .FRAGMENT_TAG )
1799+ .commit ();
17701800 }
17711801
17721802 // TODO We miss callbacks for this listener if they happens while we are paused!
0 commit comments