Add/update contacts in transaction

pull/156/head
M66B 6 years ago
parent be8c5a99e3
commit 102838c007

@ -1484,10 +1484,10 @@ class Core {
} }
} }
private static void updateContactInfo(Context context, EntityFolder folder, EntityMessage message) { private static void updateContactInfo(Context context, final EntityFolder folder, final EntityMessage message) {
DB db = DB.getInstance(context); final DB db = DB.getInstance(context);
int type = (folder.isOutgoing() ? EntityContact.TYPE_TO : EntityContact.TYPE_FROM); final int type = (folder.isOutgoing() ? EntityContact.TYPE_TO : EntityContact.TYPE_FROM);
Address[] recipients = (type == EntityContact.TYPE_TO Address[] recipients = (type == EntityContact.TYPE_TO
? message.to ? message.to
: (message.reply != null ? message.reply : message.from)); : (message.reply != null ? message.reply : message.from));
@ -1512,9 +1512,12 @@ class Core {
if (recipients != null) { if (recipients != null) {
for (Address recipient : recipients) { for (Address recipient : recipients) {
String email = ((InternetAddress) recipient).getAddress(); final String email = ((InternetAddress) recipient).getAddress();
String name = ((InternetAddress) recipient).getPersonal(); final String name = ((InternetAddress) recipient).getPersonal();
Uri avatar = ContactInfo.getLookupUri(context, new Address[]{recipient}); final Uri avatar = ContactInfo.getLookupUri(context, new Address[]{recipient});
db.runInTransaction(new Runnable() {
@Override
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();
@ -1538,6 +1541,8 @@ class Core {
Log.i("Updated contact=" + contact + " type=" + type); Log.i("Updated contact=" + contact + " type=" + type);
} }
} }
});
}
} }
} }

Loading…
Cancel
Save