mirror of https://github.com/M66B/FairEmail.git
Contact: store last used identity
This commit is contained in:
parent
7764b6450f
commit
0431c7c27c
File diff suppressed because it is too large
Load Diff
|
@ -1080,6 +1080,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
JSONObject jcontact = (JSONObject) jcontacts.get(c);
|
||||
EntityContact contact = EntityContact.fromJSON(jcontact);
|
||||
contact.account = account.id;
|
||||
contact.identity = xIdentity.get(contact.identity);
|
||||
if (db.contact().getContact(contact.account, contact.type, contact.email) == null)
|
||||
contact.id = db.contact().insertContact(contact);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
|
|||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 231,
|
||||
version = 232,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
|
@ -2312,6 +2312,12 @@ public abstract class DB extends RoomDatabase {
|
|||
logMigration(startVersion, endVersion);
|
||||
db.execSQL("UPDATE `message` SET thread = account || ':' || thread");
|
||||
}
|
||||
}).addMigrations(new Migration(231, 232) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
logMigration(startVersion, endVersion);
|
||||
db.execSQL("ALTER TABLE `contact` ADD COLUMN 'identity' INTEGER");
|
||||
}
|
||||
}).addMigrations(new Migration(998, 999) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
|
|
|
@ -35,9 +35,10 @@ public interface DaoContact {
|
|||
" WHERE account = :account")
|
||||
List<EntityContact> getContacts(long account);
|
||||
|
||||
@Query("SELECT contact.*, account.name AS accountName" +
|
||||
@Query("SELECT contact.*, account.name AS accountName, identity.email AS identityEmail" +
|
||||
" FROM contact" +
|
||||
" JOIN account ON account.id = contact.account" +
|
||||
" LEFT JOIN identity ON identity.id = contact.identity" +
|
||||
" WHERE (:account IS NULL OR contact.account = :account)" +
|
||||
" ORDER BY times_contacted DESC, last_contacted DESC")
|
||||
LiveData<List<TupleContactEx>> liveContacts(Long account);
|
||||
|
|
|
@ -79,6 +79,7 @@ public class EntityContact implements Serializable {
|
|||
public Long id;
|
||||
@NonNull
|
||||
public Long account;
|
||||
public Long identity; // no foreign key, no index
|
||||
@NonNull
|
||||
public int type;
|
||||
@NonNull
|
||||
|
@ -164,14 +165,14 @@ public class EntityContact implements Serializable {
|
|||
addresses.addAll(Arrays.asList(message.bcc));
|
||||
}
|
||||
|
||||
update(context, folder.account, addresses.toArray(new Address[0]), type, message.received);
|
||||
update(context, folder.account, message.identity, addresses.toArray(new Address[0]), type, message.received);
|
||||
}
|
||||
|
||||
public static void update(Context context, long account, Address[] addresses, int type, long time) {
|
||||
update(context, account, addresses, null, type, time);
|
||||
public static void update(Context context, long account, Long identity, Address[] addresses, int type, long time) {
|
||||
update(context, account, identity, addresses, null, type, time);
|
||||
}
|
||||
|
||||
public static void update(Context context, long account, Address[] addresses, String group, int type, long time) {
|
||||
public static void update(Context context, long account, Long identity, Address[] addresses, String group, int type, long time) {
|
||||
if (addresses == null)
|
||||
return;
|
||||
|
||||
|
@ -193,6 +194,7 @@ public class EntityContact implements Serializable {
|
|||
if (contact == null) {
|
||||
contact = new EntityContact();
|
||||
contact.account = account;
|
||||
contact.identity = identity;
|
||||
contact.type = type;
|
||||
contact.email = email;
|
||||
contact.name = name;
|
||||
|
@ -204,6 +206,7 @@ public class EntityContact implements Serializable {
|
|||
contact.id = db.contact().insertContact(contact);
|
||||
Log.i("Inserted contact=" + contact + " type=" + type);
|
||||
} else {
|
||||
contact.identity = identity;
|
||||
if (contact.name == null && name != null)
|
||||
contact.name = name;
|
||||
if (contact.group == null && group != null)
|
||||
|
@ -239,6 +242,7 @@ public class EntityContact implements Serializable {
|
|||
public JSONObject toJSON() throws JSONException {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("identity", identity);
|
||||
json.put("type", type);
|
||||
json.put("email", email);
|
||||
json.put("name", name);
|
||||
|
@ -254,6 +258,9 @@ public class EntityContact implements Serializable {
|
|||
public static EntityContact fromJSON(JSONObject json) throws JSONException {
|
||||
EntityContact contact = new EntityContact();
|
||||
// id
|
||||
if (json.has("identity") && !json.isNull("identity"))
|
||||
contact.identity = json.getLong("identity");
|
||||
|
||||
contact.type = json.getInt("type");
|
||||
contact.email = json.getString("email");
|
||||
|
||||
|
@ -279,6 +286,7 @@ public class EntityContact implements Serializable {
|
|||
if (obj instanceof EntityContact) {
|
||||
EntityContact other = (EntityContact) obj;
|
||||
return (this.account.equals(other.account) &&
|
||||
Objects.equals(this.identity, other.identity) &&
|
||||
this.type == other.type &&
|
||||
this.email.equals(other.email) &&
|
||||
Objects.equals(this.name, other.name) &&
|
||||
|
|
|
@ -273,8 +273,10 @@ public class EntityOperation {
|
|||
if (rule.isBlockingSender(message, source))
|
||||
db.rule().deleteRule(rule.id);
|
||||
|
||||
EntityContact.delete(context, message.account, message.from, EntityContact.TYPE_JUNK);
|
||||
EntityContact.update(context, message.account, message.from, EntityContact.TYPE_NO_JUNK, message.received);
|
||||
EntityContact.delete(context, message.account, message.from,
|
||||
EntityContact.TYPE_JUNK);
|
||||
EntityContact.update(context, message.account, message.identity, message.from,
|
||||
EntityContact.TYPE_NO_JUNK, message.received);
|
||||
}
|
||||
|
||||
if (EntityFolder.JUNK.equals(target.type))
|
||||
|
|
|
@ -453,6 +453,7 @@ public class FragmentContacts extends FragmentBase {
|
|||
|
||||
EntityContact.update(context,
|
||||
account,
|
||||
null,
|
||||
addresses.toArray(new Address[0]),
|
||||
group,
|
||||
type,
|
||||
|
|
|
@ -6446,7 +6446,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
if (target.block &&
|
||||
EntityFolder.JUNK.equals(target.targetFolder.type))
|
||||
EntityContact.update(context,
|
||||
message.account, message.from,
|
||||
message.account, message.identity, message.from,
|
||||
EntityContact.TYPE_JUNK, message.received);
|
||||
}
|
||||
|
||||
|
@ -8562,7 +8562,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
|
||||
if (block_sender)
|
||||
EntityContact.update(context,
|
||||
message.account, message.from,
|
||||
message.account, message.identity, message.from,
|
||||
EntityContact.TYPE_JUNK, message.received);
|
||||
|
||||
if (account.protocol == EntityAccount.TYPE_IMAP) {
|
||||
|
|
|
@ -297,7 +297,7 @@ public class ServiceUI extends IntentService {
|
|||
|
||||
if (block_sender)
|
||||
EntityContact.update(this,
|
||||
message.account, message.from,
|
||||
message.account, message.identity, message.from,
|
||||
EntityContact.TYPE_JUNK, message.received);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
|
|
@ -19,15 +19,19 @@ package eu.faircode.email;
|
|||
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class TupleContactEx extends EntityContact {
|
||||
public String accountName;
|
||||
public String identityEmail;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof TupleContactEx) {
|
||||
TupleContactEx other = (TupleContactEx) obj;
|
||||
return (super.equals(obj) &&
|
||||
accountName.equals(other.accountName));
|
||||
accountName.equals(other.accountName) &&
|
||||
Objects.equals(this.identityEmail, other.identityEmail));
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue