From aacc4bcb4a487871daae6717f77605aaba444341 Mon Sep 17 00:00:00 2001 From: Marc Deop Date: Sat, 2 Mar 2019 12:26:57 +0100 Subject: style: apply .clang-format to all .cpp and .h files --- lib/events/roommessageevent.h | 183 ++++++++++++++++++++++-------------------- 1 file changed, 95 insertions(+), 88 deletions(-) (limited to 'lib/events/roommessageevent.h') diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index c2e075eb..bd1b7c83 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -13,88 +13,94 @@ * * 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #pragma once -#include "roomevent.h" #include "eventcontent.h" +#include "roomevent.h" class QFileInfo; -namespace QMatrixClient -{ +namespace QMatrixClient { namespace MessageEventContent = EventContent; // Back-compatibility /** * The event class corresponding to m.room.message events */ - class RoomMessageEvent: public RoomEvent + class RoomMessageEvent : public RoomEvent { - Q_GADGET - Q_PROPERTY(QString msgType READ rawMsgtype CONSTANT) - Q_PROPERTY(QString plainBody READ plainBody CONSTANT) - Q_PROPERTY(QMimeType mimeType READ mimeType STORED false CONSTANT) - Q_PROPERTY(EventContent::TypedBase* content READ content CONSTANT) + Q_GADGET + Q_PROPERTY(QString msgType READ rawMsgtype CONSTANT) + Q_PROPERTY(QString plainBody READ plainBody CONSTANT) + Q_PROPERTY(QMimeType mimeType READ mimeType STORED false CONSTANT) + Q_PROPERTY(EventContent::TypedBase* content READ content CONSTANT) public: - DEFINE_EVENT_TYPEID("m.room.message", RoomMessageEvent) + DEFINE_EVENT_TYPEID("m.room.message", RoomMessageEvent) + + enum class MsgType { + Text, + Emote, + Notice, + Image, + File, + Location, + Video, + Audio, + Unknown + }; - enum class MsgType - { - Text, Emote, Notice, Image, File, Location, Video, Audio, Unknown - }; - - RoomMessageEvent(const QString& plainBody, - const QString& jsonMsgType, - EventContent::TypedBase* content = nullptr); - explicit RoomMessageEvent(const QString& plainBody, - MsgType msgType = MsgType::Text, - EventContent::TypedBase* content = nullptr); - explicit RoomMessageEvent(const QString& plainBody, - const QFileInfo& file, - bool asGenericFile = false); - explicit RoomMessageEvent(const QJsonObject& obj); - - MsgType msgtype() const; - QString rawMsgtype() const; - QString plainBody() const; - EventContent::TypedBase* content() const - { return _content.data(); } - template - void editContent(VisitorT visitor) - { - visitor(*_content); - editJson()[ContentKeyL] = + RoomMessageEvent(const QString& plainBody, const QString& jsonMsgType, + EventContent::TypedBase* content = nullptr); + explicit RoomMessageEvent(const QString& plainBody, + MsgType msgType = MsgType::Text, + EventContent::TypedBase* content = nullptr); + explicit RoomMessageEvent(const QString& plainBody, + const QFileInfo& file, + bool asGenericFile = false); + explicit RoomMessageEvent(const QJsonObject& obj); + + MsgType msgtype() const; + QString rawMsgtype() const; + QString plainBody() const; + EventContent::TypedBase* content() const { return _content.data(); } + template void editContent(VisitorT visitor) + { + visitor(*_content); + editJson()[ContentKeyL] = assembleContentJson(plainBody(), rawMsgtype(), content()); - } - QMimeType mimeType() const; - bool hasTextContent() const; - bool hasFileContent() const; - bool hasThumbnail() const; + } + QMimeType mimeType() const; + bool hasTextContent() const; + bool hasFileContent() const; + bool hasThumbnail() const; - static QString rawMsgTypeForUrl(const QUrl& url); - static QString rawMsgTypeForFile(const QFileInfo& fi); + static QString rawMsgTypeForUrl(const QUrl& url); + static QString rawMsgTypeForFile(const QFileInfo& fi); private: - QScopedPointer _content; + QScopedPointer _content; - static QJsonObject assembleContentJson(const QString& plainBody, - const QString& jsonMsgType, EventContent::TypedBase* content); + static QJsonObject + assembleContentJson(const QString& plainBody, + const QString& jsonMsgType, + EventContent::TypedBase* content); - REGISTER_ENUM(MsgType) + REGISTER_ENUM(MsgType) }; REGISTER_EVENT_TYPE(RoomMessageEvent) DEFINE_EVENTTYPE_ALIAS(RoomMessage, RoomMessageEvent) using MessageEventType = RoomMessageEvent::MsgType; - namespace EventContent - { + namespace EventContent { // Additional event content types - struct RelatesTo - { - static constexpr const char* ReplyTypeId() { return "m.in_reply_to"; } + struct RelatesTo { + static constexpr const char* ReplyTypeId() + { + return "m.in_reply_to"; + } QString type; // The only supported relation so far QString eventId; }; @@ -109,21 +115,21 @@ namespace QMatrixClient * Available fields: mimeType, body. The body can be either rich text * or plain text, depending on what mimeType specifies. */ - class TextContent: public TypedBase + class TextContent : public TypedBase { public: - TextContent(const QString& text, const QString& contentType, - Omittable relatesTo = none); - explicit TextContent(const QJsonObject& json); + TextContent(const QString& text, const QString& contentType, + Omittable relatesTo = none); + explicit TextContent(const QJsonObject& json); - QMimeType type() const override { return mimeType; } + QMimeType type() const override { return mimeType; } - QMimeType mimeType; - QString body; - Omittable relatesTo; + QMimeType mimeType; + QString body; + Omittable relatesTo; protected: - void fillJson(QJsonObject* json) const override; + void fillJson(QJsonObject* json) const override; }; /** @@ -139,47 +145,47 @@ namespace QMatrixClient * - thumbnail.mimeType * - thumbnail.imageSize */ - class LocationContent: public TypedBase + class LocationContent : public TypedBase { public: - LocationContent(const QString& geoUri, - const Thumbnail& thumbnail = {}); - explicit LocationContent(const QJsonObject& json); + LocationContent(const QString& geoUri, + const Thumbnail& thumbnail = {}); + explicit LocationContent(const QJsonObject& json); - QMimeType type() const override; + QMimeType type() const override; public: - QString geoUri; - Thumbnail thumbnail; + QString geoUri; + Thumbnail thumbnail; protected: - void fillJson(QJsonObject* o) const override; + void fillJson(QJsonObject* o) const override; }; /** * A base class for info types that include duration: audio and video */ - template - class PlayableContent : public ContentT + template class PlayableContent : public ContentT { public: - using ContentT::ContentT; - PlayableContent(const QJsonObject& json) - : ContentT(json) - , duration(ContentT::originalInfoJson["duration"_ls].toInt()) - { } + using ContentT::ContentT; + PlayableContent(const QJsonObject& json) + : ContentT(json), + duration(ContentT::originalInfoJson["duration"_ls].toInt()) + { + } protected: - void fillJson(QJsonObject* json) const override - { - ContentT::fillJson(json); - auto infoJson = json->take("info"_ls).toObject(); - infoJson.insert(QStringLiteral("duration"), duration); - json->insert(QStringLiteral("info"), infoJson); - } + void fillJson(QJsonObject* json) const override + { + ContentT::fillJson(json); + auto infoJson = json->take("info"_ls).toObject(); + infoJson.insert(QStringLiteral("duration"), duration); + json->insert(QStringLiteral("info"), infoJson); + } public: - int duration; + int duration; }; /** @@ -201,7 +207,8 @@ namespace QMatrixClient * - mimeType * - imageSize */ - using VideoContent = PlayableContent>; + using VideoContent = + PlayableContent>; /** * Content class for m.audio @@ -216,5 +223,5 @@ namespace QMatrixClient * - duration */ using AudioContent = PlayableContent>; - } // namespace EventContent -} // namespace QMatrixClient + } // namespace EventContent +} // namespace QMatrixClient -- cgit v1.2.3 From b87097866f38b90f36fb216b7516a135227930a1 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 13 Jul 2019 22:43:47 +0900 Subject: Initial support for edited messages (receive only) --- lib/events/roommessageevent.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/events/roommessageevent.h') diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index c2e075eb..7320e4ea 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -72,6 +72,7 @@ namespace QMatrixClient bool hasTextContent() const; bool hasFileContent() const; bool hasThumbnail() const; + QString replacedEvent() const; static QString rawMsgTypeForUrl(const QUrl& url); static QString rawMsgTypeForFile(const QFileInfo& fi); @@ -79,6 +80,7 @@ namespace QMatrixClient private: QScopedPointer _content; + // FIXME: should it really be static? static QJsonObject assembleContentJson(const QString& plainBody, const QString& jsonMsgType, EventContent::TypedBase* content); @@ -95,6 +97,7 @@ namespace QMatrixClient struct RelatesTo { static constexpr const char* ReplyTypeId() { return "m.in_reply_to"; } + static constexpr const char* ReplacementTypeId() { return "m.replace"; } QString type; // The only supported relation so far QString eventId; }; -- cgit v1.2.3 From c05ade838f0fce81f2bbe80a3295618a8a26ff52 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 2 Aug 2019 19:59:40 +0900 Subject: Apply the new brace wrapping to source files --- lib/events/roommessageevent.h | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'lib/events/roommessageevent.h') diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index 1f1fde41..c7a5cb47 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -23,15 +23,13 @@ class QFileInfo; -namespace QMatrixClient -{ +namespace QMatrixClient { namespace MessageEventContent = EventContent; // Back-compatibility /** * The event class corresponding to m.room.message events */ -class RoomMessageEvent : public RoomEvent -{ +class RoomMessageEvent : public RoomEvent { Q_GADGET Q_PROPERTY(QString msgType READ rawMsgtype CONSTANT) Q_PROPERTY(QString plainBody READ plainBody CONSTANT) @@ -40,8 +38,7 @@ class RoomMessageEvent : public RoomEvent public: DEFINE_EVENT_TYPEID("m.room.message", RoomMessageEvent) - enum class MsgType - { + enum class MsgType { Text, Emote, Notice, @@ -96,12 +93,10 @@ REGISTER_EVENT_TYPE(RoomMessageEvent) DEFINE_EVENTTYPE_ALIAS(RoomMessage, RoomMessageEvent) using MessageEventType = RoomMessageEvent::MsgType; -namespace EventContent -{ +namespace EventContent { // Additional event content types - struct RelatesTo - { + struct RelatesTo { static constexpr const char* ReplyTypeId() { return "m.in_reply_to"; } static constexpr const char* ReplacementTypeId() { return "m.replace"; } QString type; // The only supported relation so far @@ -118,8 +113,7 @@ namespace EventContent * Available fields: mimeType, body. The body can be either rich text * or plain text, depending on what mimeType specifies. */ - class TextContent : public TypedBase - { + class TextContent : public TypedBase { public: TextContent(const QString& text, const QString& contentType, Omittable relatesTo = none); @@ -148,8 +142,7 @@ namespace EventContent * - thumbnail.mimeType * - thumbnail.imageSize */ - class LocationContent : public TypedBase - { + class LocationContent : public TypedBase { public: LocationContent(const QString& geoUri, const Thumbnail& thumbnail = {}); explicit LocationContent(const QJsonObject& json); @@ -168,8 +161,7 @@ namespace EventContent * A base class for info types that include duration: audio and video */ template - class PlayableContent : public ContentT - { + class PlayableContent : public ContentT { public: using ContentT::ContentT; PlayableContent(const QJsonObject& json) -- cgit v1.2.3 From 27ca32a1e5a56e09b9cc1d94224d2831004dcf3d Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 7 Jul 2019 19:32:34 +0900 Subject: Namespace: QMatrixClient -> Quotient (with back comp alias) --- lib/events/roommessageevent.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/events/roommessageevent.h') diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index c7a5cb47..aa515c71 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -23,7 +23,7 @@ class QFileInfo; -namespace QMatrixClient { +namespace Quotient { namespace MessageEventContent = EventContent; // Back-compatibility /** @@ -217,4 +217,4 @@ namespace EventContent { */ using AudioContent = PlayableContent>; } // namespace EventContent -} // namespace QMatrixClient +} // namespace Quotient -- cgit v1.2.3 From 9ce16ef3123d5e63b931cafefb7dba4e894fc82b Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 11 Aug 2019 13:18:40 +0900 Subject: Drop EventType namespace and DEFINE_EVENTTYPE_ALIAS macro They've been deprecated for almost a year by now. --- lib/events/roommessageevent.h | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/events/roommessageevent.h') diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index aa515c71..d0dbbfb3 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -90,7 +90,6 @@ private: REGISTER_ENUM(MsgType) }; REGISTER_EVENT_TYPE(RoomMessageEvent) -DEFINE_EVENTTYPE_ALIAS(RoomMessage, RoomMessageEvent) using MessageEventType = RoomMessageEvent::MsgType; namespace EventContent { -- cgit v1.2.3 From e9ae0d5eaac12a276ea352f1e633fb22cdd46828 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 11 Aug 2019 17:01:41 +0900 Subject: Now that we're C++17, remove old compatibility cruft --- lib/events/roommessageevent.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/events/roommessageevent.h') diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index d0dbbfb3..b393382a 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -87,7 +87,7 @@ private: const QString& jsonMsgType, EventContent::TypedBase* content); - REGISTER_ENUM(MsgType) + Q_ENUM(MsgType) }; REGISTER_EVENT_TYPE(RoomMessageEvent) using MessageEventType = RoomMessageEvent::MsgType; -- cgit v1.2.3 From e997f214562acf30ae8d4ea7132dde6e583ac6fe Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 23 Aug 2019 08:09:28 +0900 Subject: RoomMessageEvent::content(): constify event content --- lib/events/roommessageevent.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/events/roommessageevent.h') diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index b393382a..e95aabfc 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -34,7 +34,7 @@ class RoomMessageEvent : public RoomEvent { Q_PROPERTY(QString msgType READ rawMsgtype CONSTANT) Q_PROPERTY(QString plainBody READ plainBody CONSTANT) Q_PROPERTY(QMimeType mimeType READ mimeType STORED false CONSTANT) - Q_PROPERTY(EventContent::TypedBase* content READ content CONSTANT) + Q_PROPERTY(const EventContent::TypedBase* content READ content CONSTANT) public: DEFINE_EVENT_TYPEID("m.room.message", RoomMessageEvent) @@ -62,13 +62,13 @@ public: MsgType msgtype() const; QString rawMsgtype() const; QString plainBody() const; - EventContent::TypedBase* content() const { return _content.data(); } + const EventContent::TypedBase* content() const { return _content.data(); } template - void editContent(VisitorT visitor) + void editContent(VisitorT&& visitor) { visitor(*_content); editJson()[ContentKeyL] = assembleContentJson(plainBody(), rawMsgtype(), - content()); + _content.data()); } QMimeType mimeType() const; bool hasTextContent() const; -- cgit v1.2.3 From 60bb1cf942ad0815dcf42cbfe8acd1e076d848cf Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 29 Oct 2019 22:04:40 +0900 Subject: Derive Omittable<> from std::optional<> That breaks API all over the place but: 1. The fixes are trivial. 2. More of std:: is used instead of home-baking the same stuff. --- lib/events/roommessageevent.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/events/roommessageevent.h') diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index e95aabfc..ded5e572 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -114,7 +114,7 @@ namespace EventContent { */ class TextContent : public TypedBase { public: - TextContent(const QString& text, const QString& contentType, + TextContent(QString text, const QString& contentType, Omittable relatesTo = none); explicit TextContent(const QJsonObject& json); -- cgit v1.2.3 From 14df474a5032554faf575f8becbac4c9f2bec3e5 Mon Sep 17 00:00:00 2001 From: Roland Pallai Date: Mon, 10 Feb 2020 17:25:42 +0100 Subject: Add EventContent::replacementOf() helper --- lib/events/roommessageevent.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/events/roommessageevent.h') diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index ded5e572..2501d097 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -105,6 +105,10 @@ namespace EventContent { { return { RelatesTo::ReplyTypeId(), std::move(eventId) }; } + inline RelatesTo replacementOf(QString eventId) + { + return { RelatesTo::ReplacementTypeId(), std::move(eventId) }; + } /** * Rich text content for m.text, m.emote, m.notice -- cgit v1.2.3