mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-24 02:12:15 -05:00
Modified LocalStore to use UPDATE when replacing existing messages
This way we can later use the database ID to keep track of drafts.
This commit is contained in:
parent
16003abcc1
commit
96f827d291
@ -2019,9 +2019,9 @@ public class LocalStore extends Store implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The method differs slightly from the contract; If an incoming message already has a uid
|
* The method differs slightly from the contract; If an incoming message already has a uid
|
||||||
* assigned and it matches the uid of an existing message then this message will replace the
|
* assigned and it matches the uid of an existing message then this message will replace
|
||||||
* old message. It is implemented as a delete/insert. This functionality is used in saving
|
* the old message. This functionality is used in saving of drafts and re-synchronization
|
||||||
* of drafts and re-synchronization of updated server messages.
|
* of updated server messages.
|
||||||
*
|
*
|
||||||
* NOTE that although this method is located in the LocalStore class, it is not guaranteed
|
* NOTE that although this method is located in the LocalStore class, it is not guaranteed
|
||||||
* that the messages supplied as parameters are actually {@link LocalMessage} instances (in
|
* that the messages supplied as parameters are actually {@link LocalMessage} instances (in
|
||||||
@ -2042,6 +2042,7 @@ public class LocalStore extends Store implements Serializable {
|
|||||||
throw new Error("LocalStore can only store Messages that extend MimeMessage");
|
throw new Error("LocalStore can only store Messages that extend MimeMessage");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long oldMessageId = -1;
|
||||||
String uid = message.getUid();
|
String uid = message.getUid();
|
||||||
if (uid == null || copy) {
|
if (uid == null || copy) {
|
||||||
uid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString();
|
uid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString();
|
||||||
@ -2049,20 +2050,20 @@ public class LocalStore extends Store implements Serializable {
|
|||||||
message.setUid(uid);
|
message.setUid(uid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Message oldMessage = getMessage(uid);
|
LocalMessage oldMessage = (LocalMessage) getMessage(uid);
|
||||||
if (oldMessage != null && !oldMessage.isSet(Flag.SEEN)) {
|
|
||||||
|
if (oldMessage != null) {
|
||||||
|
oldMessageId = oldMessage.getId();
|
||||||
|
|
||||||
|
if (!oldMessage.isSet(Flag.SEEN)) {
|
||||||
setUnreadMessageCount(getUnreadMessageCount() - 1);
|
setUnreadMessageCount(getUnreadMessageCount() - 1);
|
||||||
}
|
}
|
||||||
if (oldMessage != null && oldMessage.isSet(Flag.FLAGGED)) {
|
if (oldMessage.isSet(Flag.FLAGGED)) {
|
||||||
setFlaggedMessageCount(getFlaggedMessageCount() - 1);
|
setFlaggedMessageCount(getFlaggedMessageCount() - 1);
|
||||||
}
|
}
|
||||||
/*
|
}
|
||||||
* The message may already exist in this Folder, so delete it first.
|
|
||||||
*/
|
|
||||||
deleteAttachments(message.getUid());
|
deleteAttachments(message.getUid());
|
||||||
db.execSQL("DELETE FROM messages WHERE folder_id = ? AND uid = ?",
|
|
||||||
new Object[]
|
|
||||||
{ mFolderId, message.getUid() });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Part> viewables = new ArrayList<Part>();
|
ArrayList<Part> viewables = new ArrayList<Part>();
|
||||||
@ -2132,7 +2133,13 @@ public class LocalStore extends Store implements Serializable {
|
|||||||
cv.put("message_id", messageId);
|
cv.put("message_id", messageId);
|
||||||
}
|
}
|
||||||
long messageUid;
|
long messageUid;
|
||||||
|
|
||||||
|
if (oldMessageId == -1) {
|
||||||
messageUid = db.insert("messages", "uid", cv);
|
messageUid = db.insert("messages", "uid", cv);
|
||||||
|
} else {
|
||||||
|
db.update("messages", cv, "id = ?", new String[] { Long.toString(oldMessageId) });
|
||||||
|
messageUid = oldMessageId;
|
||||||
|
}
|
||||||
for (Part attachment : attachments) {
|
for (Part attachment : attachments) {
|
||||||
saveAttachment(messageUid, attachment, copy);
|
saveAttachment(messageUid, attachment, copy);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user