aboutsummaryrefslogtreecommitdiff
path: root/events/roommessageevent.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-13 19:42:37 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-13 19:42:37 +0900
commit32d2673ff6268ad00c2b80912e7675673480096c (patch)
tree685ab7a115f2bfc4be0c293c3965e8bd9ced614e /events/roommessageevent.h
parent8f4a940d70cdcfc34a2ffe2d9a9561c0d821c56e (diff)
downloadlibquotient-32d2673ff6268ad00c2b80912e7675673480096c.tar.gz
libquotient-32d2673ff6268ad00c2b80912e7675673480096c.zip
Refactor EventContent; allow to easily check files out of message events
The whole inheritance/templating structure has been considerably simplified by using a trick with mixin classes; thanks to that, *Info classes are no more templated, they are just mixed together by the almighty UrlBasedContent<> template (but the same can easily be done outside of it, as LocationContent implementation shows). RoomMessageEvent has gained hasFileContent(); it's also possible to easily get a FileInfo core object just by calling msgEvent->content()->fileInfo().
Diffstat (limited to 'events/roommessageevent.h')
-rw-r--r--events/roommessageevent.h34
1 files changed, 19 insertions, 15 deletions
diff --git a/events/roommessageevent.h b/events/roommessageevent.h
index eef6b657..6b551b76 100644
--- a/events/roommessageevent.h
+++ b/events/roommessageevent.h
@@ -32,6 +32,10 @@ namespace QMatrixClient
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)
public:
enum class MsgType
{
@@ -52,9 +56,10 @@ namespace QMatrixClient
MsgType msgtype() const;
QString rawMsgtype() const { return _msgtype; }
const QString& plainBody() const { return _plainBody; }
- const EventContent::TypedBase* content() const
+ EventContent::TypedBase* content() const
{ return _content.data(); }
QMimeType mimeType() const;
+ bool hasFileContent() const;
QJsonObject toJson() const;
@@ -107,15 +112,16 @@ namespace QMatrixClient
* - thumbnail.mimeType
* - thumbnail.imageSize
*/
- class LocationContent: public TypedBase, public Thumbnailed<>
+ class LocationContent: public TypedBase, public WithThumbnail
{
public:
LocationContent(const QString& geoUri,
- const ImageInfo<>& thumbnail);
+ const ImageInfo& thumbnail);
explicit LocationContent(const QJsonObject& json);
QMimeType type() const override;
+ public:
QString geoUri;
protected:
@@ -123,21 +129,18 @@ namespace QMatrixClient
};
/**
- * A base class for "playable" info types: audio and video
+ * A mixin class for info types that include duration: audio and video
*/
- class PlayableInfo : public FileInfo
+ class WithDuration
{
public:
- explicit PlayableInfo(const QUrl& u, int fileSize,
- const QMimeType& mimeType, int duration,
- const QString& originalFilename = {});
- PlayableInfo(const QUrl& u, const QJsonObject& infoJson,
- const QString& originalFilename = {});
+ explicit WithDuration(int duration) : duration(duration) { }
+ WithDuration(const QJsonObject& infoJson);
- int duration;
+ void fillInfoJson(QJsonObject* infoJson) const;
- protected:
- void fillInfoJson(QJsonObject* infoJson) const override;
+ public:
+ int duration;
};
/**
@@ -159,7 +162,8 @@ namespace QMatrixClient
* - mimeType
* - imageSize
*/
- using VideoContent = UrlWith<Thumbnailed<ImageInfo<PlayableInfo>>>;
+ using VideoContent =
+ UrlBasedContent<ImageInfo, WithThumbnail, WithDuration>;
/**
* Content class for m.audio
@@ -173,6 +177,6 @@ namespace QMatrixClient
* - mimeType ("mimetype" in JSON)
* - duration
*/
- using AudioContent = UrlWith<PlayableInfo>;
+ using AudioContent = UrlBasedContent<FileInfo, WithDuration>;
} // namespace EventContent
} // namespace QMatrixClient