From 86293ff20d9f8625615e855d98249175e8cd5cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 18 Dec 2022 18:56:19 +0100 Subject: Contact service and contacts using stored set --- include/erebos/contact.h | 65 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 7 deletions(-) (limited to 'include/erebos/contact.h') 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 #include +#include +#include #include #include @@ -17,31 +19,80 @@ using std::shared_ptr; using std::string; using std::vector; +struct ContactData; + class Contact { public: + Contact(vector> data); Contact(const Contact &) = default; Contact(Contact &&) = default; Contact & operator=(const Contact &) = default; Contact & operator=(Contact &&) = default; - static List prepend(const Storage &, Identity, List); - - Identity identity() const; - optional name() const; + optional identity() const; + optional customName() const; + string name() const; bool operator==(const Contact &) const; bool operator!=(const Contact &) const; - static List loadList(const vector &); - vector refs() const; + vector> data() const; private: struct Priv; shared_ptr p; Contact(shared_ptr p): p(p) {} + + friend class ContactService; +}; + +DECLARE_SHARED_TYPE(Set) + +struct ContactData +{ + static ContactData load(const Ref &); + Ref store(const Storage &) const; + + vector> prev; + vector>> identity; + optional name; +}; + +template<> struct Mergeable +{ + using Component = ContactData; + static vector> components(const Contact & c) { return c.data(); } + static Contact merge(vector> x) { return Contact(move(x)); } +}; + +struct ContactAccepted; + +class ContactService : public PairingService +{ +public: + ContactService(); + virtual ~ContactService(); + + UUID uuid() const override; + + void serverStarted(const class Server &) override; + + void request(const Peer &); + +protected: + virtual Stored handlePairingComplete(const Peer &) override; + virtual void handlePairingResult(Context &, Stored) override; + + const class Server * server; }; -DECLARE_SHARED_TYPE(List) +template class Signed; + +struct ContactAccepted +{ + static ContactAccepted load(const Ref &); + Ref store(const Storage &) const; +}; } -- cgit v1.2.3