Add class ForumTopicIcon.

This commit is contained in:
levlam 2022-10-18 15:04:52 +03:00
parent 177b5f1e89
commit be4b1bad46
6 changed files with 75 additions and 16 deletions

View File

@ -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

View File

@ -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<message> 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

View File

@ -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<td_api::forumTopicIcon> ForumTopicIcon::get_forum_topic_icon_object() const {
return td_api::make_object<td_api::forumTopicIcon>(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

View File

@ -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<td_api::forumTopicIcon> get_forum_topic_icon_object() const;
};
StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicIcon &topic_icon);
} // namespace td

View File

@ -24,18 +24,15 @@ ForumTopicInfo::ForumTopicInfo(Td *td, const tl_object_ptr<telegram_api::ForumTo
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_);
}
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<td_api::forumTopicInfo> 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<td_api::forumTopicInfo>(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<td_api::forumTopicInfo>(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

View File

@ -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;