Sync on move/fetch failure

This commit is contained in:
M66B 2021-02-06 18:30:26 +01:00
parent 1e508c0cd1
commit e3843fce91
1 changed files with 36 additions and 32 deletions

View File

@ -1118,44 +1118,48 @@ class Core {
Log.i(target.name + " moved message fetch=" + fetch); Log.i(target.name + " moved message fetch=" + fetch);
itarget.open(READ_WRITE); itarget.open(READ_WRITE);
boolean sync = false;
for (EntityMessage message : map.values()) for (EntityMessage message : map.values())
if (!TextUtils.isEmpty(message.msgid)) try {
try { if (TextUtils.isEmpty(message.msgid))
Long uid = findUid(itarget, message.msgid, false); throw new IllegalArgumentException("move: msgid missing");
if (uid != null) {
if (draft) {
Message icopy = itarget.getMessageByUID(uid);
if (icopy == null) {
Log.w(target.name + " Gone uid=" + uid);
continue;
}
// Mark read Long uid = findUid(itarget, message.msgid, false);
if (seen && !icopy.isSet(Flags.Flag.SEEN) && flags.contains(Flags.Flag.SEEN)) if (uid == null)
icopy.setFlag(Flags.Flag.SEEN, true); throw new IllegalArgumentException("move: uid not found");
// Remove star if (draft) {
if (unflag && icopy.isSet(Flags.Flag.FLAGGED) && flags.contains(Flags.Flag.FLAGGED)) Message icopy = itarget.getMessageByUID(uid);
icopy.setFlag(Flags.Flag.FLAGGED, false); if (icopy != null)
throw new IllegalArgumentException("move: gone uid=" + uid);
// Set drafts flag // Mark read
if (flags.contains(Flags.Flag.DRAFT)) if (seen && !icopy.isSet(Flags.Flag.SEEN) && flags.contains(Flags.Flag.SEEN))
icopy.setFlag(Flags.Flag.DRAFT, EntityFolder.DRAFTS.equals(target.type)); icopy.setFlag(Flags.Flag.SEEN, true);
}
if (fetch) // Remove star
try { if (unflag && icopy.isSet(Flags.Flag.FLAGGED) && flags.contains(Flags.Flag.FLAGGED))
Log.i(target.name + " Fetching uid=" + uid); icopy.setFlag(Flags.Flag.FLAGGED, false);
JSONArray fargs = new JSONArray();
fargs.put(uid); // Set drafts flag
onFetch(context, fargs, target, istore, itarget, state); if (flags.contains(Flags.Flag.DRAFT))
} catch (Throwable ex) { icopy.setFlag(Flags.Flag.DRAFT, EntityFolder.DRAFTS.equals(target.type));
Log.e(ex);
}
}
} catch (Throwable ex) {
Log.w(ex);
} }
if (fetch) {
Log.i(target.name + " Fetching uid=" + uid);
JSONArray fargs = new JSONArray();
fargs.put(uid);
onFetch(context, fargs, target, istore, itarget, state);
}
} catch (Throwable ex) {
Log.w(ex);
if (fetch)
sync = true;
}
if (sync)
EntityOperation.sync(context, target.id, false);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
} finally { } finally {