From 79f52e3f6142afd48d30b842618ef0867072443b Mon Sep 17 00:00:00 2001
From: Kitsune Ral <Kitsune-Ral@users.sf.net>
Date: Tue, 26 Sep 2017 20:57:28 +0900
Subject: Introduce EncryptionEvent class

This allows to detect if a room has been encrypted (no room state, just
an event as of yet). Closes #84.
---
 events/encryptedevent.cpp |  5 +++++
 events/encryptedevent.h   | 39 +++++++++++++++++++++++++++++++++++++++
 events/event.cpp          |  3 ++-
 events/event.h            |  4 +++-
 4 files changed, 49 insertions(+), 2 deletions(-)
 create mode 100644 events/encryptedevent.cpp
 create mode 100644 events/encryptedevent.h

(limited to 'events')

diff --git a/events/encryptedevent.cpp b/events/encryptedevent.cpp
new file mode 100644
index 00000000..90e77c36
--- /dev/null
+++ b/events/encryptedevent.cpp
@@ -0,0 +1,5 @@
+//
+// Created by rusakov on 26/09/2017.
+//
+
+#include "encryptedevent.h"
diff --git a/events/encryptedevent.h b/events/encryptedevent.h
new file mode 100644
index 00000000..9db462e1
--- /dev/null
+++ b/events/encryptedevent.h
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * Copyright (C) 2017 Kitsune Ral <kitsune-ral@users.sf.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#pragma once
+
+#include "event.h"
+
+namespace QMatrixClient
+{
+    class EncryptionEvent : public RoomEvent
+    {
+        public:
+            explicit EncryptionEvent(const QJsonObject& obj)
+                : RoomEvent(Type::RoomEncryption, obj)
+                , _algorithm(contentJson()["algorithm"].toString())
+            { }
+
+            QString algorithm() const { return _algorithm; }
+
+        private:
+            QString _algorithm;
+    };
+}  // namespace QMatrixClient
+
diff --git a/events/event.cpp b/events/event.cpp
index d718306d..304f2af6 100644
--- a/events/event.cpp
+++ b/events/event.cpp
@@ -26,7 +26,7 @@
 #include "roomtopicevent.h"
 #include "typingevent.h"
 #include "receiptevent.h"
-#include "unknownevent.h"
+#include "encryptedevent.h"
 #include "logging.h"
 
 #include <QtCore/QJsonDocument>
@@ -136,6 +136,7 @@ RoomEvent* RoomEvent::fromJson(const QJsonObject& obj)
             "m.room.canonical_alias", make<RoomCanonicalAliasEvent>,
             "m.room.member", make<RoomMemberEvent>,
             "m.room.topic", make<RoomTopicEvent>,
+            "m.room.encryption", make<EncryptionEvent>,
             /* Insert new ROOM event types BEFORE this line */
             nullptr
         );
diff --git a/events/event.h b/events/event.h
index 7db14100..ec993522 100644
--- a/events/event.h
+++ b/events/event.h
@@ -34,7 +34,8 @@ namespace QMatrixClient
             enum class Type
             {
                 RoomMessage, RoomName, RoomAliases, RoomCanonicalAlias,
-                RoomMember, RoomTopic, Typing, Receipt, Unknown
+                RoomMember, RoomTopic, RoomEncryption, RoomEncryptedMessage,
+                Typing, Receipt, Unknown
             };
 
             explicit Event(Type type) : _type(type) { }
@@ -94,6 +95,7 @@ namespace QMatrixClient
         return evs;
     }
 
+    /** This class corresponds to m.room.* events */
     class RoomEvent : public Event
     {
             Q_GADGET
-- 
cgit v1.2.3