2016-04-04 21:09:46 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-04-04 21:09:46 +00:00
|
|
|
*/
|
|
|
|
#include "inline_bots/inline_bot_send_data.h"
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_document.h"
|
2016-04-04 21:09:46 +00:00
|
|
|
#include "inline_bots/inline_bot_result.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-06-11 18:33:20 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
namespace InlineBots {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
QString SendData::getLayoutTitle(const Result *owner) const {
|
2016-04-05 20:24:27 +00:00
|
|
|
return owner->_title;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SendData::getLayoutDescription(const Result *owner) const {
|
2016-04-05 20:24:27 +00:00
|
|
|
return owner->_description;
|
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
void SendDataCommon::addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId msgId,
|
|
|
|
UserId fromId,
|
|
|
|
MTPint mtpDate,
|
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const MTPReplyMarkup &markup) const {
|
2017-03-10 19:46:28 +00:00
|
|
|
auto fields = getSentMessageFields();
|
|
|
|
if (!fields.entities.v.isEmpty()) {
|
2016-04-09 08:29:34 +00:00
|
|
|
flags |= MTPDmessage::Flag::f_entities;
|
|
|
|
}
|
2017-12-03 14:38:05 +00:00
|
|
|
history->addNewMessage(
|
|
|
|
MTP_message(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_int(msgId),
|
|
|
|
MTP_int(fromId),
|
|
|
|
peerToMTP(history->peer->id),
|
2019-03-15 15:15:56 +00:00
|
|
|
MTPMessageFwdHeader(),
|
2017-12-03 14:38:05 +00:00
|
|
|
MTP_int(viaBotId),
|
|
|
|
MTP_int(replyToId),
|
|
|
|
mtpDate,
|
|
|
|
fields.text,
|
|
|
|
fields.media,
|
|
|
|
markup,
|
|
|
|
fields.entities,
|
|
|
|
MTP_int(1),
|
|
|
|
MTPint(),
|
|
|
|
MTP_string(postAuthor),
|
|
|
|
MTPlong()),
|
|
|
|
NewMessageUnread);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
QString SendDataCommon::getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const {
|
2019-01-14 17:43:06 +00:00
|
|
|
const auto errorKey = Data::RestrictionErrorKey(
|
|
|
|
history->peer,
|
|
|
|
ChatRestriction::f_send_messages);
|
|
|
|
return errorKey ? lang(*errorKey) : QString();
|
2017-06-11 18:33:20 +00:00
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
SendDataCommon::SentMTPMessageFields SendText::getSentMessageFields() const {
|
2016-04-04 21:09:46 +00:00
|
|
|
SentMTPMessageFields result;
|
|
|
|
result.text = MTP_string(_message);
|
2017-07-06 11:37:42 +00:00
|
|
|
result.entities = TextUtilities::EntitiesToMTP(_entities);
|
2016-04-04 21:09:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
SendDataCommon::SentMTPMessageFields SendGeo::getSentMessageFields() const {
|
2016-04-04 21:09:46 +00:00
|
|
|
SentMTPMessageFields result;
|
2017-02-03 10:17:40 +00:00
|
|
|
result.media = MTP_messageMediaGeo(_location.toMTP());
|
2016-04-04 21:09:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
SendDataCommon::SentMTPMessageFields SendVenue::getSentMessageFields() const {
|
2016-04-04 21:09:46 +00:00
|
|
|
SentMTPMessageFields result;
|
2017-11-20 19:54:05 +00:00
|
|
|
auto venueType = QString();
|
|
|
|
result.media = MTP_messageMediaVenue(
|
|
|
|
_location.toMTP(),
|
|
|
|
MTP_string(_title),
|
|
|
|
MTP_string(_address),
|
|
|
|
MTP_string(_provider),
|
|
|
|
MTP_string(_venueId),
|
|
|
|
MTP_string(venueType));
|
2016-04-04 21:09:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
SendDataCommon::SentMTPMessageFields SendContact::getSentMessageFields() const {
|
2016-04-04 21:09:46 +00:00
|
|
|
SentMTPMessageFields result;
|
2018-06-26 13:58:29 +00:00
|
|
|
const auto userId = 0;
|
|
|
|
const auto vcard = QString();
|
2017-12-21 12:11:33 +00:00
|
|
|
result.media = MTP_messageMediaContact(
|
|
|
|
MTP_string(_phoneNumber),
|
|
|
|
MTP_string(_firstName),
|
|
|
|
MTP_string(_lastName),
|
2018-06-26 13:58:29 +00:00
|
|
|
MTP_string(vcard),
|
|
|
|
MTP_int(userId));
|
2016-04-04 21:09:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SendContact::getLayoutDescription(const Result *owner) const {
|
2016-04-08 15:37:14 +00:00
|
|
|
auto result = SendData::getLayoutDescription(owner);
|
|
|
|
if (result.isEmpty()) {
|
|
|
|
return App::formatPhone(_phoneNumber);
|
|
|
|
}
|
|
|
|
return result;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
void SendPhoto::addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId msgId,
|
|
|
|
UserId fromId,
|
|
|
|
MTPint mtpDate,
|
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const MTPReplyMarkup &markup) const {
|
|
|
|
history->addNewPhoto(
|
|
|
|
msgId,
|
|
|
|
flags,
|
|
|
|
viaBotId,
|
|
|
|
replyToId,
|
2018-02-03 19:52:35 +00:00
|
|
|
mtpDate.v,
|
2017-12-21 12:11:33 +00:00
|
|
|
fromId,
|
|
|
|
postAuthor,
|
|
|
|
_photo,
|
2018-01-18 13:59:22 +00:00
|
|
|
{ _message, _entities },
|
2017-12-21 12:11:33 +00:00
|
|
|
markup);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
QString SendPhoto::getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const {
|
2019-01-14 17:43:06 +00:00
|
|
|
const auto errorKey = Data::RestrictionErrorKey(
|
|
|
|
history->peer,
|
|
|
|
ChatRestriction::f_send_media);
|
|
|
|
return errorKey ? lang(*errorKey) : QString();
|
2017-06-11 18:33:20 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
void SendFile::addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId msgId,
|
|
|
|
UserId fromId,
|
|
|
|
MTPint mtpDate,
|
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const MTPReplyMarkup &markup) const {
|
|
|
|
history->addNewDocument(
|
|
|
|
msgId,
|
|
|
|
flags,
|
|
|
|
viaBotId,
|
|
|
|
replyToId,
|
2018-02-03 19:52:35 +00:00
|
|
|
mtpDate.v,
|
2017-12-21 12:11:33 +00:00
|
|
|
fromId,
|
|
|
|
postAuthor,
|
|
|
|
_document,
|
2018-01-18 13:59:22 +00:00
|
|
|
{ _message, _entities },
|
2017-12-21 12:11:33 +00:00
|
|
|
markup);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
QString SendFile::getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const {
|
2019-01-14 17:43:06 +00:00
|
|
|
const auto errorMedia = Data::RestrictionErrorKey(
|
|
|
|
history->peer,
|
|
|
|
ChatRestriction::f_send_media);
|
|
|
|
const auto errorStickers = Data::RestrictionErrorKey(
|
|
|
|
history->peer,
|
|
|
|
ChatRestriction::f_send_stickers);
|
|
|
|
const auto errorGifs = Data::RestrictionErrorKey(
|
|
|
|
history->peer,
|
|
|
|
ChatRestriction::f_send_gifs);
|
|
|
|
return errorMedia
|
|
|
|
? lang(*errorMedia)
|
|
|
|
: (errorStickers && (_document->sticker() != nullptr))
|
|
|
|
? lang(*errorStickers)
|
|
|
|
: (errorGifs
|
|
|
|
&& _document->isAnimation()
|
|
|
|
&& !_document->isVideoMessage())
|
|
|
|
? lang(*errorGifs)
|
|
|
|
: QString();
|
2017-06-11 18:33:20 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
void SendGame::addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId msgId,
|
|
|
|
UserId fromId,
|
|
|
|
MTPint mtpDate,
|
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const MTPReplyMarkup &markup) const {
|
|
|
|
history->addNewGame(
|
|
|
|
msgId,
|
|
|
|
flags,
|
|
|
|
viaBotId,
|
|
|
|
replyToId,
|
2018-02-03 19:52:35 +00:00
|
|
|
mtpDate.v,
|
2017-12-21 12:11:33 +00:00
|
|
|
fromId,
|
|
|
|
postAuthor,
|
|
|
|
_game,
|
|
|
|
markup);
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
QString SendGame::getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const {
|
2019-01-14 17:43:06 +00:00
|
|
|
const auto errorKey = Data::RestrictionErrorKey(
|
|
|
|
history->peer,
|
|
|
|
ChatRestriction::f_send_games);
|
|
|
|
return errorKey ? lang(*errorKey) : QString();
|
2017-06-11 18:33:20 +00:00
|
|
|
}
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace InlineBots
|