summaryrefslogtreecommitdiff
path: root/src/state.cpp
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2021-02-21 22:16:21 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2021-02-23 22:12:41 +0100
commitc3d6046b25ef0786b8d2919dfa9db4eb05114501 (patch)
tree19af178d6305c3a83859b7d5b07dbc9b1af3aea5 /src/state.cpp
parent52db636c108ab0a16ba0ccf8df55cf28142a230c (diff)
Sync service
Diffstat (limited to 'src/state.cpp')
-rw-r--r--src/state.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/state.cpp b/src/state.cpp
index 8790dfc..6e39b5e 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -78,13 +78,41 @@ vector<Ref> LocalState::lookupShared(UUID type) const
return res;
}
+vector<Ref> LocalState::sharedRefs() const
+{
+ vector<Ref> refs;
+ for (const auto & x : p->shared)
+ refs.push_back(x.ref());
+ return refs;
+}
+
+LocalState LocalState::sharedRefAdd(const Ref & ref) const
+{
+ const Storage * st;
+ if (p->shared.size() > 0)
+ st = &p->shared[0].ref().storage();
+ else if (p->identity)
+ st = &p->identity->ref()->storage();
+ else
+ st = &ref.storage();
+
+ LocalState ret;
+ ret.p->identity = p->identity;
+ ret.p->shared = p->shared;
+ ret.p->shared.push_back(SharedState(ref).store(*st));
+ filterAncestors(ret.p->shared);
+ return ret;
+}
+
LocalState LocalState::updateShared(UUID type, const vector<Ref> & xs) const
{
const Storage * st;
- if (xs.size() > 0)
- st = &xs[0].storage();
- else if (p->shared.size() > 0)
+ if (p->shared.size() > 0)
st = &p->shared[0].ref().storage();
+ else if (p->identity)
+ st = &p->identity->ref()->storage();
+ else if (xs.size() > 0)
+ st = &xs[0].storage();
else
return *this;