diff options
-rw-r--r-- | lib/events/accountdataevents.h | 2 | ||||
-rw-r--r-- | lib/events/callanswerevent.h | 4 | ||||
-rw-r--r-- | lib/events/callcandidatesevent.h | 6 | ||||
-rw-r--r-- | lib/events/callinviteevent.h | 4 | ||||
-rw-r--r-- | lib/events/encryptedevent.h | 12 | ||||
-rw-r--r-- | lib/events/event.h | 15 | ||||
-rw-r--r-- | lib/events/reactionevent.h | 2 | ||||
-rw-r--r-- | lib/events/redactionevent.h | 2 | ||||
-rw-r--r-- | lib/events/roomcreateevent.cpp | 8 | ||||
-rw-r--r-- | lib/events/roomevent.h | 4 | ||||
-rw-r--r-- | lib/events/roomkeyevent.h | 8 | ||||
-rw-r--r-- | lib/events/roommessageevent.cpp | 4 | ||||
-rw-r--r-- | lib/events/roomtombstoneevent.cpp | 4 | ||||
-rw-r--r-- | lib/events/stickerevent.cpp | 2 | ||||
-rw-r--r-- | lib/events/typingevent.cpp | 2 | ||||
-rw-r--r-- | lib/room.cpp | 4 |
16 files changed, 45 insertions, 38 deletions
diff --git a/lib/events/accountdataevents.h b/lib/events/accountdataevents.h index 8cea0ec8..7715d3b8 100644 --- a/lib/events/accountdataevents.h +++ b/lib/events/accountdataevents.h @@ -63,7 +63,7 @@ using TagsMap = QHash<QString, TagRecord>; {} \ auto _ContentKey() const \ { \ - return content<content_type>(#_ContentKey##_ls); \ + return contentPart<content_type>(#_ContentKey##_ls); \ } \ }; \ REGISTER_EVENT_TYPE(_Name) \ diff --git a/lib/events/callanswerevent.h b/lib/events/callanswerevent.h index 6132cb44..4c01c941 100644 --- a/lib/events/callanswerevent.h +++ b/lib/events/callanswerevent.h @@ -19,11 +19,11 @@ public: int lifetime() const { - return content<int>("lifetime"_ls); + return contentPart<int>("lifetime"_ls); } // FIXME: Omittable<>? QString sdp() const { - return contentJson()["answer"_ls].toObject().value("sdp"_ls).toString(); + return contentPart<QJsonObject>("answer"_ls).value("sdp"_ls).toString(); } }; diff --git a/lib/events/callcandidatesevent.h b/lib/events/callcandidatesevent.h index c2ccac3b..74c38f2c 100644 --- a/lib/events/callcandidatesevent.h +++ b/lib/events/callcandidatesevent.h @@ -25,17 +25,17 @@ public: QJsonArray candidates() const { - return content<QJsonArray>("candidates"_ls); + return contentPart<QJsonArray>("candidates"_ls); } QString callId() const { - return content<QString>("call_id"); + return contentPart<QString>("call_id"); } int version() const { - return content<int>("version"); + return contentPart<int>("version"); } }; diff --git a/lib/events/callinviteevent.h b/lib/events/callinviteevent.h index d3454c4f..80b7d651 100644 --- a/lib/events/callinviteevent.h +++ b/lib/events/callinviteevent.h @@ -18,11 +18,11 @@ public: int lifetime() const { - return content<int>("lifetime"_ls); + return contentPart<int>("lifetime"_ls); } // FIXME: Omittable<>? QString sdp() const { - return contentJson()["offer"_ls].toObject().value("sdp"_ls).toString(); + return contentPart<QJsonObject>("offer"_ls).value("sdp"_ls).toString(); } }; diff --git a/lib/events/encryptedevent.h b/lib/events/encryptedevent.h index 598829cd..de89a7c6 100644 --- a/lib/events/encryptedevent.h +++ b/lib/events/encryptedevent.h @@ -41,7 +41,7 @@ public: QString algorithm() const { - QString algo = content<QString>(AlgorithmKeyL); + QString algo = contentPart<QString>(AlgorithmKeyL); if (!SupportedAlgorithms.contains(algo)) { qWarning(MAIN) << "The EncryptedEvent's algorithm" << algo << "is not supported"; @@ -50,17 +50,17 @@ public: } QByteArray ciphertext() const { - return content<QString>(CiphertextKeyL).toLatin1(); + return contentPart<QString>(CiphertextKeyL).toLatin1(); } QJsonObject ciphertext(const QString& identityKey) const { - return content<QJsonObject>(CiphertextKeyL).value(identityKey).toObject(); + return contentPart<QJsonObject>(CiphertextKeyL).value(identityKey).toObject(); } - QString senderKey() const { return content<QString>(SenderKeyKeyL); } + QString senderKey() const { return contentPart<QString>(SenderKeyKeyL); } /* device_id and session_id are required with Megolm */ - QString deviceId() const { return content<QString>(DeviceIdKeyL); } - QString sessionId() const { return content<QString>(SessionIdKeyL); } + QString deviceId() const { return contentPart<QString>(DeviceIdKeyL); } + QString sessionId() const { return contentPart<QString>(SessionIdKeyL); } }; REGISTER_EVENT_TYPE(EncryptedEvent) diff --git a/lib/events/event.h b/lib/events/event.h index 89efb7f8..024e45ef 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -224,18 +224,25 @@ public: const QJsonObject contentJson() const; const QJsonObject unsignedJson() const; - template <typename T> - T content(const QString& key) const + template <typename T = QJsonValue> + const T contentPart(const QString& key) const { return fromJson<T>(contentJson()[key]); } - template <typename T> - T content(QLatin1String key) const + template <typename T = QJsonValue> + const T contentPart(QLatin1String key) const { return fromJson<T>(contentJson()[key]); } + template <typename T> + [[deprecated("Use contentPart() to get a part of the event content")]] // + T content(const QString& key) const + { + return contentPart<T>(key); + } + friend QDebug operator<<(QDebug dbg, const Event& e) { QDebugStateSaver _dss { dbg }; diff --git a/lib/events/reactionevent.h b/lib/events/reactionevent.h index 777905f2..5a2b98c4 100644 --- a/lib/events/reactionevent.h +++ b/lib/events/reactionevent.h @@ -47,7 +47,7 @@ public: explicit ReactionEvent(const QJsonObject& obj) : RoomEvent(typeId(), obj) {} EventRelation relation() const { - return content<EventRelation>(QStringLiteral("m.relates_to")); + return contentPart<EventRelation>("m.relates_to"_ls); } }; REGISTER_EVENT_TYPE(ReactionEvent) diff --git a/lib/events/redactionevent.h b/lib/events/redactionevent.h index ed560331..be20bf52 100644 --- a/lib/events/redactionevent.h +++ b/lib/events/redactionevent.h @@ -17,7 +17,7 @@ public: { return fullJson()["redacts"_ls].toString(); } - QString reason() const { return contentJson()["reason"_ls].toString(); } + QString reason() const { return contentPart<QString>("reason"_ls); } }; REGISTER_EVENT_TYPE(RedactionEvent) } // namespace Quotient 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<RoomType> { bool RoomCreateEvent::isFederated() const { - return fromJson<bool>(contentJson()["m.federate"_ls]); + return contentPart<bool>("m.federate"_ls); } QString RoomCreateEvent::version() const { - return fromJson<QString>(contentJson()["room_version"_ls]); + return contentPart<QString>("room_version"_ls); } RoomCreateEvent::Predecessor RoomCreateEvent::predecessor() const { - const auto predJson = contentJson()["predecessor"_ls].toObject(); + const auto predJson = contentPart<QJsonObject>("predecessor"_ls); return { fromJson<QString>(predJson[RoomIdKeyL]), fromJson<QString>(predJson[EventIdKeyL]) }; } @@ -45,5 +45,5 @@ bool RoomCreateEvent::isUpgrade() const RoomType RoomCreateEvent::roomType() const { - return fromJson<RoomType>(contentJson()["type"_ls]); + return contentPart<RoomType>("type"_ls); } diff --git a/lib/events/roomevent.h b/lib/events/roomevent.h index a6cd84ca..7f13f6f2 100644 --- a/lib/events/roomevent.h +++ b/lib/events/roomevent.h @@ -78,8 +78,8 @@ public: ~CallEventBase() override = default; bool isCallEvent() const override { return true; } - QString callId() const { return content<QString>("call_id"_ls); } - int version() const { return content<int>("version"_ls); } + QString callId() const { return contentPart<QString>("call_id"_ls); } + int version() const { return contentPart<int>("version"_ls); } }; } // namespace Quotient Q_DECLARE_METATYPE(Quotient::RoomEvent*) diff --git a/lib/events/roomkeyevent.h b/lib/events/roomkeyevent.h index 14e80324..d021fbec 100644 --- a/lib/events/roomkeyevent.h +++ b/lib/events/roomkeyevent.h @@ -13,10 +13,10 @@ public: explicit RoomKeyEvent(const QJsonObject& obj); - QString algorithm() const { return content<QString>("algorithm"_ls); } - QString roomId() const { return content<QString>(RoomIdKeyL); } - QString sessionId() const { return content<QString>("session_id"_ls); } - QString sessionKey() const { return content<QString>("session_key"_ls); } + QString algorithm() const { return contentPart<QString>("algorithm"_ls); } + QString roomId() const { return contentPart<QString>(RoomIdKeyL); } + QString sessionId() const { return contentPart<QString>("session_id"_ls); } + QString sessionKey() const { return contentPart<QString>("session_key"_ls); } }; REGISTER_EVENT_TYPE(RoomKeyEvent) } // namespace Quotient diff --git a/lib/events/roommessageevent.cpp b/lib/events/roommessageevent.cpp index 9b46594e..2b7b4166 100644 --- a/lib/events/roommessageevent.cpp +++ b/lib/events/roommessageevent.cpp @@ -204,12 +204,12 @@ RoomMessageEvent::MsgType RoomMessageEvent::msgtype() const QString RoomMessageEvent::rawMsgtype() const { - return contentJson()[MsgTypeKeyL].toString(); + return contentPart<QString>(MsgTypeKeyL); } QString RoomMessageEvent::plainBody() const { - return contentJson()[BodyKeyL].toString(); + return contentPart<QString>(BodyKeyL); } QMimeType RoomMessageEvent::mimeType() const diff --git a/lib/events/roomtombstoneevent.cpp b/lib/events/roomtombstoneevent.cpp index 080d269c..2c3492d6 100644 --- a/lib/events/roomtombstoneevent.cpp +++ b/lib/events/roomtombstoneevent.cpp @@ -7,10 +7,10 @@ using namespace Quotient; QString RoomTombstoneEvent::serverMessage() const { - return fromJson<QString>(contentJson()["body"_ls]); + return contentPart<QString>("body"_ls); } QString RoomTombstoneEvent::successorRoomId() const { - return fromJson<QString>(contentJson()["replacement_room"_ls]); + return contentPart<QString>("replacement_room"_ls); } diff --git a/lib/events/stickerevent.cpp b/lib/events/stickerevent.cpp index ea4dff3f..628fd154 100644 --- a/lib/events/stickerevent.cpp +++ b/lib/events/stickerevent.cpp @@ -12,7 +12,7 @@ StickerEvent::StickerEvent(const QJsonObject &obj) QString StickerEvent::body() const { - return content<QString>("body"_ls); + return contentPart<QString>("body"_ls); } const EventContent::ImageContent &StickerEvent::image() const diff --git a/lib/events/typingevent.cpp b/lib/events/typingevent.cpp index e97e978f..7e5d7ee6 100644 --- a/lib/events/typingevent.cpp +++ b/lib/events/typingevent.cpp @@ -7,5 +7,5 @@ using namespace Quotient; QStringList TypingEvent::users() const { - return fromJson<QStringList>(contentJson()["user_ids"_ls]); + return contentPart<QStringList>("user_ids"_ls); } diff --git a/lib/room.cpp b/lib/room.cpp index fac24e5e..8f430ccd 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -2507,8 +2507,8 @@ bool Room::Private::processRedaction(const RedactionEvent& redaction) RoomEventPtr makeReplaced(const RoomEvent& target, const RoomMessageEvent& replacement) { - const auto &targetReply = target.contentJson()["m.relates_to"].toObject(); - auto newContent = replacement.contentJson().value("m.new_content"_ls).toObject(); + const auto& targetReply = target.contentPart<QJsonObject>("m.relates_to"); + auto newContent = replacement.contentPart<QJsonObject>("m.new_content"_ls); if (!targetReply.empty()) { newContent["m.relates_to"] = targetReply; } |