summaryrefslogtreecommitdiff
path: root/src/message.h
blob: 7e0f597ba406d877b5ead456e40bb27bc39b15dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once

#include <erebos/identity.h>
#include <erebos/message.h>
#include <erebos/storage.h>
#include <erebos/time.h>

#include <mutex>
#include <vector>

namespace chrono = std::chrono;
using chrono::system_clock;
using std::mutex;
using std::optional;
using std::string;
using std::vector;

namespace erebos {

struct DirectMessageData
{
	static optional<DirectMessageData> load(const Ref &);
	Ref store(const Storage &) const;

	vector<Stored<DirectMessageData>> prev;
	Identity from;
	ZonedTime time;
	string text;
};

struct DirectMessage::Priv
{
	Stored<DirectMessageData> data;
};

struct DirectMessageThread::Priv
{
	const Identity peer;
	const vector<Stored<DirectMessageData>> head;

	static DirectMessageThread getThreadLocked(const Identity & peer);
	static DirectMessageThread updateThreadLocked(const Identity & peer,
			vector<Stored<DirectMessageData>> && head);
};

struct DirectMessageThread::Iterator::Priv
{
	optional<DirectMessage> current;
	vector<Stored<DirectMessageData>> next;
};

struct DirectMessageService::Priv
{
	static vector<ThreadWatcher> watchers;
	static mutex watcherLock;
};

}