From d497aa4e029c3876383667c0117fb5e6c731dbae Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 1 Aug 2020 08:05:06 +0200 Subject: [PATCH] Select identity for external drafts --- app/src/main/java/eu/faircode/email/Core.java | 3 +++ .../main/java/eu/faircode/email/DaoMessage.java | 3 +++ .../java/eu/faircode/email/FragmentCompose.java | 15 +++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index acda29b654..4ce52126f4 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -2920,6 +2920,9 @@ class Core { private static EntityIdentity matchIdentity(Context context, EntityFolder folder, EntityMessage message) { DB db = DB.getInstance(context); + if (EntityFolder.DRAFTS.equals(folder.type)) + return null; + List
addresses = new ArrayList<>(); if (folder.isOutgoing()) { if (message.from != null) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index afbc6476b1..0ca61f68ff 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -664,6 +664,9 @@ public interface DaoMessage { @Query("UPDATE message SET error = :error WHERE id = :id") int setMessageError(long id, String error); + @Query("UPDATE message SET identity = :identity WHERE id = :id") + int setMessageIdentity(long id, Long identity); + @Query("UPDATE message SET revision = :revision WHERE id = :id") int setMessageRevision(long id, Integer revision); diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index f977ca5342..e4365bb431 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -3720,6 +3720,21 @@ public class FragmentCompose extends FragmentBase { } else { args.putBoolean("saved", true); + // External draft + if (data.draft.identity == null) { + for (EntityIdentity identity : data.identities) + if (identity.account.equals(data.draft.account)) + if (identity.primary) { + data.draft.identity = identity.id; + break; + } else if (data.draft.identity == null) + data.draft.identity = identity.id; + + if (data.draft.identity != null) + db.message().setMessageIdentity(data.draft.id, data.draft.identity); + Log.i("Selected external identity=" + data.draft.identity); + } + if (data.draft.revision == null) { data.draft.revision = 1; data.draft.revisions = 1;