diff options
Diffstat (limited to 'include/erebos/contact.h')
-rw-r--r-- | include/erebos/contact.h | 65 |
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; +}; } |