matrixion/include/Sync.h

254 lines
4.7 KiB
C
Raw Normal View History

2017-04-06 02:06:42 +03:00
/*
* 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
2017-04-06 02:06:42 +03:00
#include <QJsonArray>
2017-04-06 02:06:42 +03:00
#include <QJsonDocument>
#include <QMap>
#include <QString>
#include "Deserializable.h"
class Event : public Deserializable
{
public:
2017-09-10 12:59:21 +03:00
inline QJsonObject content() const;
inline QJsonObject unsigned_content() const;
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
inline QString sender() const;
inline QString state_key() const;
inline QString type() const;
inline QString eventId() const;
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
inline uint64_t timestamp() const;
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
void deserialize(const QJsonValue &data) override;
2017-04-06 02:06:42 +03:00
private:
2017-09-10 12:59:21 +03:00
QJsonObject content_;
QJsonObject unsigned_;
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
QString sender_;
QString state_key_;
QString type_;
QString event_id_;
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
uint64_t origin_server_ts_;
2017-04-06 02:06:42 +03:00
};
2017-08-20 13:47:22 +03:00
inline QJsonObject
Event::content() const
{
2017-09-10 12:59:21 +03:00
return content_;
}
2017-08-20 13:47:22 +03:00
inline QJsonObject
Event::unsigned_content() const
{
2017-09-10 12:59:21 +03:00
return unsigned_;
}
2017-08-20 13:47:22 +03:00
inline QString
Event::sender() const
{
2017-09-10 12:59:21 +03:00
return sender_;
}
2017-08-20 13:47:22 +03:00
inline QString
Event::state_key() const
{
2017-09-10 12:59:21 +03:00
return state_key_;
}
2017-08-20 13:47:22 +03:00
inline QString
Event::type() const
{
2017-09-10 12:59:21 +03:00
return type_;
}
2017-08-20 13:47:22 +03:00
inline QString
Event::eventId() const
{
2017-09-10 12:59:21 +03:00
return event_id_;
}
2017-08-20 13:47:22 +03:00
inline uint64_t
Event::timestamp() const
{
2017-09-10 12:59:21 +03:00
return origin_server_ts_;
}
2017-04-06 02:06:42 +03:00
class State : public Deserializable
{
public:
2017-09-10 12:59:21 +03:00
void deserialize(const QJsonValue &data) override;
inline QJsonArray events() const;
2017-04-06 02:06:42 +03:00
private:
2017-09-10 12:59:21 +03:00
QJsonArray events_;
2017-04-06 02:06:42 +03:00
};
2017-08-20 13:47:22 +03:00
inline QJsonArray
State::events() const
{
2017-09-10 12:59:21 +03:00
return events_;
}
2017-04-06 02:06:42 +03:00
class Timeline : public Deserializable
{
public:
2017-09-10 12:59:21 +03:00
inline QJsonArray events() const;
inline QString previousBatch() const;
inline bool limited() const;
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
void deserialize(const QJsonValue &data) override;
2017-04-06 02:06:42 +03:00
private:
2017-09-10 12:59:21 +03:00
QJsonArray events_;
QString prev_batch_;
bool limited_;
2017-04-06 02:06:42 +03:00
};
2017-08-20 13:47:22 +03:00
inline QJsonArray
Timeline::events() const
{
2017-09-10 12:59:21 +03:00
return events_;
}
2017-08-20 13:47:22 +03:00
inline QString
Timeline::previousBatch() const
{
2017-09-10 12:59:21 +03:00
return prev_batch_;
}
2017-08-20 13:47:22 +03:00
inline bool
Timeline::limited() const
{
2017-09-10 12:59:21 +03:00
return limited_;
}
2017-10-04 11:33:34 +03:00
// TODO: Add support for account_data, undread_notifications
2017-04-06 02:06:42 +03:00
class JoinedRoom : public Deserializable
{
public:
2017-09-10 12:59:21 +03:00
inline State state() const;
inline Timeline timeline() const;
2017-10-04 11:33:34 +03:00
inline QList<QString> typingUserIDs() const;
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
void deserialize(const QJsonValue &data) override;
2017-04-06 02:06:42 +03:00
private:
2017-09-10 12:59:21 +03:00
State state_;
Timeline timeline_;
2017-10-04 11:33:34 +03:00
QList<QString> typingUserIDs_;
2017-09-10 12:59:21 +03:00
/* AccountData account_data_; */
/* UnreadNotifications unread_notifications_; */
2017-04-06 02:06:42 +03:00
};
2017-10-04 11:33:34 +03:00
inline QList<QString>
JoinedRoom::typingUserIDs() const
{
return typingUserIDs_;
}
2017-08-20 13:47:22 +03:00
inline State
JoinedRoom::state() const
{
2017-09-10 12:59:21 +03:00
return state_;
}
2017-08-20 13:47:22 +03:00
inline Timeline
JoinedRoom::timeline() const
{
2017-09-10 12:59:21 +03:00
return timeline_;
}
class LeftRoom : public Deserializable
{
public:
inline State state() const;
inline Timeline timeline() const;
void deserialize(const QJsonValue &data) override;
private:
State state_;
Timeline timeline_;
};
inline State
LeftRoom::state() const
{
return state_;
}
inline Timeline
LeftRoom::timeline() const
{
return timeline_;
}
2017-04-06 02:06:42 +03:00
// TODO: Add support for invited and left rooms.
class Rooms : public Deserializable
{
public:
2017-09-10 12:59:21 +03:00
inline QMap<QString, JoinedRoom> join() const;
inline QMap<QString, LeftRoom> leave() const;
2017-09-10 12:59:21 +03:00
void deserialize(const QJsonValue &data) override;
2017-04-06 02:06:42 +03:00
private:
2017-09-10 12:59:21 +03:00
QMap<QString, JoinedRoom> join_;
QMap<QString, LeftRoom> leave_;
2017-04-06 02:06:42 +03:00
};
2017-08-20 13:47:22 +03:00
inline QMap<QString, JoinedRoom>
Rooms::join() const
{
2017-09-10 12:59:21 +03:00
return join_;
}
inline QMap<QString, LeftRoom>
Rooms::leave() const
{
return leave_;
}
2017-04-06 02:06:42 +03:00
class SyncResponse : public Deserializable
{
public:
2017-09-10 12:59:21 +03:00
void deserialize(const QJsonDocument &data) override;
inline QString nextBatch() const;
inline Rooms rooms() const;
2017-04-06 02:06:42 +03:00
private:
2017-09-10 12:59:21 +03:00
QString next_batch_;
Rooms rooms_;
2017-04-06 02:06:42 +03:00
};
2017-08-20 13:47:22 +03:00
inline Rooms
SyncResponse::rooms() const
{
2017-09-10 12:59:21 +03:00
return rooms_;
}
2017-08-20 13:47:22 +03:00
inline QString
SyncResponse::nextBatch() const
{
2017-09-10 12:59:21 +03:00
return next_batch_;
}