Add messageForumTopicEdited.

This commit is contained in:
levlam 2022-10-18 22:16:03 +03:00
parent 739f6bd2a1
commit 5e0103c442
10 changed files with 145 additions and 5 deletions

View File

@ -2084,6 +2084,9 @@ 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 forum topic has been edited @edited_data Information about edited topic data
messageForumTopicEdited edited_data:forumTopicEditedData = 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

@ -404,6 +404,7 @@ bool DialogAction::is_canceled_by_message_of_type(MessageContentType message_con
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
return false;
default:
UNREACHABLE();

View File

@ -15,6 +15,16 @@ td_api::object_ptr<td_api::forumTopicEditedData> ForumTopicEditedData::get_forum
icon_custom_emoji_id_.get(), edit_is_closed_, is_closed_);
}
bool operator==(const ForumTopicEditedData &lhs, const ForumTopicEditedData &rhs) {
return lhs.title_ == rhs.title_ && lhs.icon_custom_emoji_id_ == rhs.icon_custom_emoji_id_ &&
lhs.edit_icon_custom_emoji_id_ == rhs.edit_icon_custom_emoji_id_ &&
lhs.edit_is_closed_ == rhs.edit_is_closed_ && lhs.is_closed_ == rhs.is_closed_;
}
bool operator!=(const ForumTopicEditedData &lhs, const ForumTopicEditedData &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicEditedData &topic_edited_data) {
if (!topic_edited_data.title_.empty()) {
string_builder << "set title to \"" << topic_edited_data.title_ << '"';

View File

@ -21,6 +21,8 @@ class ForumTopicEditedData {
bool edit_is_closed_ = false;
bool is_closed_ = false;
friend bool operator==(const ForumTopicEditedData &lhs, const ForumTopicEditedData &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicEditedData &topic_edited_data);
public:
@ -40,8 +42,17 @@ class ForumTopicEditedData {
}
td_api::object_ptr<td_api::forumTopicEditedData> get_forum_topic_edited_data_object() const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
bool operator==(const ForumTopicEditedData &lhs, const ForumTopicEditedData &rhs);
bool operator!=(const ForumTopicEditedData &lhs, const ForumTopicEditedData &rhs);
StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicEditedData &topic_edited_data);
} // namespace td

View File

@ -0,0 +1,54 @@
//
// 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/ForumTopicEditedData.h"
#include "td/utils/common.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void ForumTopicEditedData::store(StorerT &storer) const {
bool has_title = !title_.empty();
bool has_icon_custom_emoji_id = icon_custom_emoji_id_.is_valid();
BEGIN_STORE_FLAGS();
STORE_FLAG(edit_icon_custom_emoji_id_);
STORE_FLAG(edit_is_closed_);
STORE_FLAG(is_closed_);
STORE_FLAG(has_title);
STORE_FLAG(has_icon_custom_emoji_id);
END_STORE_FLAGS();
if (has_title) {
td::store(title_, storer);
}
if (has_icon_custom_emoji_id) {
td::store(icon_custom_emoji_id_, storer);
}
}
template <class ParserT>
void ForumTopicEditedData::parse(ParserT &parser) {
bool has_title;
bool has_icon_custom_emoji_id;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(edit_icon_custom_emoji_id_);
PARSE_FLAG(edit_is_closed_);
PARSE_FLAG(is_closed_);
PARSE_FLAG(has_title);
PARSE_FLAG(has_icon_custom_emoji_id);
END_PARSE_FLAGS();
if (has_title) {
td::parse(title_, parser);
}
if (has_icon_custom_emoji_id) {
td::parse(icon_custom_emoji_id_, parser);
}
}
} // namespace td

View File

@ -18,10 +18,10 @@ class ForumTopicIcon {
int32 color_ = 0x6FB9F0;
CustomEmojiId custom_emoji_id_;
friend StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicIcon &topic_icon);
friend bool operator==(const ForumTopicIcon &lhs, const ForumTopicIcon &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicIcon &topic_icon);
public:
ForumTopicIcon() = default;
ForumTopicIcon(int32 color, int64 custom_emoji_id);

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/ForumTopicEditedData.h"
#include "td/telegram/ForumTopicEditedData.hpp"
#include "td/telegram/ForumTopicIcon.h"
#include "td/telegram/ForumTopicIcon.hpp"
#include "td/telegram/Game.h"
@ -810,7 +812,7 @@ class MessageTopicCreate final : public MessageContent {
ForumTopicIcon icon;
MessageTopicCreate() = default;
explicit MessageTopicCreate(string &&title, ForumTopicIcon &&icon) : title(std::move(title)), icon(std::move(icon)) {
MessageTopicCreate(string &&title, ForumTopicIcon &&icon) : title(std::move(title)), icon(std::move(icon)) {
}
MessageContentType get_type() const final {
@ -818,6 +820,19 @@ class MessageTopicCreate final : public MessageContent {
}
};
class MessageTopicEdit final : public MessageContent {
public:
ForumTopicEditedData edited_data;
MessageTopicEdit() = default;
explicit MessageTopicEdit(ForumTopicEditedData &&edited_data) : edited_data(std::move(edited_data)) {
}
MessageContentType get_type() const final {
return MessageContentType::TopicEdit;
}
};
template <class StorerT>
static void store(const MessageContent *content, StorerT &storer) {
CHECK(content != nullptr);
@ -1152,6 +1167,11 @@ static void store(const MessageContent *content, StorerT &storer) {
store(m->icon, storer);
break;
}
case MessageContentType::TopicEdit: {
const auto *m = static_cast<const MessageTopicEdit *>(content);
store(m->edited_data, storer);
break;
}
default:
UNREACHABLE();
}
@ -1609,6 +1629,12 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
content = std::move(m);
break;
}
case MessageContentType::TopicEdit: {
auto m = make_unique<MessageTopicEdit>();
parse(m->edited_data, parser);
content = std::move(m);
break;
}
default:
LOG(FATAL) << "Have unknown message content type " << static_cast<int32>(content_type);
}
@ -2228,6 +2254,7 @@ bool can_have_input_media(const Td *td, const MessageContent *content, bool is_s
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
return false;
case MessageContentType::Animation:
case MessageContentType::Audio:
@ -2350,6 +2377,7 @@ SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
break;
default:
UNREACHABLE();
@ -2470,6 +2498,7 @@ static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl(
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
break;
default:
UNREACHABLE();
@ -2635,6 +2664,7 @@ void delete_message_content_thumbnail(MessageContent *content, Td *td) {
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
break;
default:
UNREACHABLE();
@ -2818,6 +2848,7 @@ Status can_send_message_content(DialogId dialog_id, const MessageContent *conten
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
UNREACHABLE();
}
return Status::OK();
@ -2948,6 +2979,7 @@ static int32 get_message_content_media_index_mask(const MessageContent *content,
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
return 0;
default:
UNREACHABLE();
@ -3699,6 +3731,14 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
}
break;
}
case MessageContentType::TopicEdit: {
const auto *old_ = static_cast<const MessageTopicEdit *>(old_content);
const auto *new_ = static_cast<const MessageTopicEdit *>(new_content);
if (old_->edited_data != new_->edited_data) {
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);
@ -3840,6 +3880,7 @@ bool merge_message_content_file_id(Td *td, MessageContent *message_content, File
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
LOG(ERROR) << "Receive new file " << new_file_id << " in a sent message of the type " << content_type;
break;
default:
@ -4811,6 +4852,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
return nullptr;
default:
UNREACHABLE();
@ -5115,7 +5157,11 @@ unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
}
case telegram_api::messageActionTopicEdit::ID: {
auto action = move_tl_object_as<telegram_api::messageActionTopicEdit>(action_ptr);
return make_unique<MessageUnsupported>();
auto edit_icon_custom_emoji_id = (action->flags_ & telegram_api::messageActionTopicEdit::ICON_EMOJI_ID_MASK) != 0;
auto edit_is_closed = (action->flags_ & telegram_api::messageActionTopicEdit::CLOSED_MASK) != 0;
return td::make_unique<MessageTopicEdit>(ForumTopicEditedData{std::move(action->title_),
edit_icon_custom_emoji_id, action->icon_emoji_id_,
edit_is_closed, action->closed_});
}
default:
UNREACHABLE();
@ -5397,6 +5443,10 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
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());
}
case MessageContentType::TopicEdit: {
const auto *m = static_cast<const MessageTopicEdit *>(content);
return td_api::make_object<td_api::messageForumTopicEdited>(m->edited_data.get_forum_topic_edited_data_object());
}
default:
UNREACHABLE();
return nullptr;
@ -5754,6 +5804,7 @@ string get_message_content_search_text(const Td *td, const MessageContent *conte
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
return string();
default:
UNREACHABLE();
@ -6030,6 +6081,8 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
break;
case MessageContentType::TopicCreate:
break;
case MessageContentType::TopicEdit:
break;
default:
UNREACHABLE();
break;

View File

@ -112,6 +112,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType cont
return string_builder << "GiftPremium";
case MessageContentType::TopicCreate:
return string_builder << "TopicCreate";
case MessageContentType::TopicEdit:
return string_builder << "TopicEdit";
default:
UNREACHABLE();
return string_builder;
@ -171,6 +173,7 @@ bool is_allowed_media_group_content(MessageContentType content_type) {
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
return false;
default:
UNREACHABLE();
@ -238,6 +241,7 @@ bool is_secret_message_content(int32 ttl, MessageContentType content_type) {
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
return false;
default:
UNREACHABLE();
@ -298,6 +302,7 @@ bool is_service_message_content(MessageContentType content_type) {
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
return true;
default:
UNREACHABLE();
@ -358,6 +363,7 @@ bool can_have_message_content_caption(MessageContentType content_type) {
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
return false;
default:
UNREACHABLE();

View File

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

View File

@ -27438,6 +27438,7 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
return false;
default:
UNREACHABLE();