From 9577599e6af4dfb36df81fe5d89801c4ce4a19ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 1 Jul 2023 20:08:48 +0200 Subject: Direct message shared state --- include/erebos/message.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'include/erebos/message.h') 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 #include #include #include #include +#include #include #include 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 p; }; +class DirectMessageThreads +{ +public: + DirectMessageThreads(); + DirectMessageThreads(Stored); + DirectMessageThreads(vector>); + + static DirectMessageThreads load(const vector & refs); + vector store() const; + vector> data() const; + + bool operator==(const DirectMessageThreads &) const; + bool operator!=(const DirectMessageThreads &) const; + + DirectMessageThread thread(const Identity &) const; + +private: + vector> state; + + friend class DirectMessageService; +}; + +DECLARE_SHARED_TYPE(DirectMessageThreads) + +template<> struct Mergeable +{ + using Component = DirectMessageState; + static vector> components(const DirectMessageThreads &); + static Contact merge(vector>); +}; + 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> prevState; + mutex stateMutex; + + Watched watched; }; } -- cgit v1.2.3