2018-09-28 22:57:34 +02:00
|
|
|
//
|
2018-12-31 23:02:34 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
2018-09-28 22:57:34 +02:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/telegram/Dependencies.h"
|
|
|
|
#include "td/telegram/DialogId.h"
|
|
|
|
#include "td/telegram/files/FileId.h"
|
|
|
|
#include "td/telegram/logevent/LogEvent.h"
|
|
|
|
#include "td/telegram/MessageEntity.h"
|
|
|
|
#include "td/telegram/MessageId.h"
|
|
|
|
#include "td/telegram/Photo.h"
|
|
|
|
#include "td/telegram/ReplyMarkup.h"
|
2018-09-29 03:41:15 +02:00
|
|
|
#include "td/telegram/secret_api.h"
|
2019-09-18 05:55:43 +02:00
|
|
|
#include "td/telegram/StickerSetId.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
#include "td/telegram/UserId.h"
|
|
|
|
#include "td/telegram/WebPageId.h"
|
|
|
|
|
2019-02-22 21:15:43 +01:00
|
|
|
#include "td/actor/PromiseFuture.h"
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/utils/buffer.h"
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/Status.h"
|
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class Game;
|
|
|
|
struct Photo;
|
|
|
|
class Td;
|
|
|
|
|
|
|
|
class MultiPromiseActor;
|
|
|
|
|
|
|
|
enum class MessageContentType : int32 {
|
|
|
|
None = -1,
|
|
|
|
Text,
|
|
|
|
Animation,
|
|
|
|
Audio,
|
|
|
|
Document,
|
|
|
|
Photo,
|
|
|
|
Sticker,
|
|
|
|
Video,
|
|
|
|
VoiceNote,
|
|
|
|
Contact,
|
|
|
|
Location,
|
|
|
|
Venue,
|
|
|
|
ChatCreate,
|
|
|
|
ChatChangeTitle,
|
|
|
|
ChatChangePhoto,
|
|
|
|
ChatDeletePhoto,
|
|
|
|
ChatDeleteHistory,
|
|
|
|
ChatAddUsers,
|
|
|
|
ChatJoinedByLink,
|
|
|
|
ChatDeleteUser,
|
|
|
|
ChatMigrateTo,
|
|
|
|
ChannelCreate,
|
|
|
|
ChannelMigrateFrom,
|
|
|
|
PinMessage,
|
|
|
|
Game,
|
|
|
|
GameScore,
|
|
|
|
ScreenshotTaken,
|
|
|
|
ChatSetTtl,
|
|
|
|
Unsupported,
|
|
|
|
Call,
|
|
|
|
Invoice,
|
|
|
|
PaymentSuccessful,
|
|
|
|
VideoNote,
|
|
|
|
ContactRegistered,
|
|
|
|
ExpiredPhoto,
|
|
|
|
ExpiredVideo,
|
|
|
|
LiveLocation,
|
|
|
|
CustomServiceAction,
|
|
|
|
WebsiteConnected,
|
|
|
|
PassportDataSent,
|
2019-02-19 14:45:32 +01:00
|
|
|
PassportDataReceived,
|
|
|
|
Poll
|
2018-09-28 22:57:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType content_type);
|
|
|
|
|
|
|
|
// Do not forget to update merge_message_contents when one of the inheritors of this class changes
|
|
|
|
class MessageContent {
|
|
|
|
public:
|
|
|
|
MessageContent() = default;
|
|
|
|
MessageContent(const MessageContent &) = default;
|
|
|
|
MessageContent &operator=(const MessageContent &) = default;
|
|
|
|
MessageContent(MessageContent &&) = default;
|
|
|
|
MessageContent &operator=(MessageContent &&) = default;
|
|
|
|
|
|
|
|
virtual MessageContentType get_type() const = 0;
|
|
|
|
virtual ~MessageContent() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InputMessageContent {
|
|
|
|
unique_ptr<MessageContent> content;
|
|
|
|
bool disable_web_page_preview = false;
|
|
|
|
bool clear_draft = false;
|
|
|
|
int32 ttl = 0;
|
|
|
|
UserId via_bot_user_id;
|
|
|
|
|
|
|
|
InputMessageContent(unique_ptr<MessageContent> &&content, bool disable_web_page_preview, bool clear_draft, int32 ttl,
|
|
|
|
UserId via_bot_user_id)
|
|
|
|
: content(std::move(content))
|
|
|
|
, disable_web_page_preview(disable_web_page_preview)
|
|
|
|
, clear_draft(clear_draft)
|
|
|
|
, ttl(ttl)
|
|
|
|
, via_bot_user_id(via_bot_user_id) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InlineMessageContent {
|
|
|
|
unique_ptr<MessageContent> message_content;
|
|
|
|
unique_ptr<ReplyMarkup> message_reply_markup;
|
|
|
|
bool disable_web_page_preview;
|
|
|
|
};
|
|
|
|
|
|
|
|
void store_message_content(const MessageContent *content, LogEventStorerCalcLength &storer);
|
|
|
|
|
|
|
|
void store_message_content(const MessageContent *content, LogEventStorerUnsafe &storer);
|
|
|
|
|
|
|
|
void parse_message_content(unique_ptr<MessageContent> &content, LogEventParser &parser);
|
|
|
|
|
|
|
|
InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
|
|
|
|
tl_object_ptr<telegram_api::BotInlineMessage> &&inline_message,
|
|
|
|
int32 allowed_media_content_id, Photo *photo, Game *game);
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> create_text_message_content(string text, vector<MessageEntity> entities,
|
|
|
|
WebPageId web_page_id);
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> create_contact_registered_message_content();
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> create_screenshot_taken_message_content();
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> create_chat_set_ttl_message_content(int32 ttl);
|
|
|
|
|
2018-12-12 15:36:31 +01:00
|
|
|
Result<InputMessageContent> get_input_message_content(
|
|
|
|
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
|
|
|
|
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
|
|
|
|
BufferSlice thumbnail, int32 layer);
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *content, Td *td,
|
|
|
|
tl_object_ptr<telegram_api::InputFile> input_file,
|
|
|
|
tl_object_ptr<telegram_api::InputFile> input_thumbnail,
|
2019-10-09 01:59:25 +02:00
|
|
|
FileId file_id, FileId thumbnail_file_id, int32 ttl,
|
|
|
|
bool force);
|
2019-01-25 02:38:11 +01:00
|
|
|
|
2019-03-16 22:07:10 +01:00
|
|
|
tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *content, Td *td, int32 ttl, bool force);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
void delete_message_content_thumbnail(MessageContent *content, Td *td);
|
|
|
|
|
|
|
|
bool is_allowed_media_group_content(MessageContentType content_type);
|
|
|
|
|
|
|
|
bool can_forward_message_content(const MessageContent *content);
|
|
|
|
|
|
|
|
bool is_secret_message_content(int32 ttl, MessageContentType content_type);
|
|
|
|
|
|
|
|
bool is_service_message_content(MessageContentType content_type);
|
|
|
|
|
|
|
|
bool can_have_message_content_caption(MessageContentType content_type);
|
|
|
|
|
|
|
|
bool update_opened_message_content(MessageContent *content);
|
|
|
|
|
|
|
|
int32 get_message_content_index_mask(const MessageContent *content, const Td *td, bool is_secret, bool is_outgoing);
|
|
|
|
|
|
|
|
MessageId get_message_content_pinned_message_id(const MessageContent *content);
|
|
|
|
|
|
|
|
MessageId get_message_content_replied_message_id(const MessageContent *content);
|
|
|
|
|
2019-03-12 14:20:53 +01:00
|
|
|
vector<UserId> get_message_content_added_user_ids(const MessageContent *content);
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
UserId get_message_content_deleted_user_id(const MessageContent *content);
|
|
|
|
|
2019-08-09 19:28:49 +02:00
|
|
|
UserId get_message_content_game_bot_user_id(const MessageContent *content);
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
int32 get_message_content_live_location_period(const MessageContent *content);
|
|
|
|
|
2019-02-22 16:09:55 +01:00
|
|
|
bool get_message_content_poll_is_closed(const Td *td, const MessageContent *content);
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
WebPageId get_message_content_web_page_id(const MessageContent *content);
|
|
|
|
|
|
|
|
void set_message_content_web_page_id(MessageContent *content, WebPageId web_page_id);
|
|
|
|
|
2019-02-21 13:23:05 +01:00
|
|
|
void set_message_content_poll_answer(Td *td, MessageContent *content, FullMessageId full_message_id,
|
|
|
|
vector<int32> &&option_ids, Promise<Unit> &&promise);
|
|
|
|
|
2019-04-12 01:10:33 +02:00
|
|
|
void stop_message_content_poll(Td *td, MessageContent *content, FullMessageId full_message_id,
|
|
|
|
unique_ptr<ReplyMarkup> &&reply_markup, Promise<Unit> &&promise);
|
2019-02-22 16:09:55 +01:00
|
|
|
|
2019-02-19 16:52:09 +01:00
|
|
|
void merge_message_contents(Td *td, const MessageContent *old_content, MessageContent *new_content,
|
2018-09-28 22:57:34 +02:00
|
|
|
bool need_message_changed_warning, DialogId dialog_id, bool need_merge_files,
|
|
|
|
bool &is_content_changed, bool &need_update);
|
|
|
|
|
|
|
|
bool merge_message_content_file_id(Td *td, MessageContent *message_content, FileId new_file_id);
|
|
|
|
|
2019-02-19 16:42:59 +01:00
|
|
|
void register_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id);
|
|
|
|
|
|
|
|
void unregister_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id);
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
unique_ptr<MessageContent> get_secret_message_content(
|
|
|
|
Td *td, string message_text, tl_object_ptr<telegram_api::encryptedFile> file,
|
|
|
|
tl_object_ptr<secret_api::DecryptedMessageMedia> &&media,
|
|
|
|
vector<tl_object_ptr<secret_api::MessageEntity>> &&secret_entities, DialogId owner_dialog_id,
|
|
|
|
MultiPromiseActor &load_data_multipromise);
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message_text,
|
|
|
|
tl_object_ptr<telegram_api::MessageMedia> &&media,
|
|
|
|
DialogId owner_dialog_id, bool is_content_read, UserId via_bot_user_id,
|
|
|
|
int32 *ttl);
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const MessageContent *content,
|
2019-08-09 16:41:26 +02:00
|
|
|
bool for_forward, bool remove_caption = false);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<telegram_api::MessageAction> &&action,
|
|
|
|
DialogId owner_dialog_id, MessageId reply_to_message_id);
|
|
|
|
|
|
|
|
tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageContent *content, Td *td,
|
|
|
|
int32 message_date, bool is_content_secret);
|
|
|
|
|
|
|
|
const FormattedText *get_message_content_text(const MessageContent *content);
|
|
|
|
|
|
|
|
const FormattedText *get_message_content_caption(const MessageContent *content);
|
|
|
|
|
|
|
|
int32 get_message_content_duration(const MessageContent *content, const Td *td);
|
|
|
|
|
2019-08-09 16:41:26 +02:00
|
|
|
FileId get_message_content_upload_file_id(const MessageContent *content);
|
|
|
|
|
|
|
|
FileId get_message_content_any_file_id(const MessageContent *content);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
void update_message_content_file_id_remote(MessageContent *content, FileId file_id);
|
|
|
|
|
|
|
|
FileId get_message_content_thumbnail_file_id(const MessageContent *content, const Td *td);
|
|
|
|
|
|
|
|
vector<FileId> get_message_content_file_ids(const MessageContent *content, const Td *td);
|
|
|
|
|
|
|
|
string get_message_content_search_text(const Td *td, const MessageContent *content);
|
|
|
|
|
2018-12-25 18:47:37 +01:00
|
|
|
bool need_reget_message_content(const MessageContent *content);
|
|
|
|
|
2019-01-08 19:24:06 +01:00
|
|
|
bool need_delay_message_content_notification(const MessageContent *content, UserId my_user_id);
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
void update_expired_message_content(unique_ptr<MessageContent> &content);
|
|
|
|
|
2019-02-19 15:06:48 +01:00
|
|
|
void update_failed_to_send_message_content(Td *td, unique_ptr<MessageContent> &content);
|
|
|
|
|
2018-12-12 14:11:49 +01:00
|
|
|
void add_message_content_dependencies(Dependencies &dependencies, const MessageContent *message_content);
|
|
|
|
|
2018-12-12 13:57:24 +01:00
|
|
|
void on_sent_message_content(Td *td, const MessageContent *content);
|
|
|
|
|
2019-09-18 05:55:43 +02:00
|
|
|
StickerSetId add_sticker_set(Td *td, tl_object_ptr<telegram_api::InputStickerSet> &&input_sticker_set);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
} // namespace td
|