diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 283023d4a7..c5cbdaf20c 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -339,6 +339,24 @@ public interface DaoMessage { " ORDER BY message.received DESC") List getMessageWithContent(); + @Query("SELECT message.id" + + " FROM message" + + " JOIN folder_view AS folder ON folder.id = message.folder" + + " LEFT JOIN identity_view AS identity ON identity.id = message.identity" + + " WHERE CASE" + + " WHEN :folder IS NOT NULL THEN folder.id = :folder" + + " WHEN :type IS NOT NULL THEN folder.type = :type" + + " ELSE folder.unified" + + " END" + + " AND NOT ui_seen" + + " AND (NOT :filter_unflagged OR message.ui_flagged)" + + " AND (NOT :filter_unknown OR (message.avatar IS NOT NULL AND message.sender <> identity.email))" + + " AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL OR " + is_drafts + ")" + + " AND (:filter_language IS NULL OR message.language = :filter_language)") + List getMessageUnseen( + Long folder, String type, + boolean filter_unflagged, boolean filter_unknown, boolean filter_snoozed, String filter_language); + @Query("SELECT message.*" + " FROM message" + " LEFT JOIN account_view AS account ON account.id = message.account" + diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 5e056ee01d..aa69a03ace 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -3834,48 +3834,51 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } private void onMenuMarkAllRead() { - ViewModelMessages model = new ViewModelProvider(getActivity()).get(ViewModelMessages.class); - model.getIds(getContext(), getViewLifecycleOwner(), new Observer>() { - @Override - public void onChanged(List ids) { - Bundle args = new Bundle(); - args.putLongArray("ids", Helper.toLongArray(ids)); + Bundle args = new Bundle(); + args.putString("type", type); + args.putLong("folder", folder); - new SimpleTask() { - @Override - protected void onPreExecute(Bundle args) { - ToastEx.makeText(getContext(), R.string.title_executing, Toast.LENGTH_LONG).show(); - } + new SimpleTask() { + @Override + protected Void onExecute(Context context, Bundle args) throws Throwable { + String type = args.getString("type"); + long folder = args.getLong("folder"); - @Override - protected Void onExecute(Context context, Bundle args) throws Throwable { - long[] ids = args.getLongArray("ids"); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + boolean filter_unflagged = prefs.getBoolean("filter_unflagged", false); + boolean filter_unknown = prefs.getBoolean("filter_unknown", false); + boolean filter_snoozed = prefs.getBoolean("filter_snoozed", true); + String filter_language = prefs.getString("filter_language", null); + boolean language_detection = prefs.getBoolean("language_detection", false); - DB db = DB.getInstance(context); - try { - db.beginTransaction(); + DB db = DB.getInstance(context); + try { + db.beginTransaction(); - for (long id : ids) { - EntityMessage message = db.message().getMessage(id); - if (message != null) - EntityOperation.queue(context, message, EntityOperation.SEEN, true); - } + List ids = db.message().getMessageUnseen( + folder < 0 ? null : folder, + folder < 0 ? type : null, + filter_unflagged, filter_unknown, filter_snoozed, + language_detection ? filter_language : null); + for (long id : ids) { + EntityMessage message = db.message().getMessage(id); + if (message != null) + EntityOperation.queue(context, message, EntityOperation.SEEN, true); + } - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } - return null; - } + return null; + } - @Override - protected void onException(Bundle args, Throwable ex) { - Log.unexpectedError(getParentFragmentManager(), ex); - } - }.execute(FragmentMessages.this, args, "message:read"); + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); } - }); + }.execute(FragmentMessages.this, args, "message:read"); } private void onMenuForceSync() {