diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/erebos/message.h | 43 | ||||
-rw-r--r-- | include/erebos/storage.h | 1 |
2 files changed, 44 insertions, 0 deletions
diff --git a/include/erebos/message.h b/include/erebos/message.h index 011007a..194044c 100644 --- a/include/erebos/message.h +++ b/include/erebos/message.h @@ -1,19 +1,23 @@ #pragma once +#include <erebos/merge.h> #include <erebos/service.h> #include <chrono> #include <functional> #include <memory> +#include <mutex> #include <optional> #include <string> namespace erebos { +using std::mutex; using std::unique_ptr; class Contact; class Identity; +struct DirectMessageState; class DirectMessage { @@ -67,11 +71,43 @@ public: private: friend class DirectMessageService; + friend class DirectMessageThreads; struct Priv; DirectMessageThread(Priv *); std::shared_ptr<Priv> p; }; +class DirectMessageThreads +{ +public: + DirectMessageThreads(); + DirectMessageThreads(Stored<DirectMessageState>); + DirectMessageThreads(vector<Stored<DirectMessageState>>); + + static DirectMessageThreads load(const vector<Ref> & refs); + vector<Ref> store() const; + vector<Stored<DirectMessageState>> data() const; + + bool operator==(const DirectMessageThreads &) const; + bool operator!=(const DirectMessageThreads &) const; + + DirectMessageThread thread(const Identity &) const; + +private: + vector<Stored<DirectMessageState>> state; + + friend class DirectMessageService; +}; + +DECLARE_SHARED_TYPE(DirectMessageThreads) + +template<> struct Mergeable<DirectMessageThreads> +{ + using Component = DirectMessageState; + static vector<Stored<DirectMessageState>> components(const DirectMessageThreads &); + static Contact merge(vector<Stored<DirectMessageState>>); +}; + class DirectMessageService : public Service { public: @@ -100,8 +136,15 @@ public: DirectMessage send(const Peer &, const std::string &); private: + void updateHandler(const DirectMessageThreads &); + const Config config; const Server & server; + + vector<Stored<DirectMessageState>> prevState; + mutex stateMutex; + + Watched<DirectMessageThreads> watched; }; } diff --git a/include/erebos/storage.h b/include/erebos/storage.h index 32049db..8a701e9 100644 --- a/include/erebos/storage.h +++ b/include/erebos/storage.h @@ -474,6 +474,7 @@ class Stored friend class Storage; friend class Head<T>; public: + Stored() = default; Stored(const Stored &) = default; Stored(Stored &&) = default; Stored & operator=(const Stored &) = default; |