diff --git a/app/src/main/java/eu/faircode/email/ContactInfo.java b/app/src/main/java/eu/faircode/email/ContactInfo.java index 569fd753e6..f8489a3211 100644 --- a/app/src/main/java/eu/faircode/email/ContactInfo.java +++ b/app/src/main/java/eu/faircode/email/ContactInfo.java @@ -94,7 +94,6 @@ public class ContactInfo { private static Map emailLookup = new ConcurrentHashMap<>(); private static final Map emailContactInfo = new HashMap<>(); private static final Map emailGravatar = new HashMap<>(); - private static final Map> accountIdentities = new HashMap<>(); private static final ExecutorService executorLookup = Helper.getBackgroundExecutor(1, "contact"); @@ -194,12 +193,6 @@ public class ContactInfo { }); } - static void clearIdentities() { - synchronized (accountIdentities) { - accountIdentities.clear(); - } - } - @NonNull static ContactInfo[] get(Context context, long account, String folderType, Address[] addresses) { return get(context, account, folderType, addresses, false); @@ -757,14 +750,7 @@ public class ContactInfo { // Check if from self if (type == EntityContact.TYPE_FROM) { if (message.from != null) { - List identities; - synchronized (accountIdentities) { - if (!accountIdentities.containsKey(folder.account)) - accountIdentities.put(folder.account, - db.identity().getSynchronizingIdentities(folder.account)); - identities = accountIdentities.get(folder.account); - } - + List identities = Core.getIdentities(folder.account, context); if (identities != null) { for (Address sender : message.from) { for (EntityIdentity identity : identities) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index b03d28650d..827957727c 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -158,6 +158,23 @@ class Core { private static final int FIND_RETRY_COUNT = 3; // times private static final long FIND_RETRY_DELAY = 5 * 1000L; // milliseconds + private static final Map> accountIdentities = new HashMap<>(); + + static void clearIdentities() { + synchronized (accountIdentities) { + accountIdentities.clear(); + } + } + + static List getIdentities(long account, Context context) { + synchronized (accountIdentities) { + if (!accountIdentities.containsKey(account)) + accountIdentities.put(account, + DB.getInstance(context).identity().getSynchronizingIdentities(account)); + return accountIdentities.get(account); + } + } + static void processOperations( Context context, EntityAccount account, EntityFolder folder, List ops, @@ -3603,7 +3620,7 @@ class Core { } // Search for matching identity - List identities = db.identity().getSynchronizingIdentities(folder.account); + List identities = getIdentities(folder.account, context); if (identities != null) { for (Address address : addresses) for (EntityIdentity identity : identities) diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index a04a4df3a2..a19523eeec 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -990,7 +990,7 @@ public class FragmentIdentity extends FragmentBase { db.endTransaction(); } - ContactInfo.clearIdentities(); + Core.clearIdentities(); return false; } @@ -1376,7 +1376,7 @@ public class FragmentIdentity extends FragmentBase { DB db = DB.getInstance(context); db.identity().deleteIdentity(id); - ContactInfo.clearIdentities(); + Core.clearIdentities(); return null; }