blob: 305dd45436e37f71a98b1929889584a4dee35a99 (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// SPDX-FileCopyrightText: 2016 Kitsune Ral <Kitsune-Ral@users.sf.net>
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "event.h"
#include "logging.h"
#include <QtCore/QJsonDocument>
using namespace Quotient;
void Quotient::logFactorySetup(event_mtype_t eventTypeId)
{
qCDebug(EVENTS) << "Adding factory method for" << eventTypeId;
}
event_type_t EventTypeRegistry::initializeTypeId(event_mtype_t matrixTypeId)
{
const auto id = get().eventTypes.size();
get().eventTypes.push_back(matrixTypeId);
if (strncmp(matrixTypeId, "", 1) == 0)
qCDebug(EVENTS) << "Initialized unknown event type with id" << id;
else
qCDebug(EVENTS) << "Initialized event type" << matrixTypeId << "with id"
<< id;
return id;
}
QString EventTypeRegistry::getMatrixType(event_type_t typeId)
{
return typeId < get().eventTypes.size() ? get().eventTypes[typeId]
: QString();
}
Event::Event(Type type, const QJsonObject& json) : _type(type), _json(json)
{
if (!json.contains(ContentKeyL)
&& !json.value(UnsignedKeyL).toObject().contains(RedactedCauseKeyL)) {
qCWarning(EVENTS) << "Event without 'content' node";
qCWarning(EVENTS) << formatJson << json;
}
}
Event::Event(Type type, event_mtype_t matrixType, const QJsonObject& contentJson)
: Event(type, basicEventJson(matrixType, contentJson))
{}
Event::~Event() = default;
QString Event::matrixType() const { return fullJson()[TypeKeyL].toString(); }
QByteArray Event::originalJson() const { return QJsonDocument(_json).toJson(); }
// On const below: this is to catch accidental attempts to change event JSON
// NOLINTNEXTLINE(readability-const-return-type)
const QJsonObject Event::contentJson() const
{
return fullJson()[ContentKeyL].toObject();
}
// NOLINTNEXTLINE(readability-const-return-type)
const QJsonObject Event::unsignedJson() const
{
return fullJson()[UnsignedKeyL].toObject();
}
void Event::dumpTo(QDebug dbg) const
{
dbg << QJsonDocument(contentJson()).toJson(QJsonDocument::Compact);
}
|