diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2023-01-08 22:31:08 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-01-31 21:27:00 +0100 |
commit | c2df0381313ffe5e155b7dc3d6d4c7271a4b73a2 (patch) | |
tree | 0f9385be3a08e45045291ed52b692a3579db394d /src/contact.cpp | |
parent | ed40a224e4256867d5f8c9f7c4c3ea998d4b88ce (diff) |
Contact name setting and property lookup
Diffstat (limited to 'src/contact.cpp')
-rw-r--r-- | src/contact.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/contact.cpp b/src/contact.cpp index 796e896..787831c 100644 --- a/src/contact.cpp +++ b/src/contact.cpp @@ -2,8 +2,11 @@ #include "identity.h" +#include <array> + using namespace erebos; +using std::array; using std::move; DEFINE_SHARED_TYPE(Set<Contact>, @@ -34,6 +37,19 @@ optional<string> Contact::customName() const return p->name; } +Contact Contact::customName(const Storage & st, const string & name) const +{ + auto cdata = st.store(ContactData { + .prev = p->data, + .identity = {}, + .name = name, + }); + + return Contact(shared_ptr<Contact::Priv>(new Contact::Priv { + .data = { cdata }, + })); +} + string Contact::name() const { if (auto cust = customName()) @@ -59,13 +75,33 @@ vector<Stored<ContactData>> Contact::data() const return p->data; } +Digest Contact::leastRoot() const +{ + if (p->data.empty()) + return Digest(array<uint8_t, Digest::size> {}); + + vector<Digest> roots; + for (const auto & d : p->data) + for (const auto & r : d.ref().roots()) + roots.push_back(r); + roots.erase(std::unique(roots.begin(), roots.end()), roots.end()); + return roots[0]; +} + void Contact::Priv::init() { std::call_once(initFlag, [this]() { - // TODO: property lookup - identity = Identity::load(data[0]->identity); + vector<Stored<Signed<IdentityData>>> idata; + for (const auto & c : findPropertyComponents<Contact>(data, "identity")) + for (const auto & i : c->identity) + idata.push_back(i); + + identity = Identity::load(idata); if (identity) name = identity->name(); + + if (auto opt = findPropertyComponent<Contact>(data, "name")) + name = (*opt)->name; }); } |