aboutsummaryrefslogtreecommitdiff
path: root/events/roommessageevent.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-05-22 10:22:28 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-05-22 10:22:28 +0900
commitbe838b2f4f294a7e1b3f8a771f91d9d1eac14431 (patch)
treef720ae5a5a52bdd48fdaec17dea3c1c32fe10cd9 /events/roommessageevent.h
parent34764f3020c360ebc769cfe154e79b9e7e98f0f7 (diff)
downloadlibquotient-be838b2f4f294a7e1b3f8a771f91d9d1eac14431.tar.gz
libquotient-be838b2f4f294a7e1b3f8a771f91d9d1eac14431.zip
Refactored Events
The biggest change is we have no pimpls in Event objects anymore - because it's two new's instead of one per Event, and we have thousands and even more of Events created during initial sync. The other big change is introduction of RoomEvent, so that now the structure of events almost precisely reflects the CS API spec. The refactoring made UnknownEvent unnecessary as a separate class; a respective base class (either RoomEvent or Event) is used for this purpose now. All the other changes are consequences of these (mostly of RoomEvent introduction).
Diffstat (limited to 'events/roommessageevent.h')
-rw-r--r--events/roommessageevent.h67
1 files changed, 34 insertions, 33 deletions
diff --git a/events/roommessageevent.h b/events/roommessageevent.h
index 5d5336aa..6acaad6f 100644
--- a/events/roommessageevent.h
+++ b/events/roommessageevent.h
@@ -24,44 +24,45 @@
#include <QtCore/QMimeType>
#include <QtCore/QSize>
+#include <memory>
+
namespace QMatrixClient
{
- enum class MessageEventType
- {
- Text, Emote, Notice, Image, File, Location, Video, Audio, Unknown
- };
-
namespace MessageEventContent
{
- class Base { };
- }
-
- class RoomMessageEvent: public Event
- {
- public:
- RoomMessageEvent();
- virtual ~RoomMessageEvent();
-
- QString userId() const;
- MessageEventType msgtype() const;
+ class Base
+ {
+ Q_GADGET
+ public:
+ enum class Type
+ {
+ Text, Emote, Notice, Image, File, Location, Video, Audio, Unknown
+ };
- QString plainBody() const;
+ virtual ~Base() = default;
- /**
- * Same as plainBody() for now; might change for "best-looking body"
- * in the future. For richer contents, use content-specific data.
- *
- * @deprecated
- */
- QString body() const;
+ REGISTER_ENUM(Type)
+ };
+ using CType = Base::Type;
+ } // namespace MessageEventContent
+ using MessageEventType = MessageEventContent::CType;
- MessageEventContent::Base* content() const;
+ class RoomMessageEvent: public RoomEvent
+ {
+ public:
+ explicit RoomMessageEvent(const QJsonObject& obj);
+ ~RoomMessageEvent();
- static RoomMessageEvent* fromJson( const QJsonObject& obj );
+ const QString& userId() const { return _userId; }
+ MessageEventType msgtype() const { return _msgtype; }
+ const QString& plainBody() const { return _plainBody; }
+ const MessageEventContent::Base* content() const { return _content; }
private:
- class Private;
- Private* d;
+ QString _userId;
+ MessageEventType _msgtype;
+ QString _plainBody;
+ MessageEventContent::Base* _content;
};
namespace MessageEventContent
@@ -73,7 +74,7 @@ namespace QMatrixClient
class TextContent: public Base
{
public:
- TextContent(const QJsonObject& json);
+ explicit TextContent(const QJsonObject& json);
QMimeType mimeType;
QString body;
@@ -103,7 +104,7 @@ namespace QMatrixClient
class ThumbnailedContent: public ContentInfoT
{
public:
- ThumbnailedContent(const QJsonObject& json)
+ explicit ThumbnailedContent(const QJsonObject& json)
: ContentInfoT(json["url"].toString(), json["info"].toObject())
, thumbnail(json["thumbnail_url"].toString(),
json["thumbnail_info"].toObject())
@@ -118,7 +119,7 @@ namespace QMatrixClient
class LocationContent: public Base
{
public:
- LocationContent(const QJsonObject& json);
+ explicit LocationContent(const QJsonObject& json);
QString geoUri;
ImageInfo thumbnail;
@@ -142,5 +143,5 @@ namespace QMatrixClient
int duration;
};
using AudioContent = ThumbnailedContent<AudioInfo>;
- }
-}
+ } // namespace MessageEventContent
+} // namespace QMatrixClient