summaryrefslogtreecommitdiff
path: root/include/erebos
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-07-01 20:08:48 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2023-07-01 22:07:27 +0200
commit9577599e6af4dfb36df81fe5d89801c4ce4a19ab (patch)
tree1d383f6f3466c3c2198b4de2a2f53b6ad500fe39 /include/erebos
parentafab7dc5673fbc5fd600182612626676ae36d1c0 (diff)
Direct message shared state
Diffstat (limited to 'include/erebos')
-rw-r--r--include/erebos/message.h43
-rw-r--r--include/erebos/storage.h1
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;