2016-04-05 01:09:46 +04:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-04-05 01:09:46 +04:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-04-05 01:09:46 +04:00
|
|
|
*/
|
|
|
|
#include "inline_bots/inline_bot_send_data.h"
|
|
|
|
|
2019-09-16 14:14:06 +03:00
|
|
|
#include "api/api_text_entities.h"
|
2017-09-26 14:49:16 +03:00
|
|
|
#include "data/data_document.h"
|
2016-04-05 01:09:46 +04:00
|
|
|
#include "inline_bots/inline_bot_result.h"
|
2017-03-04 13:23:56 +03:00
|
|
|
#include "storage/localstorage.h"
|
2017-06-11 20:33:20 +02:00
|
|
|
#include "lang/lang_keys.h"
|
2018-01-13 15:45:11 +03:00
|
|
|
#include "history/history.h"
|
2022-12-14 16:15:46 +04:00
|
|
|
#include "history/history_item.h"
|
2019-01-04 15:09:48 +04:00
|
|
|
#include "data/data_channel.h"
|
2021-07-26 09:32:16 +03:00
|
|
|
#include "ui/text/format_values.h" // Ui::FormatPhone
|
2016-04-05 01:09:46 +04:00
|
|
|
|
|
|
|
namespace InlineBots {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
QString SendData::getLayoutTitle(const Result *owner) const {
|
2016-04-06 00:24:27 +04:00
|
|
|
return owner->_title;
|
2016-04-05 01:09:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SendData::getLayoutDescription(const Result *owner) const {
|
2016-04-06 00:24:27 +04:00
|
|
|
return owner->_description;
|
|
|
|
}
|
|
|
|
|
2017-12-21 16:11:33 +04:00
|
|
|
void SendDataCommon::addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
2024-02-26 22:24:00 +04:00
|
|
|
HistoryItemCommonFields &&fields) const {
|
|
|
|
auto distinct = getSentMessageFields();
|
|
|
|
if (fields.replyTo) {
|
|
|
|
fields.flags |= MessageFlag::HasReplyInfo;
|
2020-09-01 10:44:18 +04:00
|
|
|
}
|
2021-07-28 14:55:02 +03:00
|
|
|
history->addNewLocalMessage(
|
2024-02-26 22:24:00 +04:00
|
|
|
std::move(fields),
|
|
|
|
std::move(distinct.text),
|
|
|
|
std::move(distinct.media));
|
2016-04-05 01:09:46 +04:00
|
|
|
}
|
|
|
|
|
2017-12-21 16:11:33 +04:00
|
|
|
QString SendDataCommon::getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const {
|
2023-01-10 22:56:20 +04:00
|
|
|
const auto type = ChatRestriction::SendOther;
|
|
|
|
return Data::RestrictionError(history->peer, type).value_or(QString());
|
2017-06-11 20:33:20 +02:00
|
|
|
}
|
|
|
|
|
2021-07-28 14:55:02 +03:00
|
|
|
SendDataCommon::SentMessageFields SendText::getSentMessageFields() const {
|
|
|
|
return { .text = { _message, _entities } };
|
2016-04-05 01:09:46 +04:00
|
|
|
}
|
|
|
|
|
2021-07-28 14:55:02 +03:00
|
|
|
SendDataCommon::SentMessageFields SendGeo::getSentMessageFields() const {
|
2021-03-30 12:36:09 +04:00
|
|
|
if (_period) {
|
|
|
|
using Flag = MTPDmessageMediaGeoLive::Flag;
|
2021-07-28 14:55:02 +03:00
|
|
|
return { .media = MTP_messageMediaGeoLive(
|
2021-03-30 12:36:09 +04:00
|
|
|
MTP_flags((_heading ? Flag::f_heading : Flag(0))
|
2021-07-28 14:55:02 +03:00
|
|
|
| (_proximityNotificationRadius
|
|
|
|
? Flag::f_proximity_notification_radius
|
|
|
|
: Flag(0))),
|
2021-03-30 12:36:09 +04:00
|
|
|
_location.toMTP(),
|
|
|
|
MTP_int(_heading.value_or(0)),
|
|
|
|
MTP_int(*_period),
|
2021-07-28 14:55:02 +03:00
|
|
|
MTP_int(_proximityNotificationRadius.value_or(0))) };
|
2021-03-30 12:36:09 +04:00
|
|
|
}
|
2021-07-28 14:55:02 +03:00
|
|
|
return { .media = MTP_messageMediaGeo(_location.toMTP()) };
|
2016-04-05 01:09:46 +04:00
|
|
|
}
|
|
|
|
|
2021-07-28 14:55:02 +03:00
|
|
|
SendDataCommon::SentMessageFields SendVenue::getSentMessageFields() const {
|
|
|
|
return { .media = MTP_messageMediaVenue(
|
2017-11-20 23:54:05 +04:00
|
|
|
_location.toMTP(),
|
|
|
|
MTP_string(_title),
|
|
|
|
MTP_string(_address),
|
|
|
|
MTP_string(_provider),
|
|
|
|
MTP_string(_venueId),
|
2021-07-28 14:55:02 +03:00
|
|
|
MTP_string(QString())) }; // venue_type
|
2016-04-05 01:09:46 +04:00
|
|
|
}
|
|
|
|
|
2021-07-28 14:55:02 +03:00
|
|
|
SendDataCommon::SentMessageFields SendContact::getSentMessageFields() const {
|
|
|
|
return { .media = MTP_messageMediaContact(
|
2017-12-21 16:11:33 +04:00
|
|
|
MTP_string(_phoneNumber),
|
|
|
|
MTP_string(_firstName),
|
|
|
|
MTP_string(_lastName),
|
2021-07-28 14:55:02 +03:00
|
|
|
MTP_string(), // vcard
|
2021-08-25 11:15:05 +03:00
|
|
|
MTP_long(0)) }; // user_id
|
2016-04-05 01:09:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SendContact::getLayoutDescription(const Result *owner) const {
|
2016-04-08 19:37:14 +04:00
|
|
|
auto result = SendData::getLayoutDescription(owner);
|
|
|
|
if (result.isEmpty()) {
|
2021-07-26 09:32:16 +03:00
|
|
|
return Ui::FormatPhone(_phoneNumber);
|
2016-04-08 19:37:14 +04:00
|
|
|
}
|
|
|
|
return result;
|
2016-04-05 01:09:46 +04:00
|
|
|
}
|
|
|
|
|
2017-12-21 16:11:33 +04:00
|
|
|
void SendPhoto::addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
2024-02-26 22:24:00 +04:00
|
|
|
HistoryItemCommonFields &&fields) const {
|
2019-07-17 16:34:39 +02:00
|
|
|
history->addNewLocalMessage(
|
2024-02-26 22:24:00 +04:00
|
|
|
std::move(fields),
|
2017-12-21 16:11:33 +04:00
|
|
|
_photo,
|
2024-02-26 22:24:00 +04:00
|
|
|
{ _message, _entities });
|
2016-04-05 01:09:46 +04:00
|
|
|
}
|
|
|
|
|
2017-12-21 16:11:33 +04:00
|
|
|
QString SendPhoto::getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const {
|
2023-01-10 22:56:20 +04:00
|
|
|
const auto type = ChatRestriction::SendPhotos;
|
|
|
|
return Data::RestrictionError(history->peer, type).value_or(QString());
|
2017-06-11 20:33:20 +02:00
|
|
|
}
|
|
|
|
|
2017-12-21 16:11:33 +04:00
|
|
|
void SendFile::addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
2024-02-26 22:24:00 +04:00
|
|
|
HistoryItemCommonFields &&fields) const {
|
2019-07-17 16:34:39 +02:00
|
|
|
history->addNewLocalMessage(
|
2024-02-26 22:24:00 +04:00
|
|
|
std::move(fields),
|
2017-12-21 16:11:33 +04:00
|
|
|
_document,
|
2024-02-26 22:24:00 +04:00
|
|
|
{ _message, _entities });
|
2016-04-05 01:09:46 +04:00
|
|
|
}
|
|
|
|
|
2017-12-21 16:11:33 +04:00
|
|
|
QString SendFile::getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const {
|
2023-01-10 22:56:20 +04:00
|
|
|
const auto type = _document->requiredSendRight();
|
|
|
|
return Data::RestrictionError(history->peer, type).value_or(QString());
|
2017-06-11 20:33:20 +02:00
|
|
|
}
|
|
|
|
|
2017-12-21 16:11:33 +04:00
|
|
|
void SendGame::addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
2024-02-26 22:24:00 +04:00
|
|
|
HistoryItemCommonFields &&fields) const {
|
|
|
|
history->addNewLocalMessage(std::move(fields), _game);
|
2016-09-28 19:23:25 +03:00
|
|
|
}
|
|
|
|
|
2017-12-21 16:11:33 +04:00
|
|
|
QString SendGame::getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const {
|
2023-01-10 22:56:20 +04:00
|
|
|
const auto type = ChatRestriction::SendGames;
|
|
|
|
return Data::RestrictionError(history->peer, type).value_or(QString());
|
2017-06-11 20:33:20 +02:00
|
|
|
}
|
|
|
|
|
2021-07-28 14:55:02 +03:00
|
|
|
SendDataCommon::SentMessageFields SendInvoice::getSentMessageFields() const {
|
|
|
|
return { .media = _media };
|
2021-03-30 15:43:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SendInvoice::getLayoutDescription(const Result *owner) const {
|
|
|
|
return qs(_media.c_messageMediaInvoice().vdescription());
|
|
|
|
}
|
|
|
|
|
2016-04-05 01:09:46 +04:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace InlineBots
|