From 0c563cf101031ddbcdf3c08659b14cb36da6baae Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Fri, 25 Oct 2019 13:26:56 +1100 Subject: [PATCH] Fix ContactStoreImpl not saving flags removed from a contact Don't try to merge contacts, just assume the updated contact passed in is canonical. --- .../common/common-contact-store-impl.vala | 31 +++---------------- .../common-contact-store-impl-test.vala | 18 ++++++++++- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/engine/common/common-contact-store-impl.vala b/src/engine/common/common-contact-store-impl.vala index 1ac675f0..8a3745a3 100644 --- a/src/engine/common/common-contact-store-impl.vala +++ b/src/engine/common/common-contact-store-impl.vala @@ -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); } } diff --git a/test/engine/common/common-contact-store-impl-test.vala b/test/engine/common/common-contact-store-impl-test.vala index b0a323ae..3974c00f 100644 --- a/test/engine/common/common-contact-store-impl-test.vala +++ b/test/engine/common/common-contact-store-impl-test.vala @@ -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"); } }