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
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
#include "history/history_location_manager.h"
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2020-06-08 08:03:45 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2019-09-13 06:06:02 +00:00
|
|
|
class History;
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
namespace InlineBots {
|
|
|
|
|
|
|
|
class Result;
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
// Abstract class describing the message that will be
|
|
|
|
// sent if the user chooses this inline bot result.
|
|
|
|
// For each type of message that can be sent there will be a subclass.
|
|
|
|
class SendData {
|
|
|
|
public:
|
2020-06-08 08:03:45 +00:00
|
|
|
explicit SendData(not_null<Main::Session*> session) : _session(session) {
|
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
SendData(const SendData &other) = delete;
|
|
|
|
SendData &operator=(const SendData &other) = delete;
|
|
|
|
virtual ~SendData() = default;
|
|
|
|
|
2020-06-08 08:03:45 +00:00
|
|
|
[[nodiscard]] Main::Session &session() const {
|
|
|
|
return *_session;
|
|
|
|
}
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
virtual bool isValid() const = 0;
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
virtual void addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
|
|
|
MTPDmessage::Flags flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2017-12-21 12:11:33 +00:00
|
|
|
MsgId msgId,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId fromId,
|
2017-12-21 12:11:33 +00:00
|
|
|
MTPint mtpDate,
|
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const MTPReplyMarkup &markup) const = 0;
|
|
|
|
virtual QString getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const = 0;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
virtual bool hasLocationCoords() const {
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-21 12:27:46 +00:00
|
|
|
virtual std::optional<Data::LocationPoint> getLocationPoint() const {
|
|
|
|
return std::nullopt;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
virtual QString getLayoutTitle(const Result *owner) const;
|
|
|
|
virtual QString getLayoutDescription(const Result *owner) const;
|
|
|
|
|
2020-06-08 08:03:45 +00:00
|
|
|
private:
|
|
|
|
not_null<Main::Session*> _session;
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
};
|
2016-04-05 20:24:27 +00:00
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
// This class implements addHistory() for most of the types hiding
|
|
|
|
// the differences in getSentMessageFields() method.
|
|
|
|
// Only SendFile and SendPhoto work by their own.
|
|
|
|
class SendDataCommon : public SendData {
|
|
|
|
public:
|
2020-06-08 08:03:45 +00:00
|
|
|
using SendData::SendData;
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
struct SentMTPMessageFields {
|
2019-07-05 13:38:38 +00:00
|
|
|
MTPString text = MTP_string();
|
|
|
|
MTPVector<MTPMessageEntity> entities = MTP_vector<MTPMessageEntity>();
|
2016-04-09 08:29:34 +00:00
|
|
|
MTPMessageMedia media = MTP_messageMediaEmpty();
|
|
|
|
};
|
|
|
|
virtual SentMTPMessageFields getSentMessageFields() const = 0;
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
void addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
|
|
|
MTPDmessage::Flags flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2017-12-21 12:11:33 +00:00
|
|
|
MsgId msgId,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId fromId,
|
2017-12-21 12:11:33 +00:00
|
|
|
MTPint mtpDate,
|
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const MTPReplyMarkup &markup) const override;
|
|
|
|
|
|
|
|
QString getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const override;
|
2017-06-11 18:33:20 +00:00
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Plain text message.
|
2016-04-09 08:29:34 +00:00
|
|
|
class SendText : public SendDataCommon {
|
2016-04-04 21:09:46 +00:00
|
|
|
public:
|
2018-01-18 11:04:50 +00:00
|
|
|
SendText(
|
2020-06-08 08:03:45 +00:00
|
|
|
not_null<Main::Session*> session,
|
2018-01-18 11:04:50 +00:00
|
|
|
const QString &message,
|
|
|
|
const EntitiesInText &entities,
|
|
|
|
bool/* noWebPage*/)
|
2020-06-08 08:03:45 +00:00
|
|
|
: SendDataCommon(session)
|
|
|
|
, _message(message)
|
2018-01-18 11:04:50 +00:00
|
|
|
, _entities(entities) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const override {
|
|
|
|
return !_message.isEmpty();
|
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
SentMTPMessageFields getSentMessageFields() const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QString _message;
|
|
|
|
EntitiesInText _entities;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Message with geo location point media.
|
2016-04-09 08:29:34 +00:00
|
|
|
class SendGeo : public SendDataCommon {
|
2016-04-04 21:09:46 +00:00
|
|
|
public:
|
2020-06-08 08:03:45 +00:00
|
|
|
SendGeo(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const MTPDgeoPoint &point)
|
|
|
|
: SendDataCommon(session)
|
|
|
|
, _location(point) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2021-03-30 08:36:09 +00:00
|
|
|
SendGeo(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const MTPDgeoPoint &point,
|
|
|
|
int period,
|
|
|
|
std::optional<int> heading,
|
|
|
|
std::optional<int> proximityNotificationRadius)
|
|
|
|
: SendDataCommon(session)
|
|
|
|
, _location(point)
|
|
|
|
, _period(period)
|
|
|
|
, _heading(heading)
|
|
|
|
, _proximityNotificationRadius(proximityNotificationRadius){
|
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
bool isValid() const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
SentMTPMessageFields getSentMessageFields() const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
bool hasLocationCoords() const override {
|
|
|
|
return true;
|
|
|
|
}
|
2019-06-21 12:27:46 +00:00
|
|
|
std::optional<Data::LocationPoint> getLocationPoint() const override {
|
|
|
|
return _location;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-06-21 12:27:46 +00:00
|
|
|
Data::LocationPoint _location;
|
2021-03-30 08:36:09 +00:00
|
|
|
std::optional<int> _period;
|
|
|
|
std::optional<int> _heading;
|
|
|
|
std::optional<int> _proximityNotificationRadius;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Message with venue media.
|
2016-04-09 08:29:34 +00:00
|
|
|
class SendVenue : public SendDataCommon {
|
2016-04-04 21:09:46 +00:00
|
|
|
public:
|
2020-06-08 08:03:45 +00:00
|
|
|
SendVenue(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const MTPDgeoPoint &point,
|
|
|
|
const QString &venueId,
|
|
|
|
const QString &provider,
|
|
|
|
const QString &title,
|
|
|
|
const QString &address)
|
|
|
|
: SendDataCommon(session)
|
|
|
|
, _location(point)
|
|
|
|
, _venueId(venueId)
|
|
|
|
, _provider(provider)
|
|
|
|
, _title(title)
|
|
|
|
, _address(address) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
SentMTPMessageFields getSentMessageFields() const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
bool hasLocationCoords() const override {
|
|
|
|
return true;
|
|
|
|
}
|
2019-06-21 12:27:46 +00:00
|
|
|
std::optional<Data::LocationPoint> getLocationPoint() const override {
|
|
|
|
return _location;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-06-21 12:27:46 +00:00
|
|
|
Data::LocationPoint _location;
|
2016-04-04 21:09:46 +00:00
|
|
|
QString _venueId, _provider, _title, _address;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Message with shared contact media.
|
2016-04-09 08:29:34 +00:00
|
|
|
class SendContact : public SendDataCommon {
|
2016-04-04 21:09:46 +00:00
|
|
|
public:
|
2020-06-08 08:03:45 +00:00
|
|
|
SendContact(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const QString &firstName,
|
|
|
|
const QString &lastName,
|
|
|
|
const QString &phoneNumber)
|
|
|
|
: SendDataCommon(session)
|
|
|
|
, _firstName(firstName)
|
|
|
|
, _lastName(lastName)
|
|
|
|
, _phoneNumber(phoneNumber) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const override {
|
|
|
|
return (!_firstName.isEmpty() || !_lastName.isEmpty()) && !_phoneNumber.isEmpty();
|
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
SentMTPMessageFields getSentMessageFields() const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
QString getLayoutDescription(const Result *owner) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _firstName, _lastName, _phoneNumber;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Message with photo.
|
|
|
|
class SendPhoto : public SendData {
|
|
|
|
public:
|
2018-01-18 11:04:50 +00:00
|
|
|
SendPhoto(
|
2020-06-08 08:03:45 +00:00
|
|
|
not_null<Main::Session*> session,
|
2018-01-18 11:04:50 +00:00
|
|
|
PhotoData *photo,
|
|
|
|
const QString &message,
|
|
|
|
const EntitiesInText &entities)
|
2020-06-08 08:03:45 +00:00
|
|
|
: SendData(session)
|
|
|
|
, _photo(photo)
|
2018-01-18 11:04:50 +00:00
|
|
|
, _message(message)
|
|
|
|
, _entities(entities) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const override {
|
2016-04-10 11:13:37 +00:00
|
|
|
return _photo != nullptr;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
void addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
|
|
|
MTPDmessage::Flags flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2017-12-21 12:11:33 +00:00
|
|
|
MsgId msgId,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId fromId,
|
2017-12-21 12:11:33 +00:00
|
|
|
MTPint mtpDate,
|
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const MTPReplyMarkup &markup) const override;
|
|
|
|
|
|
|
|
QString getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const override;
|
2017-06-11 18:33:20 +00:00
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
private:
|
|
|
|
PhotoData *_photo;
|
2018-01-18 11:04:50 +00:00
|
|
|
QString _message;
|
|
|
|
EntitiesInText _entities;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Message with file.
|
|
|
|
class SendFile : public SendData {
|
|
|
|
public:
|
2018-01-18 11:04:50 +00:00
|
|
|
SendFile(
|
2020-06-08 08:03:45 +00:00
|
|
|
not_null<Main::Session*> session,
|
2018-01-18 11:04:50 +00:00
|
|
|
DocumentData *document,
|
|
|
|
const QString &message,
|
|
|
|
const EntitiesInText &entities)
|
2020-06-08 08:03:45 +00:00
|
|
|
: SendData(session)
|
|
|
|
, _document(document)
|
2018-01-18 11:04:50 +00:00
|
|
|
, _message(message)
|
|
|
|
, _entities(entities) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const override {
|
2016-04-10 11:13:37 +00:00
|
|
|
return _document != nullptr;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
void addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
|
|
|
MTPDmessage::Flags flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2017-12-21 12:11:33 +00:00
|
|
|
MsgId msgId,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId fromId,
|
2017-12-21 12:11:33 +00:00
|
|
|
MTPint mtpDate,
|
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const MTPReplyMarkup &markup) const override;
|
|
|
|
|
|
|
|
QString getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const override;
|
2017-06-11 18:33:20 +00:00
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
private:
|
|
|
|
DocumentData *_document;
|
2018-01-18 11:04:50 +00:00
|
|
|
QString _message;
|
|
|
|
EntitiesInText _entities;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-28 16:23:25 +00:00
|
|
|
// Message with game.
|
|
|
|
class SendGame : public SendData {
|
|
|
|
public:
|
2020-06-08 08:03:45 +00:00
|
|
|
SendGame(not_null<Main::Session*> session, GameData *game)
|
|
|
|
: SendData(session)
|
|
|
|
, _game(game) {
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const override {
|
|
|
|
return _game != nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
void addToHistory(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history,
|
|
|
|
MTPDmessage::Flags flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2017-12-21 12:11:33 +00:00
|
|
|
MsgId msgId,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId fromId,
|
2017-12-21 12:11:33 +00:00
|
|
|
MTPint mtpDate,
|
|
|
|
UserId viaBotId,
|
|
|
|
MsgId replyToId,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const MTPReplyMarkup &markup) const override;
|
|
|
|
|
|
|
|
QString getErrorOnSend(
|
|
|
|
const Result *owner,
|
|
|
|
not_null<History*> history) const override;
|
2017-06-11 18:33:20 +00:00
|
|
|
|
2016-09-28 16:23:25 +00:00
|
|
|
private:
|
|
|
|
GameData *_game;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-03-30 11:43:47 +00:00
|
|
|
class SendInvoice : public SendDataCommon {
|
|
|
|
public:
|
|
|
|
SendInvoice(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
MTPMessageMedia media)
|
|
|
|
: SendDataCommon(session)
|
|
|
|
, _media(media) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SentMTPMessageFields getSentMessageFields() const override;
|
|
|
|
|
|
|
|
QString getLayoutDescription(const Result *owner) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
MTPMessageMedia _media;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace InlineBots
|