aboutsummaryrefslogtreecommitdiff
path: root/lib/events
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-01-05 13:58:47 +0100
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-05-08 17:43:58 +0200
commit4070706fcc91cd46054b00c5f3a267a9d8c44fb7 (patch)
tree982d14ed069580596af9b690d83b950b8700781e /lib/events
parentd271a171dbec4068e43e8f711d5d2e966a2072ac (diff)
downloadlibquotient-4070706fcc91cd46054b00c5f3a267a9d8c44fb7.tar.gz
libquotient-4070706fcc91cd46054b00c5f3a267a9d8c44fb7.zip
Event content: provide toJson() instead of deriving from EC::Base
EventContent::Base has been made primarily for the sake of dynamic polymorphism needed within RoomMessageEvent content (arguably, it might not be really needed even there, but that's a bigger matter for another time). When that polymorphism is not needed, it's easier for reading and maintenance to have toJson() member function (or even specialise JsonConverter<> outside of the content structure) instead of deriving from EC::Base and then still having fillJson() member function. This commit removes EventContent::Base dependency where it's not beneficial.
Diffstat (limited to 'lib/events')
-rw-r--r--lib/events/encryptionevent.cpp4
-rw-r--r--lib/events/encryptionevent.h8
-rw-r--r--lib/events/roommemberevent.cpp6
-rw-r--r--lib/events/roommemberevent.h7
-rw-r--r--lib/events/roompowerlevelsevent.cpp10
-rw-r--r--lib/events/roompowerlevelsevent.h8
6 files changed, 19 insertions, 24 deletions
diff --git a/lib/events/encryptionevent.cpp b/lib/events/encryptionevent.cpp
index 47b0a032..6e994cd4 100644
--- a/lib/events/encryptionevent.cpp
+++ b/lib/events/encryptionevent.cpp
@@ -47,10 +47,12 @@ EncryptionEventContent::EncryptionEventContent(EncryptionType et)
}
}
-void EncryptionEventContent::fillJson(QJsonObject& o) const
+QJsonObject EncryptionEventContent::toJson() const
{
+ QJsonObject o;
if (encryption != EncryptionType::Undefined)
o.insert(AlgorithmKey, algorithm);
o.insert(RotationPeriodMsKey, rotationPeriodMs);
o.insert(RotationPeriodMsgsKey, rotationPeriodMsgs);
+ return o;
}
diff --git a/lib/events/encryptionevent.h b/lib/events/encryptionevent.h
index fe76b1af..5b5420ec 100644
--- a/lib/events/encryptionevent.h
+++ b/lib/events/encryptionevent.h
@@ -4,12 +4,11 @@
#pragma once
-#include "eventcontent.h"
#include "stateevent.h"
#include "quotient_common.h"
namespace Quotient {
-class QUOTIENT_API EncryptionEventContent : public EventContent::Base {
+class QUOTIENT_API EncryptionEventContent {
public:
enum EncryptionType : size_t { MegolmV1AesSha2 = 0, Undefined };
@@ -20,13 +19,12 @@ public:
{}
explicit EncryptionEventContent(const QJsonObject& json);
+ QJsonObject toJson() const;
+
EncryptionType encryption;
QString algorithm;
int rotationPeriodMs;
int rotationPeriodMsgs;
-
-protected:
- void fillJson(QJsonObject& o) const override;
};
using EncryptionType = EncryptionEventContent::EncryptionType;
diff --git a/lib/events/roommemberevent.cpp b/lib/events/roommemberevent.cpp
index 55da5809..c3be0e00 100644
--- a/lib/events/roommemberevent.cpp
+++ b/lib/events/roommemberevent.cpp
@@ -4,8 +4,6 @@
#include "roommemberevent.h"
-#include "logging.h"
-
#include <QtCore/QtAlgorithms>
namespace Quotient {
@@ -43,8 +41,9 @@ MemberEventContent::MemberEventContent(const QJsonObject& json)
displayName = sanitized(*displayName);
}
-void MemberEventContent::fillJson(QJsonObject& o) const
+QJsonObject MemberEventContent::toJson() const
{
+ QJsonObject o;
if (membership != Membership::Invalid)
o.insert(QStringLiteral("membership"),
MembershipStrings[qCountTrailingZeroBits(
@@ -55,6 +54,7 @@ void MemberEventContent::fillJson(QJsonObject& o) const
o.insert(QStringLiteral("avatar_url"), avatarUrl->toString());
if (!reason.isEmpty())
o.insert(QStringLiteral("reason"), reason);
+ return o;
}
bool RoomMemberEvent::changesMembership() const
diff --git a/lib/events/roommemberevent.h b/lib/events/roommemberevent.h
index afbaf825..dd33ea6b 100644
--- a/lib/events/roommemberevent.h
+++ b/lib/events/roommemberevent.h
@@ -5,18 +5,18 @@
#pragma once
-#include "eventcontent.h"
#include "stateevent.h"
#include "quotient_common.h"
namespace Quotient {
-class QUOTIENT_API MemberEventContent : public EventContent::Base {
+class QUOTIENT_API MemberEventContent {
public:
using MembershipType
[[deprecated("Use Quotient::Membership instead")]] = Membership;
QUO_IMPLICIT MemberEventContent(Membership ms) : membership(ms) {}
explicit MemberEventContent(const QJsonObject& json);
+ QJsonObject toJson() const;
Membership membership;
/// (Only for invites) Whether the invite is to a direct chat
@@ -24,9 +24,6 @@ public:
Omittable<QString> displayName;
Omittable<QUrl> avatarUrl;
QString reason;
-
-protected:
- void fillJson(QJsonObject& o) const override;
};
using MembershipType [[deprecated("Use Membership instead")]] = Membership;
diff --git a/lib/events/roompowerlevelsevent.cpp b/lib/events/roompowerlevelsevent.cpp
index 1c87fd47..84a31d55 100644
--- a/lib/events/roompowerlevelsevent.cpp
+++ b/lib/events/roompowerlevelsevent.cpp
@@ -3,8 +3,6 @@
#include "roompowerlevelsevent.h"
-#include <QJsonDocument>
-
using namespace Quotient;
PowerLevelsEventContent::PowerLevelsEventContent(const QJsonObject& json) :
@@ -21,7 +19,9 @@ PowerLevelsEventContent::PowerLevelsEventContent(const QJsonObject& json) :
{
}
-void PowerLevelsEventContent::fillJson(QJsonObject& o) const {
+QJsonObject PowerLevelsEventContent::toJson() const
+{
+ QJsonObject o;
o.insert(QStringLiteral("invite"), invite);
o.insert(QStringLiteral("kick"), kick);
o.insert(QStringLiteral("ban"), ban);
@@ -31,7 +31,9 @@ void PowerLevelsEventContent::fillJson(QJsonObject& o) const {
o.insert(QStringLiteral("state_default"), stateDefault);
o.insert(QStringLiteral("users"), Quotient::toJson(users));
o.insert(QStringLiteral("users_default"), usersDefault);
- o.insert(QStringLiteral("notifications"), QJsonObject{{"room", notifications.room}});
+ o.insert(QStringLiteral("notifications"),
+ QJsonObject { { "room", notifications.room } });
+ return o;
}
int RoomPowerLevelsEvent::powerLevelForEvent(const QString &eventId) const {
diff --git a/lib/events/roompowerlevelsevent.h b/lib/events/roompowerlevelsevent.h
index 3ce83763..a1638a27 100644
--- a/lib/events/roompowerlevelsevent.h
+++ b/lib/events/roompowerlevelsevent.h
@@ -3,17 +3,16 @@
#pragma once
-#include "eventcontent.h"
#include "stateevent.h"
namespace Quotient {
-class QUOTIENT_API PowerLevelsEventContent : public EventContent::Base {
-public:
+struct QUOTIENT_API PowerLevelsEventContent {
struct Notifications {
int room;
};
explicit PowerLevelsEventContent(const QJsonObject& json);
+ QJsonObject toJson() const;
int invite;
int kick;
@@ -29,9 +28,6 @@ public:
int usersDefault;
Notifications notifications;
-
-protected:
- void fillJson(QJsonObject& o) const override;
};
class QUOTIENT_API RoomPowerLevelsEvent