summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-05-02 04:22:33 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-05-04 17:11:04 +0300
commitb064df8b45bb4b22294d1f6691638e5a98423371 (patch)
tree4d9c3c57342e408bcc67b333f0f3958f4c929843 /include
parentmacOS fixes (#15) (diff)
downloadnheko-b064df8b45bb4b22294d1f6691638e5a98423371.tar.xz
Add event contents
Diffstat (limited to 'include')
-rw-r--r--include/events/AliasesEventContent.h42
-rw-r--r--include/events/AvatarEventContent.h46
-rw-r--r--include/events/CanonicalAliasEventContent.h49
-rw-r--r--include/events/CreateEventContent.h46
-rw-r--r--include/events/HistoryVisibilityEventContent.h48
-rw-r--r--include/events/JoinRulesEventContent.h60
-rw-r--r--include/events/MemberEventContent.h77
-rw-r--r--include/events/NameEventContent.h45
-rw-r--r--include/events/PowerLevelsEventContent.h102
-rw-r--r--include/events/TopicEventContent.h45
10 files changed, 560 insertions, 0 deletions
diff --git a/include/events/AliasesEventContent.h b/include/events/AliasesEventContent.h
new file mode 100644

index 00000000..03218715 --- /dev/null +++ b/include/events/AliasesEventContent.h
@@ -0,0 +1,42 @@ +/* + * 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 diff --git a/include/events/AvatarEventContent.h b/include/events/AvatarEventContent.h new file mode 100644
index 00000000..c77cb6d6 --- /dev/null +++ b/include/events/AvatarEventContent.h
@@ -0,0 +1,46 @@ +/* + * 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 diff --git a/include/events/CanonicalAliasEventContent.h b/include/events/CanonicalAliasEventContent.h new file mode 100644
index 00000000..3c031b8e --- /dev/null +++ b/include/events/CanonicalAliasEventContent.h
@@ -0,0 +1,49 @@ + +/* + * 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 diff --git a/include/events/CreateEventContent.h b/include/events/CreateEventContent.h new file mode 100644
index 00000000..ed1a8ce7 --- /dev/null +++ b/include/events/CreateEventContent.h
@@ -0,0 +1,46 @@ +/* + * 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 diff --git a/include/events/HistoryVisibilityEventContent.h b/include/events/HistoryVisibilityEventContent.h new file mode 100644
index 00000000..ac7316f4 --- /dev/null +++ b/include/events/HistoryVisibilityEventContent.h
@@ -0,0 +1,48 @@ +/* + * 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 diff --git a/include/events/JoinRulesEventContent.h b/include/events/JoinRulesEventContent.h new file mode 100644
index 00000000..8b647fb4 --- /dev/null +++ b/include/events/JoinRulesEventContent.h
@@ -0,0 +1,60 @@ +/* + * 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 diff --git a/include/events/MemberEventContent.h b/include/events/MemberEventContent.h new file mode 100644
index 00000000..046dda0f --- /dev/null +++ b/include/events/MemberEventContent.h
@@ -0,0 +1,77 @@ +/* + * 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 diff --git a/include/events/NameEventContent.h b/include/events/NameEventContent.h new file mode 100644
index 00000000..d6f60e2d --- /dev/null +++ b/include/events/NameEventContent.h
@@ -0,0 +1,45 @@ +/* + * 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 diff --git a/include/events/PowerLevelsEventContent.h b/include/events/PowerLevelsEventContent.h new file mode 100644
index 00000000..c2a3f1fa --- /dev/null +++ b/include/events/PowerLevelsEventContent.h
@@ -0,0 +1,102 @@ +/* + * 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 diff --git a/include/events/TopicEventContent.h b/include/events/TopicEventContent.h new file mode 100644
index 00000000..fd12de98 --- /dev/null +++ b/include/events/TopicEventContent.h
@@ -0,0 +1,45 @@ +/* + * 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