From 59c9ca720093f2931c2eee1c0d5806d7e2e0c85f Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 13 Sep 2021 16:05:46 +0200 Subject: Add room types to RoomCreateEvent --- lib/events/roomcreateevent.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib/events/roomcreateevent.cpp') diff --git a/lib/events/roomcreateevent.cpp b/lib/events/roomcreateevent.cpp index 6558bade..ff93041c 100644 --- a/lib/events/roomcreateevent.cpp +++ b/lib/events/roomcreateevent.cpp @@ -5,6 +5,22 @@ using namespace Quotient; +template <> +struct Quotient::JsonConverter { + static RoomType load(const QJsonValue& jv) + { + const auto& roomTypeString = jv.toString(); + for (auto it = RoomTypeStrings.begin(); it != RoomTypeStrings.end(); + ++it) + if (roomTypeString == *it) + return RoomType(it - RoomTypeStrings.begin()); + + if (!roomTypeString.isEmpty()) + qCWarning(EVENTS) << "Unknown Room Type: " << roomTypeString; + return RoomType::Undefined; + } +}; + bool RoomCreateEvent::isFederated() const { return fromJson(contentJson()["m.federate"_ls]); @@ -26,3 +42,8 @@ bool RoomCreateEvent::isUpgrade() const { return contentJson().contains("predecessor"_ls); } + +RoomType RoomCreateEvent::roomType() const +{ + return fromJson(contentJson()["type"_ls]); +} -- cgit v1.2.3 From f4a0acf818c4c89d132b2ec96d47c5817b106149 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Fri, 26 Nov 2021 13:46:58 +0100 Subject: Drop #include "logging.h" from event.h Makes compilation a tad lighter. --- lib/events/roomcreateevent.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/events/roomcreateevent.cpp') diff --git a/lib/events/roomcreateevent.cpp b/lib/events/roomcreateevent.cpp index ff93041c..e119696f 100644 --- a/lib/events/roomcreateevent.cpp +++ b/lib/events/roomcreateevent.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include "roomcreateevent.h" +#include "logging.h" using namespace Quotient; -- cgit v1.2.3 From 4ba795556721a88d2ac258d9095a46de21d77011 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Fri, 26 Nov 2021 16:07:25 +0100 Subject: Revert "Drop #include "logging.h" from event.h" Doesn't really help build times, instead breaking the build on older Qt. --- lib/events/roomcreateevent.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/events/roomcreateevent.cpp') diff --git a/lib/events/roomcreateevent.cpp b/lib/events/roomcreateevent.cpp index e119696f..ff93041c 100644 --- a/lib/events/roomcreateevent.cpp +++ b/lib/events/roomcreateevent.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include "roomcreateevent.h" -#include "logging.h" using namespace Quotient; -- cgit v1.2.3 From 0425fd280e7eee7a4c9bcf18f79910f181322c42 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sat, 27 Nov 2021 20:14:53 +0100 Subject: Event::content() -> contentPart() There's a clash between Event::content() (a template function) and RoomMessageEvent::content() (plain member). Out of these two, the name more fits to the RME's member function - strictly speaking, Event::content() retrieves a part of content, and so is renamed. In addition, contentPart() defaults to QJsonValue now, which is pretty intuitive (the function returns values from a JSON object) and allows to implement more elaborate logic such as if (const auto v = contentPart<>("key"_ls); v.isObject()) { // foo } else if (v.isString()) { // bar } else { // boo } --- lib/events/roomcreateevent.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/events/roomcreateevent.cpp') diff --git a/lib/events/roomcreateevent.cpp b/lib/events/roomcreateevent.cpp index ff93041c..bb6de648 100644 --- a/lib/events/roomcreateevent.cpp +++ b/lib/events/roomcreateevent.cpp @@ -23,17 +23,17 @@ struct Quotient::JsonConverter { bool RoomCreateEvent::isFederated() const { - return fromJson(contentJson()["m.federate"_ls]); + return contentPart("m.federate"_ls); } QString RoomCreateEvent::version() const { - return fromJson(contentJson()["room_version"_ls]); + return contentPart("room_version"_ls); } RoomCreateEvent::Predecessor RoomCreateEvent::predecessor() const { - const auto predJson = contentJson()["predecessor"_ls].toObject(); + const auto predJson = contentPart("predecessor"_ls); return { fromJson(predJson[RoomIdKeyL]), fromJson(predJson[EventIdKeyL]) }; } @@ -45,5 +45,5 @@ bool RoomCreateEvent::isUpgrade() const RoomType RoomCreateEvent::roomType() const { - return fromJson(contentJson()["type"_ls]); + return contentPart("type"_ls); } -- cgit v1.2.3