1 | // SPDX-FileCopyrightText: 2018 Kitsune Ral <kitsune-ral@users.sf.net> |
2 | // SPDX-License-Identifier: LGPL-2.1-or-later |
3 | |
4 | #include "stateevent.h" |
5 | |
6 | using namespace Quotient; |
7 | |
8 | StateEvent::StateEvent(const QJsonObject& json) |
9 | : RoomEvent(json) |
10 | { |
11 | Q_ASSERT_X(json.contains(StateKeyKey), __FUNCTION__, |
12 | "Attempt to create a state event without state key" ); |
13 | } |
14 | |
15 | StateEvent::StateEvent(event_type_t type, const QString& stateKey, |
16 | const QJsonObject& contentJson) |
17 | : RoomEvent(basicJson(matrixTypeId: type, stateKey, contentJson)) |
18 | {} |
19 | |
20 | bool StateEvent::repeatsState() const |
21 | { |
22 | return contentJson() == unsignedPart<QJsonObject>(key: PrevContentKey); |
23 | } |
24 | |
25 | QString StateEvent::replacedState() const |
26 | { |
27 | return unsignedPart<QString>(key: "replaces_state"_ls ); |
28 | } |
29 | |
30 | void StateEvent::dumpTo(QDebug dbg) const |
31 | { |
32 | if (!stateKey().isEmpty()) |
33 | dbg << '<' << stateKey() << "> " ; |
34 | if (const auto prevContentJson = unsignedPart<QJsonObject>(key: PrevContentKey); |
35 | !prevContentJson.isEmpty()) |
36 | dbg << QJsonDocument(prevContentJson).toJson(format: QJsonDocument::Compact) |
37 | << " -> " ; |
38 | RoomEvent::dumpTo(dbg); |
39 | } |
40 | |