2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-02 07:25:46 +00:00

Improved files support in inline bot results.

This commit is contained in:
John Preston
2016-04-04 11:21:14 +04:00
parent 35785efa50
commit a2fc7f6915
7 changed files with 136 additions and 34 deletions

View File

@@ -1529,11 +1529,15 @@ InlineResultSendData::SentMTPMessageFields InlineResultSendFile::getSentMessageF
uint64 docId = rand_value<uint64>();
QVector<MTPDocumentAttribute> attributes;
int duration = getSentDuration(owner);
QSize dimensions = getSentDimensions(owner);
using Type = InlineResult::Type;
if (owner->type == Type::Gif) {
attributes.push_back(MTP_documentAttributeFilename(MTP_string((owner->content_type == qstr("video/mp4") ? "animation.gif.mp4" : "animation.gif"))));
attributes.push_back(MTP_documentAttributeAnimated());
attributes.push_back(MTP_documentAttributeVideo(MTP_int(owner->duration), MTP_int(owner->width), MTP_int(owner->height)));
attributes.push_back(MTP_documentAttributeVideo(MTP_int(duration), MTP_int(dimensions.width()), MTP_int(dimensions.height())));
} else if (owner->type == Type::Video) {
attributes.push_back(MTP_documentAttributeVideo(MTP_int(duration), MTP_int(dimensions.width()), MTP_int(dimensions.height())));
}
MTPDocument document = MTP_document(MTP_long(docId), MTP_long(0), MTP_int(unixtime()), MTP_string(owner->content_type), MTP_int(owner->data().size()), thumbSize, MTP_int(MTP::maindc()), MTP_vector<MTPDocumentAttribute>(attributes));
if (tw > 0 && th > 0) {
@@ -1546,6 +1550,13 @@ InlineResultSendData::SentMTPMessageFields InlineResultSendFile::getSentMessageF
return result;
}
int InlineResultSendFile::getSentDuration(InlineResult *owner) const {
return (_document && _document->duration()) ? _document->duration() : owner->duration;
}
QSize InlineResultSendFile::getSentDimensions(InlineResult *owner) const {
return (!_document || _document->dimensions.isEmpty()) ? QSize(owner->width, owner->height) : _document->dimensions;
}
void InlineResult::automaticLoadGif() {
if (loaded() || type != Type::Gif || (content_type != qstr("video/mp4") && content_type != "image/gif")) return;