Improved local contact handling

pull/162/head
M66B 6 years ago
parent e6e0a00767
commit 79da181f36

@ -1826,13 +1826,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean outgoing = EntityFolder.isOutgoing(folder.type); boolean outgoing = EntityFolder.isOutgoing(folder.type);
if (message.identity != null) { if (message.identity != null) {
Address[] senders = (message.reply == null || message.reply.length == 0 ? message.from : message.reply); if (message.from != null && message.from.length > 0) {
if (senders != null && senders.length > 0) {
EntityIdentity identity = db.identity().getIdentity(message.identity); EntityIdentity identity = db.identity().getIdentity(message.identity);
if (identity == null) if (identity == null)
return null; return null;
for (Address sender : senders) for (Address sender : message.from)
if (identity.similarAddress(sender)) { if (identity.similarAddress(sender)) {
outgoing = true; outgoing = true;
break; break;

@ -1788,7 +1788,7 @@ class Core {
} }
} }
static EntityMessage _synchronizeMessage( private static EntityMessage _synchronizeMessage(
Context context, Context context,
EntityAccount account, EntityFolder folder, EntityAccount account, EntityFolder folder,
long uid, MimeMessage imessage, long uid, MimeMessage imessage,
@ -2148,7 +2148,7 @@ class Core {
} }
private static void updateContactInfo(Context context, final EntityFolder folder, final EntityMessage message) { private static void updateContactInfo(Context context, final EntityFolder folder, final EntityMessage message) {
final DB db = DB.getInstance(context); DB db = DB.getInstance(context);
if (EntityFolder.DRAFTS.equals(folder.type) || if (EntityFolder.DRAFTS.equals(folder.type) ||
EntityFolder.ARCHIVE.equals(folder.type) || EntityFolder.ARCHIVE.equals(folder.type) ||
@ -2156,7 +2156,25 @@ class Core {
EntityFolder.JUNK.equals(folder.type)) EntityFolder.JUNK.equals(folder.type))
return; return;
final int type = (folder.isOutgoing() ? EntityContact.TYPE_TO : EntityContact.TYPE_FROM); int type = (folder.isOutgoing() ? EntityContact.TYPE_TO : EntityContact.TYPE_FROM);
// Check if from self
if (type == EntityContact.TYPE_FROM) {
if (message.from != null) {
List<EntityIdentity> identities = db.identity().getSynchronizingIdentities(folder.account);
if (identities != null) {
for (Address sender : message.from) {
for (EntityIdentity identity : identities)
if (identity.similarAddress(sender)) {
type = EntityContact.TYPE_TO;
break;
}
if (type == EntityContact.TYPE_TO)
break;
}
}
}
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean suggest_sent = prefs.getBoolean("suggest_sent", false); boolean suggest_sent = prefs.getBoolean("suggest_sent", false);
@ -2167,36 +2185,28 @@ class Core {
if (type == EntityContact.TYPE_FROM && !suggest_received) if (type == EntityContact.TYPE_FROM && !suggest_received)
return; return;
Address[] recipients = (type == EntityContact.TYPE_TO List<Address> addresses = new ArrayList<>();
? message.to if (type == EntityContact.TYPE_FROM) {
: (message.reply != null ? message.reply : message.from)); if (message.reply == null || message.reply.length == 0) {
if (message.from != null)
// Check if from self addresses.addAll(Arrays.asList(message.from));
if (type == EntityContact.TYPE_FROM && recipients != null && recipients.length > 0) { } else
boolean me = false; addresses.addAll(Arrays.asList(message.reply));
List<EntityIdentity> identities = db.identity().getSynchronizingIdentities(folder.account); } else if (type == EntityContact.TYPE_TO) {
if (identities != null) if (message.to != null)
for (Address recipient : recipients) { addresses.addAll(Arrays.asList(message.to));
for (EntityIdentity identity : identities) if (message.cc != null)
if (identity.similarAddress(recipient)) { addresses.addAll(Arrays.asList(message.cc));
me = true;
break;
}
if (me)
break;
}
if (me)
recipients = message.to;
} }
if (recipients != null) { for (Address address : addresses) {
for (Address recipient : recipients) { final String email = ((InternetAddress) address).getAddress();
final String email = ((InternetAddress) recipient).getAddress(); final String name = ((InternetAddress) address).getPersonal();
final String name = ((InternetAddress) recipient).getPersonal(); final Uri avatar = ContactInfo.getLookupUri(context, new Address[]{address});
final Uri avatar = ContactInfo.getLookupUri(context, new Address[]{recipient});
db.runInTransaction(new Runnable() { try {
@Override db.beginTransaction();
public void run() {
EntityContact contact = db.contact().getContact(folder.account, type, email); EntityContact contact = db.contact().getContact(folder.account, type, email);
if (contact == null) { if (contact == null) {
contact = new EntityContact(); contact = new EntityContact();
@ -2220,8 +2230,10 @@ class Core {
db.contact().updateContact(contact); db.contact().updateContact(contact);
Log.i("Updated contact=" + contact + " type=" + type); Log.i("Updated contact=" + contact + " type=" + type);
} }
}
}); db.setTransactionSuccessful();
} finally {
db.endTransaction();
} }
} }
} }

@ -163,14 +163,11 @@ public class EntityMessage implements Serializable {
} }
boolean replySelf(List<TupleIdentityEx> identities) { boolean replySelf(List<TupleIdentityEx> identities) {
if (identities != null) { if (identities != null && from != null)
Address[] senders = (reply == null || reply.length == 0 ? from : reply); for (Address sender : from)
if (senders != null)
for (Address sender : senders)
for (TupleIdentityEx identity : identities) for (TupleIdentityEx identity : identities)
if (identity.similarAddress(sender)) if (identity.similarAddress(sender))
return true; return true;
}
return false; return false;
} }

Loading…
Cancel
Save