From f7db1f1e3217978a34d3842f83515f6d97b5fda8 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 22 Mar 2024 00:43:18 +0300 Subject: [PATCH] Add MessageContentType::DialogShared. --- td/telegram/DialogAction.cpp | 1 + td/telegram/MessageContent.cpp | 99 +++++++++++++++++++++++++++++- td/telegram/MessageContentType.cpp | 7 +++ td/telegram/MessageContentType.h | 3 +- 4 files changed, 107 insertions(+), 3 deletions(-) diff --git a/td/telegram/DialogAction.cpp b/td/telegram/DialogAction.cpp index 210d4e2a1..3d217dd8c 100644 --- a/td/telegram/DialogAction.cpp +++ b/td/telegram/DialogAction.cpp @@ -421,6 +421,7 @@ bool DialogAction::is_canceled_by_message_of_type(MessageContentType message_con case MessageContentType::GiveawayResults: case MessageContentType::GiveawayWinners: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: return false; default: UNREACHABLE(); diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 9910b2c67..fe58b84d8 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -71,6 +71,7 @@ #include "td/telegram/SecureValue.hpp" #include "td/telegram/ServerMessageId.h" #include "td/telegram/SharedDialog.h" +#include "td/telegram/SharedDialog.hpp" #include "td/telegram/StickerFormat.h" #include "td/telegram/StickersManager.h" #include "td/telegram/StickersManager.hpp" @@ -1102,6 +1103,21 @@ class MessageBoostApply final : public MessageContent { } }; +class MessageDialogShared final : public MessageContent { + public: + vector shared_dialogs; + int32 button_id = 0; + + MessageDialogShared() = default; + MessageDialogShared(vector &&shared_dialogs, int32 button_id) + : shared_dialogs(std::move(shared_dialogs)), button_id(button_id) { + } + + MessageContentType get_type() const final { + return MessageContentType::DialogShared; + } +}; + template static void store(const MessageContent *content, StorerT &storer) { CHECK(content != nullptr); @@ -1658,6 +1674,14 @@ static void store(const MessageContent *content, StorerT &storer) { store(m->boost_count, storer); break; } + case MessageContentType::DialogShared: { + const auto *m = static_cast(content); + BEGIN_STORE_FLAGS(); + END_STORE_FLAGS(); + store(m->shared_dialogs, storer); + store(m->button_id, storer); + break; + } default: UNREACHABLE(); } @@ -2394,6 +2418,19 @@ static void parse(unique_ptr &content, ParserT &parser) { content = std::move(m); break; } + case MessageContentType::DialogShared: { + auto m = make_unique(); + BEGIN_PARSE_FLAGS(); + END_PARSE_FLAGS(); + parse(m->shared_dialogs, parser); + if (m->shared_dialogs.empty() || + any_of(m->shared_dialogs, [](const auto &shared_dialog) { return !shared_dialog.is_valid(); })) { + is_bad = true; + } + parse(m->button_id, parser); + content = std::move(m); + break; + } default: is_bad = true; @@ -3040,6 +3077,7 @@ bool can_have_input_media(const Td *td, const MessageContent *content, bool is_s case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: return false; case MessageContentType::Animation: case MessageContentType::Audio: @@ -3181,6 +3219,7 @@ SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td, case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: break; default: UNREACHABLE(); @@ -3324,6 +3363,7 @@ static tl_object_ptr get_input_media_impl( case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: break; default: UNREACHABLE(); @@ -3529,6 +3569,7 @@ void delete_message_content_thumbnail(MessageContent *content, Td *td) { case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: break; default: UNREACHABLE(); @@ -3754,6 +3795,7 @@ Status can_send_message_content(DialogId dialog_id, const MessageContent *conten case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: UNREACHABLE(); } return Status::OK(); @@ -3901,6 +3943,7 @@ static int32 get_message_content_media_index_mask(const MessageContent *content, case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: return 0; default: UNREACHABLE(); @@ -4184,6 +4227,8 @@ vector get_message_content_min_user_ids(const Td *td, const MessageConte break; case MessageContentType::BoostApply: break; + case MessageContentType::DialogShared: + break; default: UNREACHABLE(); break; @@ -4589,6 +4634,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: break; default: UNREACHABLE(); @@ -4739,6 +4785,7 @@ bool merge_message_content_file_id(Td *td, MessageContent *message_content, File case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: LOG(ERROR) << "Receive new file " << new_file_id << " in a sent message of the type " << content_type; break; default: @@ -5273,6 +5320,14 @@ void compare_message_contents(Td *td, const MessageContent *old_content, const M } break; } + case MessageContentType::DialogShared: { + const auto *lhs = static_cast(old_content); + const auto *rhs = static_cast(new_content); + if (lhs->shared_dialogs != rhs->shared_dialogs || lhs->button_id != rhs->button_id) { + need_update = true; + } + break; + } default: UNREACHABLE(); break; @@ -6435,6 +6490,7 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: return nullptr; default: UNREACHABLE(); @@ -6837,8 +6893,30 @@ unique_ptr get_action_message_content(Td *td, tl_object_ptr(action_ptr); return make_unique(max(action->boosts_, 0)); } - case telegram_api::messageActionRequestedPeerSentMe::ID: - return make_unique(); + case telegram_api::messageActionRequestedPeerSentMe::ID: { + auto action = move_tl_object_as(action_ptr); + vector shared_dialogs; + for (auto &peer : action->peers_) { + SharedDialog shared_dialog(td, std::move(peer)); + if (shared_dialog.is_valid()) { + shared_dialogs.push_back(std::move(shared_dialog)); + } + } + if (shared_dialogs.size() > 1) { + for (auto shared_dialog : shared_dialogs) { + if (!shared_dialog.is_user()) { + shared_dialogs.clear(); + break; + } + } + } + if (shared_dialogs.empty() || shared_dialogs.size() != action->peers_.size()) { + LOG(ERROR) << "Receive invalid " << oneline(to_string(action)); + break; + } + + return td::make_unique(std::move(shared_dialogs), action->button_id_); + } default: UNREACHABLE(); } @@ -7242,6 +7320,20 @@ tl_object_ptr get_message_content_object(const MessageCo const auto *m = static_cast(content); return td_api::make_object(m->boost_count); } + case MessageContentType::DialogShared: { + const auto *m = static_cast(content); + CHECK(!m->shared_dialogs.empty()); + if (m->shared_dialogs[0].is_user()) { + vector> users; + for (const auto &shared_dialog : m->shared_dialogs) { + users.push_back(shared_dialog.get_shared_user_object(td)); + } + return td_api::make_object(std::move(users), m->button_id); + } + CHECK(m->shared_dialogs.size() == 1); + return td_api::make_object(m->shared_dialogs[0].get_shared_chat_object(td), + m->button_id); + } default: UNREACHABLE(); return nullptr; @@ -7677,6 +7769,7 @@ string get_message_content_search_text(const Td *td, const MessageContent *conte case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: return string(); default: UNREACHABLE(); @@ -8021,6 +8114,8 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC break; case MessageContentType::BoostApply: break; + case MessageContentType::DialogShared: + break; default: UNREACHABLE(); break; diff --git a/td/telegram/MessageContentType.cpp b/td/telegram/MessageContentType.cpp index fc8a2e4d7..2e3f46fef 100644 --- a/td/telegram/MessageContentType.cpp +++ b/td/telegram/MessageContentType.cpp @@ -144,6 +144,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType cont return string_builder << "ExpiredVoiceNote"; case MessageContentType::BoostApply: return string_builder << "BoostApply"; + case MessageContentType::DialogShared: + return string_builder << "ChatShared"; default: return string_builder << "Invalid type " << static_cast(content_type); } @@ -218,6 +220,7 @@ bool is_allowed_media_group_content(MessageContentType content_type) { case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: return false; default: UNREACHABLE(); @@ -298,6 +301,7 @@ bool can_be_secret_message_content(MessageContentType content_type) { case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: return false; default: UNREACHABLE(); @@ -374,6 +378,7 @@ bool is_service_message_content(MessageContentType content_type) { case MessageContentType::GiveawayLaunch: case MessageContentType::GiveawayResults: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: return true; default: UNREACHABLE(); @@ -450,6 +455,7 @@ bool is_editable_message_content(MessageContentType content_type) { case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: return false; default: UNREACHABLE(); @@ -574,6 +580,7 @@ bool can_have_message_content_caption(MessageContentType content_type) { case MessageContentType::ExpiredVideoNote: case MessageContentType::ExpiredVoiceNote: case MessageContentType::BoostApply: + case MessageContentType::DialogShared: return false; default: UNREACHABLE(); diff --git a/td/telegram/MessageContentType.h b/td/telegram/MessageContentType.h index 64795fe5d..280b6cc14 100644 --- a/td/telegram/MessageContentType.h +++ b/td/telegram/MessageContentType.h @@ -79,7 +79,8 @@ enum class MessageContentType : int32 { GiveawayWinners, ExpiredVideoNote, ExpiredVoiceNote, - BoostApply + BoostApply, + DialogShared }; // increase MessageUnsupported::CURRENT_VERSION each time a new message content type is added