1 | // SPDX-FileCopyrightText: 2022 Kitsune Ral <kitsune-ral@users.sf.net> |
---|---|
2 | // SPDX-License-Identifier: LGPL-2.1-or-later |
3 | |
4 | #pragma once |
5 | |
6 | #include <Quotient/converters.h> |
7 | |
8 | namespace Quotient { |
9 | |
10 | constexpr inline auto RelatesToKey = "m.relates_to"_ls; |
11 | constexpr inline auto RelTypeKey = "rel_type"_ls; |
12 | |
13 | struct QUOTIENT_API EventRelation { |
14 | using reltypeid_t = QLatin1String; |
15 | |
16 | QString type; |
17 | QString eventId; |
18 | QString key = {}; // Only used for m.annotation for now |
19 | |
20 | static constexpr auto ReplyType = "m.in_reply_to"_ls; |
21 | static constexpr auto AnnotationType = "m.annotation"_ls; |
22 | static constexpr auto ReplacementType = "m.replace"_ls; |
23 | |
24 | static EventRelation replyTo(QString eventId) |
25 | { |
26 | return { .type: ReplyType, .eventId: std::move(eventId) }; |
27 | } |
28 | static EventRelation annotate(QString eventId, QString key) |
29 | { |
30 | return { .type: AnnotationType, .eventId: std::move(eventId), .key: std::move(key) }; |
31 | } |
32 | static EventRelation replace(QString eventId) |
33 | { |
34 | return { .type: ReplacementType, .eventId: std::move(eventId) }; |
35 | } |
36 | |
37 | [[deprecated("Use ReplyType variable instead")]] |
38 | static constexpr auto Reply() { return ReplyType; } |
39 | [[deprecated("Use AnnotationType variable instead")]] // |
40 | static constexpr auto Annotation() { return AnnotationType; } |
41 | [[deprecated("Use ReplacementType variable instead")]] // |
42 | static constexpr auto Replacement() { return ReplacementType; } |
43 | }; |
44 | |
45 | template <> |
46 | struct QUOTIENT_API JsonObjectConverter<EventRelation> { |
47 | static void dumpTo(QJsonObject& jo, const EventRelation& pod); |
48 | static void fillFrom(const QJsonObject& jo, EventRelation& pod); |
49 | }; |
50 | |
51 | } // namespace Quotient |
52 |