summaryrefslogtreecommitdiff
path: root/include/erebos
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-03-14 22:43:44 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2020-03-23 21:37:30 +0100
commit29ade9784fe65ecd686b5e8e18d84e6acc30b37a (patch)
tree6cb1b29880701b1f1093e9f22525678b39449baf /include/erebos
parent3357cbc91e7ff4d0d455c88785fc455067b34820 (diff)
Direct message service
Diffstat (limited to 'include/erebos')
-rw-r--r--include/erebos/identity.h2
-rw-r--r--include/erebos/message.h90
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;
+};
+
+}