Apply edited data from service message about forum topics.

This commit is contained in:
levlam 2022-10-27 19:03:58 +03:00
parent 99e6629c79
commit f79e67cab8
10 changed files with 64 additions and 0 deletions

View File

@ -25,6 +25,8 @@ class ForumTopicEditedData {
friend StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicEditedData &topic_edited_data); friend StringBuilder &operator<<(StringBuilder &string_builder, const ForumTopicEditedData &topic_edited_data);
friend class ForumTopicInfo;
public: public:
ForumTopicEditedData() = default; ForumTopicEditedData() = default;

View File

@ -12,6 +12,14 @@ ForumTopicIcon::ForumTopicIcon(int32 color, int64 custom_emoji_id)
: color_(color & 0xFFFFFF), custom_emoji_id_(custom_emoji_id) { : color_(color & 0xFFFFFF), custom_emoji_id_(custom_emoji_id) {
} }
bool ForumTopicIcon::edit_custom_emoji_id(CustomEmojiId custom_emoji_id) {
if (custom_emoji_id_ != custom_emoji_id) {
custom_emoji_id_ = custom_emoji_id;
return true;
}
return false;
}
td_api::object_ptr<td_api::forumTopicIcon> ForumTopicIcon::get_forum_topic_icon_object() const { 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()); return td_api::make_object<td_api::forumTopicIcon>(color_, custom_emoji_id_.get());
} }

View File

@ -26,6 +26,8 @@ class ForumTopicIcon {
ForumTopicIcon() = default; ForumTopicIcon() = default;
ForumTopicIcon(int32 color, int64 custom_emoji_id); ForumTopicIcon(int32 color, int64 custom_emoji_id);
bool edit_custom_emoji_id(CustomEmojiId custom_emoji_id);
td_api::object_ptr<td_api::forumTopicIcon> get_forum_topic_icon_object() const; td_api::object_ptr<td_api::forumTopicIcon> get_forum_topic_icon_object() const;
template <class StorerT> template <class StorerT>

View File

@ -35,6 +35,22 @@ ForumTopicInfo::ForumTopicInfo(const tl_object_ptr<telegram_api::ForumTopic> &fo
} }
} }
bool ForumTopicInfo::apply_edited_data(const ForumTopicEditedData &edited_data) {
bool is_changed = false;
if (!edited_data.title_.empty() && edited_data.title_ != title_) {
title_ = edited_data.title_;
is_changed = true;
}
if (edited_data.edit_icon_custom_emoji_id_ && icon_.edit_custom_emoji_id(edited_data.icon_custom_emoji_id_)) {
is_changed = true;
}
if (edited_data.edit_is_closed_ && edited_data.is_closed_ != is_closed_) {
is_closed_ = edited_data.is_closed_;
is_changed = true;
}
return is_changed;
}
td_api::object_ptr<td_api::forumTopicInfo> ForumTopicInfo::get_forum_topic_info_object(Td *td) const { td_api::object_ptr<td_api::forumTopicInfo> ForumTopicInfo::get_forum_topic_info_object(Td *td) const {
if (is_empty()) { if (is_empty()) {
return nullptr; return nullptr;

View File

@ -7,6 +7,7 @@
#pragma once #pragma once
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/ForumTopicEditedData.h"
#include "td/telegram/ForumTopicIcon.h" #include "td/telegram/ForumTopicIcon.h"
#include "td/telegram/MessageId.h" #include "td/telegram/MessageId.h"
#include "td/telegram/td_api.h" #include "td/telegram/td_api.h"
@ -54,6 +55,8 @@ class ForumTopicInfo {
return top_thread_message_id_; return top_thread_message_id_;
} }
bool apply_edited_data(const ForumTopicEditedData &edited_data);
td_api::object_ptr<td_api::forumTopicInfo> get_forum_topic_info_object(Td *td) const; td_api::object_ptr<td_api::forumTopicInfo> get_forum_topic_info_object(Td *td) const;
}; };

View File

@ -264,6 +264,15 @@ void ForumTopicManager::toggle_forum_topic_is_closed(DialogId dialog_id, Message
td_->create_handler<EditForumTopicQuery>(std::move(promise))->send(channel_id, top_thread_message_id, is_closed); td_->create_handler<EditForumTopicQuery>(std::move(promise))->send(channel_id, top_thread_message_id, is_closed);
} }
void ForumTopicManager::on_forum_topic_edited(DialogId dialog_id, MessageId top_thread_message_id,
const ForumTopicEditedData &edited_data) {
auto topic_info = get_topic_info(dialog_id, top_thread_message_id);
if (topic_info == nullptr) {
return;
}
topic_info->apply_edited_data(edited_data);
}
Status ForumTopicManager::is_forum(DialogId dialog_id) { Status ForumTopicManager::is_forum(DialogId dialog_id) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "ForumTopicManager::is_forum")) { if (!td_->messages_manager_->have_dialog_force(dialog_id, "ForumTopicManager::is_forum")) {
return Status::Error(400, "Chat not found"); return Status::Error(400, "Chat not found");

View File

@ -8,6 +8,7 @@
#include "td/telegram/CustomEmojiId.h" #include "td/telegram/CustomEmojiId.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/ForumTopicEditedData.h"
#include "td/telegram/ForumTopicInfo.h" #include "td/telegram/ForumTopicInfo.h"
#include "td/telegram/td_api.h" #include "td/telegram/td_api.h"
@ -42,6 +43,9 @@ class ForumTopicManager final : public Actor {
void toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id, bool is_closed, void toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id, bool is_closed,
Promise<Unit> &&promise); Promise<Unit> &&promise);
void on_forum_topic_edited(DialogId dialog_id, MessageId top_thread_message_id,
const ForumTopicEditedData &edited_data);
private: private:
static constexpr size_t MAX_FORUM_TOPIC_TITLE_LENGTH = 128; // server side limit for forum topic title static constexpr size_t MAX_FORUM_TOPIC_TITLE_LENGTH = 128; // server side limit for forum topic title

View File

@ -33,6 +33,7 @@
#include "td/telegram/ForumTopicEditedData.hpp" #include "td/telegram/ForumTopicEditedData.hpp"
#include "td/telegram/ForumTopicIcon.h" #include "td/telegram/ForumTopicIcon.h"
#include "td/telegram/ForumTopicIcon.hpp" #include "td/telegram/ForumTopicIcon.hpp"
#include "td/telegram/ForumTopicManager.h"
#include "td/telegram/Game.h" #include "td/telegram/Game.h"
#include "td/telegram/Game.hpp" #include "td/telegram/Game.hpp"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
@ -6102,6 +6103,21 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
add_formatted_text_dependencies(dependencies, get_message_content_text(message_content)); add_formatted_text_dependencies(dependencies, get_message_content_text(message_content));
} }
void update_forum_topic_info_by_service_message_content(Td *td, const MessageContent *content, DialogId dialog_id,
MessageId top_thread_message_id) {
if (!top_thread_message_id.is_valid()) {
return;
}
switch (content->get_type()) {
case MessageContentType::TopicEdit:
return td->forum_topic_manager_->on_forum_topic_edited(
dialog_id, top_thread_message_id, static_cast<const MessageTopicEdit *>(content)->edited_data);
default:
// nothing to do
return;
}
}
void on_sent_message_content(Td *td, const MessageContent *content) { void on_sent_message_content(Td *td, const MessageContent *content) {
switch (content->get_type()) { switch (content->get_type()) {
case MessageContentType::Animation: case MessageContentType::Animation:

View File

@ -252,6 +252,9 @@ void update_failed_to_send_message_content(Td *td, unique_ptr<MessageContent> &c
void add_message_content_dependencies(Dependencies &dependencies, const MessageContent *message_content); void add_message_content_dependencies(Dependencies &dependencies, const MessageContent *message_content);
void update_forum_topic_info_by_service_message_content(Td *td, const MessageContent *content, DialogId dialog_id,
MessageId top_thread_message_id);
void on_sent_message_content(Td *td, const MessageContent *content); void on_sent_message_content(Td *td, const MessageContent *content);
void move_message_content_sticker_set_to_top(Td *td, const MessageContent *content); void move_message_content_sticker_set_to_top(Td *td, const MessageContent *content);

View File

@ -35644,6 +35644,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
if (from_update) { if (from_update) {
speculatively_update_active_group_call_id(d, m); speculatively_update_active_group_call_id(d, m);
speculatively_update_channel_participants(dialog_id, m); speculatively_update_channel_participants(dialog_id, m);
update_forum_topic_info_by_service_message_content(td_, m->content.get(), dialog_id, m->top_thread_message_id);
update_sent_message_contents(dialog_id, m); update_sent_message_contents(dialog_id, m);
update_used_hashtags(dialog_id, m); update_used_hashtags(dialog_id, m);
update_top_dialogs(dialog_id, m); update_top_dialogs(dialog_id, m);