aboutsummaryrefslogtreecommitdiff
path: root/events
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2016-08-24 13:19:37 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2016-08-24 13:19:37 +0900
commit958675dccc0a308c02d490d0b246eade0123ce79 (patch)
tree0da1189bd48f08720e97d634a05f410fbc40a17a /events
parent77d45e9afa195f7d715a5074b16f16c6b2d15235 (diff)
downloadlibquotient-958675dccc0a308c02d490d0b246eade0123ce79.tar.gz
libquotient-958675dccc0a308c02d490d0b246eade0123ce79.zip
Moved message content classes to a dedicated namespace
Diffstat (limited to 'events')
-rw-r--r--events/roommessageevent.cpp26
-rw-r--r--events/roommessageevent.h117
2 files changed, 74 insertions, 69 deletions
diff --git a/events/roommessageevent.cpp b/events/roommessageevent.cpp
index 48f52453..03e84444 100644
--- a/events/roommessageevent.cpp
+++ b/events/roommessageevent.cpp
@@ -32,7 +32,7 @@ class RoomMessageEvent::Private
QString userId;
MessageEventType msgtype;
QDateTime hsob_ts;
- MessageEventContent* content;
+ MessageEventContent::Base* content;
};
RoomMessageEvent::RoomMessageEvent()
@@ -67,9 +67,9 @@ QDateTime RoomMessageEvent::hsob_ts() const
return d->hsob_ts;
}
-MessageEventContent* RoomMessageEvent::content() const
+MessageEventContent::Base* RoomMessageEvent::content() const
{
- return d->content;
+ return d->content;
}
RoomMessageEvent* RoomMessageEvent::fromJson(const QJsonObject& obj)
@@ -84,28 +84,30 @@ RoomMessageEvent* RoomMessageEvent::fromJson(const QJsonObject& obj)
}
if( obj.contains("content") )
{
+ using namespace MessageEventContent;
+
QJsonObject content = obj.value("content").toObject();
QString msgtype = content.value("msgtype").toString();
if( msgtype == "m.text" )
{
e->d->msgtype = MessageEventType::Text;
- e->d->content = new MessageEventContent();
+ e->d->content = new Base();
}
else if( msgtype == "m.emote" )
{
e->d->msgtype = MessageEventType::Emote;
- e->d->content = new MessageEventContent();
+ e->d->content = new Base();
}
else if( msgtype == "m.notice" )
{
e->d->msgtype = MessageEventType::Notice;
- e->d->content = new MessageEventContent();
+ e->d->content = new Base();
}
else if( msgtype == "m.image" )
{
e->d->msgtype = MessageEventType::Image;
- ImageEventContent* c = new ImageEventContent;
+ ImageContent* c = new ImageContent;
c->url = QUrl(content.value("url").toString());
QJsonObject info = content.value("info").toObject();
c->height = info.value("h").toInt();
@@ -117,7 +119,7 @@ RoomMessageEvent* RoomMessageEvent::fromJson(const QJsonObject& obj)
else if( msgtype == "m.file" )
{
e->d->msgtype = MessageEventType::File;
- FileEventContent* c = new FileEventContent;
+ FileContent* c = new FileContent;
c->filename = content.value("filename").toString();
c->url = QUrl(content.value("url").toString());
QJsonObject info = content.value("info").toObject();
@@ -128,7 +130,7 @@ RoomMessageEvent* RoomMessageEvent::fromJson(const QJsonObject& obj)
else if( msgtype == "m.location" )
{
e->d->msgtype = MessageEventType::Location;
- LocationEventContent* c = new LocationEventContent;
+ LocationContent* c = new LocationContent;
c->geoUri = content.value("geo_uri").toString();
c->thumbnailUrl = QUrl(content.value("thumbnail_url").toString());
QJsonObject info = content.value("thumbnail_info").toObject();
@@ -141,7 +143,7 @@ RoomMessageEvent* RoomMessageEvent::fromJson(const QJsonObject& obj)
else if( msgtype == "m.video" )
{
e->d->msgtype = MessageEventType::Video;
- VideoEventContent* c = new VideoEventContent;
+ VideoContent* c = new VideoContent;
c->url = QUrl(content.value("url").toString());
QJsonObject info = content.value("info").toObject();
c->height = info.value("h").toInt();
@@ -159,7 +161,7 @@ RoomMessageEvent* RoomMessageEvent::fromJson(const QJsonObject& obj)
else if( msgtype == "m.audio" )
{
e->d->msgtype = MessageEventType::Audio;
- AudioEventContent* c = new AudioEventContent;
+ AudioContent* c = new AudioContent;
c->url = QUrl(content.value("url").toString());
QJsonObject info = content.value("info").toObject();
c->duration = info.value("duration").toInt();
@@ -172,7 +174,7 @@ RoomMessageEvent* RoomMessageEvent::fromJson(const QJsonObject& obj)
qDebug() << "RoomMessageEvent: unknown msgtype: " << msgtype;
qDebug() << obj;
e->d->msgtype = MessageEventType::Unknown;
- e->d->content = new MessageEventContent;
+ e->d->content = new Base;
}
if( content.contains("body") )
diff --git a/events/roommessageevent.h b/events/roommessageevent.h
index b0d5a1cb..219f74f0 100644
--- a/events/roommessageevent.h
+++ b/events/roommessageevent.h
@@ -30,13 +30,14 @@ namespace QMatrixClient
Text, Emote, Notice, Image, File, Location, Video, Audio, Unknown
};
- class MessageEventContent
+ namespace MessageEventContent
{
- public:
- virtual ~MessageEventContent() {}
-
- QString body;
- };
+ class Base
+ {
+ public:
+ QString body;
+ };
+ }
class RoomMessageEvent: public Event
{
@@ -49,7 +50,7 @@ namespace QMatrixClient
QString body() const;
QDateTime hsob_ts() const;
- MessageEventContent* content() const;
+ MessageEventContent::Base* content() const;
static RoomMessageEvent* fromJson( const QJsonObject& obj );
@@ -58,61 +59,63 @@ namespace QMatrixClient
Private* d;
};
- class ImageEventContent: public MessageEventContent
+ namespace MessageEventContent
{
- public:
- QUrl url;
- int height;
- int width;
- int size;
- QString mimetype;
- };
-
- class FileEventContent: public MessageEventContent
- {
- public:
- QString filename;
- QString mimetype;
- int size;
- QUrl url;
- };
+ class ImageContent: public Base
+ {
+ public:
+ QUrl url;
+ int height;
+ int width;
+ int size;
+ QString mimetype;
+ };
- class LocationEventContent: public MessageEventContent
- {
- public:
- QString geoUri;
- int thumbnailHeight;
- int thumbnailWidth;
- QString thumbnailMimetype;
- int thumbnailSize;
- QUrl thumbnailUrl;
- };
+ class FileContent: public Base
+ {
+ public:
+ QString filename;
+ QString mimetype;
+ int size;
+ QUrl url;
+ };
- class VideoEventContent: public MessageEventContent
- {
- public:
- QUrl url;
- int duration;
- int width;
- int height;
- int size;
- QString mimetype;
- int thumbnailWidth;
- int thumbnailHeight;
- int thumbnailSize;
- QString thumbnailMimetype;
- QUrl thumbnailUrl;
- };
+ class LocationContent: public Base
+ {
+ public:
+ QString geoUri;
+ int thumbnailHeight;
+ int thumbnailWidth;
+ QString thumbnailMimetype;
+ int thumbnailSize;
+ QUrl thumbnailUrl;
+ };
- class AudioEventContent: public MessageEventContent
- {
- public:
- QUrl url;
- int size;
- int duration;
- QString mimetype;
- };
+ class VideoContent: public Base
+ {
+ public:
+ QUrl url;
+ int duration;
+ int width;
+ int height;
+ int size;
+ QString mimetype;
+ int thumbnailWidth;
+ int thumbnailHeight;
+ int thumbnailSize;
+ QString thumbnailMimetype;
+ QUrl thumbnailUrl;
+ };
+ class AudioContent: public Base
+ {
+ public:
+ QUrl url;
+ int size;
+ int duration;
+ QString mimetype;
+ };
+ }
}
#endif // QMATRIXCLIENT_ROOMMESSAGEEVENT_H