Fix ContactStoreImpl not saving flags removed from a contact

Don't try to merge contacts, just assume the updated contact passed in
is canonical.
This commit is contained in:
Michael Gratton 2019-10-25 13:26:56 +11:00
parent d0773078f0
commit 0c563cf101
2 changed files with 22 additions and 27 deletions

View file

@ -9,14 +9,13 @@
/**
* An database-backed implementation of Geary.Contacts
*/
internal class Geary.ContactStoreImpl : BaseObject, Geary.ContactStore {
internal class Geary.ContactStoreImpl : ContactStore, BaseObject {
private Geary.Db.Database backing;
internal ContactStoreImpl(Geary.Db.Database backing) {
base_ref();
this.backing = backing;
}
@ -158,32 +157,12 @@ internal class Geary.ContactStoreImpl : BaseObject, Geary.ContactStore {
stmt.exec(cancellable);
} else {
// Update existing contact
// Merge two flags sets together
updated.flags.add_all(existing.flags);
// update remaining fields, careful not to overwrite
// non-null real_name with null (but using latest
// real_name if supplied) ... email is not updated (it's
// how existing was keyed), normalized_email is inserted at
// the same time as email, leaving only real_name, flags,
// and highest_importance
Db.Statement stmt = cx.prepare(
"UPDATE ContactTable SET real_name=?, flags=?, highest_importance=? WHERE email=?");
stmt.bind_string(
0, !String.is_empty(updated.real_name) ? updated.real_name : existing.real_name
);
stmt.bind_string(
1, updated.flags.serialize()
);
stmt.bind_int(
2, int.max(updated.highest_importance, existing.highest_importance)
);
stmt.bind_string(
3, updated.email
);
stmt.bind_string(0, updated.real_name);
stmt.bind_string(1, updated.flags.serialize());
stmt.bind_int(2, updated.highest_importance);
stmt.bind_string(3, updated.email);
stmt.exec(cancellable);
}
}

View file

@ -269,7 +269,23 @@ class Geary.ContactStoreImplTest : TestCase {
assert_string("test@example.com", updated.normalized_email, "Updated normalized_email");
assert_string("Updated", updated.real_name, "Updated real_name");
assert_int(100, updated.highest_importance, "Updated highest_importance");
assert_true(updated.flags.always_load_remote_images(), "Updated real_name");
assert_true(updated.flags.always_load_remote_images(), "Added flags");
// Now try removing the flag and ensure it sticks
not_updated.flags.remove(Contact.Flags.ALWAYS_LOAD_REMOTE_IMAGES);
test_article.update_contacts.begin(
Collection.single(not_updated),
null,
(obj, ret) => { async_complete(ret); }
);
test_article.update_contacts.end(async_result());
test_article.get_by_rfc822.begin(
new RFC822.MailboxAddress(null, "Test@example.com"),
null,
(obj, ret) => { async_complete(ret); }
);
Contact? updated_again = test_article.get_by_rfc822.end(async_result());
assert_false(updated_again.flags.always_load_remote_images(), "Removed flags");
}
}