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
|
||||
* assigned and it matches the uid of an existing message then this message will replace the
|
||||
* old message. It is implemented as a delete/insert. This functionality is used in saving
|
||||
* of drafts and re-synchronization of updated server messages.
|
||||
* assigned and it matches the uid of an existing message then this message will replace
|
||||
* the old message. This functionality is used in saving of drafts and re-synchronization
|
||||
* of updated server messages.
|
||||
*
|
||||
* 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
|
||||
@ -2042,6 +2042,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
throw new Error("LocalStore can only store Messages that extend MimeMessage");
|
||||
}
|
||||
|
||||
long oldMessageId = -1;
|
||||
String uid = message.getUid();
|
||||
if (uid == null || copy) {
|
||||
uid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString();
|
||||
@ -2049,20 +2050,20 @@ public class LocalStore extends Store implements Serializable {
|
||||
message.setUid(uid);
|
||||
}
|
||||
} else {
|
||||
Message oldMessage = getMessage(uid);
|
||||
if (oldMessage != null && !oldMessage.isSet(Flag.SEEN)) {
|
||||
LocalMessage oldMessage = (LocalMessage) getMessage(uid);
|
||||
|
||||
if (oldMessage != null) {
|
||||
oldMessageId = oldMessage.getId();
|
||||
|
||||
if (!oldMessage.isSet(Flag.SEEN)) {
|
||||
setUnreadMessageCount(getUnreadMessageCount() - 1);
|
||||
}
|
||||
if (oldMessage != null && oldMessage.isSet(Flag.FLAGGED)) {
|
||||
if (oldMessage.isSet(Flag.FLAGGED)) {
|
||||
setFlaggedMessageCount(getFlaggedMessageCount() - 1);
|
||||
}
|
||||
/*
|
||||
* The message may already exist in this Folder, so delete it first.
|
||||
*/
|
||||
}
|
||||
|
||||
deleteAttachments(message.getUid());
|
||||
db.execSQL("DELETE FROM messages WHERE folder_id = ? AND uid = ?",
|
||||
new Object[]
|
||||
{ mFolderId, message.getUid() });
|
||||
}
|
||||
|
||||
ArrayList<Part> viewables = new ArrayList<Part>();
|
||||
@ -2132,7 +2133,13 @@ public class LocalStore extends Store implements Serializable {
|
||||
cv.put("message_id", messageId);
|
||||
}
|
||||
long messageUid;
|
||||
|
||||
if (oldMessageId == -1) {
|
||||
messageUid = db.insert("messages", "uid", cv);
|
||||
} else {
|
||||
db.update("messages", cv, "id = ?", new String[] { Long.toString(oldMessageId) });
|
||||
messageUid = oldMessageId;
|
||||
}
|
||||
for (Part attachment : attachments) {
|
||||
saveAttachment(messageUid, attachment, copy);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user