mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-05 12:24:26 +01:00
Always cache lookup URIs
This commit is contained in:
@@ -153,7 +153,7 @@ public class ContactInfo {
|
||||
return info;
|
||||
}
|
||||
|
||||
static Uri getLookupUri(Context context, Address[] addresses, boolean useCache) {
|
||||
static Uri getLookupUri(Context context, Address[] addresses) {
|
||||
if (!Helper.hasPermission(context, Manifest.permission.READ_CONTACTS))
|
||||
return null;
|
||||
|
||||
@@ -161,12 +161,11 @@ public class ContactInfo {
|
||||
return null;
|
||||
InternetAddress address = (InternetAddress) addresses[0];
|
||||
|
||||
if (useCache)
|
||||
synchronized (emailLookupInfo) {
|
||||
LookupInfo info = emailLookupInfo.get(address.getAddress());
|
||||
if (info != null && !info.isExpired())
|
||||
return info.uri;
|
||||
}
|
||||
synchronized (emailLookupInfo) {
|
||||
LookupInfo info = emailLookupInfo.get(address.getAddress());
|
||||
if (info != null && !info.isExpired())
|
||||
return info.uri;
|
||||
}
|
||||
|
||||
try {
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
|
||||
@@ -1189,7 +1189,7 @@ class Core {
|
||||
message.ui_browsed = browsed;
|
||||
|
||||
message.sender = MessageHelper.getSortKey(message.from);
|
||||
Uri lookupUri = ContactInfo.getLookupUri(context, message.from, true);
|
||||
Uri lookupUri = ContactInfo.getLookupUri(context, message.from);
|
||||
message.avatar = (lookupUri == null ? null : lookupUri.toString());
|
||||
|
||||
Address sender = helper.getSender(); // header
|
||||
@@ -1365,7 +1365,7 @@ class Core {
|
||||
for (Address recipient : recipients) {
|
||||
String email = ((InternetAddress) recipient).getAddress();
|
||||
String name = ((InternetAddress) recipient).getPersonal();
|
||||
Uri avatar = ContactInfo.getLookupUri(context, new Address[]{recipient}, true);
|
||||
Uri avatar = ContactInfo.getLookupUri(context, new Address[]{recipient});
|
||||
EntityContact contact = db.contact().getContact(folder.account, type, email);
|
||||
if (contact == null) {
|
||||
contact = new EntityContact();
|
||||
|
||||
@@ -260,7 +260,7 @@ public class EntityRule {
|
||||
reply.received = new Date().getTime();
|
||||
|
||||
reply.sender = MessageHelper.getSortKey(reply.from);
|
||||
Uri lookupUri = ContactInfo.getLookupUri(context, reply.from, true);
|
||||
Uri lookupUri = ContactInfo.getLookupUri(context, reply.from);
|
||||
reply.avatar = (lookupUri == null ? null : lookupUri.toString());
|
||||
|
||||
reply.id = db.message().insertMessage(reply);
|
||||
|
||||
@@ -1815,7 +1815,7 @@ public class FragmentCompose extends FragmentBase {
|
||||
}
|
||||
|
||||
draft.sender = MessageHelper.getSortKey(draft.from);
|
||||
Uri lookupUri = ContactInfo.getLookupUri(context, draft.from, true);
|
||||
Uri lookupUri = ContactInfo.getLookupUri(context, draft.from);
|
||||
draft.avatar = (lookupUri == null ? null : lookupUri.toString());
|
||||
|
||||
draft.received = new Date().getTime();
|
||||
@@ -2174,7 +2174,7 @@ public class FragmentCompose extends FragmentBase {
|
||||
draft.received = new Date().getTime();
|
||||
|
||||
draft.sender = MessageHelper.getSortKey(draft.from);
|
||||
Uri lookupUri = ContactInfo.getLookupUri(context, draft.from, true);
|
||||
Uri lookupUri = ContactInfo.getLookupUri(context, draft.from);
|
||||
draft.avatar = (lookupUri == null ? null : lookupUri.toString());
|
||||
|
||||
db.message().updateMessage(draft);
|
||||
|
||||
@@ -125,6 +125,7 @@ public class WorkerCleanup extends Worker {
|
||||
Log.i("Deleted logs=" + logs);
|
||||
|
||||
Log.i("Update lookup URIs");
|
||||
ContactInfo.clearCache();
|
||||
List<EntityFolder> folders = db.folder().getSynchronizingFolders();
|
||||
for (EntityFolder folder : folders) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
@@ -141,7 +142,7 @@ public class WorkerCleanup extends Worker {
|
||||
List<TupleMessageLookup> avatars = db.message().getAvatars(folder.id, sync_time);
|
||||
for (TupleMessageLookup message : avatars) {
|
||||
Uri uri = (message.avatar == null ? null : Uri.parse(message.avatar));
|
||||
Uri lookup = ContactInfo.getLookupUri(context, message.from, false);
|
||||
Uri lookup = ContactInfo.getLookupUri(context, message.from);
|
||||
if (!Objects.equals(uri, lookup)) {
|
||||
Log.i("Updating email=" + MessageHelper.formatAddresses(message.from) + " uri=" + lookup);
|
||||
db.message().setMessageAvatar(message.id, lookup == null ? null : lookup.toString());
|
||||
|
||||
Reference in New Issue
Block a user