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
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "core/basic_types.h"
|
2016-04-04 21:09:46 +00:00
|
|
|
#include "structs.h"
|
|
|
|
#include "mtproto/core_types.h"
|
2016-09-27 13:37:18 +00:00
|
|
|
#include "history/history_location_manager.h"
|
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:
|
|
|
|
SendData() = default;
|
|
|
|
SendData(const SendData &other) = delete;
|
|
|
|
SendData &operator=(const SendData &other) = delete;
|
|
|
|
virtual ~SendData() = default;
|
|
|
|
|
|
|
|
virtual bool isValid() const = 0;
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
virtual void 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 = 0;
|
2017-06-11 18:33:20 +00:00
|
|
|
virtual QString getErrorOnSend(const Result *owner, History *history) const = 0;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
virtual bool hasLocationCoords() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual bool getLocationCoords(LocationCoords *outLocation) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual QString getLayoutTitle(const Result *owner) const;
|
|
|
|
virtual QString getLayoutDescription(const Result *owner) const;
|
|
|
|
|
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:
|
|
|
|
struct SentMTPMessageFields {
|
|
|
|
MTPString text = MTP_string("");
|
|
|
|
MTPVector<MTPMessageEntity> entities = MTPnullEntities;
|
|
|
|
MTPMessageMedia media = MTP_messageMediaEmpty();
|
|
|
|
};
|
|
|
|
virtual SentMTPMessageFields getSentMessageFields() const = 0;
|
|
|
|
|
|
|
|
void 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 override;
|
2016-04-05 20:24:27 +00:00
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
QString getErrorOnSend(const Result *owner, History *history) const override;
|
|
|
|
|
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:
|
2016-04-07 10:35:09 +00:00
|
|
|
SendText(const QString &message, const EntitiesInText &entities, bool/* noWebPage*/)
|
2016-04-04 21:09:46 +00:00
|
|
|
: _message(message)
|
2016-04-07 10:35:09 +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:
|
2016-09-27 13:37:18 +00:00
|
|
|
explicit SendGeo(const MTPDgeoPoint &point) : _location(point) {
|
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;
|
|
|
|
}
|
|
|
|
bool getLocationCoords(LocationCoords *outLocation) const override {
|
|
|
|
t_assert(outLocation != nullptr);
|
|
|
|
*outLocation = _location;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
LocationCoords _location;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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:
|
|
|
|
SendVenue(const MTPDgeoPoint &point, const QString &venueId,
|
|
|
|
const QString &provider, const QString &title, const QString &address)
|
|
|
|
: _location(point)
|
|
|
|
, _venueId(venueId)
|
|
|
|
, _provider(provider)
|
|
|
|
, _title(title)
|
|
|
|
, _address(address) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
bool getLocationCoords(LocationCoords *outLocation) const override {
|
|
|
|
t_assert(outLocation != nullptr);
|
|
|
|
*outLocation = _location;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
LocationCoords _location;
|
|
|
|
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:
|
|
|
|
SendContact(const QString &firstName, const QString &lastName, const QString &phoneNumber)
|
|
|
|
: _firstName(firstName)
|
|
|
|
, _lastName(lastName)
|
|
|
|
, _phoneNumber(phoneNumber) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2016-04-10 11:13:37 +00:00
|
|
|
SendPhoto(PhotoData *photo, const QString &caption)
|
2016-04-04 21:09:46 +00:00
|
|
|
: _photo(photo)
|
|
|
|
, _caption(caption) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const override {
|
2016-04-10 11:13:37 +00:00
|
|
|
return _photo != nullptr;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
void 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 override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
QString getErrorOnSend(const Result *owner, History *history) const override;
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
private:
|
|
|
|
PhotoData *_photo;
|
2016-04-10 11:13:37 +00:00
|
|
|
QString _caption;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Message with file.
|
|
|
|
class SendFile : public SendData {
|
|
|
|
public:
|
2016-04-10 11:13:37 +00:00
|
|
|
SendFile(DocumentData *document, const QString &caption)
|
2016-04-04 21:09:46 +00:00
|
|
|
: _document(document)
|
|
|
|
, _caption(caption) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const override {
|
2016-04-10 11:13:37 +00:00
|
|
|
return _document != nullptr;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2016-04-09 08:29:34 +00:00
|
|
|
void 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 override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
QString getErrorOnSend(const Result *owner, History *history) const override;
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
private:
|
|
|
|
DocumentData *_document;
|
2016-04-10 11:13:37 +00:00
|
|
|
QString _caption;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-28 16:23:25 +00:00
|
|
|
// Message with game.
|
|
|
|
class SendGame : public SendData {
|
|
|
|
public:
|
|
|
|
SendGame(GameData *game)
|
|
|
|
: _game(game) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const override {
|
|
|
|
return _game != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void 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 override;
|
2016-09-28 16:23:25 +00:00
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
QString getErrorOnSend(const Result *owner, History *history) const override;
|
|
|
|
|
2016-09-28 16:23:25 +00:00
|
|
|
private:
|
|
|
|
GameData *_game;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace InlineBots
|