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"
|
|
|
|
|
|
|
|
class FileLoader;
|
|
|
|
|
|
|
|
namespace InlineBots {
|
|
|
|
|
|
|
|
namespace Layout {
|
|
|
|
class ItemBase;
|
|
|
|
} // namespace Layout
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
class SendData;
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
class Result {
|
|
|
|
private:
|
|
|
|
// See http://stackoverflow.com/a/8147326
|
|
|
|
struct Creator;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
// Constructor is public only for std::make_unique<>() to work.
|
2016-04-04 21:09:46 +00:00
|
|
|
// You should use create() static method instead.
|
|
|
|
explicit Result(const Creator &creator);
|
2017-02-21 13:45:56 +00:00
|
|
|
static std::unique_ptr<Result> create(uint64 queryId, const MTPBotInlineResult &mtpData);
|
2016-04-04 21:09:46 +00:00
|
|
|
Result(const Result &other) = delete;
|
|
|
|
Result &operator=(const Result &other) = delete;
|
|
|
|
|
2016-04-05 20:24:27 +00:00
|
|
|
uint64 getQueryId() const {
|
|
|
|
return _queryId;
|
|
|
|
}
|
|
|
|
QString getId() const {
|
|
|
|
return _id;
|
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-04-05 20:24:27 +00:00
|
|
|
// This is real SendClickHandler::onClick implementation for the specified
|
|
|
|
// inline bot result. If it returns true you need to send this result.
|
|
|
|
bool onChoose(Layout::ItemBase *layout);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-04-10 11:13:37 +00:00
|
|
|
void forget();
|
2016-04-05 20:24:27 +00:00
|
|
|
void openFile();
|
2016-04-04 21:09:46 +00:00
|
|
|
void cancelFile();
|
|
|
|
|
|
|
|
bool hasThumbDisplay() const;
|
|
|
|
|
2017-07-12 19:14:20 +00:00
|
|
|
void addToHistory(History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, UserId viaBotId, MsgId replyToId, const QString &postAuthor) const;
|
2017-06-11 18:33:20 +00:00
|
|
|
QString getErrorOnSend(History *history) const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
// interface for Layout:: usage
|
|
|
|
bool getLocationCoords(LocationCoords *outLocation) const;
|
|
|
|
QString getLayoutTitle() const;
|
|
|
|
QString getLayoutDescription() const;
|
|
|
|
|
2016-09-28 21:33:05 +00:00
|
|
|
~Result();
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
private:
|
2016-04-10 11:13:37 +00:00
|
|
|
void createPhoto();
|
2016-04-09 08:29:34 +00:00
|
|
|
void createDocument();
|
2016-09-28 16:23:25 +00:00
|
|
|
void createGame();
|
2016-04-09 08:29:34 +00:00
|
|
|
|
2016-04-05 20:24:27 +00:00
|
|
|
enum class Type {
|
|
|
|
Unknown,
|
|
|
|
Photo,
|
|
|
|
Video,
|
|
|
|
Audio,
|
|
|
|
Sticker,
|
|
|
|
File,
|
|
|
|
Gif,
|
|
|
|
Article,
|
|
|
|
Contact,
|
2016-04-11 10:59:01 +00:00
|
|
|
Geo,
|
2016-04-05 20:24:27 +00:00
|
|
|
Venue,
|
2016-09-28 16:23:25 +00:00
|
|
|
Game,
|
2016-04-05 20:24:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
friend class internal::SendData;
|
|
|
|
friend class Layout::ItemBase;
|
2016-04-04 21:09:46 +00:00
|
|
|
struct Creator {
|
|
|
|
uint64 queryId;
|
|
|
|
Type type;
|
|
|
|
};
|
|
|
|
|
2016-04-05 20:24:27 +00:00
|
|
|
uint64 _queryId = 0;
|
|
|
|
QString _id;
|
|
|
|
Type _type = Type::Unknown;
|
|
|
|
QString _title, _description, _url, _thumb_url;
|
|
|
|
QString _content_type, _content_url;
|
|
|
|
int _width = 0;
|
|
|
|
int _height = 0;
|
|
|
|
int _duration = 0;
|
|
|
|
|
|
|
|
DocumentData *_document = nullptr;
|
|
|
|
PhotoData *_photo = nullptr;
|
2016-09-28 16:23:25 +00:00
|
|
|
GameData *_game = nullptr;
|
2016-04-05 20:24:27 +00:00
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<MTPReplyMarkup> _mtpKeyboard;
|
2016-04-06 08:00:37 +00:00
|
|
|
|
2016-04-05 20:24:27 +00:00
|
|
|
ImagePtr _thumb, _locationThumb;
|
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<internal::SendData> sendData;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace InlineBots
|