inline_bot_result.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "data/data_cloud_file.h"
  9. #include "api/api_common.h"
  10. #include "media/view/media_view_open_common.h"
  11. #include "ui/effects/message_sending_animation_common.h"
  12. class FileLoader;
  13. class History;
  14. class UserData;
  15. struct HistoryMessageMarkupData;
  16. struct HistoryItemCommonFields;
  17. namespace Data {
  18. class LocationPoint;
  19. struct SendError;
  20. } // namespace Data
  21. namespace InlineBots {
  22. namespace Layout {
  23. class ItemBase;
  24. } // namespace Layout
  25. namespace internal {
  26. class SendData;
  27. } // namespace internal
  28. class Result {
  29. private:
  30. // See http://stackoverflow.com/a/8147326
  31. struct Creator;
  32. public:
  33. // Constructor is public only for std::make_unique<>() to work.
  34. // You should use create() static method instead.
  35. Result(not_null<Main::Session*> session, const Creator &creator);
  36. static std::shared_ptr<Result> Create(
  37. not_null<Main::Session*> session,
  38. uint64 queryId,
  39. const MTPBotInlineResult &mtpData);
  40. uint64 getQueryId() const {
  41. return _queryId;
  42. }
  43. QString getId() const {
  44. return _id;
  45. }
  46. // This is real SendClickHandler::onClick implementation for the specified
  47. // inline bot result. If it returns true you need to send this result.
  48. bool onChoose(Layout::ItemBase *layout);
  49. Media::View::OpenRequest openRequest();
  50. void cancelFile();
  51. bool hasThumbDisplay() const;
  52. void addToHistory(
  53. not_null<History*> history,
  54. HistoryItemCommonFields &&fields) const;
  55. [[nodiscard]] not_null<HistoryItem*> makeMessage(
  56. not_null<History*> history,
  57. HistoryItemCommonFields &&fields) const;
  58. [[nodiscard]] Data::SendError getErrorOnSend(
  59. not_null<History*> history) const;
  60. // interface for Layout:: usage
  61. std::optional<Data::LocationPoint> getLocationPoint() const;
  62. QString getLayoutTitle() const;
  63. QString getLayoutDescription() const;
  64. ~Result();
  65. private:
  66. void createGame(not_null<Main::Session*> session);
  67. QSize thumbBox() const;
  68. MTPWebDocument adjustAttributes(const MTPWebDocument &document);
  69. MTPVector<MTPDocumentAttribute> adjustAttributes(
  70. const MTPVector<MTPDocumentAttribute> &document,
  71. const MTPstring &mimeType);
  72. enum class Type {
  73. Unknown,
  74. Photo,
  75. Video,
  76. Audio,
  77. Sticker,
  78. File,
  79. Gif,
  80. Article,
  81. Contact,
  82. Geo,
  83. Venue,
  84. Game,
  85. };
  86. friend class internal::SendData;
  87. friend class Layout::ItemBase;
  88. struct Creator {
  89. uint64 queryId = 0;
  90. Type type = Type::Unknown;
  91. };
  92. not_null<Main::Session*> _session;
  93. uint64 _queryId = 0;
  94. QString _id;
  95. Type _type = Type::Unknown;
  96. QString _title, _description, _url;
  97. QString _content_url;
  98. DocumentData *_document = nullptr;
  99. PhotoData *_photo = nullptr;
  100. GameData *_game = nullptr;
  101. std::unique_ptr<HistoryMessageMarkupData> _replyMarkup;
  102. Data::CloudImage _thumbnail;
  103. Data::CloudImage _locationThumbnail;
  104. std::unique_ptr<internal::SendData> sendData;
  105. };
  106. struct ResultSelected {
  107. std::shared_ptr<Result> result;
  108. not_null<UserData*> bot;
  109. PeerData *recipientOverride = nullptr;
  110. Api::SendOptions options;
  111. Ui::MessageSendingAnimationFrom messageSendingFrom;
  112. // Open in OverlayWidget;
  113. bool open = false;
  114. };
  115. } // namespace InlineBots