aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTobias Fella <fella@posteo.de>2021-09-13 16:05:46 +0200
committerTobias Fella <fella@posteo.de>2021-09-14 15:29:08 +0200
commit59c9ca720093f2931c2eee1c0d5806d7e2e0c85f (patch)
tree3037646a06e50e3c4dedf8ac64a498e04e2b84d4 /lib
parenta76ed82eb298d30c7b654c74378f93a9a35580a6 (diff)
downloadlibquotient-59c9ca720093f2931c2eee1c0d5806d7e2e0c85f.tar.gz
libquotient-59c9ca720093f2931c2eee1c0d5806d7e2e0c85f.zip
Add room types to RoomCreateEvent
Diffstat (limited to 'lib')
-rw-r--r--lib/events/roomcreateevent.cpp21
-rw-r--r--lib/events/roomcreateevent.h2
-rw-r--r--lib/quotient_common.h10
3 files changed, 33 insertions, 0 deletions
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<RoomType> {
+ 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<bool>(contentJson()["m.federate"_ls]);
@@ -26,3 +42,8 @@ bool RoomCreateEvent::isUpgrade() const
{
return contentJson().contains("predecessor"_ls);
}
+
+RoomType RoomCreateEvent::roomType() const
+{
+ return fromJson<RoomType>(contentJson()["type"_ls]);
+}
diff --git a/lib/events/roomcreateevent.h b/lib/events/roomcreateevent.h
index 05e623ed..b3ad287c 100644
--- a/lib/events/roomcreateevent.h
+++ b/lib/events/roomcreateevent.h
@@ -4,6 +4,7 @@
#pragma once
#include "stateevent.h"
+#include "quotient_common.h"
namespace Quotient {
class RoomCreateEvent : public StateEventBase {
@@ -24,6 +25,7 @@ public:
QString version() const;
Predecessor predecessor() const;
bool isUpgrade() const;
+ RoomType roomType() const;
};
REGISTER_EVENT_TYPE(RoomCreateEvent)
} // namespace Quotient
diff --git a/lib/quotient_common.h b/lib/quotient_common.h
index bb2e6a6b..4444a111 100644
--- a/lib/quotient_common.h
+++ b/lib/quotient_common.h
@@ -88,6 +88,16 @@ enum UriResolveResult : short {
};
Q_ENUM_NS(UriResolveResult)
+enum RoomType {
+ Space,
+ Undefined,
+};
+Q_ENUM_NS(RoomType);
+
+constexpr inline auto RoomTypeStrings = make_array(
+ "m.space"
+);
+
} // namespace Quotient
Q_DECLARE_OPERATORS_FOR_FLAGS(Quotient::MembershipMask)
Q_DECLARE_OPERATORS_FOR_FLAGS(Quotient::JoinStates)