diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ce132234..16c8ed614 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -745,6 +745,7 @@ set(TDLIB_SOURCE td/telegram/files/FileLocation.hpp td/telegram/files/FileManager.hpp td/telegram/files/FileSourceId.hpp + td/telegram/ForumTopicIcon.hpp td/telegram/Game.hpp td/telegram/InputInvoice.hpp td/telegram/InputMessageText.hpp diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 04fa07ef1..ba5b2df26 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2073,6 +2073,9 @@ messageChatSetTheme theme_name:string = MessageContent; //@description The TTL (Time To Live) setting for messages in the chat has been changed @ttl New message TTL 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 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 14d5b5490..194696fbe 100644 --- a/td/telegram/DialogAction.cpp +++ b/td/telegram/DialogAction.cpp @@ -403,6 +403,7 @@ bool DialogAction::is_canceled_by_message_of_type(MessageContentType message_con case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: return false; default: UNREACHABLE(); diff --git a/td/telegram/ForumTopicIcon.cpp b/td/telegram/ForumTopicIcon.cpp index c5f436237..395bbae02 100644 --- a/td/telegram/ForumTopicIcon.cpp +++ b/td/telegram/ForumTopicIcon.cpp @@ -16,6 +16,14 @@ td_api::object_ptr ForumTopicIcon::get_forum_topic_icon_ return td_api::make_object(color_, custom_emoji_id_.get()); } +bool operator==(const ForumTopicIcon &lhs, const ForumTopicIcon &rhs) { + return lhs.color_ == rhs.color_ && lhs.custom_emoji_id_ == rhs.custom_emoji_id_; +} + +bool operator!=(const ForumTopicIcon &lhs, const ForumTopicIcon &rhs) { + return !(lhs == rhs); +} + StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicIcon &topic_icon) { string_builder << "icon color " << topic_icon.color_; if (topic_icon.custom_emoji_id_.is_valid()) { diff --git a/td/telegram/ForumTopicIcon.h b/td/telegram/ForumTopicIcon.h index e4b7a8947..350fc3275 100644 --- a/td/telegram/ForumTopicIcon.h +++ b/td/telegram/ForumTopicIcon.h @@ -20,13 +20,24 @@ class ForumTopicIcon { friend StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicIcon &topic_icon); + friend bool operator==(const ForumTopicIcon &lhs, const ForumTopicIcon &rhs); + public: ForumTopicIcon() = default; ForumTopicIcon(int32 color, int64 custom_emoji_id); td_api::object_ptr get_forum_topic_icon_object() const; + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); }; +bool operator==(const ForumTopicIcon &lhs, const ForumTopicIcon &rhs); +bool operator!=(const ForumTopicIcon &lhs, const ForumTopicIcon &rhs); + StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicIcon &topic_icon); } // namespace td diff --git a/td/telegram/ForumTopicIcon.hpp b/td/telegram/ForumTopicIcon.hpp new file mode 100644 index 000000000..2d4d6245e --- /dev/null +++ b/td/telegram/ForumTopicIcon.hpp @@ -0,0 +1,40 @@ +// +// 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/ForumTopicIcon.h" + +#include "td/utils/common.h" +#include "td/utils/tl_helpers.h" + +namespace td { + +template +void ForumTopicIcon::store(StorerT &storer) const { + bool has_custom_emoji_id = custom_emoji_id_.is_valid(); + BEGIN_STORE_FLAGS(); + STORE_FLAG(has_custom_emoji_id); + END_STORE_FLAGS(); + td::store(color_, storer); + if (has_custom_emoji_id) { + td::store(custom_emoji_id_, storer); + } +} + +template +void ForumTopicIcon::parse(ParserT &parser) { + bool has_custom_emoji_id; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(has_custom_emoji_id); + END_PARSE_FLAGS(); + td::parse(color_, parser); + if (has_custom_emoji_id) { + td::parse(custom_emoji_id_, parser); + } +} + +} // namespace td diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 05b904839..1d5b7920a 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/ForumTopicIcon.h" +#include "td/telegram/ForumTopicIcon.hpp" #include "td/telegram/Game.h" #include "td/telegram/Game.hpp" #include "td/telegram/Global.h" @@ -802,6 +804,20 @@ class MessageGiftPremium final : public MessageContent { } }; +class MessageTopicCreate final : public MessageContent { + public: + string title; + ForumTopicIcon icon; + + MessageTopicCreate() = default; + explicit MessageTopicCreate(string &&title, ForumTopicIcon &&icon) : title(std::move(title)), icon(std::move(icon)) { + } + + MessageContentType get_type() const final { + return MessageContentType::TopicCreate; + } +}; + template static void store(const MessageContent *content, StorerT &storer) { CHECK(content != nullptr); @@ -1130,6 +1146,12 @@ static void store(const MessageContent *content, StorerT &storer) { store(m->months, storer); break; } + case MessageContentType::TopicCreate: { + const auto *m = static_cast(content); + store(m->title, storer); + store(m->icon, storer); + break; + } default: UNREACHABLE(); } @@ -1580,6 +1602,13 @@ static void parse(unique_ptr &content, ParserT &parser) { content = std::move(m); break; } + case MessageContentType::TopicCreate: { + auto m = make_unique(); + parse(m->title, parser); + parse(m->icon, parser); + content = std::move(m); + break; + } default: LOG(FATAL) << "Have unknown message content type " << static_cast(content_type); } @@ -2198,6 +2227,7 @@ bool can_have_input_media(const Td *td, const MessageContent *content, bool is_s case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: return false; case MessageContentType::Animation: case MessageContentType::Audio: @@ -2319,6 +2349,7 @@ SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td, case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: break; default: UNREACHABLE(); @@ -2438,6 +2469,7 @@ static tl_object_ptr get_input_media_impl( case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: break; default: UNREACHABLE(); @@ -2602,6 +2634,7 @@ void delete_message_content_thumbnail(MessageContent *content, Td *td) { case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: break; default: UNREACHABLE(); @@ -2784,6 +2817,7 @@ Status can_send_message_content(DialogId dialog_id, const MessageContent *conten case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: UNREACHABLE(); } return Status::OK(); @@ -2913,6 +2947,7 @@ static int32 get_message_content_media_index_mask(const MessageContent *content, case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: return 0; default: UNREACHABLE(); @@ -3656,6 +3691,14 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo } break; } + case MessageContentType::TopicCreate: { + const auto *old_ = static_cast(old_content); + const auto *new_ = static_cast(new_content); + if (old_->title != new_->title || old_->icon != new_->icon) { + need_update = true; + } + break; + } case MessageContentType::Unsupported: { const auto *old_ = static_cast(old_content); const auto *new_ = static_cast(new_content); @@ -3796,6 +3839,7 @@ bool merge_message_content_file_id(Td *td, MessageContent *message_content, File case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: LOG(ERROR) << "Receive new file " << new_file_id << " in a sent message of the type " << content_type; break; default: @@ -4766,6 +4810,7 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: return nullptr; default: UNREACHABLE(); @@ -5065,7 +5110,8 @@ unique_ptr get_action_message_content(Td *td, tl_object_ptr(action_ptr); - return make_unique(); + return td::make_unique(std::move(action->title_), + ForumTopicIcon(action->icon_color_, action->icon_emoji_id_)); } case telegram_api::messageActionTopicEdit::ID: { auto action = move_tl_object_as(action_ptr); @@ -5347,6 +5393,10 @@ tl_object_ptr get_message_content_object(const MessageCo return make_tl_object( m->currency, m->amount, m->months, td->stickers_manager_->get_premium_gift_sticker_object(m->months)); } + case MessageContentType::TopicCreate: { + const auto *m = static_cast(content); + return td_api::make_object(m->title, m->icon.get_forum_topic_icon_object()); + } default: UNREACHABLE(); return nullptr; @@ -5703,6 +5753,7 @@ string get_message_content_search_text(const Td *td, const MessageContent *conte case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: return string(); default: UNREACHABLE(); @@ -5977,6 +6028,8 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC break; case MessageContentType::GiftPremium: break; + case MessageContentType::TopicCreate: + break; default: UNREACHABLE(); break; diff --git a/td/telegram/MessageContentType.cpp b/td/telegram/MessageContentType.cpp index 2a8e409a0..4a2e25c5f 100644 --- a/td/telegram/MessageContentType.cpp +++ b/td/telegram/MessageContentType.cpp @@ -110,6 +110,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType cont return string_builder << "WebViewDataReceived"; case MessageContentType::GiftPremium: return string_builder << "GiftPremium"; + case MessageContentType::TopicCreate: + return string_builder << "TopicCreate"; default: UNREACHABLE(); return string_builder; @@ -168,6 +170,7 @@ bool is_allowed_media_group_content(MessageContentType content_type) { case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: return false; default: UNREACHABLE(); @@ -234,6 +237,7 @@ bool is_secret_message_content(int32 ttl, MessageContentType content_type) { case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: return false; default: UNREACHABLE(); @@ -293,6 +297,7 @@ bool is_service_message_content(MessageContentType content_type) { case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: return true; default: UNREACHABLE(); @@ -352,6 +357,7 @@ bool can_have_message_content_caption(MessageContentType content_type) { case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: return false; default: UNREACHABLE(); diff --git a/td/telegram/MessageContentType.h b/td/telegram/MessageContentType.h index e3d613690..0fe2aff0e 100644 --- a/td/telegram/MessageContentType.h +++ b/td/telegram/MessageContentType.h @@ -64,7 +64,8 @@ enum class MessageContentType : int32 { ChatSetTheme, WebViewDataSent, WebViewDataReceived, - GiftPremium + GiftPremium, + TopicCreate }; StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType content_type); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index f511ddd33..5d7d2e6c3 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -27437,6 +27437,7 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo case MessageContentType::WebViewDataSent: case MessageContentType::WebViewDataReceived: case MessageContentType::GiftPremium: + case MessageContentType::TopicCreate: return false; default: UNREACHABLE();