From 29ade9784fe65ecd686b5e8e18d84e6acc30b37a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 14 Mar 2020 22:43:44 +0100 Subject: Direct message service --- include/erebos/identity.h | 2 ++ include/erebos/message.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 include/erebos/message.h (limited to 'include') 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 keyMessage() const; + bool sameAs(const Identity &) const; + std::optional 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 + +#include +#include +#include +#include + +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 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 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 p; +}; + +class DirectMessageService : public Service +{ +public: + DirectMessageService(); + virtual ~DirectMessageService(); + + UUID uuid() const override; + void handle(Context &) const override; + + typedef std::function ThreadWatcher; + static void onUpdate(ThreadWatcher); + static DirectMessageThread thread(const Identity &); + + static DirectMessage send(const Identity &, const Peer &, const std::string &); + +private: + struct Priv; +}; + +} -- cgit v1.2.3