From 79f52e3f6142afd48d30b842618ef0867072443b Mon Sep 17 00:00:00 2001 From: Kitsune Ral 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 + * + * 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 @@ -136,6 +136,7 @@ RoomEvent* RoomEvent::fromJson(const QJsonObject& obj) "m.room.canonical_alias", make, "m.room.member", make, "m.room.topic", make, + "m.room.encryption", make, /* 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 From c9dc5e12b835425f1ba5c447ddb3c3394ccac93e Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 3 Oct 2017 16:16:38 +0900 Subject: Room: cache unread indicator inside m.read content, not next to it The CS API, turns out, has a quite official extension point inside m.read event content - clients are allowed to put whatever extra data they feel reasonable. --- events/receiptevent.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'events') diff --git a/events/receiptevent.cpp b/events/receiptevent.cpp index 3d6be9f1..646bb989 100644 --- a/events/receiptevent.cpp +++ b/events/receiptevent.cpp @@ -66,6 +66,11 @@ ReceiptEvent::ReceiptEvent(const QJsonObject& obj) } _eventsWithReceipts.push_back({eventIt.key(), receipts}); } - _unreadMessages = obj["x-qmatrixclient.unread_messages"].toBool(); + static const auto UnreadMsgsKey = + QStringLiteral("x-qmatrixclient.unread_messages"); + if (contents.contains(UnreadMsgsKey)) + _unreadMessages = contents["x-qmatrixclient.unread_messages"].toBool(); + else + _unreadMessages = obj["x-qmatrixclient.unread_messages"].toBool(); } -- cgit v1.2.3