mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 12:44:42 +00:00
Delete old messages on deleting browsed messages
This commit is contained in:
parent
554961bbfe
commit
ea3f1ef6f0
2 changed files with 26 additions and 5 deletions
|
@ -764,9 +764,9 @@ public interface DaoMessage {
|
|||
|
||||
@Query("DELETE FROM message" +
|
||||
" WHERE folder = :folder" +
|
||||
" AND ui_browsed" +
|
||||
" AND (ui_browsed OR received < :before)" +
|
||||
" AND NOT uid IS NULL")
|
||||
int deleteBrowsedMessages(long folder);
|
||||
int deleteBrowsedMessages(long folder, long before);
|
||||
|
||||
@Query("DELETE FROM message" +
|
||||
" WHERE folder = :folder" +
|
||||
|
|
|
@ -58,6 +58,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -678,9 +679,29 @@ public class FragmentFolders extends FragmentBase {
|
|||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
if (browsed)
|
||||
db.message().deleteBrowsedMessages(fid);
|
||||
else {
|
||||
if (browsed) {
|
||||
EntityFolder folder = db.folder().getFolder(fid);
|
||||
if (folder == null)
|
||||
return null;
|
||||
|
||||
int keep_days = folder.keep_days;
|
||||
if (keep_days == folder.sync_days &&
|
||||
keep_days != Integer.MAX_VALUE)
|
||||
keep_days++;
|
||||
|
||||
Calendar cal_keep = Calendar.getInstance();
|
||||
cal_keep.add(Calendar.DAY_OF_MONTH, -keep_days);
|
||||
cal_keep.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal_keep.set(Calendar.MINUTE, 0);
|
||||
cal_keep.set(Calendar.SECOND, 0);
|
||||
cal_keep.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
long keep_time = cal_keep.getTimeInMillis();
|
||||
if (keep_time < 0)
|
||||
keep_time = 0;
|
||||
|
||||
db.message().deleteBrowsedMessages(fid, keep_time);
|
||||
} else {
|
||||
db.message().deleteLocalMessages(fid);
|
||||
db.folder().setFolderKeywords(fid, DB.Converters.fromStringArray(null));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue