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

File diff suppressed because it is too large Load Diff

View File

@ -714,7 +714,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
for (int c = 0; c < jcontacts.length(); c++) {
JSONObject jcontact = (JSONObject) jcontacts.get(c);
EntityContact contact = EntityContact.fromJSON(jcontact);
if (db.contact().getContacts(contact.type, contact.email).size() == 0) {
if (db.contact().getContact(contact.type, contact.email) == null) {
contact.id = db.contact().insertContact(contact);
Log.i("Imported contact=" + contact);
}

View File

@ -1219,6 +1219,34 @@ class Core {
attachment.sequence = sequence++;
attachment.id = db.attachment().insertAttachment(attachment);
}
if (!folder.isOutgoing() && !EntityFolder.ARCHIVE.equals(folder.type)) {
Address[] replies = (message.reply != null ? message.reply : message.from);
if (replies != null)
for (Address reply : replies) {
String email = ((InternetAddress) reply).getAddress();
String name = ((InternetAddress) reply).getPersonal();
EntityContact contact = db.contact().getContact(EntityContact.TYPE_FROM, email);
if (contact == null) {
contact = new EntityContact();
contact.type = EntityContact.TYPE_FROM;
contact.email = email;
contact.name = name;
contact.avatar = message.avatar;
contact.times_contacted = 1;
contact.last_contacted = new Date().getTime();
contact.id = db.contact().insertContact(contact);
Log.i("Inserted sender contact=" + contact);
} else {
contact.name = name;
contact.avatar = message.avatar;
contact.times_contacted++;
contact.last_contacted = new Date().getTime();
db.contact().updateContact(contact);
Log.i("Updated sender contact=" + contact);
}
}
}
} else {
boolean update = false;
@ -1290,31 +1318,6 @@ class Core {
Log.i(folder.name + " unchanged uid=" + uid);
}
if (!folder.isOutgoing() && !EntityFolder.ARCHIVE.equals(folder.type)) {
Address[] senders = (message.reply != null ? message.reply : message.from);
if (senders != null)
for (Address sender : senders) {
String email = ((InternetAddress) sender).getAddress();
String name = ((InternetAddress) sender).getPersonal();
List<EntityContact> contacts = db.contact().getContacts(EntityContact.TYPE_FROM, email);
if (contacts.size() == 0) {
EntityContact contact = new EntityContact();
contact.type = EntityContact.TYPE_FROM;
contact.email = email;
contact.name = name;
contact.id = db.contact().insertContact(contact);
Log.i("Inserted sender 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 sender contact=" + contact);
}
}
}
}
List<String> fkeywords = new ArrayList<>(Arrays.asList(folder.keywords));
for (String keyword : keywords)

View File

@ -50,7 +50,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 54,
version = 55,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -599,6 +599,15 @@ public abstract class DB extends RoomDatabase {
}
}
})
.addMigrations(new Migration(54, 55) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `contact` ADD COLUMN `avatar` TEXT");
db.execSQL("ALTER TABLE `contact` ADD COLUMN `times_contacted` INTEGER NOT NULL DEFAULT 1");
db.execSQL("ALTER TABLE `contact` ADD COLUMN `last_contacted` INTEGER");
}
})
.build();
}

View File

@ -37,7 +37,7 @@ public interface DaoContact {
" FROM contact" +
" WHERE email = :email" +
" AND (:type IS NULL OR type = :type)")
List<EntityContact> getContacts(Integer type, String email);
EntityContact getContact(Integer type, String email);
@Query("SELECT id AS _id, name, email" +
", CASE type" +

View File

@ -53,6 +53,11 @@ public class EntityContact implements Serializable {
@NonNull
public String email;
public String name;
public String avatar;
@NonNull
public Integer times_contacted;
public Long last_contacted;
public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject();
@ -60,6 +65,9 @@ public class EntityContact implements Serializable {
json.put("type", type);
json.put("email", email);
json.put("name", name);
json.put("avatar", avatar);
json.put("times_contacted", times_contacted);
json.put("last_contacted", last_contacted);
return json;
}
@ -68,8 +76,21 @@ public class EntityContact implements Serializable {
// id
contact.type = json.getInt("type");
contact.email = json.getString("email");
if (json.has("name"))
if (json.has("name") && !json.isNull("name"))
contact.name = json.getString("name");
if (json.has("avatar") && !json.isNull("avatar"))
contact.avatar = json.getString("avatar");
if (json.has("times_contacted"))
contact.times_contacted = json.getInt("times_contacted");
else
contact.times_contacted = 1;
if (json.has("last_contacted") && !json.isNull("last_contacted"))
contact.last_contacted = json.getLong("last_contacted");
return contact;
}

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) {