2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Allow sending animated stickers.

This commit is contained in:
John Preston
2019-05-28 17:45:30 +02:00
parent af85aec33b
commit 8b804d1995
3 changed files with 75 additions and 36 deletions

View File

@@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/mime_type.h"
#include "media/audio/media_audio.h"
#include "media/clip/media_clip_reader.h"
#include "lottie/lottie_animation.h"
#include "history/history_item.h"
#include "boxes/send_files_box.h"
#include "boxes/confirm_box.h"
@@ -74,6 +75,18 @@ PreparedFileThumbnail PrepareFileThumbnail(QImage &&original) {
return result;
}
PreparedFileThumbnail PrepareAnimatedStickerThumbnail(
const QString &file,
const QByteArray &bytes) {
return PrepareFileThumbnail(Lottie::ReadThumbnail([&] {
if (!bytes.isEmpty()) {
return bytes;
}
auto f = QFile(file);
return f.open(QIODevice::ReadOnly) ? f.readAll() : QByteArray();
}()));
}
bool FileThumbnailUploadRequired(const QString &filemime, int32 filesize) {
constexpr auto kThumbnailUploadBySize = 5 * 1024 * 1024;
const auto kThumbnailKnownMimes = {
@@ -817,6 +830,10 @@ void FileLoadTask::process() {
QByteArray goodThumbnailBytes;
QVector<MTPDocumentAttribute> attributes(1, MTP_documentAttributeFilename(MTP_string(filename)));
const auto checkAnimatedSticker = filename.endsWith(qstr(".tgs"), Qt::CaseInsensitive);
if (checkAnimatedSticker) {
filemime = "application/x-tgsticker";
}
auto thumbnail = PreparedFileThumbnail();
@@ -855,6 +872,8 @@ void FileLoadTask::process() {
}
thumbnail = PrepareFileThumbnail(std::move(video->thumbnail));
} else if (checkAnimatedSticker) {
thumbnail = PrepareAnimatedStickerThumbnail(_filepath, _content);
}
}
@@ -918,7 +937,7 @@ void FileLoadTask::process() {
std::move(thumbnail),
filemime,
filesize,
isSticker);
isSticker || checkAnimatedSticker);
if (_type == SendMediaType::Photo && photo.type() == mtpc_photoEmpty) {
_type = SendMediaType::File;