aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/events/roomcreateevent.cpp29
-rw-r--r--lib/events/roomcreateevent.h32
2 files changed, 33 insertions, 28 deletions
diff --git a/lib/events/roomcreateevent.cpp b/lib/events/roomcreateevent.cpp
index 635efb92..8fd0f1de 100644
--- a/lib/events/roomcreateevent.cpp
+++ b/lib/events/roomcreateevent.cpp
@@ -20,19 +20,26 @@
using namespace QMatrixClient;
-RoomCreateDetails::RoomCreateDetails(const QJsonObject& json)
- : federated(fromJson<bool>(json["m.federate"_ls]))
- , version(fromJson<QString>(json["room_version"_ls]))
+bool RoomCreateEvent::isFederated() const
{
- const auto predecessorJson = json["predecessor"_ls].toObject();
- if (!predecessorJson.isEmpty())
- {
- fromJson(predecessorJson["room_id"_ls], predRoomId);
- fromJson(predecessorJson["event_id"_ls], predEventId);
- }
+ return fromJson<bool>(contentJson()["m.federate"_ls]);
}
-std::pair<QString, QString> RoomCreateEvent::predecessor() const
+QString RoomCreateEvent::version() const
{
- return { content().predRoomId, content().predEventId };
+ return fromJson<QString>(contentJson()["room_version"_ls]);
+}
+
+RoomCreateEvent::Predecessor RoomCreateEvent::predecessor() const
+{
+ const auto predJson = contentJson()["predecessor"_ls].toObject();
+ return {
+ fromJson<QString>(predJson["room_id"_ls]),
+ fromJson<QString>(predJson["event_id"_ls])
+ };
+}
+
+bool RoomCreateEvent::isUpgrade() const
+{
+ return contentJson().contains("predecessor"_ls);
}
diff --git a/lib/events/roomcreateevent.h b/lib/events/roomcreateevent.h
index d93668f9..0a8f27cc 100644
--- a/lib/events/roomcreateevent.h
+++ b/lib/events/roomcreateevent.h
@@ -22,30 +22,28 @@
namespace QMatrixClient
{
- class RoomCreateDetails
- {
- public:
- explicit RoomCreateDetails(const QJsonObject& json);
-
- bool federated;
- QString version;
- QString predRoomId;
- QString predEventId;
- };
-
- class RoomCreateEvent : public StateEvent<const RoomCreateDetails>
+ class RoomCreateEvent : public StateEventBase
{
public:
DEFINE_EVENT_TYPEID("m.room.create", RoomCreateEvent)
+ explicit RoomCreateEvent()
+ : StateEventBase(typeId(), matrixTypeId())
+ { }
explicit RoomCreateEvent(const QJsonObject& obj)
- : StateEvent(typeId(), obj)
+ : StateEventBase(typeId(), obj)
{ }
- bool isFederated() const { return content().federated; }
- QString version() const { return content().version; }
- std::pair<QString, QString> predecessor() const;
- bool isUpgrade() const { return !content().predRoomId.isEmpty(); }
+ struct Predecessor
+ {
+ QString roomId;
+ QString eventId;
+ };
+
+ bool isFederated() const;
+ QString version() const;
+ Predecessor predecessor() const;
+ bool isUpgrade() const;
};
REGISTER_EVENT_TYPE(RoomCreateEvent)
}