diff options
Diffstat (limited to 'include/erebos/contact.h')
-rw-r--r-- | include/erebos/contact.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/include/erebos/contact.h b/include/erebos/contact.h new file mode 100644 index 0000000..9008ce7 --- /dev/null +++ b/include/erebos/contact.h @@ -0,0 +1,98 @@ +#pragma once + +#include <erebos/identity.h> +#include <erebos/list.h> +#include <erebos/pairing.h> +#include <erebos/set.h> +#include <erebos/state.h> +#include <erebos/storage.h> + +#include <memory> +#include <optional> +#include <string> +#include <vector> + +namespace erebos { + +using std::optional; +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; + + optional<Identity> identity() const; + optional<string> customName() const; + Contact customName(const Storage & st, const string & name) const; + string name() const; + + bool operator==(const Contact &) const; + bool operator!=(const Contact &) const; + + vector<Stored<ContactData>> data() const; + Digest leastRoot() 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<StoredIdentityPart> 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(Config &&, const Server &); + virtual ~ContactService(); + + UUID uuid() const override; + + void request(const Peer &); + +protected: + virtual Stored<ContactAccepted> handlePairingComplete(const Peer &) override; + virtual void handlePairingResult(Context &, Stored<ContactAccepted>) override; + + const Server & server; +}; + +template<class T> class Signed; + +struct ContactAccepted +{ + static ContactAccepted load(const Ref &); + Ref store(const Storage &) const; +}; + +} |