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_send_data.h"
|
|
|
|
|
|
|
|
#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"
|
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;
|
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
void SendDataCommon::addToHistory(const Result *owner, History *history,
|
|
|
|
MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate,
|
2017-07-12 19:14:20 +00:00
|
|
|
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-07-12 19:14:20 +00:00
|
|
|
history->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(msgId), MTP_int(fromId), peerToMTP(history->peer->id), MTPnullFwdHeader, MTP_int(viaBotId), MTP_int(replyToId), mtpDate, fields.text, fields.media, markup, fields.entities, MTP_int(1), MTPint(), MTP_string(postAuthor)), NewMessageUnread);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
QString SendDataCommon::getErrorOnSend(const Result *owner, History *history) const {
|
|
|
|
if (auto megagroup = history->peer->asMegagroup()) {
|
|
|
|
if (megagroup->restrictedRights().is_send_messages()) {
|
|
|
|
return lang(lng_restricted_send_message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
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-02-03 10:17:40 +00:00
|
|
|
result.media = MTP_messageMediaVenue(_location.toMTP(), MTP_string(_title), MTP_string(_address), MTP_string(_provider), MTP_string(_venueId));
|
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;
|
|
|
|
result.media = MTP_messageMediaContact(MTP_string(_phoneNumber), MTP_string(_firstName), MTP_string(_lastName), MTP_int(0));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
void SendPhoto::addToHistory(const Result *owner, History *history,
|
|
|
|
MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate,
|
2017-07-12 19:14:20 +00:00
|
|
|
UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const {
|
|
|
|
history->addNewPhoto(msgId, flags, viaBotId, replyToId, date(mtpDate), fromId, postAuthor, _photo, _caption, markup);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
QString SendPhoto::getErrorOnSend(const Result *owner, History *history) const {
|
|
|
|
if (auto megagroup = history->peer->asMegagroup()) {
|
|
|
|
if (megagroup->restrictedRights().is_send_media()) {
|
|
|
|
return lang(lng_restricted_send_media);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
void SendFile::addToHistory(const Result *owner, History *history,
|
|
|
|
MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate,
|
2017-07-12 19:14:20 +00:00
|
|
|
UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const {
|
|
|
|
history->addNewDocument(msgId, flags, viaBotId, replyToId, date(mtpDate), fromId, postAuthor, _document, _caption, markup);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
QString SendFile::getErrorOnSend(const Result *owner, History *history) const {
|
|
|
|
if (auto megagroup = history->peer->asMegagroup()) {
|
|
|
|
if (megagroup->restrictedRights().is_send_media()) {
|
|
|
|
return lang(lng_restricted_send_media);
|
|
|
|
} else if (megagroup->restrictedRights().is_send_stickers() && (_document->sticker() != nullptr)) {
|
|
|
|
return lang(lng_restricted_send_stickers);
|
|
|
|
} else if (megagroup->restrictedRights().is_send_gifs() && _document->isAnimation() && !_document->isRoundVideo()) {
|
|
|
|
return lang(lng_restricted_send_gifs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2016-09-28 16:23:25 +00:00
|
|
|
void SendGame::addToHistory(const Result *owner, History *history,
|
|
|
|
MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate,
|
2017-07-12 19:14:20 +00:00
|
|
|
UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const {
|
|
|
|
history->addNewGame(msgId, flags, viaBotId, replyToId, date(mtpDate), fromId, postAuthor, _game, markup);
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
QString SendGame::getErrorOnSend(const Result *owner, History *history) const {
|
|
|
|
if (auto megagroup = history->peer->asMegagroup()) {
|
|
|
|
if (megagroup->restrictedRights().is_send_games()) {
|
|
|
|
return lang(lng_restricted_send_inline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace InlineBots
|