1// SPDX-FileCopyrightText: 2017 Kitsune Ral <kitsune-ral@users.sf.net>
2// SPDX-FileCopyrightText: 2019 Alexey Andreyev <aa13q@ya.ru>
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#pragma once
6
7#include <Quotient/quotient_common.h>
8#include "stateevent.h"
9
10namespace Quotient {
11class QUOTIENT_API EncryptionEventContent {
12public:
13 using EncryptionType
14 [[deprecated("Use Quotient::EncryptionType instead")]] =
15 Quotient::EncryptionType;
16
17 // NOLINTNEXTLINE(google-explicit-constructor)
18 QUO_IMPLICIT EncryptionEventContent(Quotient::EncryptionType et);
19 explicit EncryptionEventContent(const QJsonObject& json);
20
21 QJsonObject toJson() const;
22
23 Quotient::EncryptionType encryption;
24 QString algorithm {};
25 int rotationPeriodMs = 604'800'000;
26 int rotationPeriodMsgs = 100;
27};
28
29class QUOTIENT_API EncryptionEvent
30 : public KeylessStateEventBase<EncryptionEvent, EncryptionEventContent> {
31public:
32 QUO_EVENT(EncryptionEvent, "m.room.encryption")
33
34 using EncryptionType
35 [[deprecated("Use Quotient::EncryptionType instead")]] =
36 Quotient::EncryptionType;
37
38 using KeylessStateEventBase::KeylessStateEventBase;
39
40 Quotient::EncryptionType encryption() const { return content().encryption; }
41 QString algorithm() const { return content().algorithm; }
42 int rotationPeriodMs() const { return content().rotationPeriodMs; }
43 int rotationPeriodMsgs() const { return content().rotationPeriodMsgs; }
44
45 bool useEncryption() const { return !algorithm().isEmpty(); }
46};
47} // namespace Quotient
48