2016-04-04 21:09:46 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-04-04 21:09:46 +00:00
|
|
|
*/
|
|
|
|
#include "inline_bots/inline_bot_result.h"
|
|
|
|
|
|
|
|
#include "inline_bots/inline_bot_layout_item.h"
|
|
|
|
#include "inline_bots/inline_bot_send_data.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/file_download.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "core/file_utilities.h"
|
2016-04-04 21:09:46 +00:00
|
|
|
#include "mainwidget.h"
|
|
|
|
|
|
|
|
namespace InlineBots {
|
|
|
|
|
2016-04-05 20:24:27 +00:00
|
|
|
Result::Result(const Creator &creator) : _queryId(creator.queryId), _type(creator.type) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<Result> Result::create(uint64 queryId, const MTPBotInlineResult &mtpData) {
|
2016-04-05 20:24:27 +00:00
|
|
|
using StringToTypeMap = QMap<QString, Result::Type>;
|
2016-04-09 18:45:55 +00:00
|
|
|
static StaticNeverFreedPointer<StringToTypeMap> stringToTypeMap{ ([]() -> StringToTypeMap* {
|
2017-02-21 13:45:56 +00:00
|
|
|
auto result = std::make_unique<StringToTypeMap>();
|
2016-04-04 21:09:46 +00:00
|
|
|
result->insert(qsl("photo"), Result::Type::Photo);
|
|
|
|
result->insert(qsl("video"), Result::Type::Video);
|
|
|
|
result->insert(qsl("audio"), Result::Type::Audio);
|
2016-04-11 04:02:39 +00:00
|
|
|
result->insert(qsl("voice"), Result::Type::Audio);
|
2016-04-04 21:09:46 +00:00
|
|
|
result->insert(qsl("sticker"), Result::Type::Sticker);
|
|
|
|
result->insert(qsl("file"), Result::Type::File);
|
|
|
|
result->insert(qsl("gif"), Result::Type::Gif);
|
|
|
|
result->insert(qsl("article"), Result::Type::Article);
|
|
|
|
result->insert(qsl("contact"), Result::Type::Contact);
|
|
|
|
result->insert(qsl("venue"), Result::Type::Venue);
|
2016-04-11 07:43:40 +00:00
|
|
|
result->insert(qsl("geo"), Result::Type::Geo);
|
2016-09-28 16:23:25 +00:00
|
|
|
result->insert(qsl("game"), Result::Type::Game);
|
2016-04-04 21:09:46 +00:00
|
|
|
return result.release();
|
2016-04-05 20:24:27 +00:00
|
|
|
})() };
|
|
|
|
|
2016-04-09 18:45:55 +00:00
|
|
|
auto getInlineResultType = [](const MTPBotInlineResult &inlineResult) -> Type {
|
2016-04-04 21:09:46 +00:00
|
|
|
QString type;
|
|
|
|
switch (inlineResult.type()) {
|
|
|
|
case mtpc_botInlineResult: type = qs(inlineResult.c_botInlineResult().vtype); break;
|
|
|
|
case mtpc_botInlineMediaResult: type = qs(inlineResult.c_botInlineMediaResult().vtype); break;
|
|
|
|
}
|
|
|
|
return stringToTypeMap->value(type, Type::Unknown);
|
|
|
|
};
|
|
|
|
Type type = getInlineResultType(mtpData);
|
|
|
|
if (type == Type::Unknown) {
|
2017-02-21 13:45:56 +00:00
|
|
|
return std::unique_ptr<Result>();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
auto result = std::make_unique<Result>(Creator{ queryId, type });
|
2016-04-04 21:09:46 +00:00
|
|
|
const MTPBotInlineMessage *message = nullptr;
|
|
|
|
switch (mtpData.type()) {
|
|
|
|
case mtpc_botInlineResult: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &r(mtpData.c_botInlineResult());
|
2016-04-05 20:24:27 +00:00
|
|
|
result->_id = qs(r.vid);
|
|
|
|
if (r.has_title()) result->_title = qs(r.vtitle);
|
|
|
|
if (r.has_description()) result->_description = qs(r.vdescription);
|
|
|
|
if (r.has_url()) result->_url = qs(r.vurl);
|
|
|
|
if (r.has_thumb_url()) result->_thumb_url = qs(r.vthumb_url);
|
|
|
|
if (r.has_content_type()) result->_content_type = qs(r.vcontent_type);
|
|
|
|
if (r.has_content_url()) result->_content_url = qs(r.vcontent_url);
|
|
|
|
if (r.has_w()) result->_width = r.vw.v;
|
|
|
|
if (r.has_h()) result->_height = r.vh.v;
|
|
|
|
if (r.has_duration()) result->_duration = r.vduration.v;
|
2016-04-10 11:13:37 +00:00
|
|
|
if (!result->_thumb_url.startsWith(qstr("http://"), Qt::CaseInsensitive) && !result->_thumb_url.startsWith(qstr("https://"), Qt::CaseInsensitive)) {
|
|
|
|
result->_thumb_url = QString();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
message = &r.vsend_message;
|
|
|
|
} break;
|
|
|
|
case mtpc_botInlineMediaResult: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &r(mtpData.c_botInlineMediaResult());
|
2016-04-05 20:24:27 +00:00
|
|
|
result->_id = qs(r.vid);
|
|
|
|
if (r.has_title()) result->_title = qs(r.vtitle);
|
|
|
|
if (r.has_description()) result->_description = qs(r.vdescription);
|
|
|
|
if (r.has_photo()) {
|
|
|
|
result->_photo = App::feedPhoto(r.vphoto);
|
|
|
|
}
|
|
|
|
if (r.has_document()) {
|
|
|
|
result->_document = App::feedDocument(r.vdocument);
|
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
message = &r.vsend_message;
|
|
|
|
} break;
|
|
|
|
}
|
2016-04-09 05:57:55 +00:00
|
|
|
bool badAttachment = (result->_photo && !result->_photo->access) || (result->_document && !result->_document->isValid());
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
if (!message) {
|
2017-02-21 13:45:56 +00:00
|
|
|
return std::unique_ptr<Result>();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
// Ensure required media fields for layouts.
|
|
|
|
if (result->_type == Type::Photo) {
|
|
|
|
if (!result->_photo && result->_content_url.isEmpty()) {
|
2017-02-21 13:45:56 +00:00
|
|
|
return std::unique_ptr<Result>();
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
result->createPhoto();
|
|
|
|
} else if (result->_type == Type::File || result->_type == Type::Gif || result->_type == Type::Sticker) {
|
|
|
|
if (!result->_document && result->_content_url.isEmpty()) {
|
2017-02-21 13:45:56 +00:00
|
|
|
return std::unique_ptr<Result>();
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
result->createDocument();
|
|
|
|
}
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
switch (message->type()) {
|
|
|
|
case mtpc_botInlineMessageMediaAuto: {
|
2016-10-20 09:46:16 +00:00
|
|
|
auto &r = message->c_botInlineMessageMediaAuto();
|
2016-04-05 20:24:27 +00:00
|
|
|
if (result->_type == Type::Photo) {
|
2016-04-10 11:13:37 +00:00
|
|
|
result->createPhoto();
|
2017-03-27 18:11:51 +00:00
|
|
|
result->sendData = std::make_unique<internal::SendPhoto>(result->_photo, qs(r.vcaption));
|
2016-09-28 16:23:25 +00:00
|
|
|
} else if (result->_type == Type::Game) {
|
|
|
|
result->createGame();
|
2017-03-27 18:11:51 +00:00
|
|
|
result->sendData = std::make_unique<internal::SendGame>(result->_game);
|
2016-04-04 21:09:46 +00:00
|
|
|
} else {
|
2016-04-10 11:13:37 +00:00
|
|
|
result->createDocument();
|
2017-03-27 18:11:51 +00:00
|
|
|
result->sendData = std::make_unique<internal::SendFile>(result->_document, qs(r.vcaption));
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2016-04-06 08:00:37 +00:00
|
|
|
if (r.has_reply_markup()) {
|
2017-02-21 13:45:56 +00:00
|
|
|
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(r.vreply_markup);
|
2016-04-06 08:00:37 +00:00
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_botInlineMessageText: {
|
2016-10-20 09:46:16 +00:00
|
|
|
auto &r = message->c_botInlineMessageText();
|
2017-03-10 19:46:28 +00:00
|
|
|
auto entities = r.has_entities() ? entitiesFromMTP(r.ventities.v) : EntitiesInText();
|
2017-03-27 18:11:51 +00:00
|
|
|
result->sendData = std::make_unique<internal::SendText>(qs(r.vmessage), entities, r.is_no_webpage());
|
2016-06-08 08:59:39 +00:00
|
|
|
if (result->_type == Type::Photo) {
|
|
|
|
result->createPhoto();
|
|
|
|
} else if (result->_type == Type::Audio || result->_type == Type::File || result->_type == Type::Video || result->_type == Type::Sticker || result->_type == Type::Gif) {
|
|
|
|
result->createDocument();
|
|
|
|
}
|
2016-04-06 08:00:37 +00:00
|
|
|
if (r.has_reply_markup()) {
|
2017-02-21 13:45:56 +00:00
|
|
|
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(r.vreply_markup);
|
2016-04-06 08:00:37 +00:00
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_botInlineMessageMediaGeo: {
|
2016-10-20 09:46:16 +00:00
|
|
|
auto &r = message->c_botInlineMessageMediaGeo();
|
2016-04-04 21:09:46 +00:00
|
|
|
if (r.vgeo.type() == mtpc_geoPoint) {
|
2017-03-27 18:11:51 +00:00
|
|
|
result->sendData = std::make_unique<internal::SendGeo>(r.vgeo.c_geoPoint());
|
2016-04-04 21:09:46 +00:00
|
|
|
} else {
|
|
|
|
badAttachment = true;
|
|
|
|
}
|
2016-04-06 08:00:37 +00:00
|
|
|
if (r.has_reply_markup()) {
|
2017-02-21 13:45:56 +00:00
|
|
|
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(r.vreply_markup);
|
2016-04-06 08:00:37 +00:00
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_botInlineMessageMediaVenue: {
|
2016-10-20 09:46:16 +00:00
|
|
|
auto &r = message->c_botInlineMessageMediaVenue();
|
2016-04-04 21:09:46 +00:00
|
|
|
if (r.vgeo.type() == mtpc_geoPoint) {
|
2017-03-27 18:11:51 +00:00
|
|
|
result->sendData = std::make_unique<internal::SendVenue>(r.vgeo.c_geoPoint(), qs(r.vvenue_id), qs(r.vprovider), qs(r.vtitle), qs(r.vaddress));
|
2016-04-04 21:09:46 +00:00
|
|
|
} else {
|
|
|
|
badAttachment = true;
|
|
|
|
}
|
2016-04-06 08:00:37 +00:00
|
|
|
if (r.has_reply_markup()) {
|
2017-02-21 13:45:56 +00:00
|
|
|
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(r.vreply_markup);
|
2016-04-06 08:00:37 +00:00
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_botInlineMessageMediaContact: {
|
2016-10-20 09:46:16 +00:00
|
|
|
auto &r = message->c_botInlineMessageMediaContact();
|
2017-03-27 18:11:51 +00:00
|
|
|
result->sendData = std::make_unique<internal::SendContact>(qs(r.vfirst_name), qs(r.vlast_name), qs(r.vphone_number));
|
2016-04-06 08:00:37 +00:00
|
|
|
if (r.has_reply_markup()) {
|
2017-02-21 13:45:56 +00:00
|
|
|
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(r.vreply_markup);
|
2016-04-06 08:00:37 +00:00
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
badAttachment = true;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (badAttachment || !result->sendData || !result->sendData->isValid()) {
|
2017-02-21 13:45:56 +00:00
|
|
|
return std::unique_ptr<Result>();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2016-04-05 20:24:27 +00:00
|
|
|
|
2016-04-10 11:13:37 +00:00
|
|
|
if (result->_thumb->isNull() && !result->_thumb_url.isEmpty()) {
|
|
|
|
result->_thumb = ImagePtr(result->_thumb_url);
|
|
|
|
}
|
2016-04-05 20:24:27 +00:00
|
|
|
LocationCoords location;
|
|
|
|
if (result->getLocationCoords(&location)) {
|
|
|
|
int32 w = st::inlineThumbSize, h = st::inlineThumbSize;
|
|
|
|
int32 zoom = 13, scale = 1;
|
|
|
|
if (cScale() == dbisTwo || cRetina()) {
|
|
|
|
scale = 2;
|
|
|
|
w /= 2;
|
|
|
|
h /= 2;
|
|
|
|
}
|
2017-02-03 10:17:40 +00:00
|
|
|
auto coords = location.latAsString() + ',' + location.lonAsString();
|
2016-04-05 20:24:27 +00:00
|
|
|
QString url = qsl("https://maps.googleapis.com/maps/api/staticmap?center=") + coords + qsl("&zoom=%1&size=%2x%3&maptype=roadmap&scale=%4&markers=color:red|size:big|").arg(zoom).arg(w).arg(h).arg(scale) + coords + qsl("&sensor=false");
|
|
|
|
result->_locationThumb = ImagePtr(url);
|
|
|
|
}
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-04-05 20:24:27 +00:00
|
|
|
bool Result::onChoose(Layout::ItemBase *layout) {
|
|
|
|
if (_photo && _type == Type::Photo) {
|
|
|
|
if (_photo->medium->loaded() || _photo->thumb->loaded()) {
|
|
|
|
return true;
|
|
|
|
} else if (!_photo->medium->loading()) {
|
|
|
|
_photo->thumb->loadEvenCancelled();
|
|
|
|
_photo->medium->loadEvenCancelled();
|
|
|
|
}
|
2016-05-19 15:02:07 +00:00
|
|
|
return false;
|
2016-04-05 20:24:27 +00:00
|
|
|
}
|
|
|
|
if (_document && (
|
|
|
|
_type == Type::Video ||
|
|
|
|
_type == Type::Audio ||
|
|
|
|
_type == Type::Sticker ||
|
|
|
|
_type == Type::File ||
|
|
|
|
_type == Type::Gif)) {
|
|
|
|
if (_type == Type::Gif) {
|
|
|
|
if (_document->loaded()) {
|
|
|
|
return true;
|
|
|
|
} else if (_document->loading()) {
|
|
|
|
_document->cancel();
|
|
|
|
} else {
|
2016-10-12 19:34:25 +00:00
|
|
|
DocumentOpenClickHandler::doOpen(_document, nullptr, ActionOnLoadNone);
|
2016-04-05 20:24:27 +00:00
|
|
|
}
|
2016-05-19 15:02:07 +00:00
|
|
|
return false;
|
2016-04-05 20:24:27 +00:00
|
|
|
}
|
2016-05-19 15:02:07 +00:00
|
|
|
return true;
|
2016-04-05 20:24:27 +00:00
|
|
|
}
|
2016-04-10 11:13:37 +00:00
|
|
|
return true;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Result::forget() {
|
2016-04-05 20:24:27 +00:00
|
|
|
_thumb->forget();
|
|
|
|
if (_document) {
|
|
|
|
_document->forget();
|
|
|
|
}
|
|
|
|
if (_photo) {
|
|
|
|
_photo->forget();
|
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 11:13:37 +00:00
|
|
|
void Result::openFile() {
|
|
|
|
if (_document) {
|
|
|
|
DocumentOpenClickHandler(_document).onClick(Qt::LeftButton);
|
|
|
|
} else if (_photo) {
|
|
|
|
PhotoOpenClickHandler(_photo).onClick(Qt::LeftButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Result::cancelFile() {
|
|
|
|
if (_document) {
|
|
|
|
DocumentCancelClickHandler(_document).onClick(Qt::LeftButton);
|
|
|
|
} else if (_photo) {
|
|
|
|
PhotoCancelClickHandler(_photo).onClick(Qt::LeftButton);
|
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Result::hasThumbDisplay() const {
|
2016-04-05 20:24:27 +00:00
|
|
|
if (!_thumb->isNull()) {
|
2016-04-04 21:09:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-04-05 20:24:27 +00:00
|
|
|
if (_type == Type::Contact) {
|
2016-04-04 21:09:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (sendData->hasLocationCoords()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
void Result::addToHistory(History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, UserId viaBotId, MsgId replyToId) const {
|
2016-04-06 08:00:37 +00:00
|
|
|
flags |= MTPDmessage_ClientFlag::f_from_inline_bot;
|
|
|
|
|
|
|
|
MTPReplyMarkup markup = MTPnullMarkup;
|
|
|
|
if (_mtpKeyboard) {
|
|
|
|
flags |= MTPDmessage::Flag::f_reply_markup;
|
|
|
|
markup = *_mtpKeyboard;
|
|
|
|
}
|
2016-04-09 08:29:34 +00:00
|
|
|
sendData->addToHistory(this, history, flags, msgId, fromId, mtpDate, viaBotId, replyToId, markup);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Result::getLocationCoords(LocationCoords *outLocation) const {
|
|
|
|
return sendData->getLocationCoords(outLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Result::getLayoutTitle() const {
|
|
|
|
return sendData->getLayoutTitle(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Result::getLayoutDescription() const {
|
|
|
|
return sendData->getLayoutDescription(this);
|
|
|
|
}
|
|
|
|
|
2016-09-28 21:33:05 +00:00
|
|
|
// just to make unique_ptr see the destructors.
|
|
|
|
Result::~Result() {
|
|
|
|
}
|
|
|
|
|
2016-04-10 11:13:37 +00:00
|
|
|
void Result::createPhoto() {
|
|
|
|
if (_photo) return;
|
|
|
|
|
|
|
|
if (_thumb_url.isEmpty()) {
|
2016-04-10 14:53:01 +00:00
|
|
|
QSize thumbsize = shrinkToKeepAspect(_width, _height, 100, 100);
|
|
|
|
_thumb = ImagePtr(thumbsize.width(), thumbsize.height());
|
2016-04-10 11:13:37 +00:00
|
|
|
} else {
|
2016-04-10 14:53:01 +00:00
|
|
|
_thumb = ImagePtr(_thumb_url, QSize(320, 320));
|
2016-04-10 11:13:37 +00:00
|
|
|
}
|
2016-04-10 14:53:01 +00:00
|
|
|
// ImagePtr medium = ImagePtr(_content_url, QSize(320, 320));
|
|
|
|
QSize mediumsize = shrinkToKeepAspect(_width, _height, 320, 320);
|
|
|
|
ImagePtr medium = ImagePtr(mediumsize.width(), mediumsize.height());
|
2016-04-10 11:13:37 +00:00
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
ImagePtr full = ImagePtr(_content_url, _width, _height);
|
2016-09-28 16:23:25 +00:00
|
|
|
auto photoId = rand_value<PhotoId>();
|
2016-04-10 18:18:26 +00:00
|
|
|
_photo = App::photoSet(photoId, 0, 0, unixtime(), _thumb, medium, full);
|
2016-04-10 11:13:37 +00:00
|
|
|
_photo->thumb = _thumb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Result::createDocument() {
|
|
|
|
if (_document) return;
|
|
|
|
|
|
|
|
if (!_thumb_url.isEmpty()) {
|
|
|
|
_thumb = ImagePtr(_thumb_url, QSize(90, 90));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString mime = _content_type;
|
|
|
|
|
|
|
|
QVector<MTPDocumentAttribute> attributes;
|
|
|
|
QSize dimensions(_width, _height);
|
|
|
|
if (_type == Type::Gif) {
|
|
|
|
const char *filename = (mime == qstr("video/mp4") ? "animation.gif.mp4" : "animation.gif");
|
|
|
|
attributes.push_back(MTP_documentAttributeFilename(MTP_string(filename)));
|
|
|
|
attributes.push_back(MTP_documentAttributeAnimated());
|
|
|
|
attributes.push_back(MTP_documentAttributeVideo(MTP_int(_duration), MTP_int(_width), MTP_int(_height)));
|
|
|
|
} else if (_type == Type::Video) {
|
|
|
|
attributes.push_back(MTP_documentAttributeVideo(MTP_int(_duration), MTP_int(_width), MTP_int(_height)));
|
|
|
|
} else if (_type == Type::Audio) {
|
2017-03-25 15:42:01 +00:00
|
|
|
auto flags = MTPDdocumentAttributeAudio::Flags(0);
|
2016-04-10 11:13:37 +00:00
|
|
|
if (mime == qstr("audio/ogg")) {
|
|
|
|
flags |= MTPDdocumentAttributeAudio::Flag::f_voice;
|
|
|
|
} else {
|
|
|
|
QStringList p = mimeTypeForName(mime).globPatterns();
|
|
|
|
QString pattern = p.isEmpty() ? QString() : p.front();
|
|
|
|
QString extension = pattern.isEmpty() ? qsl(".unknown") : pattern.replace('*', QString());
|
|
|
|
QString filename = filedialogDefaultName(qsl("inline"), extension, QString(), true);
|
|
|
|
attributes.push_back(MTP_documentAttributeFilename(MTP_string(filename)));
|
|
|
|
}
|
|
|
|
attributes.push_back(MTP_documentAttributeAudio(MTP_flags(flags), MTP_int(_duration), MTPstring(), MTPstring(), MTPbytes()));
|
|
|
|
}
|
|
|
|
|
2016-09-28 16:23:25 +00:00
|
|
|
auto documentId = rand_value<DocumentId>();
|
|
|
|
_document = App::documentSet(documentId, nullptr, 0, 0, unixtime(), attributes, mime, _thumb, MTP::maindc(), 0, StorageImageLocation());
|
2016-04-10 11:13:37 +00:00
|
|
|
_document->setContentUrl(_content_url);
|
|
|
|
}
|
|
|
|
|
2016-09-28 16:23:25 +00:00
|
|
|
void Result::createGame() {
|
|
|
|
if (_game) return;
|
|
|
|
|
|
|
|
auto gameId = rand_value<GameId>();
|
|
|
|
_game = App::gameSet(gameId, nullptr, 0, QString(), _title, _description, _photo, _document);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace InlineBots
|