diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-12-28 12:46:13 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-01-05 21:01:31 +0900 |
commit | 77830a97e524a4bd27d8cbcd3830cbe450a5755a (patch) | |
tree | 0c704d0d6d576ebfb72efb4b6502f948f98829bf /lib/events/eventcontent.cpp | |
parent | 4ec3dd92d2cb5af4cf4893770e29db51d23e0e67 (diff) | |
download | libquotient-77830a97e524a4bd27d8cbcd3830cbe450a5755a.tar.gz libquotient-77830a97e524a4bd27d8cbcd3830cbe450a5755a.zip |
EventContent: only dump to json non-empty/valid values
Diffstat (limited to 'lib/events/eventcontent.cpp')
-rw-r--r-- | lib/events/eventcontent.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/events/eventcontent.cpp b/lib/events/eventcontent.cpp index bac2b72f..03880885 100644 --- a/lib/events/eventcontent.cpp +++ b/lib/events/eventcontent.cpp @@ -53,8 +53,10 @@ FileInfo::FileInfo(const QUrl& u, const QJsonObject& infoJson, void FileInfo::fillInfoJson(QJsonObject* infoJson) const { Q_ASSERT(infoJson); - infoJson->insert(QStringLiteral("size"), payloadSize); - infoJson->insert(QStringLiteral("mimetype"), mimeType.name()); + if (payloadSize != -1) + infoJson->insert(QStringLiteral("size"), payloadSize); + if (mimeType.isValid()) + infoJson->insert(QStringLiteral("mimetype"), mimeType.name()); } ImageInfo::ImageInfo(const QUrl& u, qint64 fileSize, QMimeType mimeType, @@ -71,8 +73,10 @@ ImageInfo::ImageInfo(const QUrl& u, const QJsonObject& infoJson, void ImageInfo::fillInfoJson(QJsonObject* infoJson) const { FileInfo::fillInfoJson(infoJson); - infoJson->insert(QStringLiteral("w"), imageSize.width()); - infoJson->insert(QStringLiteral("h"), imageSize.height()); + if (imageSize.width() != -1) + infoJson->insert(QStringLiteral("w"), imageSize.width()); + if (imageSize.height() != -1) + infoJson->insert(QStringLiteral("h"), imageSize.height()); } Thumbnail::Thumbnail(const QJsonObject& infoJson) @@ -82,7 +86,9 @@ Thumbnail::Thumbnail(const QJsonObject& infoJson) void Thumbnail::fillInfoJson(QJsonObject* infoJson) const { - infoJson->insert(QStringLiteral("thumbnail_url"), url.toString()); - infoJson->insert(QStringLiteral("thumbnail_info"), - toInfoJson<ImageInfo>(*this)); + if (url.isValid()) + infoJson->insert(QStringLiteral("thumbnail_url"), url.toString()); + if (!imageSize.isEmpty()) + infoJson->insert(QStringLiteral("thumbnail_info"), + toInfoJson<ImageInfo>(*this)); } |