Browse Source

Prevent duplicate attachment sequence numbers

main
M66B 6 years ago
parent
commit
e9b91c049a
2 changed files with 4 additions and 4 deletions
  1. +2
    -2
      app/src/main/java/eu/faircode/email/DaoAttachment.java
  2. +2
    -2
      app/src/main/java/eu/faircode/email/FragmentCompose.java

+ 2
- 2
app/src/main/java/eu/faircode/email/DaoAttachment.java View File

@ -34,10 +34,10 @@ public interface DaoAttachment {
" ORDER BY sequence") " ORDER BY sequence")
LiveData<List<EntityAttachment>> liveAttachments(long message); LiveData<List<EntityAttachment>> liveAttachments(long message);
@Query("SELECT COUNT(id)" +
@Query("SELECT ifnull(MAX(sequence), 0)" +
" FROM attachment" + " FROM attachment" +
" WHERE message = :message") " WHERE message = :message")
int getAttachmentCount(long message);
int getAttachmentSequence(long message);
@Query("SELECT COUNT(id)" + @Query("SELECT COUNT(id)" +
" FROM attachment" + " FROM attachment" +


+ 2
- 2
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -578,7 +578,7 @@ public class FragmentCompose extends FragmentEx {
try { try {
db.beginTransaction(); db.beginTransaction();
int seq = db.attachment().getAttachmentCount(id);
int seq = db.attachment().getAttachmentSequence(id);
attachment1.message = id; attachment1.message = id;
attachment1.sequence = seq + 1; attachment1.sequence = seq + 1;
@ -868,7 +868,7 @@ public class FragmentCompose extends FragmentEx {
Log.i(Helper.TAG, "Attaching to id=" + id); Log.i(Helper.TAG, "Attaching to id=" + id);
attachment.message = draft.id; attachment.message = draft.id;
attachment.sequence = db.attachment().getAttachmentCount(draft.id) + 1;
attachment.sequence = db.attachment().getAttachmentSequence(draft.id) + 1;
attachment.name = name; attachment.name = name;
String extension = Helper.getExtension(attachment.name); String extension = Helper.getExtension(attachment.name);


Loading…
Cancel
Save