aboutsummaryrefslogtreecommitdiff
path: root/lib/events/eventrelation.h
blob: e445ee42a5d56dee22127139fa09507cfb7391f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-FileCopyrightText: 2022 Kitsune Ral <kitsune-ral@users.sf.net>
// SPDX-License-Identifier: LGPL-2.1-or-later

#pragma once

#include "converters.h"

namespace Quotient {

[[maybe_unused]] constexpr auto RelatesToKey = "m.relates_to"_ls;
constexpr auto RelTypeKey = "rel_type"_ls;

struct QUOTIENT_API EventRelation {
    using reltypeid_t = QLatin1String;

    QString type;
    QString eventId;
    QString key = {}; // Only used for m.annotation for now

    static constexpr auto ReplyType = "m.in_reply_to"_ls;
    static constexpr auto AnnotationType = "m.annotation"_ls;
    static constexpr auto ReplacementType = "m.replace"_ls;

    static EventRelation replyTo(QString eventId)
    {
        return { ReplyType, std::move(eventId) };
    }
    static EventRelation annotate(QString eventId, QString key)
    {
        return { AnnotationType, std::move(eventId), std::move(key) };
    }
    static EventRelation replace(QString eventId)
    {
        return { ReplacementType, std::move(eventId) };
    }

    [[deprecated("Use ReplyRelation variable instead")]]
    static constexpr auto Reply() { return ReplyType; }
    [[deprecated("Use AnnotationRelation variable instead")]] //
    static constexpr auto Annotation() { return AnnotationType; }
    [[deprecated("Use ReplacementRelation variable instead")]] //
    static constexpr auto Replacement() { return ReplacementType; }
};

template <>
struct QUOTIENT_API JsonObjectConverter<EventRelation> {
    static void dumpTo(QJsonObject& jo, const EventRelation& pod);
    static void fillFrom(const QJsonObject& jo, EventRelation& pod);
};

}