lib: fix 'personal' handling in contacts

This commit is contained in:
Dirk-Jan C. Binnema
2020-10-18 11:58:32 +03:00
parent 1957bfa966
commit 2eb8fc82ad
4 changed files with 9 additions and 33 deletions

View File

@ -32,18 +32,6 @@
using namespace Mu; 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, ContactInfo::ContactInfo (const std::string& _full_address,
const std::string& _email, const std::string& _email,
const std::string& _name, const std::string& _name,
@ -233,12 +221,12 @@ Contacts::add (ContactInfo&& ci)
auto it = priv_->contacts_.find(ci.email); auto it = priv_->contacts_.find(ci.email);
if (it == priv_->contacts_.end()) { // completely new contact if (it == priv_->contacts_.end()) { // completely new contact
wash(ci.name); wash(ci.name);
wash(ci.full_address); wash(ci.full_address);
ci.freq = 1;
ci.personal = is_personal(ci.email);
auto email{ci.email}; auto email{ci.email};
priv_->contacts_.emplace(ContactUMap::value_type(email, std::move(ci))); priv_->contacts_.emplace(ContactUMap::value_type(email, std::move(ci)));
} else { // existing contact. } else { // existing contact.
auto& ci_existing{it->second}; auto& ci_existing{it->second};
++ci_existing.freq; ++ci_existing.freq;
@ -247,12 +235,12 @@ Contacts::add (ContactInfo&& ci)
// update. // update.
wash(ci.name); wash(ci.name);
ci_existing.name = std::move(ci.name); ci_existing.name = std::move(ci.name);
ci_existing.email = std::move(ci.email); ci_existing.email = std::move(ci.email);
wash(ci.full_address); wash(ci.full_address);
ci_existing.full_address = std::move(ci.full_address); ci_existing.full_address = std::move(ci.full_address);
ci_existing.tstamp = g_get_monotonic_time(); ci_existing.tstamp = g_get_monotonic_time();
ci_existing.last_seen = ci.last_seen;
} }
} }
} }

View File

@ -41,19 +41,6 @@ namespace Mu {
/// Data-structure representing information about some contact. /// Data-structure representing information about some contact.
struct ContactInfo { 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 * Construct a new ContactInfo
* *
@ -69,7 +56,7 @@ struct ContactInfo {
const std::string& _name, const std::string& _name,
bool personal, bool personal,
time_t _last_seen, time_t _last_seen,
size_t freq); size_t freq=1);
std::string full_address; /**< Full name <email> */ std::string full_address; /**< Full name <email> */
std::string email; /**< email address */ std::string email; /**< email address */

View File

@ -1045,6 +1045,7 @@ each_contact_info (MuMsgContact *contact, MsgDoc *msgdoc)
contacts.add(Mu::ContactInfo(contact->full_address, contacts.add(Mu::ContactInfo(contact->full_address,
contact->email, contact->email,
contact->name ? contact->name : "", contact->name ? contact->name : "",
msgdoc->_personal,
mu_msg_get_date(msgdoc->_msg))); mu_msg_get_date(msgdoc->_msg)));
} }

View File

@ -33,21 +33,21 @@ test_mu_contacts_01()
g_assert_cmpuint (contacts.size(), ==, 0); g_assert_cmpuint (contacts.size(), ==, 0);
contacts.add(std::move(Mu::ContactInfo ("Foo <foo.bar@example.com>", contacts.add(std::move(Mu::ContactInfo ("Foo <foo.bar@example.com>",
"foo.bar@example.com", "Foo", 12345))); "foo.bar@example.com", "Foo", false, 12345)));
g_assert_false (contacts.empty()); g_assert_false (contacts.empty());
g_assert_cmpuint (contacts.size(), ==, 1); g_assert_cmpuint (contacts.size(), ==, 1);
contacts.add(std::move(Mu::ContactInfo ("Cuux <cuux.fnorb@example.com>", contacts.add(std::move(Mu::ContactInfo ("Cuux <cuux.fnorb@example.com>",
"cuux@example.com", "Cuux", 54321))); "cuux@example.com", "Cuux", false, 54321)));
g_assert_cmpuint (contacts.size(), ==, 2); g_assert_cmpuint (contacts.size(), ==, 2);
contacts.add(std::move(Mu::ContactInfo ("foo.bar@example.com", 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); g_assert_cmpuint (contacts.size(), ==, 2);
contacts.add(std::move(Mu::ContactInfo ("Foo.Bar@Example.Com", 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); g_assert_cmpuint (contacts.size(), ==, 2);
// note: replaces first. // note: replaces first.