mirror of https://github.com/djcb/mu.git
parent
9a1e749cc5
commit
fb34824232
|
@ -26,6 +26,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
#include <utils/mu-utils.hh>
|
#include <utils/mu-utils.hh>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
@ -76,13 +77,17 @@ struct ContactInfoEqual {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr auto RecentOffset{15 * 24 * 3600};
|
||||||
struct ContactInfoLessThan {
|
struct ContactInfoLessThan {
|
||||||
|
|
||||||
|
ContactInfoLessThan(): recently_{::time({}) - RecentOffset} {}
|
||||||
|
|
||||||
bool operator()(const Mu::ContactInfo& ci1, const Mu::ContactInfo& ci2) const {
|
bool operator()(const Mu::ContactInfo& ci1, const Mu::ContactInfo& ci2) const {
|
||||||
|
|
||||||
if (ci1.personal != ci2.personal)
|
if (ci1.personal != ci2.personal)
|
||||||
return ci1.personal; // personal comes first
|
return ci1.personal; // personal comes first
|
||||||
|
|
||||||
if (ci1.last_seen != ci2.last_seen) // more recent comes first
|
if (ci1.last_seen > recently_)
|
||||||
return ci1.last_seen > ci2.last_seen;
|
return ci1.last_seen > ci2.last_seen;
|
||||||
|
|
||||||
if (ci1.freq != ci2.freq) // more frequent comes first
|
if (ci1.freq != ci2.freq) // more frequent comes first
|
||||||
|
@ -90,6 +95,9 @@ struct ContactInfoLessThan {
|
||||||
|
|
||||||
return g_ascii_strcasecmp(ci1.email.c_str(), ci2.email.c_str()) < 0;
|
return g_ascii_strcasecmp(ci1.email.c_str(), ci2.email.c_str()) < 0;
|
||||||
}
|
}
|
||||||
|
// only sort recently seen contacts by recency; approx 15 days.
|
||||||
|
// this changes during the lifetime, but that's all fine.
|
||||||
|
const time_t recently_;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ContactUMap = std::unordered_map<const std::string, ContactInfo, EmailHash, EmailEqual>;
|
using ContactUMap = std::unordered_map<const std::string, ContactInfo, EmailHash, EmailEqual>;
|
||||||
|
@ -144,8 +152,6 @@ Contacts::Private::make_personal (const StringVec& personal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ContactUMap
|
ContactUMap
|
||||||
Contacts::Private::deserialize(const std::string& serialized) const
|
Contacts::Private::deserialize(const std::string& serialized) const
|
||||||
{
|
{
|
||||||
|
@ -231,8 +237,7 @@ Contacts::add (ContactInfo&& ci)
|
||||||
auto& ci_existing{it->second};
|
auto& ci_existing{it->second};
|
||||||
++ci_existing.freq;
|
++ci_existing.freq;
|
||||||
|
|
||||||
if (ci.last_seen > ci_existing.last_seen) {
|
if (ci.last_seen > ci_existing.last_seen) { // 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);
|
||||||
|
|
Loading…
Reference in New Issue