From be4b1bad46853c94f47a2416f7cbee22a32f0ff1 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 Oct 2022 15:04:52 +0300 Subject: [PATCH] Add class ForumTopicIcon. --- CMakeLists.txt | 2 ++ td/generate/scheme/td_api.tl | 8 +++++--- td/telegram/ForumTopicIcon.cpp | 27 +++++++++++++++++++++++++++ td/telegram/ForumTopicIcon.h | 32 ++++++++++++++++++++++++++++++++ td/telegram/ForumTopicInfo.cpp | 17 +++++++---------- td/telegram/ForumTopicInfo.h | 5 ++--- 6 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 td/telegram/ForumTopicIcon.cpp create mode 100644 td/telegram/ForumTopicIcon.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ddb2794f3..2ce132234 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -352,6 +352,7 @@ set(TDLIB_SOURCE td/telegram/files/FileUploader.cpp td/telegram/files/PartsManager.cpp td/telegram/files/ResourceManager.cpp + td/telegram/ForumTopicIcon.cpp td/telegram/ForumTopicInfo.cpp td/telegram/Game.cpp td/telegram/GameManager.cpp @@ -580,6 +581,7 @@ set(TDLIB_SOURCE td/telegram/files/ResourceManager.h td/telegram/files/ResourceState.h td/telegram/FolderId.h + td/telegram/ForumTopicIcon.h td/telegram/ForumTopicInfo.h td/telegram/FullMessageId.h td/telegram/Game.h diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 51f3ce6cb..04fa07ef1 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1298,16 +1298,18 @@ webAppInfo launch_id:int64 url:string = WebAppInfo; messageThreadInfo chat_id:int53 message_thread_id:int53 reply_info:messageReplyInfo unread_message_count:int32 messages:vector draft_message:draftMessage = MessageThreadInfo; +//@description Describes a forum topic icon @color Color of the topic icon in RGB format @custom_emoji_id Unique identifier of the custom emoji shown on the topic icon; 0 if none +forumTopicIcon color:int32 custom_emoji_id:int64 = ForumTopicIcon; + //@description Contains basic information about a forum topic //@message_thread_id Thread identifier of the topic //@title Title of the topic -//@icon_color Color of the topic icon -//@icon_custom_emoji_id Unique identifier of the custom emoji shown on the topic icon; 0 if none +//@icon Icon of the topic //@creation_date Date the topic was created //@creator_id Identifier of the creator of the topic //@is_outgoing True, if the topic was created by the current user //@is_closed True, if the topic is closed -forumTopicInfo message_thread_id:int53 title:string icon_color:int32 icon_custom_emoji_id:int64 creation_date:int32 creator_id:MessageSender is_outgoing:Bool is_closed:Bool = ForumTopicInfo; +forumTopicInfo message_thread_id:int53 title:string icon:forumTopicIcon creation_date:int32 creator_id:MessageSender is_outgoing:Bool is_closed:Bool = ForumTopicInfo; //@class RichText @description Describes a text object inside an instant-view web page diff --git a/td/telegram/ForumTopicIcon.cpp b/td/telegram/ForumTopicIcon.cpp new file mode 100644 index 000000000..c5f436237 --- /dev/null +++ b/td/telegram/ForumTopicIcon.cpp @@ -0,0 +1,27 @@ +// +// 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) +// +#include "td/telegram/ForumTopicIcon.h" + +namespace td { + +ForumTopicIcon::ForumTopicIcon(int32 color, int64 custom_emoji_id) + : color_(color & 0xFFFFFF), custom_emoji_id_(custom_emoji_id) { +} + +td_api::object_ptr ForumTopicIcon::get_forum_topic_icon_object() const { + return td_api::make_object(color_, custom_emoji_id_.get()); +} + +StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicIcon &topic_icon) { + string_builder << "icon color " << topic_icon.color_; + if (topic_icon.custom_emoji_id_.is_valid()) { + string_builder << " and " << topic_icon.custom_emoji_id_; + } + return string_builder; +} + +} // namespace td diff --git a/td/telegram/ForumTopicIcon.h b/td/telegram/ForumTopicIcon.h new file mode 100644 index 000000000..e4b7a8947 --- /dev/null +++ b/td/telegram/ForumTopicIcon.h @@ -0,0 +1,32 @@ +// +// 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/CustomEmojiId.h" +#include "td/telegram/td_api.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +class ForumTopicIcon { + int32 color_ = 0x6FB9F0; + CustomEmojiId custom_emoji_id_; + + friend StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicIcon &topic_icon); + + public: + ForumTopicIcon() = default; + ForumTopicIcon(int32 color, int64 custom_emoji_id); + + td_api::object_ptr get_forum_topic_icon_object() const; +}; + +StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicIcon &topic_icon); + +} // namespace td diff --git a/td/telegram/ForumTopicInfo.cpp b/td/telegram/ForumTopicInfo.cpp index 258b89c68..1aff5f3bc 100644 --- a/td/telegram/ForumTopicInfo.cpp +++ b/td/telegram/ForumTopicInfo.cpp @@ -24,18 +24,15 @@ ForumTopicInfo::ForumTopicInfo(Td *td, const tl_object_ptrid_)); title_ = forum_topic->title_; - icon_color_ = (forum_topic->icon_color_ & 0xFFFFFF); - if ((forum_topic->flags_ & telegram_api::forumTopic::ICON_EMOJI_ID_MASK) != 0) { - icon_custom_emoji_id_ = CustomEmojiId(forum_topic->icon_emoji_id_); - } + icon_ = ForumTopicIcon(forum_topic->icon_color_, forum_topic->icon_emoji_id_); creation_date_ = forum_topic->date_; creator_dialog_id_ = DialogId(forum_topic->from_id_); is_outgoing_ = forum_topic->my_; is_closed_ = forum_topic->closed_; + if (creation_date_ <= 0 || !top_thread_message_id_.is_valid() || !creator_dialog_id_.is_valid()) { LOG(ERROR) << "Receive " << to_string(forum_topic_ptr); - top_thread_message_id_ = MessageId(); - return; + *this = ForumTopicInfo(); } } @@ -45,14 +42,14 @@ td_api::object_ptr ForumTopicInfo::get_forum_topic_info_ } auto creator_id = get_message_sender_object_const(td, creator_dialog_id_, "get_forum_topic_info_object"); - return td_api::make_object(top_thread_message_id_.get(), title_, icon_color_, - icon_custom_emoji_id_.get(), creation_date_, std::move(creator_id), - is_outgoing_, is_closed_); + return td_api::make_object(top_thread_message_id_.get(), title_, + icon_.get_forum_topic_icon_object(), creation_date_, + std::move(creator_id), is_outgoing_, is_closed_); } StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicInfo &topic_info) { return string_builder << "Forum topic " << topic_info.top_thread_message_id_.get() << '/' << topic_info.title_ - << " by " << topic_info.creator_dialog_id_; + << " by " << topic_info.creator_dialog_id_ << " with " << topic_info.icon_; } } // namespace td diff --git a/td/telegram/ForumTopicInfo.h b/td/telegram/ForumTopicInfo.h index ffa72ae72..213d91e7c 100644 --- a/td/telegram/ForumTopicInfo.h +++ b/td/telegram/ForumTopicInfo.h @@ -6,8 +6,8 @@ // #pragma once -#include "td/telegram/CustomEmojiId.h" #include "td/telegram/DialogId.h" +#include "td/telegram/ForumTopicIcon.h" #include "td/telegram/MessageId.h" #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" @@ -22,8 +22,7 @@ class Td; class ForumTopicInfo { MessageId top_thread_message_id_; string title_; - int32 icon_color_ = 0x6FB9F0; - CustomEmojiId icon_custom_emoji_id_; + ForumTopicIcon icon_; int32 creation_date_ = 0; DialogId creator_dialog_id_; bool is_outgoing_ = false;