tdesktop/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp

216 lines
5.2 KiB
C++
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "inline_bots/inline_bot_send_data.h"
2019-09-16 11:14:06 +00:00
#include "api/api_text_entities.h"
#include "data/data_document.h"
#include "inline_bots/inline_bot_result.h"
2017-03-04 10:23:56 +00:00
#include "storage/localstorage.h"
#include "lang/lang_keys.h"
#include "history/history.h"
2022-12-14 12:15:46 +00:00
#include "history/history_item.h"
#include "data/data_channel.h"
2021-07-26 06:32:16 +00:00
#include "ui/text/format_values.h" // Ui::FormatPhone
namespace InlineBots {
namespace internal {
QString SendData::getLayoutTitle(const Result *owner) const {
return owner->_title;
}
QString SendData::getLayoutDescription(const Result *owner) const {
return owner->_description;
}
void SendDataCommon::addToHistory(
const Result *owner,
not_null<History*> history,
2021-07-28 11:55:02 +00:00
MessageFlags flags,
MsgId msgId,
PeerId fromId,
2021-07-28 11:55:02 +00:00
TimeId date,
UserId viaBotId,
FullReplyTo replyTo,
const QString &postAuthor,
2021-10-02 11:28:21 +00:00
HistoryMessageMarkupData &&markup) const {
auto fields = getSentMessageFields();
if (replyTo) {
2021-07-28 11:55:02 +00:00
flags |= MessageFlag::HasReplyInfo;
}
2021-07-28 11:55:02 +00:00
history->addNewLocalMessage(
msgId,
flags,
viaBotId,
replyTo,
2021-07-28 11:55:02 +00:00
date,
fromId,
postAuthor,
std::move(fields.text),
std::move(fields.media),
2021-10-02 11:28:21 +00:00
std::move(markup));
}
QString SendDataCommon::getErrorOnSend(
const Result *owner,
not_null<History*> history) const {
const auto type = ChatRestriction::SendOther;
return Data::RestrictionError(history->peer, type).value_or(QString());
}
2021-07-28 11:55:02 +00:00
SendDataCommon::SentMessageFields SendText::getSentMessageFields() const {
return { .text = { _message, _entities } };
}
2021-07-28 11:55:02 +00:00
SendDataCommon::SentMessageFields SendGeo::getSentMessageFields() const {
if (_period) {
using Flag = MTPDmessageMediaGeoLive::Flag;
2021-07-28 11:55:02 +00:00
return { .media = MTP_messageMediaGeoLive(
MTP_flags((_heading ? Flag::f_heading : Flag(0))
2021-07-28 11:55:02 +00:00
| (_proximityNotificationRadius
? Flag::f_proximity_notification_radius
: Flag(0))),
_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-07-28 11:55:02 +00:00
return { .media = MTP_messageMediaGeo(_location.toMTP()) };
}
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
}
2021-07-28 11:55:02 +00:00
SendDataCommon::SentMessageFields SendContact::getSentMessageFields() const {
return { .media = MTP_messageMediaContact(
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
}
QString SendContact::getLayoutDescription(const Result *owner) const {
auto result = SendData::getLayoutDescription(owner);
if (result.isEmpty()) {
2021-07-26 06:32:16 +00:00
return Ui::FormatPhone(_phoneNumber);
}
return result;
}
void SendPhoto::addToHistory(
const Result *owner,
not_null<History*> history,
2021-07-28 11:55:02 +00:00
MessageFlags flags,
MsgId msgId,
PeerId fromId,
2021-07-28 11:55:02 +00:00
TimeId date,
UserId viaBotId,
FullReplyTo replyTo,
const QString &postAuthor,
2021-10-02 11:28:21 +00:00
HistoryMessageMarkupData &&markup) const {
2019-07-17 14:34:39 +00:00
history->addNewLocalMessage(
msgId,
flags,
viaBotId,
replyTo,
2021-07-28 11:55:02 +00:00
date,
fromId,
postAuthor,
_photo,
2018-01-18 13:59:22 +00:00
{ _message, _entities },
2021-10-02 11:28:21 +00:00
std::move(markup));
}
QString SendPhoto::getErrorOnSend(
const Result *owner,
not_null<History*> history) const {
const auto type = ChatRestriction::SendPhotos;
return Data::RestrictionError(history->peer, type).value_or(QString());
}
void SendFile::addToHistory(
const Result *owner,
not_null<History*> history,
2021-07-28 11:55:02 +00:00
MessageFlags flags,
MsgId msgId,
PeerId fromId,
2021-07-28 11:55:02 +00:00
TimeId date,
UserId viaBotId,
FullReplyTo replyTo,
const QString &postAuthor,
2021-10-02 11:28:21 +00:00
HistoryMessageMarkupData &&markup) const {
2019-07-17 14:34:39 +00:00
history->addNewLocalMessage(
msgId,
flags,
viaBotId,
replyTo,
2021-07-28 11:55:02 +00:00
date,
fromId,
postAuthor,
_document,
2018-01-18 13:59:22 +00:00
{ _message, _entities },
2021-10-02 11:28:21 +00:00
std::move(markup));
}
QString SendFile::getErrorOnSend(
const Result *owner,
not_null<History*> history) const {
const auto type = _document->requiredSendRight();
return Data::RestrictionError(history->peer, type).value_or(QString());
}
void SendGame::addToHistory(
const Result *owner,
not_null<History*> history,
2021-07-28 11:55:02 +00:00
MessageFlags flags,
MsgId msgId,
PeerId fromId,
2021-07-28 11:55:02 +00:00
TimeId date,
UserId viaBotId,
FullReplyTo replyTo,
const QString &postAuthor,
2021-10-02 11:28:21 +00:00
HistoryMessageMarkupData &&markup) const {
2019-07-17 14:34:39 +00:00
history->addNewLocalMessage(
msgId,
flags,
viaBotId,
replyTo,
2021-07-28 11:55:02 +00:00
date,
fromId,
postAuthor,
_game,
2021-10-02 11:28:21 +00:00
std::move(markup));
}
QString SendGame::getErrorOnSend(
const Result *owner,
not_null<History*> history) const {
const auto type = ChatRestriction::SendGames;
return Data::RestrictionError(history->peer, type).value_or(QString());
}
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());
}
} // namespace internal
} // namespace InlineBots