Skip to content
Snippets Groups Projects
Commit b064df8b authored by Konstantinos Sideris's avatar Konstantinos Sideris
Browse files

Add event contents

parent 9cc9b623
No related branches found
No related tags found
No related merge requests found
Showing
with 907 additions and 7 deletions
......@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.1)
project(nheko CXX)
option(BUILD_TESTS "Build all tests" OFF)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Network REQUIRED)
......@@ -114,8 +116,22 @@ set(SRC_FILES
src/ui/ThemeManager.cc
)
set(MATRIX_EVENTS
src/events/AliasesEventContent.cc
src/events/AvatarEventContent.cc
src/events/CanonicalAliasEventContent.cc
src/events/CreateEventContent.cc
src/events/HistoryVisibilityEventContent.cc
src/events/JoinRulesEventContent.cc
src/events/MemberEventContent.cc
src/events/NameEventContent.cc
src/events/PowerLevelsEventContent.cc
src/events/TopicEventContent.cc
)
include_directories(include)
include_directories(include/ui)
include_directories(include/events)
qt5_wrap_ui (UI_HEADERS
forms/ChatPage.ui
......@@ -161,9 +177,24 @@ qt5_wrap_cpp(MOC_HEADERS
qt5_add_resources(QRC resources/res.qrc)
add_executable (nheko ${OS_BUNDLE} ${SRC_FILES} ${UI_HEADERS} ${MOC_HEADERS} ${QRC})
target_link_libraries (nheko Qt5::Widgets Qt5::Network)
add_library(matrix_events ${MATRIX_EVENTS} src/Deserializable.cc)
target_link_libraries(matrix_events Qt5::Core)
if (BUILD_TESTS)
enable_testing()
if(WIN32)
target_link_libraries(nheko Qt5::WinMain)
endif(WIN32)
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(events_test tests/events.cc)
target_link_libraries(events_test matrix_events ${GTEST_BOTH_LIBRARIES})
add_test(MatrixEvents events_test)
else()
add_executable (nheko ${OS_BUNDLE} ${SRC_FILES} ${UI_HEADERS} ${MOC_HEADERS} ${QRC})
target_link_libraries (nheko matrix_events Qt5::Widgets Qt5::Network)
if(WIN32)
target_link_libraries(nheko Qt5::WinMain)
endif(WIN32)
endif()
SRC := $(shell find include src -type f -type f \( -iname "*.cc" -o -iname "*.h" \))
debug:
@cmake -H. -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Debug
@cmake -DBUILD_TESTS=OFF -H. -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Debug
@cmake --build build
release-debug:
@cmake -H. -GNinja -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo
@cmake -DBUILD_TESTS=OFF -H. -GNinja -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo
@cmake --build build
run:
......@@ -14,6 +14,11 @@ run:
lint:
@clang-format -i $(SRC)
test:
@cmake -DBUILD_TESTS=ON -H. -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release
@cmake --build build
@cd build && GTEST_COLOR=1 ctest --verbose
clean:
rm -rf build
......
/*
* 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/>.
*/
#ifndef ALIASES_EVENT_CONTENT_H
#define ALIASES_EVENT_CONTENT_H
#include <QJsonValue>
#include <QList>
#include "Deserializable.h"
class AliasesEventContent : public Deserializable
{
public:
void deserialize(const QJsonValue &data) override;
inline QList<QString> aliases() const;
private:
QList<QString> aliases_;
};
inline QList<QString> AliasesEventContent::aliases() const
{
return aliases_;
}
#endif // ALIASES_EVENT_CONTENT_H
/*
* 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/>.
*/
#ifndef AVATAR_EVENT_CONTENT_H
#define AVATAR_EVENT_CONTENT_H
#include <QJsonValue>
#include <QUrl>
#include "Deserializable.h"
/*
* A picture that is associated with the room.
*/
class AvatarEventContent : public Deserializable
{
public:
void deserialize(const QJsonValue &data) override;
inline QUrl url() const;
private:
QUrl url_;
};
inline QUrl AvatarEventContent::url() const
{
return url_;
}
#endif // AVATAR_EVENT_CONTENT_H
/*
* 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/>.
*/
#ifndef CANONICAL_ALIAS_EVENT_CONTENT_H
#define CANONICAL_ALIAS_EVENT_CONTENT_H
#include <QJsonValue>
#include "CanonicalAliasEventContent.h"
#include "Deserializable.h"
/*
* 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:
void deserialize(const QJsonValue &data) override;
inline QString alias() const;
private:
QString alias_;
};
inline QString CanonicalAliasEventContent::alias() const
{
return alias_;
}
#endif // CANONICAL_ALIAS_EVENT_CONTENT_H
/*
* 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/>.
*/
#ifndef CREATE_EVENT_CONTENT_H
#define CREATE_EVENT_CONTENT_H
#include <QJsonValue>
#include "Deserializable.h"
/*
* 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:
void deserialize(const QJsonValue &data) override;
inline QString creator() const;
private:
// The user_id of the room creator. This is set by the homeserver.
QString creator_;
};
inline QString CreateEventContent::creator() const
{
return creator_;
}
#endif // CREATE_EVENT_CONTENT_H
/*
* 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/>.
*/
#ifndef HISTORY_VISIBILITY_EVENT_CONTENT_H
#define HISTORY_VISIBILITY_EVENT_CONTENT_H
#include <QJsonValue>
#include "Deserializable.h"
enum HistoryVisibility {
Invited,
Joined,
Shared,
WorldReadable,
};
class HistoryVisibilityEventContent : public Deserializable
{
public:
inline HistoryVisibility historyVisibility() const;
void deserialize(const QJsonValue &data) override;
private:
HistoryVisibility history_visibility_;
};
inline HistoryVisibility HistoryVisibilityEventContent::historyVisibility() const
{
return history_visibility_;
}
#endif // HISTORY_VISIBILITY_EVENT_CONTENT_H
/*
* 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/>.
*/
#ifndef JOIN_RULES_EVENT_CONTENT_H
#define JOIN_RULES_EVENT_CONTENT_H
#include <QJsonValue>
#include "Deserializable.h"
enum 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:
void deserialize(const QJsonValue &data) override;
inline JoinRule joinRule() const;
private:
JoinRule join_rule_;
};
inline JoinRule JoinRulesEventContent::joinRule() const
{
return join_rule_;
}
#endif // JOIN_RULES_EVENT_CONTENT_H
/*
* 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/>.
*/
#ifndef MEMBER_EVENT_CONTENT_H
#define MEMBER_EVENT_CONTENT_H
#include <QJsonValue>
#include <QUrl>
#include "Deserializable.h"
enum Membership {
// The user is banned.
BanState,
// The user has been invited.
InviteState,
// The user has joined.
JoinState,
// The user has requested to join.
KnockState,
// The user has left.
LeaveState,
};
/*
* The current membership state of a user in the room.
*/
class MemberEventContent : public Deserializable
{
public:
void deserialize(const QJsonValue &data) override;
inline QUrl avatarUrl() const;
inline QString displayName() const;
inline Membership membershipState() const;
private:
QUrl avatar_url_;
QString display_name_;
Membership membership_state_;
};
inline QUrl MemberEventContent::avatarUrl() const
{
return avatar_url_;
}
inline QString MemberEventContent::displayName() const
{
return display_name_;
}
inline Membership MemberEventContent::membershipState() const
{
return membership_state_;
}
#endif // MEMBER_EVENT_CONTENT_H
/*
* 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/>.
*/
#ifndef NAME_EVENT_CONTENT_H
#define NAME_EVENT_CONTENT_H
#include <QJsonValue>
#include "Deserializable.h"
/*
* A human-friendly room name designed to be displayed to the end-user.
*/
class NameEventContent : public Deserializable
{
public:
void deserialize(const QJsonValue &data) override;
inline QString name() const;
private:
QString name_;
};
inline QString NameEventContent::name() const
{
return name_;
}
#endif // NAME_EVENT_CONTENT_H
/*
* 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/>.
*/
#ifndef POWER_LEVELS_EVENT_CONTENT_H
#define POWER_LEVELS_EVENT_CONTENT_H
#include <QJsonValue>
#include <QMap>
#include "Deserializable.h"
enum PowerLevels {
User = 0,
Moderator = 50,
Admin = 100,
};
/*
* Defines the power levels (privileges) of users in the room.
*/
class PowerLevelsEventContent : public Deserializable
{
public:
void deserialize(const QJsonValue &data) override;
inline int banLevel() const;
inline int inviteLevel() const;
inline int kickLevel() const;
inline int redactLevel() const;
inline int eventsDefaultLevel() const;
inline int stateDefaultLevel() const;
inline int usersDefaultLevel() const;
int eventLevel(QString event_type) const;
int userLevel(QString user_id) const;
private:
int ban_ = PowerLevels::Moderator;
int invite_ = PowerLevels::Moderator;
int kick_ = PowerLevels::Moderator;
int redact_ = PowerLevels::Moderator;
int events_default_ = PowerLevels::User;
int state_default_ = PowerLevels::Moderator;
int users_default_ = PowerLevels::User;
QMap<QString, int> events_;
QMap<QString, int> users_;
};
inline int PowerLevelsEventContent::banLevel() const
{
return ban_;
}
inline int PowerLevelsEventContent::inviteLevel() const
{
return invite_;
}
inline int PowerLevelsEventContent::kickLevel() const
{
return kick_;
}
inline int PowerLevelsEventContent::redactLevel() const
{
return redact_;
}
inline int PowerLevelsEventContent::eventsDefaultLevel() const
{
return events_default_;
}
inline int PowerLevelsEventContent::stateDefaultLevel() const
{
return state_default_;
}
inline int PowerLevelsEventContent::usersDefaultLevel() const
{
return users_default_;
}
#endif // POWER_LEVELS_EVENT_CONTENT_H
/*
* 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/>.
*/
#ifndef TOPIC_EVENT_CONTENT_H
#define TOPIC_EVENT_CONTENT_H
#include <QJsonValue>
#include "Deserializable.h"
/*
* A topic is a short message detailing what is currently being discussed in the room.
*/
class TopicEventContent : public Deserializable
{
public:
void deserialize(const QJsonValue &data) override;
inline QString topic() const;
private:
QString topic_;
};
inline QString TopicEventContent::topic() const
{
return topic_;
}
#endif // TOPIC_EVENT_CONTENT_H
/*
* 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"
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());
}
/*
* 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"
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_;
}
/*
* 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"
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();
}
/*
* 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"
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();
}
/*
* 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"
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());
}
/*
* 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"
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());
}
/*
* 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"
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::BanState;
else if (value == "invite")
membership_state_ = Membership::InviteState;
else if (value == "join")
membership_state_ = Membership::JoinState;
else if (value == "knock")
membership_state_ = Membership::KnockState;
else if (value == "leave")
membership_state_ = Membership::LeaveState;
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();
}
/*
* 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"
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();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment