Force sync old messages

pull/190/head
M66B 4 years ago
parent 638a639016
commit 125c7066ff

@ -2167,13 +2167,14 @@ class Core {
// Legacy
if (jargs.length() == 0)
jargs = folder.getSyncArgs();
jargs = folder.getSyncArgs(false);
int sync_days = jargs.getInt(0);
int keep_days = jargs.getInt(1);
boolean download = jargs.optBoolean(2, false);
boolean auto_delete = jargs.optBoolean(3, false);
int initialize = jargs.optInt(4, folder.initialize);
boolean force = jargs.optBoolean(5, false);
if (keep_days == sync_days && keep_days != Integer.MAX_VALUE)
keep_days++;
@ -2186,6 +2187,7 @@ class Core {
boolean delete_unseen = prefs.getBoolean("delete_unseen", false);
Log.i(folder.name + " start sync after=" + sync_days + "/" + keep_days +
" force=" + force +
" sync unseen=" + sync_unseen + " flagged=" + sync_flagged +
" delete unseen=" + delete_unseen + " kept=" + sync_kept);
@ -2248,7 +2250,7 @@ class Core {
}
// Get list of local uids
final List<Long> uids = db.message().getUids(folder.id, sync_kept ? null : sync_time);
final List<Long> uids = db.message().getUids(folder.id, sync_kept || force ? null : sync_time);
Log.i(folder.name + " local count=" + uids.size());
// Reduce list of local uids

@ -143,4 +143,7 @@ public interface DaoOperation {
@Query("DELETE FROM operation WHERE id = :id")
int deleteOperation(long id);
@Query("DELETE FROM operation WHERE folder = :folder AND name = :name")
int deleteOperation(long folder, String name);
}

@ -284,7 +284,7 @@ public class EntityFolder extends EntityOrder implements Serializable {
return "notification.folder." + id;
}
JSONArray getSyncArgs() {
JSONArray getSyncArgs(boolean force) {
int days = sync_days;
if (last_sync != null) {
int ago_days = (int) ((new Date().getTime() - last_sync) / (24 * 3600 * 1000L)) + 1;
@ -298,6 +298,7 @@ public class EntityFolder extends EntityOrder implements Serializable {
jargs.put(download);
jargs.put(auto_delete);
jargs.put(initialize);
jargs.put(force);
return jargs;
}

@ -387,20 +387,27 @@ public class EntityOperation {
}
static void sync(Context context, long fid, boolean foreground) {
sync(context, fid, foreground, false);
}
static void sync(Context context, long fid, boolean foreground, boolean force) {
DB db = DB.getInstance(context);
EntityFolder folder = db.folder().getFolder(fid);
if (folder == null)
return;
if (force)
db.operation().deleteOperation(fid, SYNC);
// TODO: replace sync parameters?
if (db.operation().getOperationCount(fid, EntityOperation.SYNC) == 0) {
if (db.operation().getOperationCount(fid, SYNC) == 0) {
EntityOperation operation = new EntityOperation();
operation.account = folder.account;
operation.folder = folder.id;
operation.message = null;
operation.name = SYNC;
operation.args = folder.getSyncArgs().toString();
operation.args = folder.getSyncArgs(force).toString();
operation.created = new Date().getTime();
operation.id = db.operation().insertOperation(operation);

@ -919,6 +919,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
try {
wlAccount.acquire();
boolean forced = false;
final DB db = DB.getInstance(this);
long thread = Thread.currentThread().getId();
@ -1123,7 +1124,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
// Update folder list
if (account.protocol == EntityAccount.TYPE_IMAP)
Core.onSynchronizeFolders(this, account, iservice.getStore(), state, force);
Core.onSynchronizeFolders(this, account, iservice.getStore(), state, force && !forced);
// Open synchronizing folders
List<EntityFolder> folders = db.folder().getFolders(account.id, false, true);
@ -1312,7 +1313,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
idlers.add(idler);
if (sync && folder.selectable)
EntityOperation.sync(this, folder.id, false);
EntityOperation.sync(this, folder.id, false, force && !forced);
if (capNotify && EntityFolder.INBOX.equals(folder.type))
ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
@ -1357,6 +1358,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}
}
forced = true;
Log.i(account.name + " observing operations");
getMainHandler().post(new Runnable() {
@Override

Loading…
Cancel
Save