summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-03-30 22:58:00 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2022-04-29 23:39:12 +0200
commit0bee44226cc60f2d18188dfb23f485e166073363 (patch)
tree0f0feecf00898a938c8eed574cbc9ae7ec4976eb /src
parentcad8af9d9a5a714ebefa7801f295234e22e2d5f1 (diff)
Identity update
Diffstat (limited to 'src')
-rw-r--r--src/identity.cpp55
-rw-r--r--src/identity.h1
2 files changed, 54 insertions, 2 deletions
diff --git a/src/identity.cpp b/src/identity.cpp
index 0d35122..9077db2 100644
--- a/src/identity.cpp
+++ b/src/identity.cpp
@@ -109,12 +109,13 @@ bool Identity::sameAs(const Identity & other) const
bool Identity::operator==(const Identity & other) const
{
- return p->data == other.p->data;
+ return p->data == other.p->data &&
+ p->updates == other.p->updates;
}
bool Identity::operator!=(const Identity & other) const
{
- return p->data != other.p->data;
+ return !(*this == other);
}
optional<Ref> Identity::ref() const
@@ -124,6 +125,24 @@ optional<Ref> Identity::ref() const
return nullopt;
}
+vector<Ref> Identity::refs() const
+{
+ vector<Ref> res;
+ res.reserve(p->data.size());
+ for (const auto & idata : p->data)
+ res.push_back(idata.ref());
+ return res;
+}
+
+vector<Ref> Identity::updates() const
+{
+ vector<Ref> res;
+ res.reserve(p->updates.size());
+ for (const auto & idata : p->updates)
+ res.push_back(idata.ref());
+ return res;
+}
+
Identity::Builder Identity::create(const Storage & st)
{
return Builder (new Builder::Priv {
@@ -143,6 +162,37 @@ Identity::Builder Identity::modify() const
});
}
+Identity Identity::update(const vector<Stored<Signed<IdentityData>>> & updates) const
+{
+ vector<Stored<Signed<IdentityData>>> ndata = p->data;
+ vector<Stored<Signed<IdentityData>>> ownerUpdates = p->updates;
+
+ for (const auto & u : updates) {
+ vector<Stored<Signed<IdentityData>>> tmp = p->data;
+ tmp.push_back(u);
+
+ size_t tmp_size = tmp.size();
+ filterAncestors(tmp);
+
+ if (tmp.size() < tmp_size)
+ ndata.push_back(u);
+ else
+ ownerUpdates.push_back(u);
+ }
+
+ filterAncestors(ndata);
+ filterAncestors(ownerUpdates);
+
+ if (auto p = Priv::validate(ndata)) {
+ p->updates = move(ownerUpdates);
+ if (p->owner && !p->updates.empty())
+ p->owner = p->owner->update(p->updates);
+ return Identity(move(p));
+ }
+
+ return *this;
+}
+
Identity::Builder::Builder(Priv * p): p(p) {}
@@ -263,6 +313,7 @@ shared_ptr<Identity::Priv> Identity::Priv::validate(const vector<Stored<Signed<I
auto p = new Priv {
.data = sdata,
+ .updates = {},
.name = {},
.owner = nullopt,
.keyMessage = keyMessageItem.value()->keyMessage.value(),
diff --git a/src/identity.h b/src/identity.h
index e0d2803..4b61c66 100644
--- a/src/identity.h
+++ b/src/identity.h
@@ -28,6 +28,7 @@ struct IdentityData
struct Identity::Priv
{
vector<Stored<Signed<IdentityData>>> data;
+ vector<Stored<Signed<IdentityData>>> updates;
shared_future<optional<string>> name;
optional<Identity> owner;
Stored<PublicKey> keyMessage;