Extend local contact info

This commit is contained in:
M66B
2019-03-14 17:46:45 +00:00
parent 013cb9e965
commit 0a80d21534
7 changed files with 1639 additions and 39 deletions

View File

@@ -365,21 +365,24 @@ public class ServiceSend extends LifecycleService {
for (Address recipient : message.to) {
String email = ((InternetAddress) recipient).getAddress();
String name = ((InternetAddress) recipient).getPersonal();
List<EntityContact> contacts = db.contact().getContacts(EntityContact.TYPE_TO, email);
if (contacts.size() == 0) {
EntityContact contact = new EntityContact();
EntityContact contact = db.contact().getContact(EntityContact.TYPE_TO, email);
if (contact == null) {
contact = new EntityContact();
contact.type = EntityContact.TYPE_TO;
contact.email = email;
contact.name = name;
db.contact().insertContact(contact);
contact.avatar = message.avatar;
contact.times_contacted = 1;
contact.last_contacted = new Date().getTime();
contact.id = db.contact().insertContact(contact);
Log.i("Inserted recipient contact=" + contact);
} else {
EntityContact contact = contacts.get(0);
if (name != null && !name.equals(contact.name)) {
contact.name = name;
db.contact().updateContact(contact);
Log.i("Updated recipient contact=" + contact);
}
contact.name = name;
contact.avatar = message.avatar;
contact.times_contacted++;
contact.last_contacted = new Date().getTime();
db.contact().updateContact(contact);
Log.i("Updated recipient contact=" + contact);
}
}
} catch (MessagingException ex) {