mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-27 02:07:12 +00:00
Transactional synchronize message
This commit is contained in:
parent
670c0f04ae
commit
f0cf9dafa4
1 changed files with 83 additions and 70 deletions
|
@ -1153,15 +1153,20 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
boolean seen = helper.getSeen();
|
||||
|
||||
DB db = DB.getInstance(this);
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
// Find message by uid (fast, no headers required)
|
||||
EntityMessage message = db.message().getMessageByUid(folder.id, uid);
|
||||
|
||||
// Find by Message-ID
|
||||
// Find message by Message-ID (slow, headers required)
|
||||
// - messages in inbox have same id as message sent to self
|
||||
// - messages in archive have same id as original
|
||||
if (message == null &&
|
||||
!EntityFolder.SENT.equals(folder.type) &&
|
||||
!EntityFolder.ARCHIVE.equals(folder.type)) {
|
||||
String msgid = imessage.getMessageID(); // Will fetch headers
|
||||
// Will fetch headers within database transaction
|
||||
String msgid = imessage.getMessageID();
|
||||
message = db.message().getMessageByMsgId(msgid);
|
||||
if (message != null) {
|
||||
Log.i(Helper.TAG, folder.name + " found as id=" + message.id + " uid=" + message.uid + " msgid=" + msgid);
|
||||
|
@ -1171,7 +1176,25 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
}
|
||||
}
|
||||
|
||||
if (message == null) {
|
||||
if (message != null) {
|
||||
if (message.seen != seen) {
|
||||
message.seen = seen;
|
||||
message.ui_seen = seen;
|
||||
db.message().updateMessage(message);
|
||||
Log.v(Helper.TAG, folder.name + " updated id=" + message.id + " uid=" + message.uid);
|
||||
return -1;
|
||||
} else {
|
||||
Log.v(Helper.TAG, folder.name + " unchanged id=" + message.id + " uid=" + message.uid);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
FetchProfile fp1 = new FetchProfile();
|
||||
fp1.add(FetchProfile.Item.ENVELOPE);
|
||||
fp1.add(FetchProfile.Item.CONTENT_INFO);
|
||||
|
@ -1179,7 +1202,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
fp1.add(IMAPFolder.FetchProfileItem.MESSAGE);
|
||||
ifolder.fetch(new Message[]{imessage}, fp1);
|
||||
|
||||
message = new EntityMessage();
|
||||
EntityMessage message = new EntityMessage();
|
||||
message.account = folder.account;
|
||||
message.folder = folder.id;
|
||||
message.uid = uid;
|
||||
|
@ -1221,16 +1244,6 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
}
|
||||
|
||||
return 1;
|
||||
} else if (message.seen != seen) {
|
||||
message.seen = seen;
|
||||
message.ui_seen = seen;
|
||||
db.message().updateMessage(message);
|
||||
Log.v(Helper.TAG, folder.name + " updated id=" + message.id + " uid=" + message.uid);
|
||||
return -1;
|
||||
} else {
|
||||
Log.v(Helper.TAG, folder.name + " unchanged id=" + message.id + " uid=" + message.uid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} finally {
|
||||
Log.v(Helper.TAG, folder.name + " end sync uid=" + uid);
|
||||
|
|
Loading…
Reference in a new issue