Add messageForumTopicCreated.

This commit is contained in:
levlam 2022-10-18 16:08:53 +03:00
parent be4b1bad46
commit d68836f482
10 changed files with 127 additions and 2 deletions

View File

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

View File

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

View File

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

View File

@ -16,6 +16,14 @@ td_api::object_ptr<td_api::forumTopicIcon> ForumTopicIcon::get_forum_topic_icon_
return td_api::make_object<td_api::forumTopicIcon>(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()) {

View File

@ -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<td_api::forumTopicIcon> get_forum_topic_icon_object() const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
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

View File

@ -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 <class StorerT>
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 <class ParserT>
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

View File

@ -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 <class StorerT>
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<const MessageTopicCreate *>(content);
store(m->title, storer);
store(m->icon, storer);
break;
}
default:
UNREACHABLE();
}
@ -1580,6 +1602,13 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
content = std::move(m);
break;
}
case MessageContentType::TopicCreate: {
auto m = make_unique<MessageTopicCreate>();
parse(m->title, parser);
parse(m->icon, parser);
content = std::move(m);
break;
}
default:
LOG(FATAL) << "Have unknown message content type " << static_cast<int32>(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<telegram_api::InputMedia> 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<const MessageTopicCreate *>(old_content);
const auto *new_ = static_cast<const MessageTopicCreate *>(new_content);
if (old_->title != new_->title || old_->icon != new_->icon) {
need_update = true;
}
break;
}
case MessageContentType::Unsupported: {
const auto *old_ = static_cast<const MessageUnsupported *>(old_content);
const auto *new_ = static_cast<const MessageUnsupported *>(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<MessageContent> 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<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
}
case telegram_api::messageActionTopicCreate::ID: {
auto action = move_tl_object_as<telegram_api::messageActionTopicCreate>(action_ptr);
return make_unique<MessageUnsupported>();
return td::make_unique<MessageTopicCreate>(std::move(action->title_),
ForumTopicIcon(action->icon_color_, action->icon_emoji_id_));
}
case telegram_api::messageActionTopicEdit::ID: {
auto action = move_tl_object_as<telegram_api::messageActionTopicEdit>(action_ptr);
@ -5347,6 +5393,10 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
return make_tl_object<td_api::messageGiftedPremium>(
m->currency, m->amount, m->months, td->stickers_manager_->get_premium_gift_sticker_object(m->months));
}
case MessageContentType::TopicCreate: {
const auto *m = static_cast<const MessageTopicCreate *>(content);
return td_api::make_object<td_api::messageForumTopicCreated>(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;

View File

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

View File

@ -64,7 +64,8 @@ enum class MessageContentType : int32 {
ChatSetTheme,
WebViewDataSent,
WebViewDataReceived,
GiftPremium
GiftPremium,
TopicCreate
};
StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType content_type);

View File

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