diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 603eb3eeb..8845758e3 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7591,10 +7591,12 @@ vector ContactsManager::get_channel_ids(vectoris_megagroup) { + update_created_public_broadcasts(); + } + // TODO reload the list } } @@ -7668,8 +7674,29 @@ void ContactsManager::update_created_public_channels(Channel *c, ChannelId chann void ContactsManager::on_get_created_public_channels(PublicDialogType type, vector> &&chats) { auto index = static_cast(type); - created_public_channels_[index] = get_channel_ids(std::move(chats), "on_get_created_public_channels"); + auto channel_ids = get_channel_ids(std::move(chats), "on_get_created_public_channels"); + if (created_public_channels_inited_[index] && created_public_channels_[index] == channel_ids) { + return; + } + created_public_channels_[index] = std::move(channel_ids); created_public_channels_inited_[index] = true; + + if (type == PublicDialogType::HasUsername) { + update_created_public_broadcasts(); + } +} + +void ContactsManager::update_created_public_broadcasts() { + CHECK(created_public_channels_inited_[0]); + vector channel_ids; + for (auto &channel_id : created_public_channels_[0]) { + auto c = get_channel(channel_id); + if (!c->is_megagroup) { + channel_ids.push_back(channel_id); + } + } + send_closure_later(G()->messages_manager(), &MessagesManager::on_update_created_public_broadcasts, + std::move(channel_ids)); } void ContactsManager::check_created_public_dialogs_limit(PublicDialogType type, Promise &&promise) { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index a121465c0..36f742c93 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1412,6 +1412,8 @@ class ContactsManager final : public Actor { void update_created_public_channels(Channel *c, ChannelId channel_id); + void update_created_public_broadcasts(); + void export_dialog_invite_link_impl(DialogId dialog_id, string title, int32 expire_date, int32 usage_limit, bool creates_join_request, bool is_permanent, Promise> &&promise); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 14cb71b20..e572e4444 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -7156,6 +7156,24 @@ void MessagesManager::on_update_delete_scheduled_messages(DialogId dialog_id, send_update_chat_has_scheduled_messages(d, true); } +void MessagesManager::on_update_created_public_broadcasts(vector channel_ids) { + if (td_->auth_manager_->is_bot()) { + // just in case + return; + } + + if (created_public_broadcasts_inited_ && created_public_broadcasts_ == channel_ids) { + return; + } + + for (auto channel_id : channel_ids) { + force_create_dialog(DialogId(channel_id), "on_update_created_public_broadcasts"); + } + + created_public_broadcasts_inited_ = true; + created_public_broadcasts_ = std::move(channel_ids); +} + void MessagesManager::on_dialog_action(DialogId dialog_id, MessageId top_thread_message_id, DialogId typing_dialog_id, DialogAction action, int32 date, MessageContentType message_content_type) { if (td_->auth_manager_->is_bot() || !typing_dialog_id.is_valid()) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index af8dc759c..bed410d44 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -354,6 +354,8 @@ class MessagesManager final : public Actor { void on_update_delete_scheduled_messages(DialogId dialog_id, vector &&server_message_ids); + void on_update_created_public_broadcasts(vector channel_ids); + void on_dialog_action(DialogId dialog_id, MessageId top_thread_message_id, DialogId typing_dialog_id, DialogAction action, int32 date, MessageContentType message_content_type = MessageContentType::None); @@ -3325,6 +3327,9 @@ class MessagesManager final : public Actor { std::unordered_map message_id_to_dialog_id_; std::unordered_map last_clear_history_message_id_to_dialog_id_; + bool created_public_broadcasts_inited_ = false; + vector created_public_broadcasts_; + std::unordered_map created_dialogs_; // random_id -> dialog_id std::unordered_map, DialogIdHash> pending_created_dialogs_; // dialog_id -> promise