blob: e53d47d4f014d6da92dbd486c78d16f2abac4a94 (
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
|
// SPDX-FileCopyrightText: 2018 Kitsune Ral <kitsune-ral@users.sf.net>
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "stateevent.h"
using namespace Quotient;
StateEventBase::StateEventBase(Type type, const QJsonObject& json)
: RoomEvent(json.contains(StateKeyKeyL) ? type : unknownEventTypeId(), json)
{
if (Event::type() == unknownEventTypeId() && !json.contains(StateKeyKeyL))
qWarning(EVENTS) << "Attempt to create a state event with no stateKey -"
"forcing the event type to unknown to avoid damage";
}
StateEventBase::StateEventBase(Event::Type type, event_mtype_t matrixType,
const QString& stateKey,
const QJsonObject& contentJson)
: RoomEvent(type, basicStateEventJson(matrixType, contentJson, stateKey))
{}
bool StateEventBase::repeatsState() const
{
const auto prevContentJson = unsignedPart(PrevContentKeyL);
return fullJson().value(ContentKeyL) == prevContentJson;
}
QString StateEventBase::replacedState() const
{
return unsignedPart<QString>("replaces_state"_ls);
}
void StateEventBase::dumpTo(QDebug dbg) const
{
if (!stateKey().isEmpty())
dbg << '<' << stateKey() << "> ";
if (const auto prevContentJson = unsignedPart<QJsonObject>(PrevContentKeyL);
!prevContentJson.isEmpty())
dbg << QJsonDocument(prevContentJson).toJson(QJsonDocument::Compact)
<< " -> ";
RoomEvent::dumpTo(dbg);
}
|