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"
|
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "api/api_text_entities.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"
|
2020-09-01 06:44:18 +00:00
|
|
|
#include "history/history_message.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
2021-07-26 06:32:16 +00:00
|
|
|
#include "ui/text/format_values.h" // Ui::FormatPhone
|
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,
|
2021-07-28 11:55:02 +00:00
|
|
|
MessageFlags flags,
|
2017-12-21 12:11:33 +00:00
|
|
|
MsgId msgId,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId fromId,
|
2021-07-28 11:55:02 +00:00
|
|
|
TimeId date,
|
2017-12-21 12:11:33 +00:00
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
2021-10-02 11:28:21 +00:00
|
|
|
HistoryMessageMarkupData &&markup) const {
|
2017-03-10 19:46:28 +00:00
|
|
|
auto fields = getSentMessageFields();
|
2020-09-01 06:44:18 +00:00
|
|
|
if (replyToId) {
|
2021-07-28 11:55:02 +00:00
|
|
|
flags |= MessageFlag::HasReplyInfo;
|
2020-09-01 06:44:18 +00:00
|
|
|
}
|
2021-07-28 11:55:02 +00:00
|
|
|
history->addNewLocalMessage(
|
|
|
|
msgId,
|
|
|
|
flags,
|
|
|
|
viaBotId,
|
|
|
|
replyToId,
|
|
|
|
date,
|
|
|
|
fromId,
|
|
|
|
postAuthor,
|
|
|
|
std::move(fields.text),
|
|
|
|
std::move(fields.media),
|
2021-10-02 11:28:21 +00:00
|
|
|
std::move(markup));
|
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-06-19 15:09:03 +00:00
|
|
|
const auto error = Data::RestrictionError(
|
2019-01-14 17:43:06 +00:00
|
|
|
history->peer,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestriction::SendMessages);
|
2019-06-19 15:09:03 +00:00
|
|
|
return error.value_or(QString());
|
2017-06-11 18:33:20 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 11:55:02 +00:00
|
|
|
SendDataCommon::SentMessageFields SendText::getSentMessageFields() const {
|
|
|
|
return { .text = { _message, _entities } };
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 11:55:02 +00:00
|
|
|
SendDataCommon::SentMessageFields SendGeo::getSentMessageFields() const {
|
2021-03-30 08:36:09 +00:00
|
|
|
if (_period) {
|
|
|
|
using Flag = MTPDmessageMediaGeoLive::Flag;
|
2021-07-28 11:55:02 +00:00
|
|
|
return { .media = MTP_messageMediaGeoLive(
|
2021-03-30 08:36:09 +00:00
|
|
|
MTP_flags((_heading ? Flag::f_heading : Flag(0))
|
2021-07-28 11:55:02 +00:00
|
|
|
| (_proximityNotificationRadius
|
|
|
|
? Flag::f_proximity_notification_radius
|
|
|
|
: Flag(0))),
|
2021-03-30 08:36:09 +00:00
|
|
|
_location.toMTP(),
|
|
|
|
MTP_int(_heading.value_or(0)),
|
|
|
|
MTP_int(*_period),
|
2021-07-28 11:55:02 +00:00
|
|
|
MTP_int(_proximityNotificationRadius.value_or(0))) };
|
2021-03-30 08:36:09 +00:00
|
|
|
}
|
2021-07-28 11:55:02 +00:00
|
|
|
return { .media = MTP_messageMediaGeo(_location.toMTP()) };
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 11:55:02 +00:00
|
|
|
SendDataCommon::SentMessageFields SendVenue::getSentMessageFields() const {
|
|
|
|
const auto venueType = QString();
|
|
|
|
return { .media = MTP_messageMediaVenue(
|
2017-11-20 19:54:05 +00:00
|
|
|
_location.toMTP(),
|
|
|
|
MTP_string(_title),
|
|
|
|
MTP_string(_address),
|
|
|
|
MTP_string(_provider),
|
|
|
|
MTP_string(_venueId),
|
2021-07-28 11:55:02 +00:00
|
|
|
MTP_string(QString())) }; // venue_type
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 11:55:02 +00:00
|
|
|
SendDataCommon::SentMessageFields SendContact::getSentMessageFields() const {
|
|
|
|
return { .media = MTP_messageMediaContact(
|
2017-12-21 12:11:33 +00:00
|
|
|
MTP_string(_phoneNumber),
|
|
|
|
MTP_string(_firstName),
|
|
|
|
MTP_string(_lastName),
|
2021-07-28 11:55:02 +00:00
|
|
|
MTP_string(), // vcard
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_long(0)) }; // user_id
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SendContact::getLayoutDescription(const Result *owner) const {
|
2016-04-08 15:37:14 +00:00
|
|
|
auto result = SendData::getLayoutDescription(owner);
|
|
|
|
if (result.isEmpty()) {
|
2021-07-26 06:32:16 +00:00
|
|
|
return Ui::FormatPhone(_phoneNumber);
|
2016-04-08 15:37:14 +00:00
|
|
|
}
|
|
|
|
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,
|
2021-07-28 11:55:02 +00:00
|
|
|
MessageFlags flags,
|
2017-12-21 12:11:33 +00:00
|
|
|
MsgId msgId,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId fromId,
|
2021-07-28 11:55:02 +00:00
|
|
|
TimeId date,
|
2017-12-21 12:11:33 +00:00
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
2021-10-02 11:28:21 +00:00
|
|
|
HistoryMessageMarkupData &&markup) const {
|
2019-07-17 14:34:39 +00:00
|
|
|
history->addNewLocalMessage(
|
2017-12-21 12:11:33 +00:00
|
|
|
msgId,
|
|
|
|
flags,
|
|
|
|
viaBotId,
|
|
|
|
replyToId,
|
2021-07-28 11:55:02 +00:00
|
|
|
date,
|
2017-12-21 12:11:33 +00:00
|
|
|
fromId,
|
|
|
|
postAuthor,
|
|
|
|
_photo,
|
2018-01-18 13:59:22 +00:00
|
|
|
{ _message, _entities },
|
2021-10-02 11:28:21 +00:00
|
|
|
std::move(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-06-19 15:09:03 +00:00
|
|
|
const auto error = Data::RestrictionError(
|
2019-01-14 17:43:06 +00:00
|
|
|
history->peer,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestriction::SendMedia);
|
2019-06-19 15:09:03 +00:00
|
|
|
return error.value_or(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,
|
2021-07-28 11:55:02 +00:00
|
|
|
MessageFlags flags,
|
2017-12-21 12:11:33 +00:00
|
|
|
MsgId msgId,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId fromId,
|
2021-07-28 11:55:02 +00:00
|
|
|
TimeId date,
|
2017-12-21 12:11:33 +00:00
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
2021-10-02 11:28:21 +00:00
|
|
|
HistoryMessageMarkupData &&markup) const {
|
2019-07-17 14:34:39 +00:00
|
|
|
history->addNewLocalMessage(
|
2017-12-21 12:11:33 +00:00
|
|
|
msgId,
|
|
|
|
flags,
|
|
|
|
viaBotId,
|
|
|
|
replyToId,
|
2021-07-28 11:55:02 +00:00
|
|
|
date,
|
2017-12-21 12:11:33 +00:00
|
|
|
fromId,
|
|
|
|
postAuthor,
|
|
|
|
_document,
|
2018-01-18 13:59:22 +00:00
|
|
|
{ _message, _entities },
|
2021-10-02 11:28:21 +00:00
|
|
|
std::move(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-06-19 15:09:03 +00:00
|
|
|
const auto errorMedia = Data::RestrictionError(
|
2019-01-14 17:43:06 +00:00
|
|
|
history->peer,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestriction::SendMedia);
|
2019-06-19 15:09:03 +00:00
|
|
|
const auto errorStickers = Data::RestrictionError(
|
2019-01-14 17:43:06 +00:00
|
|
|
history->peer,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestriction::SendStickers);
|
2019-06-19 15:09:03 +00:00
|
|
|
const auto errorGifs = Data::RestrictionError(
|
2019-01-14 17:43:06 +00:00
|
|
|
history->peer,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestriction::SendGifs);
|
2019-01-14 17:43:06 +00:00
|
|
|
return errorMedia
|
2019-06-19 15:09:03 +00:00
|
|
|
? *errorMedia
|
2019-01-14 17:43:06 +00:00
|
|
|
: (errorStickers && (_document->sticker() != nullptr))
|
2019-06-19 15:09:03 +00:00
|
|
|
? *errorStickers
|
2019-01-14 17:43:06 +00:00
|
|
|
: (errorGifs
|
|
|
|
&& _document->isAnimation()
|
|
|
|
&& !_document->isVideoMessage())
|
2019-06-19 15:09:03 +00:00
|
|
|
? *errorGifs
|
2019-01-14 17:43:06 +00:00
|
|
|
: 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,
|
2021-07-28 11:55:02 +00:00
|
|
|
MessageFlags flags,
|
2017-12-21 12:11:33 +00:00
|
|
|
MsgId msgId,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId fromId,
|
2021-07-28 11:55:02 +00:00
|
|
|
TimeId date,
|
2017-12-21 12:11:33 +00:00
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
2021-10-02 11:28:21 +00:00
|
|
|
HistoryMessageMarkupData &&markup) const {
|
2019-07-17 14:34:39 +00:00
|
|
|
history->addNewLocalMessage(
|
2017-12-21 12:11:33 +00:00
|
|
|
msgId,
|
|
|
|
flags,
|
|
|
|
viaBotId,
|
|
|
|
replyToId,
|
2021-07-28 11:55:02 +00:00
|
|
|
date,
|
2017-12-21 12:11:33 +00:00
|
|
|
fromId,
|
|
|
|
postAuthor,
|
|
|
|
_game,
|
2021-10-02 11:28:21 +00:00
|
|
|
std::move(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-06-19 15:09:03 +00:00
|
|
|
const auto error = Data::RestrictionError(
|
2019-01-14 17:43:06 +00:00
|
|
|
history->peer,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestriction::SendGames);
|
2019-06-19 15:09:03 +00:00
|
|
|
return error.value_or(QString());
|
2017-06-11 18:33:20 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 11:55:02 +00:00
|
|
|
SendDataCommon::SentMessageFields SendInvoice::getSentMessageFields() const {
|
|
|
|
return { .media = _media };
|
2021-03-30 11:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SendInvoice::getLayoutDescription(const Result *owner) const {
|
|
|
|
return qs(_media.c_messageMediaInvoice().vdescription());
|
|
|
|
}
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace InlineBots
|