summaryrefslogtreecommitdiff
path: root/include/erebos/contact.h
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-12-18 18:56:19 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2022-12-18 21:37:11 +0100
commit86293ff20d9f8625615e855d98249175e8cd5cd3 (patch)
tree7eb1fe3a34ce1d6a24a9338f3dd3008b500fffe0 /include/erebos/contact.h
parent77fc16d21158c6542addcbaaff47b801d3b5f5c7 (diff)
Contact service and contacts using stored set
Diffstat (limited to 'include/erebos/contact.h')
-rw-r--r--include/erebos/contact.h65
1 files changed, 58 insertions, 7 deletions
diff --git a/include/erebos/contact.h b/include/erebos/contact.h
index e56346a..ef9c3b6 100644
--- a/include/erebos/contact.h
+++ b/include/erebos/contact.h
@@ -2,6 +2,8 @@
#include <erebos/identity.h>
#include <erebos/list.h>
+#include <erebos/pairing.h>
+#include <erebos/set.h>
#include <erebos/state.h>
#include <erebos/storage.h>
@@ -17,31 +19,80 @@ using std::shared_ptr;
using std::string;
using std::vector;
+struct ContactData;
+
class Contact
{
public:
+ Contact(vector<Stored<ContactData>> data);
Contact(const Contact &) = default;
Contact(Contact &&) = default;
Contact & operator=(const Contact &) = default;
Contact & operator=(Contact &&) = default;
- static List<Contact> prepend(const Storage &, Identity, List<Contact>);
-
- Identity identity() const;
- optional<string> name() const;
+ optional<Identity> identity() const;
+ optional<string> customName() const;
+ string name() const;
bool operator==(const Contact &) const;
bool operator!=(const Contact &) const;
- static List<Contact> loadList(const vector<Ref> &);
- vector<Ref> refs() const;
+ vector<Stored<ContactData>> data() const;
private:
struct Priv;
shared_ptr<Priv> p;
Contact(shared_ptr<Priv> p): p(p) {}
+
+ friend class ContactService;
+};
+
+DECLARE_SHARED_TYPE(Set<Contact>)
+
+struct ContactData
+{
+ static ContactData load(const Ref &);
+ Ref store(const Storage &) const;
+
+ vector<Stored<ContactData>> prev;
+ vector<Stored<Signed<IdentityData>>> identity;
+ optional<string> name;
+};
+
+template<> struct Mergeable<Contact>
+{
+ using Component = ContactData;
+ static vector<Stored<ContactData>> components(const Contact & c) { return c.data(); }
+ static Contact merge(vector<Stored<ContactData>> x) { return Contact(move(x)); }
+};
+
+struct ContactAccepted;
+
+class ContactService : public PairingService<ContactAccepted>
+{
+public:
+ ContactService();
+ virtual ~ContactService();
+
+ UUID uuid() const override;
+
+ void serverStarted(const class Server &) override;
+
+ void request(const Peer &);
+
+protected:
+ virtual Stored<ContactAccepted> handlePairingComplete(const Peer &) override;
+ virtual void handlePairingResult(Context &, Stored<ContactAccepted>) override;
+
+ const class Server * server;
};
-DECLARE_SHARED_TYPE(List<Contact>)
+template<class T> class Signed;
+
+struct ContactAccepted
+{
+ static ContactAccepted load(const Ref &);
+ Ref store(const Storage &) const;
+};
}