| 1 | // SPDX-FileCopyrightText: 2022 Kitsune Ral <kitsune-ral@users.sf.net> |
|---|---|
| 2 | // SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 | |
| 4 | #include "eventrelation.h" |
| 5 | |
| 6 | #include "../logging_categories_p.h" |
| 7 | #include "event.h" |
| 8 | |
| 9 | using namespace Quotient; |
| 10 | |
| 11 | void JsonObjectConverter<EventRelation>::dumpTo(QJsonObject& jo, |
| 12 | const EventRelation& pod) |
| 13 | { |
| 14 | if (pod.type.isEmpty()) { |
| 15 | qCWarning(MAIN) << "Empty relation type; won't dump to JSON"; |
| 16 | return; |
| 17 | } |
| 18 | jo.insert(key: RelTypeKey, value: pod.type); |
| 19 | jo.insert(key: EventIdKey, value: pod.eventId); |
| 20 | if (pod.type == EventRelation::AnnotationType) |
| 21 | jo.insert(QStringLiteral("key"), value: pod.key); |
| 22 | } |
| 23 | |
| 24 | void JsonObjectConverter<EventRelation>::fillFrom(const QJsonObject& jo, |
| 25 | EventRelation& pod) |
| 26 | { |
| 27 | if (const auto replyJson = jo.value(key: EventRelation::ReplyType).toObject(); |
| 28 | !replyJson.isEmpty()) { |
| 29 | pod.type = EventRelation::ReplyType; |
| 30 | fromJson(json: replyJson[EventIdKey], pod&: pod.eventId); |
| 31 | } else { |
| 32 | // The experimental logic for generic relationships (MSC1849) |
| 33 | fromJson(json: jo[RelTypeKey], pod&: pod.type); |
| 34 | fromJson(json: jo[EventIdKey], pod&: pod.eventId); |
| 35 | if (pod.type == EventRelation::AnnotationType) |
| 36 | fromJson(json: jo["key"_ls], pod&: pod.key); |
| 37 | } |
| 38 | } |
| 39 |