forked from mirror/nheko
parent
1976a3280c
commit
a605e4486f
@ -1,19 +0,0 @@ |
|||||||
#!/usr/bin/env bash |
|
||||||
|
|
||||||
set -evx |
|
||||||
|
|
||||||
sudo apt-get -qq update |
|
||||||
sudo apt-get install -y libgtest-dev |
|
||||||
wget https://github.com/google/googletest/archive/release-1.8.0.tar.gz |
|
||||||
tar xf release-1.8.0.tar.gz |
|
||||||
cd googletest-release-1.8.0 |
|
||||||
|
|
||||||
cmake -DBUILD_SHARED_LIBS=ON . |
|
||||||
make |
|
||||||
sudo cp -a googletest/include/gtest /usr/include |
|
||||||
sudo cp -a googlemock/gtest/*.so /usr/lib/ |
|
||||||
|
|
||||||
sudo ldconfig -v | grep gtest |
|
||||||
|
|
||||||
cd $TRAVIS_BUILD_DIR |
|
||||||
|
|
@ -1,7 +0,0 @@ |
|||||||
#!/usr/bin/env bash |
|
||||||
|
|
||||||
set -evx |
|
||||||
|
|
||||||
cmake -DBUILD_TESTS=ON -H. -Bbuild && cmake --build build |
|
||||||
|
|
||||||
cd build && GTEST_COLOR=1 ctest --verbose |
|
@ -1,131 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QMap> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
class Event : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
QJsonObject content() const { return content_; }; |
|
||||||
QJsonObject unsigned_content() const { return unsigned_; }; |
|
||||||
|
|
||||||
QString sender() const { return sender_; }; |
|
||||||
QString state_key() const { return state_key_; }; |
|
||||||
QString type() const { return type_; }; |
|
||||||
QString eventId() const { return event_id_; }; |
|
||||||
|
|
||||||
uint64_t timestamp() const { return origin_server_ts_; }; |
|
||||||
|
|
||||||
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_; |
|
||||||
}; |
|
||||||
|
|
||||||
class State : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonArray events() const { return events_; }; |
|
||||||
|
|
||||||
private: |
|
||||||
QJsonArray events_; |
|
||||||
}; |
|
||||||
|
|
||||||
class Timeline : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
QJsonArray events() const { return events_; }; |
|
||||||
QString previousBatch() const { return prev_batch_; }; |
|
||||||
bool limited() const { return limited_; }; |
|
||||||
|
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
|
|
||||||
private: |
|
||||||
QJsonArray events_; |
|
||||||
QString prev_batch_; |
|
||||||
bool limited_; |
|
||||||
}; |
|
||||||
|
|
||||||
// TODO: Add support for account_data, undread_notifications
|
|
||||||
class JoinedRoom : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
State state() const { return state_; }; |
|
||||||
Timeline timeline() const { return timeline_; }; |
|
||||||
QList<QString> typingUserIDs() const { return typingUserIDs_; }; |
|
||||||
|
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
|
|
||||||
private: |
|
||||||
State state_; |
|
||||||
Timeline timeline_; |
|
||||||
QList<QString> typingUserIDs_; |
|
||||||
/* AccountData account_data_; */ |
|
||||||
/* UnreadNotifications unread_notifications_; */ |
|
||||||
}; |
|
||||||
|
|
||||||
class LeftRoom : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
State state() const { return state_; }; |
|
||||||
Timeline timeline() const { return timeline_; }; |
|
||||||
|
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
|
|
||||||
private: |
|
||||||
State state_; |
|
||||||
Timeline timeline_; |
|
||||||
}; |
|
||||||
|
|
||||||
// TODO: Add support for invited and left rooms.
|
|
||||||
class Rooms : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
QMap<QString, JoinedRoom> join() const { return join_; }; |
|
||||||
QMap<QString, LeftRoom> leave() const { return leave_; }; |
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
|
|
||||||
private: |
|
||||||
QMap<QString, JoinedRoom> join_; |
|
||||||
QMap<QString, LeftRoom> leave_; |
|
||||||
}; |
|
||||||
|
|
||||||
class SyncResponse : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonDocument &data) override; |
|
||||||
QString nextBatch() const { return next_batch_; }; |
|
||||||
Rooms rooms() const { return rooms_; }; |
|
||||||
|
|
||||||
private: |
|
||||||
QString next_batch_; |
|
||||||
Rooms rooms_; |
|
||||||
}; |
|
@ -1,42 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
#include <QList> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
class AliasesEventContent |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
QList<QString> aliases() const { return aliases_; }; |
|
||||||
|
|
||||||
private: |
|
||||||
QList<QString> aliases_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,46 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
#include <QUrl> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
/*
|
|
||||||
* A picture that is associated with the room. |
|
||||||
*/ |
|
||||||
|
|
||||||
class AvatarEventContent |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
QUrl url() const { return url_; }; |
|
||||||
|
|
||||||
private: |
|
||||||
QUrl url_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,48 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
|
|
||||||
#include "CanonicalAliasEventContent.h" |
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
/*
|
|
||||||
* This event is used to inform the room about which alias should be considered |
|
||||||
* the canonical one. This could be for display purposes or as suggestion to |
|
||||||
* users which alias to use to advertise the room. |
|
||||||
*/ |
|
||||||
|
|
||||||
class CanonicalAliasEventContent |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
QString alias() const { return alias_; }; |
|
||||||
|
|
||||||
private: |
|
||||||
QString alias_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,47 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
/*
|
|
||||||
* This is the first event in a room and cannot be changed. It acts as the root |
|
||||||
* of all other events. |
|
||||||
*/ |
|
||||||
|
|
||||||
class CreateEventContent |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
QString creator() const { return creator_; }; |
|
||||||
|
|
||||||
private: |
|
||||||
// The user_id of the room creator. This is set by the homeserver.
|
|
||||||
QString creator_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,183 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QDebug> |
|
||||||
#include <QJsonValue> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
enum class EventType |
|
||||||
{ |
|
||||||
/// m.room.aliases
|
|
||||||
RoomAliases, |
|
||||||
/// m.room.avatar
|
|
||||||
RoomAvatar, |
|
||||||
/// m.room.canonical_alias
|
|
||||||
RoomCanonicalAlias, |
|
||||||
/// m.room.create
|
|
||||||
RoomCreate, |
|
||||||
/// m.room.history_visibility
|
|
||||||
RoomHistoryVisibility, |
|
||||||
/// m.room.join_rules
|
|
||||||
RoomJoinRules, |
|
||||||
/// m.room.member
|
|
||||||
RoomMember, |
|
||||||
/// m.room.message
|
|
||||||
RoomMessage, |
|
||||||
/// m.room.name
|
|
||||||
RoomName, |
|
||||||
/// m.room.power_levels
|
|
||||||
RoomPowerLevels, |
|
||||||
/// m.room.topic
|
|
||||||
RoomTopic, |
|
||||||
// Unsupported event
|
|
||||||
Unsupported, |
|
||||||
}; |
|
||||||
|
|
||||||
EventType |
|
||||||
extractEventType(const QJsonObject &data); |
|
||||||
|
|
||||||
bool |
|
||||||
isMessageEvent(EventType type); |
|
||||||
bool |
|
||||||
isStateEvent(EventType type); |
|
||||||
|
|
||||||
class UnsignedData |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
double age() const { return age_; } |
|
||||||
QString transactionId() const { return transaction_id_; } |
|
||||||
|
|
||||||
bool isEmpty() const { return age_ <= 0 && transaction_id_.isEmpty(); } |
|
||||||
|
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
private: |
|
||||||
double age_ = 0; |
|
||||||
QString transaction_id_; |
|
||||||
}; |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
class Event |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
Content content() const; |
|
||||||
EventType eventType() const; |
|
||||||
UnsignedData unsignedData() const { return unsignedData_; } |
|
||||||
|
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
private: |
|
||||||
Content content_; |
|
||||||
EventType type_; |
|
||||||
UnsignedData unsignedData_; |
|
||||||
}; |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
inline Content |
|
||||||
Event<Content>::content() const |
|
||||||
{ |
|
||||||
return content_; |
|
||||||
} |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
inline EventType |
|
||||||
Event<Content>::eventType() const |
|
||||||
{ |
|
||||||
return type_; |
|
||||||
} |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
void |
|
||||||
Event<Content>::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("Event is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
content_.deserialize(object.value("content")); |
|
||||||
type_ = extractEventType(object); |
|
||||||
|
|
||||||
if (object.contains("unsigned")) |
|
||||||
unsignedData_.deserialize(object.value("unsigned")); |
|
||||||
} |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
QJsonObject |
|
||||||
Event<Content>::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
switch (type_) { |
|
||||||
case EventType::RoomAliases: |
|
||||||
object["type"] = "m.room.aliases"; |
|
||||||
break; |
|
||||||
case EventType::RoomAvatar: |
|
||||||
object["type"] = "m.room.avatar"; |
|
||||||
break; |
|
||||||
case EventType::RoomCanonicalAlias: |
|
||||||
object["type"] = "m.room.canonical_alias"; |
|
||||||
break; |
|
||||||
case EventType::RoomCreate: |
|
||||||
object["type"] = "m.room.create"; |
|
||||||
break; |
|
||||||
case EventType::RoomHistoryVisibility: |
|
||||||
object["type"] = "m.room.history_visibility"; |
|
||||||
break; |
|
||||||
case EventType::RoomJoinRules: |
|
||||||
object["type"] = "m.room.join_rules"; |
|
||||||
break; |
|
||||||
case EventType::RoomMember: |
|
||||||
object["type"] = "m.room.member"; |
|
||||||
break; |
|
||||||
case EventType::RoomMessage: |
|
||||||
object["type"] = "m.room.message"; |
|
||||||
break; |
|
||||||
case EventType::RoomName: |
|
||||||
object["type"] = "m.room.name"; |
|
||||||
break; |
|
||||||
case EventType::RoomPowerLevels: |
|
||||||
object["type"] = "m.room.power_levels"; |
|
||||||
break; |
|
||||||
case EventType::RoomTopic: |
|
||||||
object["type"] = "m.room.topic"; |
|
||||||
break; |
|
||||||
case EventType::Unsupported: |
|
||||||
qWarning() << "Unsupported type to serialize"; |
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
object["content"] = content_.serialize(); |
|
||||||
|
|
||||||
if (!unsignedData_.isEmpty()) |
|
||||||
object["unsigned"] = unsignedData_.serialize(); |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,49 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
enum class HistoryVisibility |
|
||||||
{ |
|
||||||
Invited, |
|
||||||
Joined, |
|
||||||
Shared, |
|
||||||
WorldReadable, |
|
||||||
}; |
|
||||||
|
|
||||||
class HistoryVisibilityEventContent |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
HistoryVisibility historyVisibility() const { return history_visibility_; }; |
|
||||||
|
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
private: |
|
||||||
HistoryVisibility history_visibility_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,61 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
enum class JoinRule |
|
||||||
{ |
|
||||||
// A user who wishes to join the room must first receive
|
|
||||||
// an invite to the room from someone already inside of the room.
|
|
||||||
Invite, |
|
||||||
|
|
||||||
// Reserved but not yet implemented by the Matrix specification.
|
|
||||||
Knock, |
|
||||||
|
|
||||||
// Reserved but not yet implemented by the Matrix specification.
|
|
||||||
Private, |
|
||||||
|
|
||||||
/// Anyone can join the room without any prior action.
|
|
||||||
Public, |
|
||||||
}; |
|
||||||
|
|
||||||
/*
|
|
||||||
* Describes how users are allowed to join the room. |
|
||||||
*/ |
|
||||||
|
|
||||||
class JoinRulesEventContent |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
JoinRule joinRule() const { return join_rule_; }; |
|
||||||
|
|
||||||
private: |
|
||||||
JoinRule join_rule_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,68 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
#include <QUrl> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
enum class Membership |
|
||||||
{ |
|
||||||
// The user is banned.
|
|
||||||
Ban, |
|
||||||
|
|
||||||
// The user has been invited.
|
|
||||||
Invite, |
|
||||||
|
|
||||||
// The user has joined.
|
|
||||||
Join, |
|
||||||
|
|
||||||
// The user has requested to join.
|
|
||||||
Knock, |
|
||||||
|
|
||||||
// The user has left.
|
|
||||||
Leave, |
|
||||||
}; |
|
||||||
|
|
||||||
/*
|
|
||||||
* The current membership state of a user in the room. |
|
||||||
*/ |
|
||||||
|
|
||||||
class MemberEventContent |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
QUrl avatarUrl() const { return avatar_url_; }; |
|
||||||
QString displayName() const { return display_name_; }; |
|
||||||
Membership membershipState() const { return membership_state_; }; |
|
||||||
|
|
||||||
private: |
|
||||||
QUrl avatar_url_; |
|
||||||
QString display_name_; |
|
||||||
Membership membership_state_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,64 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 "MessageEventContent.h" |
|
||||||
#include "RoomEvent.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
template<class MsgContent> |
|
||||||
class MessageEvent : public RoomEvent<MessageEventContent> |
|
||||||
{ |
|
||||||
public: |
|
||||||
MsgContent msgContent() const; |
|
||||||
|
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
|
|
||||||
private: |
|
||||||
MsgContent msg_content_; |
|
||||||
}; |
|
||||||
|
|
||||||
template<class MsgContent> |
|
||||||
inline MsgContent |
|
||||||
MessageEvent<MsgContent>::msgContent() const |
|
||||||
{ |
|
||||||
return msg_content_; |
|
||||||
} |
|
||||||
|
|
||||||
template<class MsgContent> |
|
||||||
void |
|
||||||
MessageEvent<MsgContent>::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
RoomEvent<MessageEventContent>::deserialize(data); |
|
||||||
|
|
||||||
msg_content_.deserialize(data.toObject().value("content").toObject()); |
|
||||||
} |
|
||||||
|
|
||||||
namespace messages { |
|
||||||
struct ThumbnailInfo |
|
||||||
{ |
|
||||||
int h; |
|
||||||
int w; |
|
||||||
int size = 0; |
|
||||||
|
|
||||||
QString mimetype; |
|
||||||
}; |
|
||||||
} // namespace messages
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,74 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
enum class MessageEventType |
|
||||||
{ |
|
||||||
// m.audio
|
|
||||||
Audio, |
|
||||||
|
|
||||||
// m.emote
|
|
||||||
Emote, |
|
||||||
|
|
||||||
// m.file
|
|
||||||
File, |
|
||||||
|
|
||||||
// m.image
|
|
||||||
Image, |
|
||||||
|
|
||||||
// m.location
|
|
||||||
Location, |
|
||||||
|
|
||||||
// m.notice
|
|
||||||
Notice, |
|
||||||
|
|
||||||
// m.text
|
|
||||||
Text, |
|
||||||
|
|
||||||
// m.video
|
|
||||||
Video, |
|
||||||
|
|
||||||
// Unrecognized message type
|
|
||||||
Unknown, |
|
||||||
}; |
|
||||||
|
|
||||||
MessageEventType |
|
||||||
extractMessageEventType(const QJsonObject &data); |
|
||||||
|
|
||||||
class MessageEventContent |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
QString body() const { return body_; }; |
|
||||||
|
|
||||||
private: |
|
||||||
QString body_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,45 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
/*
|
|
||||||
* A human-friendly room name designed to be displayed to the end-user. |
|
||||||
*/ |
|
||||||
|
|
||||||
class NameEventContent |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
QString name() const { return name_; }; |
|
||||||
|
|
||||||
private: |
|
||||||
QString name_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,73 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
#include <QMap> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
enum class PowerLevels |
|
||||||
{ |
|
||||||
User = 0, |
|
||||||
Moderator = 50, |
|
||||||
Admin = 100, |
|
||||||
}; |
|
||||||
|
|
||||||
/*
|
|
||||||
* Defines the power levels (privileges) of users in the room. |
|
||||||
*/ |
|
||||||
|
|
||||||
class PowerLevelsEventContent |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
int banLevel() const { return ban_; }; |
|
||||||
int inviteLevel() const { return invite_; }; |
|
||||||
int kickLevel() const { return kick_; }; |
|
||||||
int redactLevel() const { return redact_; }; |
|
||||||
|
|
||||||
int eventsDefaultLevel() const { return events_default_; }; |
|
||||||
int stateDefaultLevel() const { return state_default_; }; |
|
||||||
int usersDefaultLevel() const { return users_default_; }; |
|
||||||
|
|
||||||
int eventLevel(QString event_type) const; |
|
||||||
int userLevel(QString user_id) const; |
|
||||||
|
|
||||||
private: |
|
||||||
int ban_ = static_cast<int>(PowerLevels::Moderator); |
|
||||||
int invite_ = static_cast<int>(PowerLevels::Moderator); |
|
||||||
int kick_ = static_cast<int>(PowerLevels::Moderator); |
|
||||||
int redact_ = static_cast<int>(PowerLevels::Moderator); |
|
||||||
|
|
||||||
int events_default_ = static_cast<int>(PowerLevels::User); |
|
||||||
int state_default_ = static_cast<int>(PowerLevels::Moderator); |
|
||||||
int users_default_ = static_cast<int>(PowerLevels::User); |
|
||||||
|
|
||||||
QMap<QString, int> events_; |
|
||||||
QMap<QString, int> users_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,116 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
#include <QString> |
|
||||||
|
|
||||||
#include "Event.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
template<class Content> |
|
||||||
class RoomEvent : public Event<Content> |
|
||||||
{ |
|
||||||
public: |
|
||||||
QString eventId() const; |
|
||||||
QString roomId() const; |
|
||||||
QString sender() const; |
|
||||||
uint64_t timestamp() const; |
|
||||||
|
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
private: |
|
||||||
QString event_id_; |
|
||||||
QString room_id_; |
|
||||||
QString sender_; |
|
||||||
|
|
||||||
uint64_t origin_server_ts_; |
|
||||||
}; |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
inline QString |
|
||||||
RoomEvent<Content>::eventId() const |
|
||||||
{ |
|
||||||
return event_id_; |
|
||||||
} |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
inline QString |
|
||||||
RoomEvent<Content>::roomId() const |
|
||||||
{ |
|
||||||
return room_id_; |
|
||||||
} |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
inline QString |
|
||||||
RoomEvent<Content>::sender() const |
|
||||||
{ |
|
||||||
return sender_; |
|
||||||
} |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
inline uint64_t |
|
||||||
RoomEvent<Content>::timestamp() const |
|
||||||
{ |
|
||||||
return origin_server_ts_; |
|
||||||
} |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
void |
|
||||||
RoomEvent<Content>::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
Event<Content>::deserialize(data); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (!object.contains("event_id")) |
|
||||||
throw DeserializationException("event_id key is missing"); |
|
||||||
|
|
||||||
if (!object.contains("origin_server_ts")) |
|
||||||
throw DeserializationException("origin_server_ts key is missing"); |
|
||||||
|
|
||||||
// FIXME: Synapse doesn't include room id?!
|
|
||||||
/* if (!object.contains("room_id")) */ |
|
||||||
/* throw DeserializationException("room_id key is missing"); */ |
|
||||||
|
|
||||||
if (!object.contains("sender")) |
|
||||||
throw DeserializationException("sender key is missing"); |
|
||||||
|
|
||||||
event_id_ = object.value("event_id").toString(); |
|
||||||
room_id_ = object.value("room_id").toString(); |
|
||||||
sender_ = object.value("sender").toString(); |
|
||||||
origin_server_ts_ = object.value("origin_server_ts").toDouble(); |
|
||||||
} |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
QJsonObject |
|
||||||
RoomEvent<Content>::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object = Event<Content>::serialize(); |
|
||||||
|
|
||||||
object["event_id"] = event_id_; |
|
||||||
object["room_id"] = room_id_; |
|
||||||
object["sender"] = sender_; |
|
||||||
object["origin_server_ts"] = QJsonValue(static_cast<qint64>(origin_server_ts_)); |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,88 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
|
|
||||||
#include "RoomEvent.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
template<class Content> |
|
||||||
class StateEvent : public RoomEvent<Content> |
|
||||||
{ |
|
||||||
public: |
|
||||||
QString stateKey() const; |
|
||||||
Content previousContent() const; |
|
||||||
|
|
||||||
void deserialize(const QJsonValue &data); |
|
||||||
QJsonObject serialize() const; |
|
||||||
|
|
||||||
private: |
|
||||||
QString state_key_; |
|
||||||
Content prev_content_; |
|
||||||
}; |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
inline QString |
|
||||||
StateEvent<Content>::stateKey() const |
|
||||||
{ |
|
||||||
return state_key_; |
|
||||||
} |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
inline Content |
|
||||||
StateEvent<Content>::previousContent() const |
|
||||||
{ |
|
||||||
return prev_content_; |
|
||||||
} |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
void |
|
||||||
StateEvent<Content>::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
RoomEvent<Content>::deserialize(data); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (!object.contains("state_key")) |
|
||||||
throw DeserializationException("state_key key is missing"); |
|
||||||
|
|
||||||
state_key_ = object.value("state_key").toString(); |
|
||||||
|
|
||||||
if (object.contains("prev_content")) |
|
||||||
prev_content_.deserialize(object.value("prev_content")); |
|
||||||
} |
|
||||||
|
|
||||||
template<class Content> |
|
||||||
QJsonObject |
|
||||||
StateEvent<Content>::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object = RoomEvent<Content>::serialize(); |
|
||||||
|
|
||||||
object["state_key"] = state_key_; |
|
||||||
|
|
||||||
auto prev = prev_content_.serialize(); |
|
||||||
|
|
||||||
if (!prev.isEmpty()) |
|
||||||
object["prev_content"] = prev; |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,46 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonValue> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
/*
|
|
||||||
* A topic is a short message detailing what is currently being discussed in the |
|
||||||
* room. |
|
||||||
*/ |
|
||||||
|
|
||||||
class TopicEventContent |
|
||||||
: public Deserializable |
|
||||||
, public Serializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonValue &data) override; |
|
||||||
QJsonObject serialize() const override; |
|
||||||
|
|
||||||
QString topic() const { return topic_; }; |
|
||||||
|
|
||||||
private: |
|
||||||
QString topic_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,50 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonObject> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
namespace messages { |
|
||||||
struct AudioInfo |
|
||||||
{ |
|
||||||
uint64_t duration; |
|
||||||
int size = 0; |
|
||||||
|
|
||||||
QString mimetype; |
|
||||||
}; |
|
||||||
|
|
||||||
class Audio : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
QString url() const { return url_; }; |
|
||||||
AudioInfo info() const { return info_; }; |
|
||||||
|
|
||||||
void deserialize(const QJsonObject &object) override; |
|
||||||
|
|
||||||
private: |
|
||||||
QString url_; |
|
||||||
AudioInfo info_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace messages
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,34 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonObject> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
namespace messages { |
|
||||||
class Emote : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonObject &obj) override; |
|
||||||
}; |
|
||||||
} // namespace messages
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,55 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonObject> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
#include "MessageEvent.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
namespace messages { |
|
||||||
struct FileInfo |
|
||||||
{ |
|
||||||
int size = 0; |
|
||||||
|
|
||||||
QString mimetype; |
|
||||||
QString thumbnail_url; |
|
||||||
ThumbnailInfo thumbnail_info; |
|
||||||
}; |
|
||||||
|
|
||||||
class File : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
QString url() const { return url_; }; |
|
||||||
QString filename() const { return filename_; }; |
|
||||||
FileInfo info() const { return info_; }; |
|
||||||
|
|
||||||
void deserialize(const QJsonObject &object) override; |
|
||||||
|
|
||||||
private: |
|
||||||
QString url_; |
|
||||||
QString filename_; |
|
||||||
|
|
||||||
FileInfo info_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace messages
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,54 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonObject> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
#include "MessageEvent.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
namespace messages { |
|
||||||
struct ImageInfo |
|
||||||
{ |
|
||||||
int h; |
|
||||||
int w; |
|
||||||
int size = 0; |
|
||||||
|
|
||||||
QString mimetype; |
|
||||||
QString thumbnail_url; |
|
||||||
ThumbnailInfo thumbnail_info; |
|
||||||
}; |
|
||||||
|
|
||||||
class Image : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
QString url() const { return url_; }; |
|
||||||
ImageInfo info() const { return info_; }; |
|
||||||
|
|
||||||
void deserialize(const QJsonObject &object) override; |
|
||||||
|
|
||||||
private: |
|
||||||
QString url_; |
|
||||||
ImageInfo info_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace messages
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,50 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonObject> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
#include "MessageEvent.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
namespace messages { |
|
||||||
struct LocationInfo |
|
||||||
{ |
|
||||||
QString thumbnail_url; |
|
||||||
ThumbnailInfo thumbnail_info; |
|
||||||
}; |
|
||||||
|
|
||||||
class Location : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
QString geoUri() const { return geo_uri_; }; |
|
||||||
LocationInfo info() const { return info_; }; |
|
||||||
|
|
||||||
void deserialize(const QJsonObject &object) override; |
|
||||||
|
|
||||||
private: |
|
||||||
QString geo_uri_; |
|
||||||
|
|
||||||
LocationInfo info_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace messages
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,34 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonObject> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
namespace messages { |
|
||||||
class Notice : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonObject &obj) override; |
|
||||||
}; |
|
||||||
} // namespace messages
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,34 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonObject> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
namespace messages { |
|
||||||
class Text : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonObject &obj) override; |
|
||||||
}; |
|
||||||
} // namespace messages
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1,55 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 <QJsonObject> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
#include "MessageEvent.h" |
|
||||||
|
|
||||||
namespace matrix { |
|
||||||
namespace events { |
|
||||||
namespace messages { |
|
||||||
struct VideoInfo |
|
||||||
{ |
|
||||||
int h; |
|
||||||
int w; |
|
||||||
int size = 0; |
|
||||||
int duration; |
|
||||||
|
|
||||||
QString mimetype; |
|
||||||
QString thumbnail_url; |
|
||||||
ThumbnailInfo thumbnail_info; |
|
||||||
}; |
|
||||||
|
|
||||||
class Video : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
QString url() const { return url_; }; |
|
||||||
VideoInfo info() const { return info_; }; |
|
||||||
|
|
||||||
void deserialize(const QJsonObject &object) override; |
|
||||||
|
|
||||||
private: |
|
||||||
QString url_; |
|
||||||
VideoInfo info_; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace messages
|
|
||||||
} // namespace events
|
|
||||||
} // namespace matrix
|
|
@ -1 +1 @@ |
|||||||
Subproject commit 190f297478153930780a119268b908076599c8db |
Subproject commit ea10ea843bccebf54b7b4ebdf1be92a3624597b4 |
@ -1,307 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include <QDebug> |
|
||||||
|
|
||||||
#include "Sync.h" |
|
||||||
|
|
||||||
void |
|
||||||
SyncResponse::deserialize(const QJsonDocument &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("Sync response is not a JSON object"); |
|
||||||
|
|
||||||
QJsonObject object = data.object(); |
|
||||||
|
|
||||||
if (!object.contains("next_batch")) |
|
||||||
throw DeserializationException("Sync: missing next_batch parameter"); |
|
||||||
|
|
||||||
if (object.contains("rooms")) { |
|
||||||
if (!object.value("rooms").isObject()) { |
|
||||||
throw DeserializationException("Sync: rooms is not a JSON object"); |
|
||||||
} |
|
||||||
rooms_.deserialize(object.value("rooms")); |
|
||||||
} |
|
||||||
|
|
||||||
if (object.contains("presence")) { |
|
||||||
if (!object.value("presence").isObject()) { |
|
||||||
throw DeserializationException("Sync: presence is not a JSON object"); |
|
||||||
} |
|
||||||
// TODO: implement presence handling
|
|
||||||
} |
|
||||||
|
|
||||||
if (object.contains("account_data")) { |
|
||||||
if (!object.value("account_data").isObject()) { |
|
||||||
throw DeserializationException("Sync: account_data is not a JSON object"); |
|
||||||
} |
|
||||||
// TODO: implement account_data handling
|
|
||||||
} |
|
||||||
|
|
||||||
if (object.contains("to_device")) { |
|
||||||
if (!object.value("to_device").isObject()) { |
|
||||||
throw DeserializationException("Sync: to_device is not a JSON object"); |
|
||||||
} |
|
||||||
// TODO: implement to_device handling
|
|
||||||
} |
|
||||||
|
|
||||||
// for device_lists updates (for e2e)
|
|
||||||
if (object.contains("device_lists")) { |
|
||||||
if (!object.value("device_lists").isObject()) { |
|
||||||
throw DeserializationException("Sync: device_lists is not a JSON object"); |
|
||||||
} |
|
||||||
// TODO: implement device_lists handling
|
|
||||||
} |
|
||||||
|
|
||||||
next_batch_ = object.value("next_batch").toString(); |
|
||||||
} |
|
||||||
|
|
||||||
void |
|
||||||
Rooms::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("Rooms value is not a JSON object"); |
|
||||||
|
|
||||||
QJsonObject object = data.toObject(); |
|
||||||
|
|
||||||
if (object.contains("join")) { |
|
||||||
if (!object.value("join").isObject()) |
|
||||||
throw DeserializationException("rooms/join must be a JSON object"); |
|
||||||
|
|
||||||
auto join = object.value("join").toObject(); |
|
||||||
|
|
||||||
for (auto it = join.constBegin(); it != join.constEnd(); ++it) { |
|
||||||
JoinedRoom tmp_room; |
|
||||||
try { |
|
||||||
tmp_room.deserialize(it.value()); |
|
||||||
join_.insert(it.key(), tmp_room); |
|
||||||
} catch (DeserializationException &e) { |
|
||||||
qWarning() << e.what(); |
|
||||||
qWarning() << "Skipping malformed object for room" << it.key(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (object.contains("invite")) { |
|
||||||
if (!object.value("invite").isObject()) { |
|
||||||
throw DeserializationException("rooms/invite must be a JSON object"); |
|
||||||
} |
|
||||||
// TODO: Implement invite handling
|
|
||||||
} |
|
||||||
|
|
||||||
if (object.contains("leave")) { |
|
||||||
if (!object.value("leave").isObject()) { |
|
||||||
throw DeserializationException("rooms/leave must be a JSON object"); |
|
||||||
} |
|
||||||
auto leave = object.value("leave").toObject(); |
|
||||||
|
|
||||||
for (auto it = leave.constBegin(); it != leave.constEnd(); ++it) { |
|
||||||
LeftRoom tmp_room; |
|
||||||
|
|
||||||
try { |
|
||||||
tmp_room.deserialize(it.value()); |
|
||||||
leave_.insert(it.key(), tmp_room); |
|
||||||
} catch (DeserializationException &e) { |
|
||||||
qWarning() << e.what(); |
|
||||||
qWarning() << "Skipping malformed object for room" << it.key(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void |
|
||||||
JoinedRoom::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("JoinedRoom is not a JSON object"); |
|
||||||
|
|
||||||
QJsonObject object = data.toObject(); |
|
||||||
|
|
||||||
if (object.contains("state")) { |
|
||||||
if (!object.value("state").isObject()) { |
|
||||||
throw DeserializationException("join/state should be an object"); |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject state = object.value("state").toObject(); |
|
||||||
|
|
||||||
if (state.contains("events")) { |
|
||||||
if (!state.value("events").isArray()) { |
|
||||||
throw DeserializationException( |
|
||||||
"join/state/events should be an array"); |
|
||||||
} |
|
||||||
|
|
||||||
state_.deserialize(state.value("events")); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (object.contains("timeline")) { |
|
||||||
if (!object.value("timeline").isObject()) |
|
||||||
throw DeserializationException("join/timeline should be an object"); |
|
||||||
timeline_.deserialize(object.value("timeline")); |
|
||||||
} |
|
||||||
|
|
||||||
if (object.contains("ephemeral")) { |
|
||||||
if (!object.value("ephemeral").isObject()) |
|
||||||
throw DeserializationException("join/ephemeral should be an object"); |
|
||||||
|
|
||||||
QJsonObject ephemeral = object.value("ephemeral").toObject(); |
|
||||||
|
|
||||||
if (ephemeral.contains("events")) { |
|
||||||
if (!ephemeral.value("events").isArray()) |
|
||||||
qWarning() << "join/ephemeral/events should be an array"; |
|
||||||
|
|
||||||
auto ephemeralEvents = ephemeral.value("events").toArray(); |
|
||||||
|
|
||||||
for (const auto e : ephemeralEvents) { |
|
||||||
auto obj = e.toObject(); |
|
||||||
|
|
||||||
if (obj.contains("type") && obj.value("type") == "m.typing") { |
|
||||||
auto ids = obj.value("content") |
|
||||||
.toObject() |
|
||||||
.value("user_ids") |
|
||||||
.toArray(); |
|
||||||
|
|
||||||
for (const auto uid : ids) |
|
||||||
typingUserIDs_.push_back(uid.toString()); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (object.contains("account_data")) { |
|
||||||
if (!object.value("account_data").isObject()) |
|
||||||
throw DeserializationException("join/account_data is not a JSON object"); |
|
||||||
// TODO: Implement account_data handling
|
|
||||||
} |
|
||||||
|
|
||||||
if (object.contains("unread_notifications")) { |
|
||||||
if (!object.value("unread_notifications").isObject()) { |
|
||||||
throw DeserializationException( |
|
||||||
"join/unread_notifications is not a JSON object"); |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject unreadNotifications = object.value("unread_notifications").toObject(); |
|
||||||
|
|
||||||
if (unreadNotifications.contains("highlight_count")) { |
|
||||||
// TODO: Implement unread_notifications handling
|
|
||||||
} |
|
||||||
if (unreadNotifications.contains("notification_count")) { |
|
||||||
// TODO: Implement unread_notifications handling
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void |
|
||||||
LeftRoom::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("LeftRoom is not a JSON object"); |
|
||||||
|
|
||||||
QJsonObject object = data.toObject(); |
|
||||||
|
|
||||||
if (!object.contains("state")) |
|
||||||
throw DeserializationException("leave/state is missing"); |
|
||||||
|
|
||||||
if (!object.contains("timeline")) |
|
||||||
throw DeserializationException("leave/timeline is missing"); |
|
||||||
|
|
||||||
if (!object.value("state").isObject()) |
|
||||||
throw DeserializationException("leave/state should be an object"); |
|
||||||
|
|
||||||
QJsonObject state = object.value("state").toObject(); |
|
||||||
|
|
||||||
if (!state.contains("events")) |
|
||||||
throw DeserializationException("leave/state/events is missing"); |
|
||||||
|
|
||||||
state_.deserialize(state.value("events")); |
|
||||||
timeline_.deserialize(object.value("timeline")); |
|
||||||
} |
|
||||||
|
|
||||||
void |
|
||||||
Event::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("Event is not a JSON object"); |
|
||||||
|
|
||||||
QJsonObject object = data.toObject(); |
|
||||||
|
|
||||||
if (!object.contains("content")) |
|
||||||
throw DeserializationException("event/content is missing"); |
|
||||||
|
|
||||||
if (!object.contains("unsigned")) |
|
||||||
throw DeserializationException("event/content is missing"); |
|
||||||
|
|
||||||
if (!object.contains("sender")) |
|
||||||
throw DeserializationException("event/sender is missing"); |
|
||||||
|
|
||||||
if (!object.contains("event_id")) |
|
||||||
throw DeserializationException("event/event_id is missing"); |
|
||||||
|
|
||||||
// TODO: Make this optional
|
|
||||||
/* if (!object.contains("state_key")) */ |
|
||||||
/* throw DeserializationException("event/state_key is missing"); */ |
|
||||||
|
|
||||||
if (!object.contains("type")) |
|
||||||
throw DeserializationException("event/type is missing"); |
|
||||||
|
|
||||||
if (!object.contains("origin_server_ts")) |
|
||||||
throw DeserializationException("event/origin_server_ts is missing"); |
|
||||||
|
|
||||||
content_ = object.value("content").toObject(); |
|
||||||
unsigned_ = object.value("unsigned").toObject(); |
|
||||||
|
|
||||||
sender_ = object.value("sender").toString(); |
|
||||||
state_key_ = object.value("state_key").toString(); |
|
||||||
type_ = object.value("type").toString(); |
|
||||||
event_id_ = object.value("event_id").toString(); |
|
||||||
|
|
||||||
origin_server_ts_ = object.value("origin_server_ts").toDouble(); |
|
||||||
} |
|
||||||
|
|
||||||
void |
|
||||||
State::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isArray()) |
|
||||||
throw DeserializationException("State is not a JSON array"); |
|
||||||
|
|
||||||
events_ = data.toArray(); |
|
||||||
} |
|
||||||
|
|
||||||
void |
|
||||||
Timeline::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("Timeline is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (!object.contains("events")) |
|
||||||
throw DeserializationException("timeline/events is missing"); |
|
||||||
|
|
||||||
if (!object.contains("prev_batch")) |
|
||||||
throw DeserializationException("timeline/prev_batch is missing"); |
|
||||||
|
|
||||||
if (!object.contains("limited")) |
|
||||||
throw DeserializationException("timeline/limited is missing"); |
|
||||||
|
|
||||||
prev_batch_ = object.value("prev_batch").toString(); |
|
||||||
limited_ = object.value("limited").toBool(); |
|
||||||
|
|
||||||
if (!object.value("events").isArray()) |
|
||||||
throw DeserializationException("timeline/events is not a JSON array"); |
|
||||||
|
|
||||||
events_ = object.value("events").toArray(); |
|
||||||
} |
|
@ -1,55 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include <QJsonArray> |
|
||||||
|
|
||||||
#include "AliasesEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
void |
|
||||||
AliasesEventContent::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("AliasesEventContent is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (object.value("aliases") == QJsonValue::Undefined) |
|
||||||
throw DeserializationException("aliases key is missing"); |
|
||||||
|
|
||||||
auto aliases = object.value("aliases").toArray(); |
|
||||||
|
|
||||||
for (const auto &alias : aliases) |
|
||||||
aliases_.push_back(alias.toString()); |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject |
|
||||||
AliasesEventContent::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
QJsonArray aliases; |
|
||||||
|
|
||||||
for (const auto &alias : aliases_) |
|
||||||
aliases.push_back(alias); |
|
||||||
|
|
||||||
if (aliases.size() > 0) |
|
||||||
object["aliases"] = aliases; |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
@ -1,50 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include <QDebug> |
|
||||||
|
|
||||||
#include "AvatarEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
void |
|
||||||
AvatarEventContent::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("AvatarEventContent is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (object.value("url") == QJsonValue::Undefined) |
|
||||||
throw DeserializationException("url key is missing"); |
|
||||||
|
|
||||||
url_ = QUrl(object.value("url").toString()); |
|
||||||
|
|
||||||
if (!url_.isValid()) |
|
||||||
qWarning() << "Invalid avatar url" << url_; |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject |
|
||||||
AvatarEventContent::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
if (!url_.isEmpty()) |
|
||||||
object["url"] = url_.toString(); |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
@ -1,45 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "CanonicalAliasEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
void |
|
||||||
CanonicalAliasEventContent::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("CanonicalAliasEventContent is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (object.value("alias") == QJsonValue::Undefined) |
|
||||||
throw DeserializationException("alias key is missing"); |
|
||||||
|
|
||||||
alias_ = object.value("alias").toString(); |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject |
|
||||||
CanonicalAliasEventContent::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
if (!alias_.isEmpty()) |
|
||||||
object["alias"] = alias_; |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
@ -1,45 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "CreateEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
void |
|
||||||
CreateEventContent::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("CreateEventContent is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (object.value("creator") == QJsonValue::Undefined) |
|
||||||
throw DeserializationException("creator key is missing"); |
|
||||||
|
|
||||||
creator_ = object.value("creator").toString(); |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject |
|
||||||
CreateEventContent::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
if (!creator_.isEmpty()) |
|
||||||
object["creator"] = creator_; |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
@ -1,106 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "events/Event.h" |
|
||||||
|
|
||||||
#include "AliasesEventContent.h" |
|
||||||
#include "AvatarEventContent.h" |
|
||||||
#include "CanonicalAliasEventContent.h" |
|
||||||
#include "CreateEventContent.h" |
|
||||||
#include "Deserializable.h" |
|
||||||
#include "HistoryVisibilityEventContent.h" |
|
||||||
#include "JoinRulesEventContent.h" |
|
||||||
#include "MemberEventContent.h" |
|
||||||
#include "NameEventContent.h" |
|
||||||
#include "PowerLevelsEventContent.h" |
|
||||||
#include "TopicEventContent.h" |
|
||||||
|
|
||||||
matrix::events::EventType |
|
||||||
matrix::events::extractEventType(const QJsonObject &object) |
|
||||||
{ |
|
||||||
if (!object.contains("type")) |
|
||||||
throw DeserializationException("Missing event type"); |
|
||||||
|
|
||||||
auto type = object.value("type").toString(); |
|
||||||
|
|
||||||
if (type == "m.room.aliases") |
|
||||||
return EventType::RoomAliases; |
|
||||||
else if (type == "m.room.avatar") |
|
||||||
return EventType::RoomAvatar; |
|
||||||
else if (type == "m.room.canonical_alias") |
|
||||||
return EventType::RoomCanonicalAlias; |
|
||||||
else if (type == "m.room.create") |
|
||||||
return EventType::RoomCreate; |
|
||||||
else if (type == "m.room.history_visibility") |
|
||||||
return EventType::RoomHistoryVisibility; |
|
||||||
else if (type == "m.room.join_rules") |
|
||||||
return EventType::RoomJoinRules; |
|
||||||
else if (type == "m.room.member") |
|
||||||
return EventType::RoomMember; |
|
||||||
else if (type == "m.room.message") |
|
||||||
return EventType::RoomMessage; |
|
||||||
else if (type == "m.room.name") |
|
||||||
return EventType::RoomName; |
|
||||||
else if (type == "m.room.power_levels") |
|
||||||
return EventType::RoomPowerLevels; |
|
||||||
else if (type == "m.room.topic") |
|
||||||
return EventType::RoomTopic; |
|
||||||
else |
|
||||||
return EventType::Unsupported; |
|
||||||
} |
|
||||||
|
|
||||||
bool |
|
||||||
matrix::events::isStateEvent(EventType type) |
|
||||||
{ |
|
||||||
return type == EventType::RoomAliases || type == EventType::RoomAvatar || |
|
||||||
type == EventType::RoomCanonicalAlias || type == EventType::RoomCreate || |
|
||||||
type == EventType::RoomHistoryVisibility || type == EventType::RoomJoinRules || |
|
||||||
type == EventType::RoomMember || type == EventType::RoomName || |
|
||||||
type == EventType::RoomPowerLevels || type == EventType::RoomTopic; |
|
||||||
} |
|
||||||
|
|
||||||
bool |
|
||||||
matrix::events::isMessageEvent(EventType type) |
|
||||||
{ |
|
||||||
return type == EventType::RoomMessage; |
|
||||||
} |
|
||||||
|
|
||||||
void |
|
||||||
matrix::events::UnsignedData::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("UnsignedData is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
transaction_id_ = object.value("transaction_id").toString(); |
|
||||||
age_ = object.value("age").toDouble(); |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject |
|
||||||
matrix::events::UnsignedData::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
if (!transaction_id_.isEmpty()) |
|
||||||
object["transaction_id"] = transaction_id_; |
|
||||||
|
|
||||||
if (age_ > 0) |
|
||||||
object["age"] = age_; |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
@ -1,64 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "HistoryVisibilityEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
void |
|
||||||
HistoryVisibilityEventContent::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException( |
|
||||||
"HistoryVisibilityEventContent is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (object.value("history_visibility") == QJsonValue::Undefined) |
|
||||||
throw DeserializationException("history_visibility key is missing"); |
|
||||||
|
|
||||||
auto value = object.value("history_visibility").toString(); |
|
||||||
|
|
||||||
if (value == "invited") |
|
||||||
history_visibility_ = HistoryVisibility::Invited; |
|
||||||
else if (value == "joined") |
|
||||||
history_visibility_ = HistoryVisibility::Joined; |
|
||||||
else if (value == "shared") |
|
||||||
history_visibility_ = HistoryVisibility::Shared; |
|
||||||
else if (value == "world_readable") |
|
||||||
history_visibility_ = HistoryVisibility::WorldReadable; |
|
||||||
else |
|
||||||
throw DeserializationException( |
|
||||||
QString("Unknown history_visibility value: %1").arg(value).toUtf8().constData()); |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject |
|
||||||
HistoryVisibilityEventContent::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
if (history_visibility_ == HistoryVisibility::Invited) |
|
||||||
object["history_visibility"] = "invited"; |
|
||||||
else if (history_visibility_ == HistoryVisibility::Joined) |
|
||||||
object["history_visibility"] = "joined"; |
|
||||||
else if (history_visibility_ == HistoryVisibility::Shared) |
|
||||||
object["history_visibility"] = "shared"; |
|
||||||
else if (history_visibility_ == HistoryVisibility::WorldReadable) |
|
||||||
object["history_visibility"] = "world_readable"; |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
@ -1,63 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "JoinRulesEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
void |
|
||||||
JoinRulesEventContent::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("JoinRulesEventContent is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (object.value("join_rule") == QJsonValue::Undefined) |
|
||||||
throw DeserializationException("join_rule key is missing"); |
|
||||||
|
|
||||||
auto value = object.value("join_rule").toString(); |
|
||||||
|
|
||||||
if (value == "invite") |
|
||||||
join_rule_ = JoinRule::Invite; |
|
||||||
else if (value == "knock") |
|
||||||
join_rule_ = JoinRule::Knock; |
|
||||||
else if (value == "private") |
|
||||||
join_rule_ = JoinRule::Private; |
|
||||||
else if (value == "public") |
|
||||||
join_rule_ = JoinRule::Public; |
|
||||||
else |
|
||||||
throw DeserializationException( |
|
||||||
QString("Unknown join_rule value: %1").arg(value).toUtf8().constData()); |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject |
|
||||||
JoinRulesEventContent::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
if (join_rule_ == JoinRule::Invite) |
|
||||||
object["join_rule"] = "invite"; |
|
||||||
else if (join_rule_ == JoinRule::Knock) |
|
||||||
object["join_rule"] = "knock"; |
|
||||||
else if (join_rule_ == JoinRule::Private) |
|
||||||
object["join_rule"] = "private"; |
|
||||||
else if (join_rule_ == JoinRule::Public) |
|
||||||
object["join_rule"] = "public"; |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
@ -1,84 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include <QDebug> |
|
||||||
|
|
||||||
#include "MemberEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
void |
|
||||||
MemberEventContent::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("MemberEventContent is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (!object.contains("membership")) |
|
||||||
throw DeserializationException("membership key is missing"); |
|
||||||
|
|
||||||
auto value = object.value("membership").toString(); |
|
||||||
|
|
||||||
if (value == "ban") |
|
||||||
membership_state_ = Membership::Ban; |
|
||||||
else if (value == "invite") |
|
||||||
membership_state_ = Membership::Invite; |
|
||||||
else if (value == "join") |
|
||||||
membership_state_ = Membership::Join; |
|
||||||
else if (value == "knock") |
|
||||||
membership_state_ = Membership::Knock; |
|
||||||
else if (value == "leave") |
|
||||||
membership_state_ = Membership::Leave; |
|
||||||
else |
|
||||||
throw DeserializationException( |
|
||||||
QString("Unknown membership value: %1").arg(value).toUtf8().constData()); |
|
||||||
|
|
||||||
if (object.contains("avatar_url")) |
|
||||||
avatar_url_ = QUrl(object.value("avatar_url").toString()); |
|
||||||
|
|
||||||
if (!avatar_url_.toString().isEmpty() && !avatar_url_.isValid()) |
|
||||||
qWarning() << "Invalid avatar url" << avatar_url_; |
|
||||||
|
|
||||||
if (object.contains("displayname")) |
|
||||||
display_name_ = object.value("displayname").toString(); |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject |
|
||||||
MemberEventContent::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
if (membership_state_ == Membership::Ban) |
|
||||||
object["membership"] = "ban"; |
|
||||||
else if (membership_state_ == Membership::Invite) |
|
||||||
object["membership"] = "invite"; |
|
||||||
else if (membership_state_ == Membership::Join) |
|
||||||
object["membership"] = "join"; |
|
||||||
else if (membership_state_ == Membership::Knock) |
|
||||||
object["membership"] = "knock"; |
|
||||||
else if (membership_state_ == Membership::Leave) |
|
||||||
object["membership"] = "leave"; |
|
||||||
|
|
||||||
if (!avatar_url_.isEmpty()) |
|
||||||
object["avatar_url"] = avatar_url_.toString(); |
|
||||||
|
|
||||||
if (!display_name_.isEmpty()) |
|
||||||
object["displayname"] = display_name_; |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
@ -1,74 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include <QDebug> |
|
||||||
|
|
||||||
#include "MessageEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
MessageEventType |
|
||||||
matrix::events::extractMessageEventType(const QJsonObject &data) |
|
||||||
{ |
|
||||||
if (!data.contains("content")) |
|
||||||
return MessageEventType::Unknown; |
|
||||||
|
|
||||||
auto content = data.value("content").toObject(); |
|
||||||
auto msgtype = content.value("msgtype").toString(); |
|
||||||
|
|
||||||
if (msgtype == "m.audio") |
|
||||||
return MessageEventType::Audio; |
|
||||||
else if (msgtype == "m.emote") |
|
||||||
return MessageEventType::Emote; |
|
||||||
else if (msgtype == "m.file") |
|
||||||
return MessageEventType::File; |
|
||||||
else if (msgtype == "m.image") |
|
||||||
return MessageEventType::Image; |
|
||||||
else if (msgtype == "m.location") |
|
||||||
return MessageEventType::Location; |
|
||||||
else if (msgtype == "m.notice") |
|
||||||
return MessageEventType::Notice; |
|
||||||
else if (msgtype == "m.text") |
|
||||||
return MessageEventType::Text; |
|
||||||
else if (msgtype == "m.video") |
|
||||||
return MessageEventType::Video; |
|
||||||
else |
|
||||||
return MessageEventType::Unknown; |
|
||||||
} |
|
||||||
|
|
||||||
void |
|
||||||
MessageEventContent::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("MessageEventContent is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (!object.contains("body")) |
|
||||||
throw DeserializationException("body key is missing"); |
|
||||||
|
|
||||||
body_ = object.value("body").toString(); |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject |
|
||||||
MessageEventContent::serialize() const |
|
||||||
{ |
|
||||||
// TODO: Add for all the message contents.
|
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
@ -1,45 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "NameEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
void |
|
||||||
NameEventContent::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("NameEventContent is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (object.value("name") == QJsonValue::Undefined) |
|
||||||
throw DeserializationException("name key is missing"); |
|
||||||
|
|
||||||
name_ = object.value("name").toString(); |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject |
|
||||||
NameEventContent::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
if (!name_.isEmpty()) |
|
||||||
object["name"] = name_; |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
@ -1,114 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include <QJsonObject> |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
#include "PowerLevelsEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
void |
|
||||||
PowerLevelsEventContent::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("PowerLevelsEventContent is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (object.value("ban") != QJsonValue::Undefined) |
|
||||||
ban_ = object.value("ban").toInt(); |
|
||||||
|
|
||||||
if (object.value("invite") != QJsonValue::Undefined) |
|
||||||
invite_ = object.value("invite").toInt(); |
|
||||||
|
|
||||||
if (object.value("kick") != QJsonValue::Undefined) |
|
||||||
kick_ = object.value("kick").toInt(); |
|
||||||
|
|
||||||
if (object.value("redact") != QJsonValue::Undefined) |
|
||||||
redact_ = object.value("redact").toInt(); |
|
||||||
|
|
||||||
if (object.value("events_default") != QJsonValue::Undefined) |
|
||||||
events_default_ = object.value("events_default").toInt(); |
|
||||||
|
|
||||||
if (object.value("state_default") != QJsonValue::Undefined) |
|
||||||
state_default_ = object.value("state_default").toInt(); |
|
||||||
|
|
||||||
if (object.value("users_default") != QJsonValue::Undefined) |
|
||||||
users_default_ = object.value("users_default").toInt(); |
|
||||||
|
|
||||||
if (object.value("users").isObject()) { |
|
||||||
auto users = object.value("users").toObject(); |
|
||||||
|
|
||||||
for (auto it = users.constBegin(); it != users.constEnd(); ++it) |
|
||||||
users_.insert(it.key(), it.value().toInt()); |
|
||||||
} |
|
||||||
|
|
||||||
if (object.value("events").isObject()) { |
|
||||||
auto events = object.value("events").toObject(); |
|
||||||
|
|
||||||
for (auto it = events.constBegin(); it != events.constEnd(); ++it) |
|
||||||
events_.insert(it.key(), it.value().toInt()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject |
|
||||||
PowerLevelsEventContent::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
object["ban"] = ban_; |
|
||||||
object["invite"] = invite_; |
|
||||||
object["kick"] = kick_; |
|
||||||
object["redact"] = redact_; |
|
||||||
|
|
||||||
object["events_default"] = events_default_; |
|
||||||
object["users_default"] = users_default_; |
|
||||||
object["state_default"] = state_default_; |
|
||||||
|
|
||||||
QJsonObject users; |
|
||||||
QJsonObject events; |
|
||||||
|
|
||||||
for (auto it = users_.constBegin(); it != users_.constEnd(); ++it) |
|
||||||
users.insert(it.key(), it.value()); |
|
||||||
|
|
||||||
for (auto it = events_.constBegin(); it != events_.constEnd(); ++it) |
|
||||||
events.insert(it.key(), it.value()); |
|
||||||
|
|
||||||
object["users"] = users; |
|
||||||
object["events"] = events; |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
||||||
|
|
||||||
int |
|
||||||
PowerLevelsEventContent::eventLevel(QString event_type) const |
|
||||||
{ |
|
||||||
if (events_.contains(event_type)) |
|
||||||
return events_[event_type]; |
|
||||||
|
|
||||||
return events_default_; |
|
||||||
} |
|
||||||
|
|
||||||
int |
|
||||||
PowerLevelsEventContent::userLevel(QString userid) const |
|
||||||
{ |
|
||||||
if (users_.contains(userid)) |
|
||||||
return users_[userid]; |
|
||||||
|
|
||||||
return users_default_; |
|
||||||
} |
|
@ -1,45 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "TopicEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
void |
|
||||||
TopicEventContent::deserialize(const QJsonValue &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("TopicEventContent is not a JSON object"); |
|
||||||
|
|
||||||
auto object = data.toObject(); |
|
||||||
|
|
||||||
if (object.value("topic") == QJsonValue::Undefined) |
|
||||||
throw DeserializationException("topic key is missing"); |
|
||||||
|
|
||||||
topic_ = object.value("topic").toString(); |
|
||||||
} |
|
||||||
|
|
||||||
QJsonObject |
|
||||||
TopicEventContent::serialize() const |
|
||||||
{ |
|
||||||
QJsonObject object; |
|
||||||
|
|
||||||
if (!topic_.isEmpty()) |
|
||||||
object["topic"] = topic_; |
|
||||||
|
|
||||||
return object; |
|
||||||
} |
|
@ -1,40 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Audio.h" |
|
||||||
|
|
||||||
using namespace matrix::events::messages; |
|
||||||
|
|
||||||
void |
|
||||||
Audio::deserialize(const QJsonObject &object) |
|
||||||
{ |
|
||||||
if (!object.contains("url")) |
|
||||||
throw DeserializationException("url key is missing"); |
|
||||||
|
|
||||||
url_ = object.value("url").toString(); |
|
||||||
|
|
||||||
if (object.value("msgtype") != "m.audio") |
|
||||||
throw DeserializationException("invalid msgtype for audio"); |
|
||||||
|
|
||||||
if (object.contains("info")) { |
|
||||||
auto info = object.value("info").toObject(); |
|
||||||
|
|
||||||
info_.duration = info.value("duration").toInt(); |
|
||||||
info_.mimetype = info.value("mimetype").toString(); |
|
||||||
info_.size = info.value("size").toInt(); |
|
||||||
} |
|
||||||
} |
|
@ -1,27 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Emote.h" |
|
||||||
|
|
||||||
using namespace matrix::events::messages; |
|
||||||
|
|
||||||
void |
|
||||||
Emote::deserialize(const QJsonObject &object) |
|
||||||
{ |
|
||||||
if (object.value("msgtype") != "m.emote") |
|
||||||
throw DeserializationException("invalid msgtype for emote"); |
|
||||||
} |
|
@ -1,50 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "File.h" |
|
||||||
|
|
||||||
using namespace matrix::events::messages; |
|
||||||
|
|
||||||
void |
|
||||||
File::deserialize(const QJsonObject &object) |
|
||||||
{ |
|
||||||
if (!object.contains("url")) |
|
||||||
throw DeserializationException("messages::File url key is missing"); |
|
||||||
|
|
||||||
if (object.value("msgtype") != "m.file") |
|
||||||
throw DeserializationException("invalid msgtype for file"); |
|
||||||
|
|
||||||
url_ = object.value("url").toString(); |
|
||||||
filename_ = object.value("filename").toString(); |
|
||||||
|
|
||||||
if (object.contains("info")) { |
|
||||||
auto file_info = object.value("info").toObject(); |
|
||||||
|
|
||||||
info_.size = file_info.value("size").toInt(); |
|
||||||
info_.mimetype = file_info.value("mimetype").toString(); |
|
||||||
info_.thumbnail_url = file_info.value("thumbnail_url").toString(); |
|
||||||
|
|
||||||
if (file_info.contains("thumbnail_info")) { |
|
||||||
auto thumbinfo = file_info.value("thumbnail_info").toObject(); |
|
||||||
|
|
||||||
info_.thumbnail_info.h = thumbinfo.value("h").toInt(); |
|
||||||
info_.thumbnail_info.w = thumbinfo.value("w").toInt(); |
|
||||||
info_.thumbnail_info.size = thumbinfo.value("size").toInt(); |
|
||||||
info_.thumbnail_info.mimetype = thumbinfo.value("mimetype").toString(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,52 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Image.h" |
|
||||||
|
|
||||||
using namespace matrix::events::messages; |
|
||||||
|
|
||||||
void |
|
||||||
Image::deserialize(const QJsonObject &object) |
|
||||||
{ |
|
||||||
if (!object.contains("url")) |
|
||||||
throw DeserializationException("messages::Image url key is missing"); |
|
||||||
|
|
||||||
url_ = object.value("url").toString(); |
|
||||||
|
|
||||||
if (object.value("msgtype") != "m.image") |
|
||||||
throw DeserializationException("invalid msgtype for image"); |
|
||||||
|
|
||||||
if (object.contains("info")) { |
|
||||||
auto imginfo = object.value("info").toObject(); |
|
||||||
|
|
||||||
info_.w = imginfo.value("w").toInt(); |
|
||||||
info_.h = imginfo.value("h").toInt(); |
|
||||||
info_.size = imginfo.value("size").toInt(); |
|
||||||
|
|
||||||
info_.mimetype = imginfo.value("mimetype").toString(); |
|
||||||
info_.thumbnail_url = imginfo.value("thumbnail_url").toString(); |
|
||||||
|
|
||||||
if (imginfo.contains("thumbnail_info")) { |
|
||||||
auto thumbinfo = imginfo.value("thumbnail_info").toObject(); |
|
||||||
|
|
||||||
info_.thumbnail_info.h = thumbinfo.value("h").toInt(); |
|
||||||
info_.thumbnail_info.w = thumbinfo.value("w").toInt(); |
|
||||||
info_.thumbnail_info.size = thumbinfo.value("size").toInt(); |
|
||||||
info_.thumbnail_info.mimetype = thumbinfo.value("mimetype").toString(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,47 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Location.h" |
|
||||||
|
|
||||||
using namespace matrix::events::messages; |
|
||||||
|
|
||||||
void |
|
||||||
Location::deserialize(const QJsonObject &object) |
|
||||||
{ |
|
||||||
if (!object.contains("geo_uri")) |
|
||||||
throw DeserializationException("messages::Location geo_uri key is missing"); |
|
||||||
|
|
||||||
if (object.value("msgtype") != "m.location") |
|
||||||
throw DeserializationException("invalid msgtype for location"); |
|
||||||
|
|
||||||
geo_uri_ = object.value("geo_uri").toString(); |
|
||||||
|
|
||||||
if (object.contains("info")) { |
|
||||||
auto location_info = object.value("info").toObject(); |
|
||||||
|
|
||||||
info_.thumbnail_url = location_info.value("thumbnail_url").toString(); |
|
||||||
|
|
||||||
if (location_info.contains("thumbnail_info")) { |
|
||||||
auto thumbinfo = location_info.value("thumbnail_info").toObject(); |
|
||||||
|
|
||||||
info_.thumbnail_info.h = thumbinfo.value("h").toInt(); |
|
||||||
info_.thumbnail_info.w = thumbinfo.value("w").toInt(); |
|
||||||
info_.thumbnail_info.size = thumbinfo.value("size").toInt(); |
|
||||||
info_.thumbnail_info.mimetype = thumbinfo.value("mimetype").toString(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,27 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Notice.h" |
|
||||||
|
|
||||||
using namespace matrix::events::messages; |
|
||||||
|
|
||||||
void |
|
||||||
Notice::deserialize(const QJsonObject &object) |
|
||||||
{ |
|
||||||
if (object.value("msgtype") != "m.notice") |
|
||||||
throw DeserializationException("invalid msgtype for notice"); |
|
||||||
} |
|
@ -1,27 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Text.h" |
|
||||||
|
|
||||||
using namespace matrix::events::messages; |
|
||||||
|
|
||||||
void |
|
||||||
Text::deserialize(const QJsonObject &object) |
|
||||||
{ |
|
||||||
if (object.value("msgtype") != "m.text") |
|
||||||
throw DeserializationException("invalid msgtype for text"); |
|
||||||
} |
|
@ -1,53 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Video.h" |
|
||||||
|
|
||||||
using namespace matrix::events::messages; |
|
||||||
|
|
||||||
void |
|
||||||
Video::deserialize(const QJsonObject &object) |
|
||||||
{ |
|
||||||
if (!object.contains("url")) |
|
||||||
throw DeserializationException("messages::Video url key is missing"); |
|
||||||
|
|
||||||
url_ = object.value("url").toString(); |
|
||||||
|
|
||||||
if (object.value("msgtype") != "m.video") |
|
||||||
throw DeserializationException("invalid msgtype for video"); |
|
||||||
|
|
||||||
if (object.contains("info")) { |
|
||||||
auto video_info = object.value("info").toObject(); |
|
||||||
|
|
||||||
info_.w = video_info.value("w").toInt(); |
|
||||||
info_.h = video_info.value("h").toInt(); |
|
||||||
info_.size = video_info.value("size").toInt(); |
|
||||||
info_.duration = video_info.value("duration").toInt(); |
|
||||||
|
|
||||||
info_.mimetype = video_info.value("mimetype").toString(); |
|
||||||
info_.thumbnail_url = video_info.value("thumbnail_url").toString(); |
|
||||||
|
|
||||||
if (video_info.contains("thumbnail_info")) { |
|
||||||
auto thumbinfo = video_info.value("thumbnail_info").toObject(); |
|
||||||
|
|
||||||
info_.thumbnail_info.h = thumbinfo.value("h").toInt(); |
|
||||||
info_.thumbnail_info.w = thumbinfo.value("w").toInt(); |
|
||||||
info_.thumbnail_info.size = thumbinfo.value("size").toInt(); |
|
||||||
info_.thumbnail_info.mimetype = thumbinfo.value("mimetype").toString(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,111 +0,0 @@ |
|||||||
#include <gtest/gtest.h> |
|
||||||
|
|
||||||
#include <QJsonArray> |
|
||||||
#include <QJsonObject> |
|
||||||
|
|
||||||
#include "Event.h" |
|
||||||
#include "RoomEvent.h" |
|
||||||
#include "StateEvent.h" |
|
||||||
|
|
||||||
#include "AliasesEventContent.h" |
|
||||||
#include "AvatarEventContent.h" |
|
||||||
#include "CanonicalAliasEventContent.h" |
|
||||||
#include "CreateEventContent.h" |
|
||||||
#include "HistoryVisibilityEventContent.h" |
|
||||||
#include "JoinRulesEventContent.h" |
|
||||||
#include "MemberEventContent.h" |
|
||||||
#include "NameEventContent.h" |
|
||||||
#include "PowerLevelsEventContent.h" |
|
||||||
#include "TopicEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
TEST(EventCollection, Deserialize) |
|
||||||
{ |
|
||||||
auto events = QJsonArray{ |
|
||||||
QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } }, |
|
||||||
{ "event_id", "$asdfafdf8af:matrix.org" }, |
|
||||||
{ "prev_content", QJsonObject{ { "name", "Previous Name" } } }, |
|
||||||
{ "room_id", "!aasdfaeae23r9:matrix.org" }, |
|
||||||
{ "sender", "@alice:matrix.org" }, |
|
||||||
{ "origin_server_ts", 1323238293289323LL }, |
|
||||||
{ "state_key", "" }, |
|
||||||
{ "type", "m.room.name" } }, |
|
||||||
QJsonObject{ { "content", QJsonObject{ { "topic", "Topic" } } }, |
|
||||||
{ "event_id", "$asdfafdf8af:matrix.org" }, |
|
||||||
{ "prev_content", QJsonObject{ { "topic", "Previous Topic" } } }, |
|
||||||
{ "room_id", "!aasdfaeae23r9:matrix.org" }, |
|
||||||
{ "state_key", "" }, |
|
||||||
{ "sender", "@alice:matrix.org" }, |
|
||||||
{ "origin_server_ts", 1323238293289323LL }, |
|
||||||
{ "type", "m.room.topic" } }, |
|
||||||
}; |
|
||||||
|
|
||||||
for (const auto &event : events) { |
|
||||||
EventType ty = extractEventType(event.toObject()); |
|
||||||
|
|
||||||
if (ty == EventType::RoomName) { |
|
||||||
StateEvent<NameEventContent> name_event; |
|
||||||
name_event.deserialize(event); |
|
||||||
|
|
||||||
EXPECT_EQ(name_event.content().name(), "Name"); |
|
||||||
EXPECT_EQ(name_event.previousContent().name(), "Previous Name"); |
|
||||||
} else if (ty == EventType::RoomTopic) { |
|
||||||
StateEvent<TopicEventContent> topic_event; |
|
||||||
topic_event.deserialize(event); |
|
||||||
|
|
||||||
EXPECT_EQ(topic_event.content().topic(), "Topic"); |
|
||||||
EXPECT_EQ(topic_event.previousContent().topic(), "Previous Topic"); |
|
||||||
} else { |
|
||||||
ASSERT_EQ(false, true); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(EventCollection, DeserializationException) |
|
||||||
{ |
|
||||||
// Using wrong event types.
|
|
||||||
auto events = QJsonArray{ |
|
||||||
QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } }, |
|
||||||
{ "event_id", "$asdfafdf8af:matrix.org" }, |
|
||||||
{ "prev_content", QJsonObject{ { "name", "Previous Name" } } }, |
|
||||||
{ "room_id", "!aasdfaeae23r9:matrix.org" }, |
|
||||||
{ "sender", "@alice:matrix.org" }, |
|
||||||
{ "origin_server_ts", 1323238293289323LL }, |
|
||||||
{ "state_key", "" }, |
|
||||||
{ "type", "m.room.topic" } }, |
|
||||||
QJsonObject{ { "content", QJsonObject{ { "topic", "Topic" } } }, |
|
||||||
{ "event_id", "$asdfafdf8af:matrix.org" }, |
|
||||||
{ "prev_content", QJsonObject{ { "topic", "Previous Topic" } } }, |
|
||||||
{ "room_id", "!aasdfaeae23r9:matrix.org" }, |
|
||||||
{ "state_key", "" }, |
|
||||||
{ "sender", "@alice:matrix.org" }, |
|
||||||
{ "origin_server_ts", 1323238293289323LL }, |
|
||||||
{ "type", "m.room.name" } }, |
|
||||||
}; |
|
||||||
|
|
||||||
for (const auto &event : events) { |
|
||||||
EventType ty = extractEventType(event.toObject()); |
|
||||||
|
|
||||||
if (ty == EventType::RoomName) { |
|
||||||
StateEvent<NameEventContent> name_event; |
|
||||||
|
|
||||||
try { |
|
||||||
name_event.deserialize(event); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("name key is missing", e.what()); |
|
||||||
} |
|
||||||
|
|
||||||
} else if (ty == EventType::RoomTopic) { |
|
||||||
StateEvent<TopicEventContent> topic_event; |
|
||||||
|
|
||||||
try { |
|
||||||
topic_event.deserialize(event); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("topic key is missing", e.what()); |
|
||||||
} |
|
||||||
} else { |
|
||||||
ASSERT_EQ(false, true); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,707 +0,0 @@ |
|||||||
#include <QDebug> |
|
||||||
#include <QJsonArray> |
|
||||||
#include <gtest/gtest.h> |
|
||||||
|
|
||||||
#include "Event.h" |
|
||||||
#include "RoomEvent.h" |
|
||||||
#include "StateEvent.h" |
|
||||||
|
|
||||||
#include "AliasesEventContent.h" |
|
||||||
#include "AvatarEventContent.h" |
|
||||||
#include "CanonicalAliasEventContent.h" |
|
||||||
#include "CreateEventContent.h" |
|
||||||
#include "HistoryVisibilityEventContent.h" |
|
||||||
#include "JoinRulesEventContent.h" |
|
||||||
#include "MemberEventContent.h" |
|
||||||
#include "NameEventContent.h" |
|
||||||
#include "PowerLevelsEventContent.h" |
|
||||||
#include "TopicEventContent.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
TEST(BaseEvent, Deserialization) |
|
||||||
{ |
|
||||||
// NameEventContent
|
|
||||||
auto data = |
|
||||||
QJsonObject{{"content", QJsonObject{{"name", "Room Name"}}}, {"type", "m.room.name"}}; |
|
||||||
|
|
||||||
Event<NameEventContent> name_event; |
|
||||||
name_event.deserialize(data); |
|
||||||
EXPECT_EQ(name_event.content().name(), "Room Name"); |
|
||||||
EXPECT_EQ(name_event.serialize(), data); |
|
||||||
|
|
||||||
// TopicEventContent
|
|
||||||
data = QJsonObject{{"content", QJsonObject{{"topic", "Room Topic"}}}, |
|
||||||
{"unsigned", QJsonObject{{"age", 22}, {"transaction_id", "randomid"}}}, |
|
||||||
{"type", "m.room.topic"}}; |
|
||||||
|
|
||||||
Event<TopicEventContent> topic_event; |
|
||||||
topic_event.deserialize(data); |
|
||||||
EXPECT_EQ(topic_event.content().topic(), "Room Topic"); |
|
||||||
EXPECT_EQ(topic_event.unsignedData().age(), 22); |
|
||||||
EXPECT_EQ(topic_event.unsignedData().transactionId(), "randomid"); |
|
||||||
EXPECT_EQ(topic_event.serialize(), data); |
|
||||||
|
|
||||||
// AvatarEventContent
|
|
||||||
data = QJsonObject{ |
|
||||||
{"content", QJsonObject{{"url", "https://matrix.org"}}}, |
|
||||||
{"unsigned", QJsonObject{{"age", 1343434343}, {"transaction_id", "m33434.33"}}}, |
|
||||||
{"type", "m.room.avatar"}}; |
|
||||||
|
|
||||||
Event<AvatarEventContent> avatar_event; |
|
||||||
avatar_event.deserialize(data); |
|
||||||
EXPECT_EQ(avatar_event.content().url().toString(), "https://matrix.org"); |
|
||||||
EXPECT_EQ(avatar_event.unsignedData().age(), 1343434343); |
|
||||||
EXPECT_EQ(avatar_event.unsignedData().transactionId(), "m33434.33"); |
|
||||||
EXPECT_EQ(avatar_event.serialize(), data); |
|
||||||
|
|
||||||
// AliasesEventContent
|
|
||||||
data = QJsonObject{ |
|
||||||
{"content", |
|
||||||
QJsonObject{{"aliases", QJsonArray{"#test:matrix.org", "#test2:matrix.org"}}}}, |
|
||||||
{"unsigned", QJsonObject{{"transaction_id", "m33434.33"}}}, |
|
||||||
{"type", "m.room.aliases"}}; |
|
||||||
|
|
||||||
Event<AliasesEventContent> aliases_event; |
|
||||||
aliases_event.deserialize(data); |
|
||||||
EXPECT_EQ(aliases_event.content().aliases().size(), 2); |
|
||||||
EXPECT_EQ(aliases_event.unsignedData().transactionId(), "m33434.33"); |
|
||||||
EXPECT_EQ(aliases_event.serialize(), data); |
|
||||||
|
|
||||||
// CreateEventContent
|
|
||||||
data = QJsonObject{{"content", QJsonObject{{"creator", "@alice:matrix.org"}}}, |
|
||||||
{"unsigned", QJsonObject{{"age", 2233}}}, |
|
||||||
{"type", "m.room.create"}}; |
|
||||||
|
|
||||||
Event<CreateEventContent> create_event; |
|
||||||
create_event.deserialize(data); |
|
||||||
EXPECT_EQ(create_event.content().creator(), "@alice:matrix.org"); |
|
||||||
EXPECT_EQ(create_event.unsignedData().age(), 2233); |
|
||||||
EXPECT_EQ(create_event.serialize(), data); |
|
||||||
|
|
||||||
// JoinRulesEventContent
|
|
||||||
data = QJsonObject{{"content", QJsonObject{{"join_rule", "private"}}}, |
|
||||||
{"type", "m.room.join_rules"}}; |
|
||||||
|
|
||||||
Event<JoinRulesEventContent> join_rules_event; |
|
||||||
join_rules_event.deserialize(data); |
|
||||||
EXPECT_EQ(join_rules_event.content().joinRule(), JoinRule::Private); |
|
||||||
EXPECT_EQ(join_rules_event.serialize(), data); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(BaseEvent, DeserializationException) |
|
||||||
{ |
|
||||||
auto data = |
|
||||||
QJsonObject{{"content", QJsonObject{{"rule", "private"}}}, {"type", "m.room.join_rules"}}; |
|
||||||
|
|
||||||
Event<JoinRulesEventContent> event1; |
|
||||||
ASSERT_THROW(event1.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
data = QJsonObject{{"contents", QJsonObject{{"join_rule", "private"}}}, |
|
||||||
{"type", "m.room.join_rules"}}; |
|
||||||
|
|
||||||
Event<JoinRulesEventContent> event2; |
|
||||||
ASSERT_THROW(event2.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
data = QJsonObject{{"contents", QJsonObject{{"join_rule", "private"}}}, |
|
||||||
{"unsigned", QJsonObject{{"age", "222"}}}, |
|
||||||
{"type", "m.room.join_rules"}}; |
|
||||||
|
|
||||||
Event<JoinRulesEventContent> event3; |
|
||||||
ASSERT_THROW(event3.deserialize(data), DeserializationException); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(RoomEvent, Deserialization) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"content", QJsonObject{{"name", "Name"}}}, |
|
||||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
|
||||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
|
||||||
{"sender", "@alice:matrix.org"}, |
|
||||||
{"origin_server_ts", 1323238293289323LL}, |
|
||||||
{"type", "m.room.name"}}; |
|
||||||
|
|
||||||
RoomEvent<NameEventContent> event; |
|
||||||
event.deserialize(data); |
|
||||||
|
|
||||||
EXPECT_EQ(event.eventId(), "$asdfafdf8af:matrix.org"); |
|
||||||
EXPECT_EQ(event.roomId(), "!aasdfaeae23r9:matrix.org"); |
|
||||||
EXPECT_EQ(event.sender(), "@alice:matrix.org"); |
|
||||||
EXPECT_EQ(event.timestamp(), 1323238293289323); |
|
||||||
EXPECT_EQ(event.content().name(), "Name"); |
|
||||||
EXPECT_EQ(event.serialize(), data); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(RoomEvent, DeserializationException) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"content", QJsonObject{{"name", "Name"}}}, |
|
||||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
|
||||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
|
||||||
{"origin_server_ts", 1323238293289323LL}, |
|
||||||
{"type", "m.room.name"}}; |
|
||||||
|
|
||||||
RoomEvent<NameEventContent> event; |
|
||||||
|
|
||||||
try { |
|
||||||
event.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("sender key is missing", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(StateEvent, Deserialization) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"content", QJsonObject{{"name", "Name"}}}, |
|
||||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
|
||||||
{"state_key", "some_state_key"}, |
|
||||||
{"prev_content", QJsonObject{{"name", "Previous Name"}}}, |
|
||||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
|
||||||
{"sender", "@alice:matrix.org"}, |
|
||||||
{"origin_server_ts", 1323238293289323LL}, |
|
||||||
{"type", "m.room.name"}}; |
|
||||||
|
|
||||||
StateEvent<NameEventContent> event; |
|
||||||
event.deserialize(data); |
|
||||||
|
|
||||||
EXPECT_EQ(event.eventId(), "$asdfafdf8af:matrix.org"); |
|
||||||
EXPECT_EQ(event.roomId(), "!aasdfaeae23r9:matrix.org"); |
|
||||||
EXPECT_EQ(event.sender(), "@alice:matrix.org"); |
|
||||||
EXPECT_EQ(event.timestamp(), 1323238293289323); |
|
||||||
EXPECT_EQ(event.content().name(), "Name"); |
|
||||||
EXPECT_EQ(event.stateKey(), "some_state_key"); |
|
||||||
EXPECT_EQ(event.previousContent().name(), "Previous Name"); |
|
||||||
EXPECT_EQ(event.serialize(), data); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(StateEvent, DeserializationException) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"content", QJsonObject{{"name", "Name"}}}, |
|
||||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
|
||||||
{"prev_content", QJsonObject{{"name", "Previous Name"}}}, |
|
||||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
|
||||||
{"sender", "@alice:matrix.org"}, |
|
||||||
{"origin_server_ts", 1323238293289323LL}, |
|
||||||
{"type", "m.room.name"}}; |
|
||||||
|
|
||||||
StateEvent<NameEventContent> event; |
|
||||||
|
|
||||||
try { |
|
||||||
event.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("state_key key is missing", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(EventType, Mapping) |
|
||||||
{ |
|
||||||
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.aliases"}}), |
|
||||||
EventType::RoomAliases); |
|
||||||
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.avatar"}}), EventType::RoomAvatar); |
|
||||||
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.canonical_alias"}}), |
|
||||||
EventType::RoomCanonicalAlias); |
|
||||||
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.create"}}), EventType::RoomCreate); |
|
||||||
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.history_visibility"}}), |
|
||||||
EventType::RoomHistoryVisibility); |
|
||||||
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.join_rules"}}), |
|
||||||
EventType::RoomJoinRules); |
|
||||||
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.member"}}), EventType::RoomMember); |
|
||||||
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.message"}}), |
|
||||||
EventType::RoomMessage); |
|
||||||
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.name"}}), EventType::RoomName); |
|
||||||
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.power_levels"}}), |
|
||||||
EventType::RoomPowerLevels); |
|
||||||
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.topic"}}), EventType::RoomTopic); |
|
||||||
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.unknown"}}), |
|
||||||
EventType::Unsupported); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(AliasesEventContent, Deserialization) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"aliases", QJsonArray{"#test:matrix.org", "#test2:matrix.org"}}}; |
|
||||||
|
|
||||||
AliasesEventContent content; |
|
||||||
content.deserialize(data); |
|
||||||
|
|
||||||
EXPECT_EQ(content.aliases().size(), 2); |
|
||||||
EXPECT_EQ(content.serialize(), data); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(AliasesEventContent, NotAnObject) |
|
||||||
{ |
|
||||||
auto data = QJsonArray{"#test:matrix.org", "#test2:matrix.org"}; |
|
||||||
|
|
||||||
AliasesEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(AliasesEventContent, MissingKey) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"key", QJsonArray{"#test:matrix.org", "#test2:matrix.org"}}}; |
|
||||||
|
|
||||||
AliasesEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
try { |
|
||||||
content.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("aliases key is missing", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(AvatarEventContent, Deserialization) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"url", "https://matrix.org/avatar.png"}}; |
|
||||||
|
|
||||||
AvatarEventContent content; |
|
||||||
content.deserialize(data); |
|
||||||
|
|
||||||
EXPECT_EQ(content.url().toString(), "https://matrix.org/avatar.png"); |
|
||||||
EXPECT_EQ(content.serialize(), data); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(AvatarEventContent, NotAnObject) |
|
||||||
{ |
|
||||||
auto data = QJsonArray{"key", "url"}; |
|
||||||
|
|
||||||
AvatarEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(AvatarEventContent, MissingKey) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"key", "https://matrix.org"}}; |
|
||||||
|
|
||||||
AvatarEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
try { |
|
||||||
content.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("url key is missing", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(CreateEventContent, Deserialization) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"creator", "@alice:matrix.org"}}; |
|
||||||
|
|
||||||
CreateEventContent content; |
|
||||||
content.deserialize(data); |
|
||||||
|
|
||||||
EXPECT_EQ(content.creator(), "@alice:matrix.org"); |
|
||||||
EXPECT_EQ(content.serialize(), data); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(CreateEventContent, NotAnObject) |
|
||||||
{ |
|
||||||
auto data = QJsonArray{"creator", "alice"}; |
|
||||||
|
|
||||||
CreateEventContent content; |
|
||||||
|
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(CreateEventContent, MissingKey) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"key", "@alice:matrix.org"}}; |
|
||||||
|
|
||||||
CreateEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
try { |
|
||||||
content.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("creator key is missing", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(HistoryVisibilityEventContent, Deserialization) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"history_visibility", "invited"}}; |
|
||||||
|
|
||||||
HistoryVisibilityEventContent content; |
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Invited); |
|
||||||
|
|
||||||
data = QJsonObject{{"history_visibility", "joined"}}; |
|
||||||
|
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Joined); |
|
||||||
|
|
||||||
data = QJsonObject{{"history_visibility", "shared"}}; |
|
||||||
|
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Shared); |
|
||||||
|
|
||||||
data = QJsonObject{{"history_visibility", "world_readable"}}; |
|
||||||
|
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.historyVisibility(), HistoryVisibility::WorldReadable); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(HistoryVisibilityEventContent, NotAnObject) |
|
||||||
{ |
|
||||||
auto data = QJsonArray{"history_visibility", "alice"}; |
|
||||||
|
|
||||||
HistoryVisibilityEventContent content; |
|
||||||
|
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(HistoryVisibilityEventContent, InvalidHistoryVisibility) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"history_visibility", "wrong"}}; |
|
||||||
|
|
||||||
HistoryVisibilityEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
try { |
|
||||||
content.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("Unknown history_visibility value: wrong", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(HistoryVisibilityEventContent, MissingKey) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"key", "joined"}}; |
|
||||||
|
|
||||||
HistoryVisibilityEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
try { |
|
||||||
content.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("history_visibility key is missing", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(JoinRulesEventContent, Deserialization) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"join_rule", "invite"}}; |
|
||||||
|
|
||||||
JoinRulesEventContent content; |
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.joinRule(), JoinRule::Invite); |
|
||||||
|
|
||||||
data = QJsonObject{{"join_rule", "knock"}}; |
|
||||||
|
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.joinRule(), JoinRule::Knock); |
|
||||||
|
|
||||||
data = QJsonObject{{"join_rule", "private"}}; |
|
||||||
|
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.joinRule(), JoinRule::Private); |
|
||||||
|
|
||||||
data = QJsonObject{{"join_rule", "public"}}; |
|
||||||
|
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.joinRule(), JoinRule::Public); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(JoinRulesEventContent, NotAnObject) |
|
||||||
{ |
|
||||||
auto data = QJsonArray{"rule", "alice"}; |
|
||||||
|
|
||||||
JoinRulesEventContent content; |
|
||||||
|
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(JoinRulesEventContent, InvalidHistoryVisibility) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"join_rule", "wrong"}}; |
|
||||||
|
|
||||||
JoinRulesEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
try { |
|
||||||
content.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("Unknown join_rule value: wrong", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(JoinRulesEventContent, MissingKey) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"key", "invite"}}; |
|
||||||
|
|
||||||
JoinRulesEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
try { |
|
||||||
content.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("join_rule key is missing", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(CanonicalAliasEventContent, Deserialization) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"alias", "Room Alias"}}; |
|
||||||
|
|
||||||
CanonicalAliasEventContent content; |
|
||||||
content.deserialize(data); |
|
||||||
|
|
||||||
EXPECT_EQ(content.alias(), "Room Alias"); |
|
||||||
EXPECT_EQ(content.serialize(), data); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(CanonicalAliasEventContent, NotAnObject) |
|
||||||
{ |
|
||||||
auto data = QJsonArray{"alias", "Room Alias"}; |
|
||||||
|
|
||||||
CanonicalAliasEventContent content; |
|
||||||
|
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(CanonicalAliasEventContent, MissingKey) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"key", "alias"}}; |
|
||||||
|
|
||||||
CanonicalAliasEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
try { |
|
||||||
content.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("alias key is missing", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(MemberEventContent, Deserialization) |
|
||||||
{ |
|
||||||
MemberEventContent content; |
|
||||||
|
|
||||||
auto data = QJsonObject{{"membership", "join"}}; |
|
||||||
|
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.membershipState(), Membership::Join); |
|
||||||
|
|
||||||
data = QJsonObject{{"membership", "invite"}, {"displayname", "Username"}}; |
|
||||||
|
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.membershipState(), Membership::Invite); |
|
||||||
EXPECT_EQ(content.displayName(), "Username"); |
|
||||||
|
|
||||||
data = QJsonObject{{"membership", "leave"}, {"avatar_url", "https://matrix.org"}}; |
|
||||||
|
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.membershipState(), Membership::Leave); |
|
||||||
EXPECT_EQ(content.avatarUrl().toString(), "https://matrix.org"); |
|
||||||
|
|
||||||
data = QJsonObject{{"membership", "ban"}}; |
|
||||||
|
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.membershipState(), Membership::Ban); |
|
||||||
|
|
||||||
data = QJsonObject{{"membership", "knock"}}; |
|
||||||
|
|
||||||
content.deserialize(data); |
|
||||||
EXPECT_EQ(content.membershipState(), Membership::Knock); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(MemberEventContent, InvalidMembership) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"membership", "wrong"}}; |
|
||||||
|
|
||||||
MemberEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
try { |
|
||||||
content.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("Unknown membership value: wrong", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(MemberEventContent, NotAnObject) |
|
||||||
{ |
|
||||||
auto data = QJsonArray{"name", "join"}; |
|
||||||
|
|
||||||
MemberEventContent content; |
|
||||||
|
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(MemberEventContent, MissingName) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"key", "random"}}; |
|
||||||
|
|
||||||
MemberEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
try { |
|
||||||
content.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("membership key is missing", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(NameEventContent, Deserialization) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"name", "Room Name"}}; |
|
||||||
|
|
||||||
NameEventContent content; |
|
||||||
content.deserialize(data); |
|
||||||
|
|
||||||
EXPECT_EQ(content.name(), "Room Name"); |
|
||||||
EXPECT_EQ(content.serialize(), data); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(NameEventContent, NotAnObject) |
|
||||||
{ |
|
||||||
auto data = QJsonArray{"name", "Room Name"}; |
|
||||||
|
|
||||||
NameEventContent content; |
|
||||||
|
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(NameEventContent, MissingName) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"key", "Room Name"}}; |
|
||||||
|
|
||||||
NameEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
try { |
|
||||||
content.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("name key is missing", e.what()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
TEST(PowerLevelsEventContent, DefaultValues) |
|
||||||
{ |
|
||||||
PowerLevelsEventContent power_levels; |
|
||||||
|
|
||||||
EXPECT_EQ(power_levels.banLevel(), static_cast<int>(PowerLevels::Moderator)); |
|
||||||
EXPECT_EQ(power_levels.inviteLevel(), static_cast<int>(PowerLevels::Moderator)); |
|
||||||
EXPECT_EQ(power_levels.kickLevel(), static_cast<int>(PowerLevels::Moderator)); |
|
||||||
EXPECT_EQ(power_levels.redactLevel(), static_cast<int>(PowerLevels::Moderator)); |
|
||||||
|
|
||||||
EXPECT_EQ(power_levels.eventsDefaultLevel(), static_cast<int>(PowerLevels::User)); |
|
||||||
EXPECT_EQ(power_levels.usersDefaultLevel(), static_cast<int>(PowerLevels::User)); |
|
||||||
EXPECT_EQ(power_levels.stateDefaultLevel(), static_cast<int>(PowerLevels::Moderator)); |
|
||||||
|
|
||||||
// Default levels.
|
|
||||||
EXPECT_EQ(power_levels.userLevel("@joe:matrix.org"), static_cast<int>(PowerLevels::User)); |
|
||||||
EXPECT_EQ(power_levels.eventLevel("m.room.message"), static_cast<int>(PowerLevels::User)); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(PowerLevelsEventContent, FullDeserialization) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{ |
|
||||||
{"ban", 1}, |
|
||||||
{"invite", 2}, |
|
||||||
{"kick", 3}, |
|
||||||
{"redact", 4}, |
|
||||||
|
|
||||||
{"events_default", 5}, |
|
||||||
{"state_default", 6}, |
|
||||||
{"users_default", 7}, |
|
||||||
|
|
||||||
{"events", QJsonObject{{"m.message.text", 8}, {"m.message.image", 9}}}, |
|
||||||
{"users", QJsonObject{{"@alice:matrix.org", 10}, {"@bob:matrix.org", 11}}}, |
|
||||||
}; |
|
||||||
|
|
||||||
PowerLevelsEventContent power_levels; |
|
||||||
power_levels.deserialize(data); |
|
||||||
|
|
||||||
EXPECT_EQ(power_levels.banLevel(), 1); |
|
||||||
EXPECT_EQ(power_levels.inviteLevel(), 2); |
|
||||||
EXPECT_EQ(power_levels.kickLevel(), 3); |
|
||||||
EXPECT_EQ(power_levels.redactLevel(), 4); |
|
||||||
|
|
||||||
EXPECT_EQ(power_levels.eventsDefaultLevel(), 5); |
|
||||||
EXPECT_EQ(power_levels.stateDefaultLevel(), 6); |
|
||||||
EXPECT_EQ(power_levels.usersDefaultLevel(), 7); |
|
||||||
|
|
||||||
EXPECT_EQ(power_levels.userLevel("@alice:matrix.org"), 10); |
|
||||||
EXPECT_EQ(power_levels.userLevel("@bob:matrix.org"), 11); |
|
||||||
EXPECT_EQ(power_levels.userLevel("@carl:matrix.org"), 7); |
|
||||||
|
|
||||||
EXPECT_EQ(power_levels.eventLevel("m.message.text"), 8); |
|
||||||
EXPECT_EQ(power_levels.eventLevel("m.message.image"), 9); |
|
||||||
EXPECT_EQ(power_levels.eventLevel("m.message.gif"), 5); |
|
||||||
|
|
||||||
EXPECT_EQ(power_levels.serialize(), data); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(PowerLevelsEventContent, PartialDeserialization) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{ |
|
||||||
{"ban", 1}, |
|
||||||
{"invite", 2}, |
|
||||||
|
|
||||||
{"events_default", 5}, |
|
||||||
{"users_default", 7}, |
|
||||||
|
|
||||||
{"users", QJsonObject{{"@alice:matrix.org", 10}, {"@bob:matrix.org", 11}}}, |
|
||||||
}; |
|
||||||
|
|
||||||
PowerLevelsEventContent power_levels; |
|
||||||
power_levels.deserialize(data); |
|
||||||
|
|
||||||
EXPECT_EQ(power_levels.banLevel(), 1); |
|
||||||
EXPECT_EQ(power_levels.inviteLevel(), 2); |
|
||||||
EXPECT_EQ(power_levels.kickLevel(), static_cast<int>(PowerLevels::Moderator)); |
|
||||||
EXPECT_EQ(power_levels.redactLevel(), static_cast<int>(PowerLevels::Moderator)); |
|
||||||
|
|
||||||
EXPECT_EQ(power_levels.eventsDefaultLevel(), 5); |
|
||||||
EXPECT_EQ(power_levels.stateDefaultLevel(), static_cast<int>(PowerLevels::Moderator)); |
|
||||||
EXPECT_EQ(power_levels.usersDefaultLevel(), 7); |
|
||||||
|
|
||||||
EXPECT_EQ(power_levels.userLevel("@alice:matrix.org"), 10); |
|
||||||
EXPECT_EQ(power_levels.userLevel("@bob:matrix.org"), 11); |
|
||||||
EXPECT_EQ(power_levels.userLevel("@carl:matrix.org"), 7); |
|
||||||
|
|
||||||
EXPECT_EQ(power_levels.eventLevel("m.message.text"), 5); |
|
||||||
EXPECT_EQ(power_levels.eventLevel("m.message.image"), 5); |
|
||||||
EXPECT_EQ(power_levels.eventLevel("m.message.gif"), 5); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(PowerLevelsEventContent, NotAnObject) |
|
||||||
{ |
|
||||||
auto data = QJsonArray{"test", "test2"}; |
|
||||||
|
|
||||||
PowerLevelsEventContent power_levels; |
|
||||||
|
|
||||||
ASSERT_THROW(power_levels.deserialize(data), DeserializationException); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(TopicEventContent, Deserialization) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"topic", "Room Topic"}}; |
|
||||||
|
|
||||||
TopicEventContent content; |
|
||||||
content.deserialize(data); |
|
||||||
|
|
||||||
EXPECT_EQ(content.topic(), "Room Topic"); |
|
||||||
EXPECT_EQ(content.serialize(), data); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(TopicEventContent, NotAnObject) |
|
||||||
{ |
|
||||||
auto data = QJsonArray{"topic", "Room Topic"}; |
|
||||||
|
|
||||||
TopicEventContent content; |
|
||||||
|
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(TopicEventContent, MissingName) |
|
||||||
{ |
|
||||||
auto data = QJsonObject{{"key", "Room Name"}}; |
|
||||||
|
|
||||||
TopicEventContent content; |
|
||||||
ASSERT_THROW(content.deserialize(data), DeserializationException); |
|
||||||
|
|
||||||
try { |
|
||||||
content.deserialize(data); |
|
||||||
} catch (const DeserializationException &e) { |
|
||||||
ASSERT_STREQ("topic key is missing", e.what()); |
|
||||||
} |
|
||||||
} |
|
@ -1,287 +0,0 @@ |
|||||||
#include <gtest/gtest.h> |
|
||||||
|
|
||||||
#include <QJsonArray> |
|
||||||
#include <QJsonObject> |
|
||||||
|
|
||||||
#include "MessageEvent.h" |
|
||||||
#include "MessageEventContent.h" |
|
||||||
|
|
||||||
#include "Audio.h" |
|
||||||
#include "Emote.h" |
|
||||||
#include "File.h" |
|
||||||
#include "Image.h" |
|
||||||
#include "Location.h" |
|
||||||
#include "Notice.h" |
|
||||||
#include "Text.h" |
|
||||||
#include "Video.h" |
|
||||||
|
|
||||||
using namespace matrix::events; |
|
||||||
|
|
||||||
TEST(MessageEvent, Audio) |
|
||||||
{ |
|
||||||
auto info = |
|
||||||
QJsonObject{ { "duration", 2140786 }, { "mimetype", "audio/mpeg" }, { "size", 1563688 } }; |
|
||||||
|
|
||||||
auto content = QJsonObject{ { "body", "Bee Gees - Stayin' Alive" }, |
|
||||||
{ "msgtype", "m.audio" }, |
|
||||||
{ "url", "mxc://localhost/2sdfj23f33r3faad" }, |
|
||||||
{ "info", info } }; |
|
||||||
|
|
||||||
auto event = QJsonObject{ { "content", content }, |
|
||||||
{ "event_id", "$asdfafdf8af:matrix.org" }, |
|
||||||
{ "room_id", "!aasdfaeae23r9:matrix.org" }, |
|
||||||
{ "sender", "@alice:matrix.org" }, |
|
||||||
{ "origin_server_ts", 1323238293289323LL }, |
|
||||||
{ "type", "m.room.message" } }; |
|
||||||
|
|
||||||
MessageEvent<messages::Audio> audio; |
|
||||||
audio.deserialize(event); |
|
||||||
|
|
||||||
EXPECT_EQ(audio.msgContent().info().duration, 2140786); |
|
||||||
EXPECT_EQ(audio.msgContent().info().size, 1563688); |
|
||||||
EXPECT_EQ(audio.msgContent().info().mimetype, "audio/mpeg"); |
|
||||||
EXPECT_EQ(audio.content().body(), "Bee Gees - Stayin' Alive"); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(MessageEvent, Emote) |
|
||||||
{ |
|
||||||
auto content = QJsonObject{ { "body", "emote message" }, { "msgtype", "m.emote" } }; |
|
||||||
|
|
||||||
auto event = QJsonObject{ { "content", content }, |
|
||||||
{ "event_id", "$asdfafdf8af:matrix.org" }, |
|
||||||
{ "room_id", "!aasdfaeae23r9:matrix.org" }, |
|
||||||
{ "sender", "@alice:matrix.org" }, |
|
||||||
{ "origin_server_ts", 1323238293289323LL }, |
|
||||||
{ "type", "m.room.message" } }; |
|
||||||
|
|
||||||
MessageEvent<messages::Emote> emote; |
|
||||||
emote.deserialize(event); |
|
||||||
|
|
||||||
EXPECT_EQ(emote.content().body(), "emote message"); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(MessageEvent, File) |
|
||||||
{ |
|
||||||
auto thumbnail_info = QJsonObject{ |
|
||||||
{ "h", 300 }, { "w", 400 }, { "size", 3432434 }, { "mimetype", "image/jpeg" } |
|
||||||
}; |
|
||||||
|
|
||||||
auto file_info = QJsonObject{ { "size", 24242424 }, |
|
||||||
{ "mimetype", "application/msword" }, |
|
||||||
{ "thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3" }, |
|
||||||
{ "thumbnail_info", thumbnail_info } }; |
|
||||||
|
|
||||||
auto content = QJsonObject{ { "body", "something-important.doc" }, |
|
||||||
{ "filename", "something-important.doc" }, |
|
||||||
{ "url", "mxc://localhost/23d233d32r3r2r" }, |
|
||||||
{ "info", file_info }, |
|
||||||
{ "msgtype", "m.file" } }; |
|
||||||
|
|
||||||
auto event = QJsonObject{ { "content", content }, |
|
||||||
{ "event_id", "$asdfafdf8af:matrix.org" }, |
|
||||||
{ "room_id", "!aasdfaeae23r9:matrix.org" }, |
|
||||||
{ "sender", "@alice:matrix.org" }, |
|
||||||
{ "origin_server_ts", 1323238293289323LL }, |
|
||||||
{ "type", "m.room.message" } }; |
|
||||||
|
|
||||||
MessageEvent<messages::File> file; |
|
||||||
file.deserialize(event); |
|
||||||
|
|
||||||
EXPECT_EQ(file.content().body(), "something-important.doc"); |
|
||||||
EXPECT_EQ(file.msgContent().info().thumbnail_info.h, 300); |
|
||||||
EXPECT_EQ(file.msgContent().info().thumbnail_info.w, 400); |
|
||||||
EXPECT_EQ(file.msgContent().info().thumbnail_info.mimetype, "image/jpeg"); |
|
||||||
EXPECT_EQ(file.msgContent().info().mimetype, "application/msword"); |
|
||||||
EXPECT_EQ(file.msgContent().info().size, 24242424); |
|
||||||
EXPECT_EQ(file.content().body(), "something-important.doc"); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(MessageEvent, Image) |
|
||||||
{ |
|
||||||
auto thumbinfo = QJsonObject{ |
|
||||||
{ "h", 11 }, { "w", 22 }, { "size", 212 }, { "mimetype", "img/jpeg" }, |
|
||||||
}; |
|
||||||
|
|
||||||
auto imginfo = QJsonObject{ |
|
||||||
{ "h", 110 }, |
|
||||||
{ "w", 220 }, |
|
||||||
{ "size", 2120 }, |
|
||||||
{ "mimetype", "img/jpeg" }, |
|
||||||
{ "thumbnail_url", "https://images.com/image-thumb.jpg" }, |
|
||||||
{ "thumbnail_info", thumbinfo }, |
|
||||||
}; |
|
||||||
|
|
||||||
auto content = QJsonObject{ { "body", "Image title" }, |
|
||||||
{ "msgtype", "m.image" }, |
|
||||||
{ "url", "https://images.com/image.jpg" }, |
|
||||||
{ "info", imginfo } }; |
|
||||||
|
|
||||||
auto event = QJsonObject{ { "content", content }, |
|
||||||
{ "event_id", "$asdfafdf8af:matrix.org" }, |
|
||||||
{ "room_id", "!aasdfaeae23r9:matrix.org" }, |
|
||||||
{ "sender", "@alice:matrix.org" }, |
|
||||||
{ "origin_server_ts", 1323238293289323LL }, |
|
||||||
{ "type", "m.room.message" } }; |
|
||||||
|
|
||||||
MessageEvent<messages::Image> img; |
|
||||||
img.deserialize(event); |
|
||||||
|
|
||||||
EXPECT_EQ(img.content().body(), "Image title"); |
|
||||||
EXPECT_EQ(img.msgContent().info().h, 110); |
|
||||||
EXPECT_EQ(img.msgContent().info().w, 220); |
|
||||||
EXPECT_EQ(img.msgContent().info().thumbnail_info.w, 22); |
|
||||||
EXPECT_EQ(img.msgContent().info().mimetype, "img/jpeg"); |
|
||||||
EXPECT_EQ(img.msgContent().info().thumbnail_url, "https://images.com/image-thumb.jpg"); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(MessageEvent, Location) |
|
||||||
{ |
|
||||||
auto thumbnail_info = QJsonObject{ |
|
||||||
{ "h", 300 }, { "w", 400 }, { "size", 3432434 }, { "mimetype", "image/jpeg" } |
|
||||||
}; |
|
||||||
|
|
||||||
auto info = QJsonObject{ { "thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3" }, |
|
||||||
{ "thumbnail_info", thumbnail_info } }; |
|
||||||
|
|
||||||
auto content = QJsonObject{ { "body", "Big Ben, London, UK" }, |
|
||||||
{ "geo_uri", "geo:51.5008,0.1247" }, |
|
||||||
{ "info", info }, |
|
||||||
{ "msgtype", "m.location" } }; |
|
||||||
|
|
||||||
auto event = QJsonObject{ { "content", content }, |
|
||||||
{ "event_id", "$asdfafdf8af:matrix.org" }, |
|
||||||
{ "room_id", "!aasdfaeae23r9:matrix.org" }, |
|
||||||
{ "sender", "@alice:matrix.org" }, |
|
||||||
{ "origin_server_ts", 1323238293289323LL }, |
|
||||||
{ "type", "m.room.message" } }; |
|
||||||
|
|
||||||
MessageEvent<messages::Location> location; |
|
||||||
location.deserialize(event); |
|
||||||
|
|
||||||
EXPECT_EQ(location.msgContent().info().thumbnail_info.h, 300); |
|
||||||
EXPECT_EQ(location.msgContent().info().thumbnail_info.w, 400); |
|
||||||
EXPECT_EQ(location.msgContent().info().thumbnail_info.mimetype, "image/jpeg"); |
|
||||||
EXPECT_EQ(location.msgContent().info().thumbnail_url, "mxc://localhost/adfaefaFAFSDFF3"); |
|
||||||
EXPECT_EQ(location.content().body(), "Big Ben, London, UK"); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(MessageEvent, Notice) |
|
||||||
{ |
|
||||||
auto content = QJsonObject{ { "body", "notice message" }, { "msgtype", "m.notice" } }; |
|
||||||
|
|
||||||
auto event = QJsonObject{ { "content", content }, |
|
||||||
{ "event_id", "$asdfafdf8af:matrix.org" }, |
|
||||||
{ "room_id", "!aasdfaeae23r9:matrix.org" }, |
|
||||||
{ "sender", "@alice:matrix.org" }, |
|
||||||
{ "origin_server_ts", 1323238293289323LL }, |
|
||||||
{ "type", "m.room.message" } }; |
|
||||||
|
|
||||||
MessageEvent<messages::Notice> notice; |
|
||||||
notice.deserialize(event); |
|
||||||
|
|
||||||
EXPECT_EQ(notice.content().body(), "notice message"); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(MessageEvent, Text) |
|
||||||
{ |
|
||||||
auto content = QJsonObject{ { "body", "text message" }, { "msgtype", "m.text" } }; |
|
||||||
|
|
||||||
auto event = QJsonObject{ { "content", content }, |
|
||||||
{ "event_id", "$asdfafdf8af:matrix.org" }, |
|
||||||
{ "room_id", "!aasdfaeae23r9:matrix.org" }, |
|
||||||
{ "sender", "@alice:matrix.org" }, |
|
||||||
{ "origin_server_ts", 1323238293289323LL }, |
|
||||||
{ "type", "m.room.message" } }; |
|
||||||
|
|
||||||
MessageEvent<messages::Text> text; |
|
||||||
text.deserialize(event); |
|
||||||
|
|
||||||
EXPECT_EQ(text.content().body(), "text message"); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(MessageEvent, Video) |
|
||||||
{ |
|
||||||
auto thumbnail_info = QJsonObject{ |
|
||||||
{ "h", 300 }, { "w", 400 }, { "size", 3432434 }, { "mimetype", "image/jpeg" } |
|
||||||
}; |
|
||||||
|
|
||||||
auto video_info = QJsonObject{ { "h", 222 }, |
|
||||||
{ "w", 333 }, |
|
||||||
{ "duration", 232323 }, |
|
||||||
{ "size", 24242424 }, |
|
||||||
{ "mimetype", "video/mp4" }, |
|
||||||
{ "thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3" }, |
|
||||||
{ "thumbnail_info", thumbnail_info } }; |
|
||||||
|
|
||||||
auto content = QJsonObject{ { "body", "Gangnam Style" }, |
|
||||||
{ "url", "mxc://localhost/23d233d32r3r2r" }, |
|
||||||
{ "info", video_info }, |
|
||||||
{ "msgtype", "m.video" } }; |
|
||||||
|
|
||||||
auto event = QJsonObject{ { "content", content }, |
|
||||||
{ "event_id", "$asdfafdf8af:matrix.org" }, |
|
||||||
{ "room_id", "!aasdfaeae23r9:matrix.org" }, |
|
||||||
{ "sender", "@alice:matrix.org" }, |
|
||||||
{ "origin_server_ts", 1323238293289323LL }, |
|
||||||
{ "type", "m.room.message" } }; |
|
||||||
|
|
||||||
MessageEvent<messages::Video> video; |
|
||||||
video.deserialize(event); |
|
||||||
|
|
||||||
EXPECT_EQ(video.msgContent().info().thumbnail_info.h, 300); |
|
||||||
EXPECT_EQ(video.msgContent().info().thumbnail_info.w, 400); |
|
||||||
EXPECT_EQ(video.msgContent().info().thumbnail_info.mimetype, "image/jpeg"); |
|
||||||
EXPECT_EQ(video.msgContent().info().duration, 232323); |
|
||||||
EXPECT_EQ(video.msgContent().info().size, 24242424); |
|
||||||
EXPECT_EQ(video.msgContent().info().mimetype, "video/mp4"); |
|
||||||
EXPECT_EQ(video.content().body(), "Gangnam Style"); |
|
||||||
} |
|
||||||
|
|
||||||
TEST(MessageEvent, Types) |
|
||||||
{ |
|
||||||
EXPECT_EQ( |
|
||||||
extractMessageEventType(QJsonObject{ |
|
||||||
{ "content", QJsonObject{ { "msgtype", "m.audio" } } }, { "type", "m.room.message" }, |
|
||||||
}), |
|
||||||
MessageEventType::Audio); |
|
||||||
EXPECT_EQ( |
|
||||||
extractMessageEventType(QJsonObject{ |
|
||||||
{ "content", QJsonObject{ { "msgtype", "m.emote" } } }, { "type", "m.room.message" }, |
|
||||||
}), |
|
||||||
MessageEventType::Emote); |
|
||||||
EXPECT_EQ( |
|
||||||
extractMessageEventType(QJsonObject{ |
|
||||||
{ "content", QJsonObject{ { "msgtype", "m.file" } } }, { "type", "m.room.message" }, |
|
||||||
}), |
|
||||||
MessageEventType::File); |
|
||||||
EXPECT_EQ( |
|
||||||
extractMessageEventType(QJsonObject{ |
|
||||||
{ "content", QJsonObject{ { "msgtype", "m.image" } } }, { "type", "m.room.message" }, |
|
||||||
}), |
|
||||||
MessageEventType::Image); |
|
||||||
EXPECT_EQ( |
|
||||||
extractMessageEventType(QJsonObject{ |
|
||||||
{ "content", QJsonObject{ { "msgtype", "m.location" } } }, { "type", "m.room.message" }, |
|
||||||
}), |
|
||||||
MessageEventType::Location); |
|
||||||
EXPECT_EQ( |
|
||||||
extractMessageEventType(QJsonObject{ |
|
||||||
{ "content", QJsonObject{ { "msgtype", "m.notice" } } }, { "type", "m.room.message" }, |
|
||||||
}), |
|
||||||
MessageEventType::Notice); |
|
||||||
EXPECT_EQ( |
|
||||||
extractMessageEventType(QJsonObject{ |
|
||||||
{ "content", QJsonObject{ { "msgtype", "m.text" } } }, { "type", "m.room.message" }, |
|
||||||
}), |
|
||||||
MessageEventType::Text); |
|
||||||
EXPECT_EQ( |
|
||||||
extractMessageEventType(QJsonObject{ |
|
||||||
{ "content", QJsonObject{ { "msgtype", "m.video" } } }, { "type", "m.room.message" }, |
|
||||||
}), |
|
||||||
MessageEventType::Video); |
|
||||||
EXPECT_EQ( |
|
||||||
extractMessageEventType(QJsonObject{ |
|
||||||
{ "content", QJsonObject{ { "msgtype", "m.random" } } }, { "type", "m.room.message" }, |
|
||||||
}), |
|
||||||
MessageEventType::Unknown); |
|
||||||
} |
|
Loading…
Reference in new issue