diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/erebos/identity.h | 2 | ||||
-rw-r--r-- | include/erebos/message.h | 90 |
2 files changed, 92 insertions, 0 deletions
diff --git a/include/erebos/identity.h b/include/erebos/identity.h index dce6093..7ba3f29 100644 --- a/include/erebos/identity.h +++ b/include/erebos/identity.h @@ -16,6 +16,8 @@ public: Stored<class PublicKey> keyMessage() const; + bool sameAs(const Identity &) const; + std::optional<Ref> ref() const; class Builder diff --git a/include/erebos/message.h b/include/erebos/message.h new file mode 100644 index 0000000..6415f92 --- /dev/null +++ b/include/erebos/message.h @@ -0,0 +1,90 @@ +#pragma once + +#include <erebos/service.h> + +#include <chrono> +#include <functional> +#include <optional> +#include <string> + +namespace erebos { + +class Identity; + +class DirectMessage +{ +public: + const Identity & from() const; + const ZonedTime & time() const; + const std::string & text() const; + +private: + friend class DirectMessageThread; + friend class DirectMessageService; + struct Priv; + DirectMessage(Priv *); + std::shared_ptr<Priv> p; +}; + +class DirectMessageThread +{ +public: + class Iterator + { + struct Priv; + Iterator(Priv *); + public: + using iterator_category = std::forward_iterator_tag; + using value_type = DirectMessage; + using difference_type = ssize_t; + using pointer = const DirectMessage *; + using reference = const DirectMessage &; + + Iterator(const Iterator &); + ~Iterator(); + Iterator & operator=(const Iterator &); + Iterator & operator++(); + value_type operator*() const; + bool operator==(const Iterator &) const; + bool operator!=(const Iterator &) const; + + private: + friend DirectMessageThread; + std::unique_ptr<Priv> p; + }; + + Iterator begin() const; + Iterator end() const; + + size_t size() const; + DirectMessage at(size_t) const; + + const Identity & peer() const; + +private: + friend class DirectMessageService; + struct Priv; + DirectMessageThread(Priv *); + std::shared_ptr<Priv> p; +}; + +class DirectMessageService : public Service +{ +public: + DirectMessageService(); + virtual ~DirectMessageService(); + + UUID uuid() const override; + void handle(Context &) const override; + + typedef std::function<void(const DirectMessageThread &, ssize_t, ssize_t)> ThreadWatcher; + static void onUpdate(ThreadWatcher); + static DirectMessageThread thread(const Identity &); + + static DirectMessage send(const Identity &, const Peer &, const std::string &); + +private: + struct Priv; +}; + +} |