aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-11-26 14:02:49 +0100
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-11-26 14:02:49 +0100
commitb3d62050befbb1c526f03e4356f3263d197c45f2 (patch)
tree37284e7f8274245d223a394975e8acf6ada63c02
parentf4a0acf818c4c89d132b2ec96d47c5817b106149 (diff)
downloadlibquotient-b3d62050befbb1c526f03e4356f3263d197c45f2.tar.gz
libquotient-b3d62050befbb1c526f03e4356f3263d197c45f2.zip
Event: deprecate originalJson[Object]()
The "original JSON" wording is misleading: the returned JSON can be and is routinely edited as a part of event construction, redaction, editing. Also, originalJson() name is misleading in that it returns a stringified (in a very specific way) JSON and not an object. You have to call fullJson() to get the object, and originalJsonObject(), confusingly, returns exactly the same thing but as a value rather than as a reference. The original intention of keeping originalJsonObject() was to make it Q_INVOKABLE or use it as an accessor for a Q_PROPERTY. unfortunately, this was never really practical as discussed in the previous commit. All that implies that clients have to handle passing event JSON to QML themselves, in the form they prefer (as an object or a string). The added complexity is negligible though; on the other hand, there's added flexibility in, e.g., choosing a compact instead of default JSON layout or even generate a highlighted JSON representation.
-rw-r--r--lib/events/event.h3
-rw-r--r--lib/room.cpp9
2 files changed, 8 insertions, 4 deletions
diff --git a/lib/events/event.h b/lib/events/event.h
index e9963eae..52e3d025 100644
--- a/lib/events/event.h
+++ b/lib/events/event.h
@@ -210,7 +210,10 @@ public:
Type type() const { return _type; }
QString matrixType() const;
+ [[deprecated("Use fullJson() and stringify it with QJsonDocument::toJson() "
+ "or by other means")]]
QByteArray originalJson() const;
+ [[deprecated("Use fullJson() instead")]] //
QJsonObject originalJsonObject() const { return fullJson(); }
const QJsonObject& fullJson() const { return _json; }
diff --git a/lib/room.cpp b/lib/room.cpp
index 3090cb7b..aa00025c 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -1589,7 +1589,8 @@ void Room::Private::removeMemberFromMap(User* u)
inline auto makeErrorStr(const Event& e, QByteArray msg)
{
- return msg.append("; event dump follows:\n").append(e.originalJson());
+ return msg.append("; event dump follows:\n")
+ .append(QJsonDocument(e.fullJson()).toJson());
}
Room::Timeline::size_type
@@ -2363,7 +2364,7 @@ void Room::Private::dropDuplicateEvents(RoomEvents& events) const
RoomEventPtr makeRedacted(const RoomEvent& target,
const RedactionEvent& redaction)
{
- auto originalJson = target.originalJsonObject();
+ auto originalJson = target.fullJson();
// clang-format off
static const QStringList keepKeys {
EventIdKey, TypeKey, RoomIdKey, SenderKey, StateKeyKey,
@@ -2409,7 +2410,7 @@ RoomEventPtr makeRedacted(const RoomEvent& target,
originalJson.insert(ContentKey, content);
}
auto unsignedData = originalJson.take(UnsignedKeyL).toObject();
- unsignedData[RedactedCauseKeyL] = redaction.originalJsonObject();
+ unsignedData[RedactedCauseKeyL] = redaction.fullJson();
originalJson.insert(QStringLiteral("unsigned"), unsignedData);
return loadEvent<RoomEvent>(originalJson);
@@ -2479,7 +2480,7 @@ RoomEventPtr makeReplaced(const RoomEvent& target,
if (!targetReply.empty()) {
newContent["m.relates_to"] = targetReply;
}
- auto originalJson = target.originalJsonObject();
+ auto originalJson = target.fullJson();
originalJson[ContentKeyL] = newContent;
auto unsignedData = originalJson.take(UnsignedKeyL).toObject();