Fixed moving draft from accounts

This commit is contained in:
M66B 2019-01-25 19:23:41 +00:00
parent fb8646f371
commit f2d76246f3
1 changed files with 6 additions and 2 deletions

View File

@ -1812,24 +1812,28 @@ public class FragmentCompose extends FragmentBase {
Long uid = draft.uid; Long uid = draft.uid;
String msgid = draft.msgid; String msgid = draft.msgid;
// To prevent violating constraints
draft.uid = null; draft.uid = null;
draft.msgid = null; draft.msgid = null;
db.message().updateMessage(draft); db.message().updateMessage(draft);
// Create copy to delete
draft.id = null; draft.id = null;
draft.uid = uid; draft.uid = uid;
draft.msgid = msgid; draft.msgid = msgid;
draft.content = false; draft.content = false;
draft.ui_hide = true; draft.ui_hide = true;
draft.id = db.message().insertMessage(draft); draft.id = db.message().insertMessage(draft);
EntityOperation.queue(context, db, draft, EntityOperation.DELETE); EntityOperation.queue(context, db, draft, EntityOperation.DELETE); // by msgid
// Restore original with new account, no uid and new msgid
draft.id = id; draft.id = id;
draft.account = aid; draft.account = aid;
draft.folder = db.folder().getFolderByType(aid, EntityFolder.DRAFTS).id; draft.folder = db.folder().getFolderByType(aid, EntityFolder.DRAFTS).id;
draft.uid = null;
draft.msgid = EntityMessage.generateMessageId();
draft.content = true; draft.content = true;
draft.ui_hide = false; draft.ui_hide = false;
EntityOperation.queue(context, db, draft, EntityOperation.ADD);
} }
List<EntityAttachment> attachments = db.attachment().getAttachments(draft.id); List<EntityAttachment> attachments = db.attachment().getAttachments(draft.id);