libQuotient
A Qt library for building matrix clients
encryptionevent.h
Go to the documentation of this file.
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 
10 namespace Quotient {
11 class QUOTIENT_API EncryptionEventContent {
12 public:
13  Q_IMPLICIT EncryptionEventContent(Quotient::EncryptionType et);
14  explicit EncryptionEventContent(const QJsonObject& json);
15 
16  QJsonObject toJson() const;
17 
18  Quotient::EncryptionType encryption;
19  QString algorithm {};
20  int rotationPeriodMs = 604'800'000;
21  int rotationPeriodMsgs = 100;
22 };
23 
24 class QUOTIENT_API EncryptionEvent
25  : public KeylessStateEventBase<EncryptionEvent, EncryptionEventContent> {
26 public:
27  QUO_EVENT(EncryptionEvent, "m.room.encryption")
28 
29  using KeylessStateEventBase::KeylessStateEventBase;
30 
31  Quotient::EncryptionType encryption() const { return content().encryption; }
32  QString algorithm() const { return content().algorithm; }
33  int rotationPeriodMs() const { return content().rotationPeriodMs; }
34  int rotationPeriodMsgs() const { return content().rotationPeriodMsgs; }
35 
36  bool useEncryption() const { return !algorithm().isEmpty(); }
37 };
38 } // namespace Quotient