summary refs log tree commit diff
path: root/include/Sync.h
blob: 26cfdb48b21bed00e4968565282d9e904984d895 (plain) (blame)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
 * nheko Copyright (C) 2017  Konstantinos Sideris <siderisk@auth.gr>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <QJsonArray>
#include <QJsonDocument>
#include <QMap>
#include <QString>

#include "Deserializable.h"

class Event : public Deserializable
{
public:
	inline QJsonObject content() const;
	inline QJsonObject unsigned_content() const;

	inline QString sender() const;
	inline QString state_key() const;
	inline QString type() const;
	inline QString eventId() const;

	inline uint64_t timestamp() const;

	void deserialize(const QJsonValue &data) override;

private:
	QJsonObject content_;
	QJsonObject unsigned_;

	QString sender_;
	QString state_key_;
	QString type_;
	QString event_id_;

	uint64_t origin_server_ts_;
};

inline QJsonObject Event::content() const
{
	return content_;
}

inline QJsonObject Event::unsigned_content() const
{
	return unsigned_;
}

inline QString Event::sender() const
{
	return sender_;
}

inline QString Event::state_key() const
{
	return state_key_;
}

inline QString Event::type() const
{
	return type_;
}

inline QString Event::eventId() const
{
	return event_id_;
}

inline uint64_t Event::timestamp() const
{
	return origin_server_ts_;
}

class State : public Deserializable
{
public:
	void deserialize(const QJsonValue &data) override;
	inline QJsonArray events() const;

private:
	QJsonArray events_;
};

inline QJsonArray State::events() const
{
	return events_;
}

class Timeline : public Deserializable
{
public:
	inline QJsonArray events() const;
	inline QString previousBatch() const;
	inline bool limited() const;

	void deserialize(const QJsonValue &data) override;

private:
	QJsonArray events_;
	QString prev_batch_;
	bool limited_;
};

inline QJsonArray Timeline::events() const
{
	return events_;
}

inline QString Timeline::previousBatch() const
{
	return prev_batch_;
}

inline bool Timeline::limited() const
{
	return limited_;
}

// TODO: Add support for ehpmeral, account_data, undread_notifications
class JoinedRoom : public Deserializable
{
public:
	inline State state() const;
	inline Timeline timeline() const;

	void deserialize(const QJsonValue &data) override;

private:
	State state_;
	Timeline timeline_;
	/* Ephemeral ephemeral_; */
	/* AccountData account_data_; */
	/* UnreadNotifications unread_notifications_; */
};

inline State JoinedRoom::state() const
{
	return state_;
}

inline Timeline JoinedRoom::timeline() const
{
	return timeline_;
}

// TODO: Add support for invited and left rooms.
class Rooms : public Deserializable
{
public:
	inline QMap<QString, JoinedRoom> join() const;
	void deserialize(const QJsonValue &data) override;

private:
	QMap<QString, JoinedRoom> join_;
};

inline QMap<QString, JoinedRoom> Rooms::join() const
{
	return join_;
}

class SyncResponse : public Deserializable
{
public:
	void deserialize(const QJsonDocument &data) override;
	inline QString nextBatch() const;
	inline Rooms rooms() const;

private:
	QString next_batch_;
	Rooms rooms_;
};

inline Rooms SyncResponse::rooms() const
{
	return rooms_;
}

inline QString SyncResponse::nextBatch() const
{
	return next_batch_;
}