diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 6eed37e24d..a3c3d0836d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -4898,26 +4898,12 @@ public class FragmentCompose extends FragmentBase { }); if (extras.getBoolean("archive")) { - boolean threading = prefs.getBoolean("threading", true); EntityFolder archive = db.folder().getFolderByType(draft.account, EntityFolder.ARCHIVE); - List messages = db.message().getMessagesByThread( - draft.account, draft.thread, null, null); - for (EntityMessage threaded : messages) { - EntityFolder source = db.folder().getFolder(threaded.folder); - boolean repliedto = - (!TextUtils.isEmpty(draft.inreplyto) && - draft.inreplyto.equals(threaded.msgid)); - if ((threaded.ui_seen || repliedto) && - (threading || repliedto) && - source != null && !source.read_only && - archive != null && !archive.id.equals(threaded.folder) && - !EntityFolder.isOutgoing(source.type) && - !EntityFolder.TRASH.equals(source.type) && - !EntityFolder.JUNK.equals(source.type)) { - if (repliedto) - EntityOperation.queue(context, threaded, EntityOperation.SEEN, true); - EntityOperation.queue(context, threaded, EntityOperation.MOVE, archive.id); - } + if (archive != null) { + List messages = db.message().getMessagesByMsgId(draft.account, draft.inreplyto); + if (messages != null) + for (EntityMessage message : messages) + EntityOperation.queue(context, message, EntityOperation.MOVE, archive.id); } } } @@ -5926,8 +5912,6 @@ public class FragmentCompose extends FragmentBase { DB db = DB.getInstance(getContext()); db.message().liveMessage(id).observe(getViewLifecycleOwner(), new Observer() { - private Boolean archive = null; - @Override public void onChanged(TupleMessageEx draft) { if (draft == null) { @@ -5979,71 +5963,75 @@ public class FragmentCompose extends FragmentBase { grpDsn.setVisibility(dsn ? View.GONE : View.VISIBLE); - if (!TextUtils.isEmpty(draft.inreplyto)) - if (archive == null) { - Bundle args = new Bundle(); - args.putLong("account", draft.account); - args.putString("inreplyto", draft.inreplyto); - - new SimpleTask() { - @Override - protected void onPreExecute(Bundle args) { - archive = false; - } - - @Override - protected @NonNull - Boolean onExecute(Context context, Bundle args) { - long account = args.getLong("account"); - String inreplyto = args.getString("inreplyto"); - - if (TextUtils.isEmpty(inreplyto)) - return false; - - List messages = db.message().getMessagesByMsgId(account, inreplyto); - if (messages == null) - return false; - - boolean canArchive = false; - for (EntityMessage message : messages) { - EntityFolder folder = db.folder().getFolder(message.folder); - if (folder == null) - continue; - if (EntityFolder.INBOX.equals(folder.type) || - EntityFolder.USER.equals(folder.type)) { - canArchive = true; - break; - } - } - - if (!canArchive) - return false; - - DB db = DB.getInstance(context); - EntityFolder archive = db.folder().getFolderByType(account, EntityFolder.ARCHIVE); - - return (archive != null); - } - - @Override - protected void onExecuted(Bundle args, Boolean data) { - archive = data; - cbArchive.setChecked(send_archive && archive); - cbArchive.setEnabled(archive); - } - - @Override - protected void onException(Bundle args, Throwable ex) { - // Ignored - } - }.execute(FragmentDialogSend.this, args, "send:archive"); - } else - cbArchive.setEnabled(archive); - Helper.setViewsEnabled(dview, true); } }); + Bundle aargs = new Bundle(); + aargs.putLong("id", id); + + new SimpleTask() { + @Override + protected @NonNull + Boolean onExecute(Context context, Bundle args) { + long id = args.getLong("id"); + + DB db = DB.getInstance(context); + EntityMessage draft = db.message().getMessage(id); + if (draft == null) { + args.putString("reason", "Draft gone"); + return false; + } + + if (TextUtils.isEmpty(draft.inreplyto)) { + args.putString("reason", "No in-reply-to"); + return false; + } + + EntityFolder archive = db.folder().getFolderByType(draft.account, EntityFolder.ARCHIVE); + if (archive == null) { + args.putString("reason", "No archive"); + return false; + } + + List messages = db.message().getMessagesByMsgId(draft.account, draft.inreplyto); + if (messages == null || messages.size() == 0) { + args.putString("reason", "In-reply-to gone"); + return false; + } + + for (EntityMessage message : messages) { + EntityFolder folder = db.folder().getFolder(message.folder); + if (folder == null) + continue; + if (EntityFolder.INBOX.equals(folder.type) || EntityFolder.USER.equals(folder.type)) + return true; + } + + args.putString("reason", "Not in inbox or unread"); + return false; + } + + @Override + protected void onExecuted(Bundle args, Boolean data) { + if (!data) { + String reason = args.getString("reason"); + if (BuildConfig.DEBUG) + cbArchive.setText(reason); + else + Log.i("Auto archive reason=" + reason); + } + if (send_archive && data) + cbArchive.setChecked(true); + cbArchive.setEnabled(data); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + // Ignored + } + }.execute(FragmentDialogSend.this, aargs, "send:archive"); + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()) .setView(dview) .setNegativeButton(android.R.string.cancel, null); diff --git a/app/src/main/res/layout/dialog_send.xml b/app/src/main/res/layout/dialog_send.xml index 4a03822bf3..6a4059f3f3 100644 --- a/app/src/main/res/layout/dialog_send.xml +++ b/app/src/main/res/layout/dialog_send.xml @@ -328,8 +328,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="12dp" - android:text="@string/title_send_archive" - android:textAppearance="@style/TextAppearance.AppCompat.Medium" + android:tag="ignore" + android:text="@string/title_send_auto_archive" + android:textAppearance="@style/TextAppearance.AppCompat.Small" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/ibSendAt" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aabd9bb3fa..f490c2f0f9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -980,7 +980,7 @@ Send now Send via Send at … - Archive read messages + Archive replied message Encryption Priority No server found at \'%1$s\'