diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 93ee1ab0c..2a4552be4 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2084,6 +2084,9 @@ messageChatSetTtl ttl:int32 = MessageContent; //@description A forum topic has been created @title Title of the topic @icon Icon of the topic messageForumTopicCreated title:string icon:forumTopicIcon = MessageContent; +//@description A forum topic has been edited @edited_data Information about edited topic data +messageForumTopicEdited edited_data:forumTopicEditedData = MessageContent; + //@description A non-standard action has happened in the chat @text Message text to be shown in the chat messageCustomServiceAction text:string = MessageContent; diff --git a/td/telegram/DialogAction.cpp b/td/telegram/DialogAction.cpp index 194696fbe..b2941a313 100644 --- a/td/telegram/DialogAction.cpp +++ b/td/telegram/DialogAction.cpp @@ -404,6 +404,7 @@ bool DialogAction::is_canceled_by_message_of_type(MessageContentType message_con case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: return false; default: UNREACHABLE(); diff --git a/td/telegram/ForumTopicEditedData.cpp b/td/telegram/ForumTopicEditedData.cpp index 9fc9dd9b4..e388313bd 100644 --- a/td/telegram/ForumTopicEditedData.cpp +++ b/td/telegram/ForumTopicEditedData.cpp @@ -15,6 +15,16 @@ td_api::object_ptr ForumTopicEditedData::get_forum icon_custom_emoji_id_.get(), edit_is_closed_, is_closed_); } +bool operator==(const ForumTopicEditedData &lhs, const ForumTopicEditedData &rhs) { + return lhs.title_ == rhs.title_ && lhs.icon_custom_emoji_id_ == rhs.icon_custom_emoji_id_ && + lhs.edit_icon_custom_emoji_id_ == rhs.edit_icon_custom_emoji_id_ && + lhs.edit_is_closed_ == rhs.edit_is_closed_ && lhs.is_closed_ == rhs.is_closed_; +} + +bool operator!=(const ForumTopicEditedData &lhs, const ForumTopicEditedData &rhs) { + return !(lhs == rhs); +} + StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicEditedData &topic_edited_data) { if (!topic_edited_data.title_.empty()) { string_builder << "set title to \"" << topic_edited_data.title_ << '"'; diff --git a/td/telegram/ForumTopicEditedData.h b/td/telegram/ForumTopicEditedData.h index 3ac4c4933..db2f416cc 100644 --- a/td/telegram/ForumTopicEditedData.h +++ b/td/telegram/ForumTopicEditedData.h @@ -21,6 +21,8 @@ class ForumTopicEditedData { bool edit_is_closed_ = false; bool is_closed_ = false; + friend bool operator==(const ForumTopicEditedData &lhs, const ForumTopicEditedData &rhs); + friend StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicEditedData &topic_edited_data); public: @@ -40,8 +42,17 @@ class ForumTopicEditedData { } td_api::object_ptr get_forum_topic_edited_data_object() const; + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); }; +bool operator==(const ForumTopicEditedData &lhs, const ForumTopicEditedData &rhs); +bool operator!=(const ForumTopicEditedData &lhs, const ForumTopicEditedData &rhs); + StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicEditedData &topic_edited_data); } // namespace td diff --git a/td/telegram/ForumTopicEditedData.hpp b/td/telegram/ForumTopicEditedData.hpp new file mode 100644 index 000000000..6385da0a2 --- /dev/null +++ b/td/telegram/ForumTopicEditedData.hpp @@ -0,0 +1,54 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 +// +// 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/ForumTopicEditedData.h" + +#include "td/utils/common.h" +#include "td/utils/tl_helpers.h" + +namespace td { + +template +void ForumTopicEditedData::store(StorerT &storer) const { + bool has_title = !title_.empty(); + bool has_icon_custom_emoji_id = icon_custom_emoji_id_.is_valid(); + BEGIN_STORE_FLAGS(); + STORE_FLAG(edit_icon_custom_emoji_id_); + STORE_FLAG(edit_is_closed_); + STORE_FLAG(is_closed_); + STORE_FLAG(has_title); + STORE_FLAG(has_icon_custom_emoji_id); + END_STORE_FLAGS(); + if (has_title) { + td::store(title_, storer); + } + if (has_icon_custom_emoji_id) { + td::store(icon_custom_emoji_id_, storer); + } +} + +template +void ForumTopicEditedData::parse(ParserT &parser) { + bool has_title; + bool has_icon_custom_emoji_id; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(edit_icon_custom_emoji_id_); + PARSE_FLAG(edit_is_closed_); + PARSE_FLAG(is_closed_); + PARSE_FLAG(has_title); + PARSE_FLAG(has_icon_custom_emoji_id); + END_PARSE_FLAGS(); + if (has_title) { + td::parse(title_, parser); + } + if (has_icon_custom_emoji_id) { + td::parse(icon_custom_emoji_id_, parser); + } +} + +} // namespace td diff --git a/td/telegram/ForumTopicIcon.h b/td/telegram/ForumTopicIcon.h index 350fc3275..8ba9af1cb 100644 --- a/td/telegram/ForumTopicIcon.h +++ b/td/telegram/ForumTopicIcon.h @@ -18,10 +18,10 @@ class ForumTopicIcon { int32 color_ = 0x6FB9F0; CustomEmojiId custom_emoji_id_; - friend StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicIcon &topic_icon); - friend bool operator==(const ForumTopicIcon &lhs, const ForumTopicIcon &rhs); + friend StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicIcon &topic_icon); + public: ForumTopicIcon() = default; ForumTopicIcon(int32 color, int64 custom_emoji_id); diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 1d5b7920a..f14c55a64 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -29,6 +29,8 @@ #include "td/telegram/files/FileLocation.h" #include "td/telegram/files/FileManager.h" #include "td/telegram/files/FileType.h" +#include "td/telegram/ForumTopicEditedData.h" +#include "td/telegram/ForumTopicEditedData.hpp" #include "td/telegram/ForumTopicIcon.h" #include "td/telegram/ForumTopicIcon.hpp" #include "td/telegram/Game.h" @@ -810,7 +812,7 @@ class MessageTopicCreate final : public MessageContent { ForumTopicIcon icon; MessageTopicCreate() = default; - explicit MessageTopicCreate(string &&title, ForumTopicIcon &&icon) : title(std::move(title)), icon(std::move(icon)) { + MessageTopicCreate(string &&title, ForumTopicIcon &&icon) : title(std::move(title)), icon(std::move(icon)) { } MessageContentType get_type() const final { @@ -818,6 +820,19 @@ class MessageTopicCreate final : public MessageContent { } }; +class MessageTopicEdit final : public MessageContent { + public: + ForumTopicEditedData edited_data; + + MessageTopicEdit() = default; + explicit MessageTopicEdit(ForumTopicEditedData &&edited_data) : edited_data(std::move(edited_data)) { + } + + MessageContentType get_type() const final { + return MessageContentType::TopicEdit; + } +}; + template static void store(const MessageContent *content, StorerT &storer) { CHECK(content != nullptr); @@ -1152,6 +1167,11 @@ static void store(const MessageContent *content, StorerT &storer) { store(m->icon, storer); break; } + case MessageContentType::TopicEdit: { + const auto *m = static_cast(content); + store(m->edited_data, storer); + break; + } default: UNREACHABLE(); } @@ -1609,6 +1629,12 @@ static void parse(unique_ptr &content, ParserT &parser) { content = std::move(m); break; } + case MessageContentType::TopicEdit: { + auto m = make_unique(); + parse(m->edited_data, parser); + content = std::move(m); + break; + } default: LOG(FATAL) << "Have unknown message content type " << static_cast(content_type); } @@ -2228,6 +2254,7 @@ bool can_have_input_media(const Td *td, const MessageContent *content, bool is_s case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: return false; case MessageContentType::Animation: case MessageContentType::Audio: @@ -2350,6 +2377,7 @@ SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td, case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: break; default: UNREACHABLE(); @@ -2470,6 +2498,7 @@ static tl_object_ptr get_input_media_impl( case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: break; default: UNREACHABLE(); @@ -2635,6 +2664,7 @@ void delete_message_content_thumbnail(MessageContent *content, Td *td) { case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: break; default: UNREACHABLE(); @@ -2818,6 +2848,7 @@ Status can_send_message_content(DialogId dialog_id, const MessageContent *conten case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: UNREACHABLE(); } return Status::OK(); @@ -2948,6 +2979,7 @@ static int32 get_message_content_media_index_mask(const MessageContent *content, case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: return 0; default: UNREACHABLE(); @@ -3699,6 +3731,14 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo } break; } + case MessageContentType::TopicEdit: { + const auto *old_ = static_cast(old_content); + const auto *new_ = static_cast(new_content); + if (old_->edited_data != new_->edited_data) { + need_update = true; + } + break; + } case MessageContentType::Unsupported: { const auto *old_ = static_cast(old_content); const auto *new_ = static_cast(new_content); @@ -3840,6 +3880,7 @@ bool merge_message_content_file_id(Td *td, MessageContent *message_content, File case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: LOG(ERROR) << "Receive new file " << new_file_id << " in a sent message of the type " << content_type; break; default: @@ -4811,6 +4852,7 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: return nullptr; default: UNREACHABLE(); @@ -5115,7 +5157,11 @@ unique_ptr get_action_message_content(Td *td, tl_object_ptr(action_ptr); - return make_unique(); + auto edit_icon_custom_emoji_id = (action->flags_ & telegram_api::messageActionTopicEdit::ICON_EMOJI_ID_MASK) != 0; + auto edit_is_closed = (action->flags_ & telegram_api::messageActionTopicEdit::CLOSED_MASK) != 0; + return td::make_unique(ForumTopicEditedData{std::move(action->title_), + edit_icon_custom_emoji_id, action->icon_emoji_id_, + edit_is_closed, action->closed_}); } default: UNREACHABLE(); @@ -5397,6 +5443,10 @@ tl_object_ptr get_message_content_object(const MessageCo const auto *m = static_cast(content); return td_api::make_object(m->title, m->icon.get_forum_topic_icon_object()); } + case MessageContentType::TopicEdit: { + const auto *m = static_cast(content); + return td_api::make_object(m->edited_data.get_forum_topic_edited_data_object()); + } default: UNREACHABLE(); return nullptr; @@ -5754,6 +5804,7 @@ string get_message_content_search_text(const Td *td, const MessageContent *conte case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: return string(); default: UNREACHABLE(); @@ -6030,6 +6081,8 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC break; case MessageContentType::TopicCreate: break; + case MessageContentType::TopicEdit: + break; default: UNREACHABLE(); break; diff --git a/td/telegram/MessageContentType.cpp b/td/telegram/MessageContentType.cpp index 4a2e25c5f..1395b1e70 100644 --- a/td/telegram/MessageContentType.cpp +++ b/td/telegram/MessageContentType.cpp @@ -112,6 +112,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType cont return string_builder << "GiftPremium"; case MessageContentType::TopicCreate: return string_builder << "TopicCreate"; + case MessageContentType::TopicEdit: + return string_builder << "TopicEdit"; default: UNREACHABLE(); return string_builder; @@ -171,6 +173,7 @@ bool is_allowed_media_group_content(MessageContentType content_type) { case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: return false; default: UNREACHABLE(); @@ -238,6 +241,7 @@ bool is_secret_message_content(int32 ttl, MessageContentType content_type) { case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: return false; default: UNREACHABLE(); @@ -298,6 +302,7 @@ bool is_service_message_content(MessageContentType content_type) { case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: return true; default: UNREACHABLE(); @@ -358,6 +363,7 @@ bool can_have_message_content_caption(MessageContentType content_type) { case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: return false; default: UNREACHABLE(); diff --git a/td/telegram/MessageContentType.h b/td/telegram/MessageContentType.h index 0fe2aff0e..9d1750b41 100644 --- a/td/telegram/MessageContentType.h +++ b/td/telegram/MessageContentType.h @@ -65,7 +65,8 @@ enum class MessageContentType : int32 { WebViewDataSent, WebViewDataReceived, GiftPremium, - TopicCreate + TopicCreate, + TopicEdit }; StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType content_type); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 5d7d2e6c3..a23eee5e5 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -27438,6 +27438,7 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: case MessageContentType::TopicCreate: + case MessageContentType::TopicEdit: return false; default: UNREACHABLE();