From 2eb8fc82ad77196ccf801bbf93a199b0a365081a Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 18 Oct 2020 11:58:32 +0300 Subject: [PATCH] lib: fix 'personal' handling in contacts --- lib/mu-contacts.cc | 18 +++--------------- lib/mu-contacts.hh | 15 +-------------- lib/mu-store.cc | 1 + lib/test-mu-contacts.cc | 8 ++++---- 4 files changed, 9 insertions(+), 33 deletions(-) diff --git a/lib/mu-contacts.cc b/lib/mu-contacts.cc index b59e0590..d2088ddd 100644 --- a/lib/mu-contacts.cc +++ b/lib/mu-contacts.cc @@ -32,18 +32,6 @@ using namespace Mu; -ContactInfo::ContactInfo (const std::string& _full_address, - const std::string& _email, - const std::string& _name, - time_t _last_seen): - full_address{_full_address}, - email{_email}, - name{_name}, - last_seen{_last_seen}, - freq{1}, - tstamp{g_get_monotonic_time()} {} - - ContactInfo::ContactInfo (const std::string& _full_address, const std::string& _email, const std::string& _name, @@ -233,12 +221,12 @@ Contacts::add (ContactInfo&& ci) auto it = priv_->contacts_.find(ci.email); if (it == priv_->contacts_.end()) { // completely new contact + wash(ci.name); wash(ci.full_address); - ci.freq = 1; - ci.personal = is_personal(ci.email); auto email{ci.email}; priv_->contacts_.emplace(ContactUMap::value_type(email, std::move(ci))); + } else { // existing contact. auto& ci_existing{it->second}; ++ci_existing.freq; @@ -247,12 +235,12 @@ Contacts::add (ContactInfo&& ci) // update. wash(ci.name); ci_existing.name = std::move(ci.name); - ci_existing.email = std::move(ci.email); wash(ci.full_address); ci_existing.full_address = std::move(ci.full_address); ci_existing.tstamp = g_get_monotonic_time(); + ci_existing.last_seen = ci.last_seen; } } } diff --git a/lib/mu-contacts.hh b/lib/mu-contacts.hh index c6e4b01e..6eeaccd2 100644 --- a/lib/mu-contacts.hh +++ b/lib/mu-contacts.hh @@ -41,19 +41,6 @@ namespace Mu { /// Data-structure representing information about some contact. struct ContactInfo { - /** - * Construct a new ContactInfo - * - * @param _full_address the full email address + name. - * @param _email email address - * @param _name name or empty - * @param _last_seen when was this contact last seen? - */ - ContactInfo (const std::string& _full_address, - const std::string& _email, - const std::string& _name, - time_t _last_seen); - /** * Construct a new ContactInfo * @@ -69,7 +56,7 @@ struct ContactInfo { const std::string& _name, bool personal, time_t _last_seen, - size_t freq); + size_t freq=1); std::string full_address; /**< Full name */ std::string email; /**< email address */ diff --git a/lib/mu-store.cc b/lib/mu-store.cc index d0e7cc7a..90e9e511 100644 --- a/lib/mu-store.cc +++ b/lib/mu-store.cc @@ -1045,6 +1045,7 @@ each_contact_info (MuMsgContact *contact, MsgDoc *msgdoc) contacts.add(Mu::ContactInfo(contact->full_address, contact->email, contact->name ? contact->name : "", + msgdoc->_personal, mu_msg_get_date(msgdoc->_msg))); } diff --git a/lib/test-mu-contacts.cc b/lib/test-mu-contacts.cc index 0d598c28..2c7bad81 100644 --- a/lib/test-mu-contacts.cc +++ b/lib/test-mu-contacts.cc @@ -33,21 +33,21 @@ test_mu_contacts_01() g_assert_cmpuint (contacts.size(), ==, 0); contacts.add(std::move(Mu::ContactInfo ("Foo ", - "foo.bar@example.com", "Foo", 12345))); + "foo.bar@example.com", "Foo", false, 12345))); g_assert_false (contacts.empty()); g_assert_cmpuint (contacts.size(), ==, 1); contacts.add(std::move(Mu::ContactInfo ("Cuux ", - "cuux@example.com", "Cuux", 54321))); + "cuux@example.com", "Cuux", false, 54321))); g_assert_cmpuint (contacts.size(), ==, 2); contacts.add(std::move(Mu::ContactInfo ("foo.bar@example.com", - "foo.bar@example.com", "Foo", 77777))); + "foo.bar@example.com", "Foo", false, 77777))); g_assert_cmpuint (contacts.size(), ==, 2); contacts.add(std::move(Mu::ContactInfo ("Foo.Bar@Example.Com", - "Foo.Bar@Example.Com", "Foo", 88888))); + "Foo.Bar@Example.Com", "Foo", false, 88888))); g_assert_cmpuint (contacts.size(), ==, 2); // note: replaces first.