aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2016-08-29 09:02:59 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2016-08-29 09:02:59 +0900
commit32ff7cd24bda52c889fd969a43adcf1f845b6e3a (patch)
tree8979cb97430d7e54fc1bd5717c864d29a231e5a8
parent6a288217f1279fff1867fbd4c2d2b22e44e43d59 (diff)
downloadlibquotient-32ff7cd24bda52c889fd969a43adcf1f845b6e3a.tar.gz
libquotient-32ff7cd24bda52c889fd969a43adcf1f845b6e3a.zip
Align AudioContent with the rest; special-case creation of VideoContent only
The spec is told to allow any event to have a thumbnail in future, and the thumbnail will reside under "content" JSON key rather than "info".
-rw-r--r--events/roommessageevent.cpp33
-rw-r--r--events/roommessageevent.h15
2 files changed, 25 insertions, 23 deletions
diff --git a/events/roommessageevent.cpp b/events/roommessageevent.cpp
index 513534ad..09465238 100644
--- a/events/roommessageevent.cpp
+++ b/events/roommessageevent.cpp
@@ -65,21 +65,30 @@ QString RoomMessageEvent::body() const
return plainBody();
}
-MessageEventContent::Base* RoomMessageEvent::content() const
+using namespace MessageEventContent;
+
+Base* RoomMessageEvent::content() const
{
return d->content;
}
template <class ContentT>
-MessageEventContent::Base* make(const QJsonObject& json)
+Base* make(const QJsonObject& json)
{
return new ContentT(json);
}
-template <class ContentT>
-MessageEventContent::Base* make2(const QJsonObject& json)
+Base* makeVideoContent(const QJsonObject& json)
{
- return new ContentT(json["url"].toString(), json["info"].toObject());
+ auto c = new VideoContent(json);
+ // Only for m.video, the spec puts a thumbnail inside "info" JSON key. Once
+ // this is fixed, VideoContent creation will switch to make<>().
+ const QJsonObject infoJson = json["info"].toObject();
+ if (infoJson.contains("thumbnail_url"))
+ c->thumbnail = ImageInfo(infoJson["thumbnail_url"].toString(),
+ infoJson["thumbnail_info"].toObject());
+
+ return c;
};
RoomMessageEvent* RoomMessageEvent::fromJson(const QJsonObject& obj)
@@ -97,15 +106,13 @@ RoomMessageEvent* RoomMessageEvent::fromJson(const QJsonObject& obj)
const QJsonObject content = obj["content"].toObject();
if ( content.contains("msgtype") && content.contains("body") )
{
- using namespace MessageEventContent;
-
e->d->plainBody = content["body"].toString();
struct Factory
{
QString jsonTag;
MessageEventType enumTag;
- MessageEventContent::Base*(*make)(const QJsonObject& json);
+ Base*(*make)(const QJsonObject& json);
};
const Factory factories[] {
@@ -115,8 +122,8 @@ RoomMessageEvent* RoomMessageEvent::fromJson(const QJsonObject& obj)
{ "m.image", MessageEventType::Image, make<ImageContent> },
{ "m.file", MessageEventType::File, make<FileContent> },
{ "m.location", MessageEventType::Location, make<LocationContent> },
- { "m.video", MessageEventType::Video, make2<VideoContent> },
- { "m.audio", MessageEventType::Audio, make2<AudioContent> },
+ { "m.video", MessageEventType::Video, makeVideoContent },
+ { "m.audio", MessageEventType::Audio, make<AudioContent> },
// Insert new message types before this line
};
@@ -186,15 +193,13 @@ LocationContent::LocationContent(const QJsonObject& json)
json["thumbnail_info"].toObject())
{ }
-VideoContent::VideoContent(QUrl u, const QJsonObject& infoJson)
+VideoInfo::VideoInfo(QUrl u, const QJsonObject& infoJson)
: FileInfo(u, infoJson)
, duration(infoJson["duration"].toInt())
, imageSize(infoJson["w"].toInt(), infoJson["h"].toInt())
- , thumbnail(infoJson["thumbnail_url"].toString(),
- infoJson["thumbnail_info"].toObject())
{ }
-AudioContent::AudioContent(QUrl u, const QJsonObject& infoJson)
+AudioInfo::AudioInfo(QUrl u, const QJsonObject& infoJson)
: FileInfo(u, infoJson)
, duration(infoJson["duration"].toInt())
{ }
diff --git a/events/roommessageevent.h b/events/roommessageevent.h
index 83022b4d..591b2df9 100644
--- a/events/roommessageevent.h
+++ b/events/roommessageevent.h
@@ -125,27 +125,24 @@ namespace QMatrixClient
ImageInfo thumbnail;
};
- // The spec structures m.video messages differently for some reason -
- // instead of putting a thumbnail block on the top level, as with
- // file and image, it puts it inside "info" key. So instead of
- // using ThumbnailContent<> base, we add the thumbnail into VideoInfo explicitly.
- class VideoContent: public FileInfo
+ class VideoInfo: public FileInfo
{
public:
- VideoContent(QUrl u, const QJsonObject& infoJson);
+ VideoInfo(QUrl u, const QJsonObject& infoJson);
int duration;
QSize imageSize;
- ImageInfo thumbnail;
};
+ using VideoContent = ThumbnailedContent<VideoInfo>;
- class AudioContent: public FileInfo
+ class AudioInfo: public FileInfo
{
public:
- AudioContent(QUrl u, const QJsonObject& infoJson);
+ AudioInfo(QUrl u, const QJsonObject& infoJson);
int duration;
};
+ using AudioContent = ThumbnailedContent<AudioInfo>;
}
}