From e9b91c049aeab3028dc0c855a81661123c3ec69c Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 29 Oct 2018 07:51:02 +0000 Subject: [PATCH] Prevent duplicate attachment sequence numbers --- app/src/main/java/eu/faircode/email/DaoAttachment.java | 4 ++-- app/src/main/java/eu/faircode/email/FragmentCompose.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoAttachment.java b/app/src/main/java/eu/faircode/email/DaoAttachment.java index 1b4ffc38..5da1b516 100644 --- a/app/src/main/java/eu/faircode/email/DaoAttachment.java +++ b/app/src/main/java/eu/faircode/email/DaoAttachment.java @@ -34,10 +34,10 @@ public interface DaoAttachment { " ORDER BY sequence") LiveData> liveAttachments(long message); - @Query("SELECT COUNT(id)" + + @Query("SELECT ifnull(MAX(sequence), 0)" + " FROM attachment" + " WHERE message = :message") - int getAttachmentCount(long message); + int getAttachmentSequence(long message); @Query("SELECT COUNT(id)" + " FROM attachment" + diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 606b88e1..7196e497 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -578,7 +578,7 @@ public class FragmentCompose extends FragmentEx { try { db.beginTransaction(); - int seq = db.attachment().getAttachmentCount(id); + int seq = db.attachment().getAttachmentSequence(id); attachment1.message = id; attachment1.sequence = seq + 1; @@ -868,7 +868,7 @@ public class FragmentCompose extends FragmentEx { Log.i(Helper.TAG, "Attaching to id=" + id); attachment.message = draft.id; - attachment.sequence = db.attachment().getAttachmentCount(draft.id) + 1; + attachment.sequence = db.attachment().getAttachmentSequence(draft.id) + 1; attachment.name = name; String extension = Helper.getExtension(attachment.name);