diff --git a/CMakeLists.txt b/CMakeLists.txt index 943ee751a..ddb2794f3 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/ForumTopicInfo.cpp td/telegram/Game.cpp td/telegram/GameManager.cpp td/telegram/Global.cpp @@ -579,6 +580,7 @@ set(TDLIB_SOURCE td/telegram/files/ResourceManager.h td/telegram/files/ResourceState.h td/telegram/FolderId.h + td/telegram/ForumTopicInfo.h td/telegram/FullMessageId.h td/telegram/Game.h td/telegram/GameManager.h diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 87e56998a..cb25559f2 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1297,6 +1297,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 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 +//@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; + + //@class RichText @description Describes a text object inside an instant-view web page //@description A plain text @text Text diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index a0125b05c..0fb4de91c 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -6876,7 +6876,7 @@ void ContactsManager::toggle_username_is_active_impl(string &&username, bool is_ const User *u = get_user(get_my_id()); CHECK(u != nullptr); if (!u->usernames.can_toggle(username)) { - return promise.set_error(Status::Error(400, "Unknown username specified")); + return promise.set_error(Status::Error(400, "Wrong username specified")); } td_->create_handler(std::move(promise))->send(std::move(username), is_active); } @@ -7001,7 +7001,7 @@ void ContactsManager::toggle_channel_username_is_active(ChannelId channel_id, st return promise.set_error(Status::Error(400, "Not enough rights to change username")); } if (!c->usernames.can_toggle(username)) { - return promise.set_error(Status::Error(400, "Unknown username specified")); + return promise.set_error(Status::Error(400, "Wrong username specified")); } td_->create_handler(std::move(promise))->send(channel_id, std::move(username), is_active); } diff --git a/td/telegram/ForumTopicInfo.cpp b/td/telegram/ForumTopicInfo.cpp new file mode 100644 index 000000000..258b89c68 --- /dev/null +++ b/td/telegram/ForumTopicInfo.cpp @@ -0,0 +1,58 @@ +// +// 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/ForumTopicInfo.h" + +#include "td/telegram/MessageSender.h" +#include "td/telegram/ServerMessageId.h" +#include "td/telegram/Td.h" + +#include "td/utils/logging.h" + +namespace td { + +ForumTopicInfo::ForumTopicInfo(Td *td, const tl_object_ptr &forum_topic_ptr) { + CHECK(forum_topic_ptr != nullptr); + if (forum_topic_ptr->get_id() != telegram_api::forumTopic::ID) { + LOG(ERROR) << "Receive " << to_string(forum_topic_ptr); + return; + } + const telegram_api::forumTopic *forum_topic = static_cast(forum_topic_ptr.get()); + + top_thread_message_id_ = MessageId(ServerMessageId(forum_topic->id_)); + 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_); + } + 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; + } +} + +td_api::object_ptr ForumTopicInfo::get_forum_topic_info_object(Td *td) const { + if (is_empty()) { + return nullptr; + } + + 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_); +} + +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_; +} + +} // namespace td diff --git a/td/telegram/ForumTopicInfo.h b/td/telegram/ForumTopicInfo.h new file mode 100644 index 000000000..ffa72ae72 --- /dev/null +++ b/td/telegram/ForumTopicInfo.h @@ -0,0 +1,48 @@ +// +// 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/DialogId.h" +#include "td/telegram/MessageId.h" +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +class Td; + +class ForumTopicInfo { + MessageId top_thread_message_id_; + string title_; + int32 icon_color_ = 0x6FB9F0; + CustomEmojiId icon_custom_emoji_id_; + int32 creation_date_ = 0; + DialogId creator_dialog_id_; + bool is_outgoing_ = false; + bool is_closed_ = false; + + friend StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicInfo &topic_info); + + public: + ForumTopicInfo() = default; + + ForumTopicInfo(Td *td, const tl_object_ptr &forum_topic_ptr); + + bool is_empty() const { + return !top_thread_message_id_.is_valid(); + } + + td_api::object_ptr get_forum_topic_info_object(Td *td) const; +}; + +StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicInfo &topic_info); + +} // namespace td