Explicitly delete browsed messages

pull/153/head
M66B 6 years ago
parent 832c4068db
commit c5df0034e3

@ -87,9 +87,10 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private final static int action_synchronize_now = 1;
private final static int action_delete_local = 2;
private final static int action_empty_trash = 3;
private final static int action_edit_properties = 4;
private final static int action_edit_rules = 5;
private final static int action_delete_browsed = 3;
private final static int action_empty_trash = 4;
private final static int action_edit_properties = 5;
private final static int action_edit_rules = 6;
ViewHolder(View itemView) {
super(itemView);
@ -249,15 +250,17 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
popupMenu.getMenu().add(Menu.NONE, action_synchronize_now, 1, R.string.title_synchronize_now);
if (folder.account != null)
if (folder.account != null) { // outbox
popupMenu.getMenu().add(Menu.NONE, action_delete_local, 2, R.string.title_delete_local);
popupMenu.getMenu().add(Menu.NONE, action_delete_browsed, 3, R.string.title_delete_browsed);
}
if (EntityFolder.TRASH.equals(folder.type))
popupMenu.getMenu().add(Menu.NONE, action_empty_trash, 3, R.string.title_empty_trash);
popupMenu.getMenu().add(Menu.NONE, action_empty_trash, 4, R.string.title_empty_trash);
if (folder.account != null) {
popupMenu.getMenu().add(Menu.NONE, action_edit_rules, 4, R.string.title_edit_rules);
popupMenu.getMenu().add(Menu.NONE, action_edit_properties, 5, R.string.title_edit_properties);
popupMenu.getMenu().add(Menu.NONE, action_edit_rules, 5, R.string.title_edit_rules);
popupMenu.getMenu().add(Menu.NONE, action_edit_properties, 6, R.string.title_edit_properties);
}
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@ -269,7 +272,11 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
return true;
case action_delete_local:
OnActionDeleteLocal();
OnActionDeleteLocal(false);
return true;
case action_delete_browsed:
OnActionDeleteLocal(true);
return true;
case action_empty_trash:
@ -326,19 +333,19 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
}.execute(context, owner, args, "folder:sync");
}
private void OnActionDeleteLocal() {
private void OnActionDeleteLocal(boolean browsed) {
Bundle args = new Bundle();
args.putLong("id", folder.id);
args.putBoolean("outbox", folder.account == null);
args.putBoolean("browsed", browsed);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
boolean outbox = args.getBoolean("outbox");
Log.i("Delete local messages outbox=" + outbox);
if (outbox)
DB.getInstance(context).message().deleteSeenMessages(id);
boolean browsed = args.getBoolean("browsed");
Log.i("Delete local messages browsed=" + browsed);
if (browsed)
DB.getInstance(context).message().deleteBrowsedMessages(id);
else
DB.getInstance(context).message().deleteLocalMessages(id);
return null;

@ -852,7 +852,7 @@ class Core {
Log.i(folder.name + " sync=" + new Date(sync_time) + " keep=" + new Date(keep_time));
// Delete old local messages
int old = db.message().deleteMessagesBefore(folder.id, keep_time, false);
int old = db.message().deleteMessagesBefore(folder.id, keep_time);
Log.i(folder.name + " local old=" + old);
// Get list of local uids

@ -354,6 +354,12 @@ public interface DaoMessage {
" AND NOT uid IS NULL")
int deleteLocalMessages(long folder);
@Query("DELETE FROM message" +
" WHERE folder = :folder" +
" AND ui_browsed" +
" AND NOT uid IS NULL")
int deleteBrowsedMessages(long folder);
@Query("DELETE FROM message" +
" WHERE folder = :folder" +
" AND uid IS NULL" +
@ -364,16 +370,10 @@ public interface DaoMessage {
" AND operation.name = '" + EntityOperation.ADD + "')")
int deleteOrphans(long folder);
@Query("DELETE FROM message" +
" WHERE folder = :folder" +
" AND seen")
int deleteSeenMessages(long folder);
@Query("DELETE FROM message" +
" WHERE folder = :folder" +
" AND received < :received" +
" AND NOT uid IS NULL" +
" AND (NOT ui_browsed OR :browsed)" +
" AND NOT ui_flagged")
int deleteMessagesBefore(long folder, long received, boolean browsed);
int deleteMessagesBefore(long folder, long received);
}

@ -248,7 +248,7 @@ public class FragmentFolder extends FragmentBase {
sync_days, keep_days);
db.folder().setFolderError(id, null);
db.message().deleteMessagesBefore(id, keep_time, true);
db.message().deleteMessagesBefore(id, keep_time);
EntityOperation.sync(context, folder.id, true);
}

@ -56,7 +56,7 @@ public class WorkerCleanup extends Worker {
if (keep_time < 0)
keep_time = 0;
int messages = db.message().deleteMessagesBefore(folder.id, keep_time, false);
int messages = db.message().deleteMessagesBefore(folder.id, keep_time);
if (messages > 0)
Log.i("Cleanup folder=" + folder.account + "/" + folder.name +
" before=" + new Date(keep_time) + " deleted=" + messages);

@ -272,6 +272,7 @@
<string name="title_synchronize_now">Synchronize now</string>
<string name="title_delete_local">Delete local messages</string>
<string name="title_delete_browsed">Delete browsed/searched messages</string>
<string name="title_empty_trash">Empty trash</string>
<string name="title_edit_properties">Edit properties</string>
<string name="title_edit_rules">Edit rules</string>

Loading…
Cancel
Save