Optimize mark all read

pull/182/head
M66B 5 years ago
parent 718e5797ff
commit 848c1d343a

@ -339,6 +339,24 @@ public interface DaoMessage {
" ORDER BY message.received DESC")
List<Long> 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<Long> 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" +

@ -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<List<Long>>() {
@Override
public void onChanged(List<Long> 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<Void>() {
@Override
protected void onPreExecute(Bundle args) {
ToastEx.makeText(getContext(), R.string.title_executing, Toast.LENGTH_LONG).show();
}
new SimpleTask<Void>() {
@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<Long> 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() {

Loading…
Cancel
Save