Store created public broadcasts in MessagesManager.

This commit is contained in:
levlam 2021-12-03 12:28:33 +03:00
parent cffe34e5b2
commit 93af4377b7
4 changed files with 55 additions and 3 deletions

View File

@ -7591,10 +7591,12 @@ vector<ChannelId> ContactsManager::get_channel_ids(vector<tl_object_ptr<telegram
auto channel_id = get_channel_id(chat);
if (!channel_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << channel_id << " from " << source << " in " << to_string(chat);
} else {
channel_ids.push_back(channel_id);
continue;
}
on_get_chat(std::move(chat), source);
if (have_channel(channel_id)) {
channel_ids.push_back(channel_id);
}
}
return channel_ids;
}
@ -7646,6 +7648,10 @@ void ContactsManager::update_created_public_channels(Channel *c, ChannelId chann
}
}
if (was_changed) {
if (!c->is_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<tl_object_ptr<telegram_api::Chat>> &&chats) {
auto index = static_cast<int32>(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<ChannelId> 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<Unit> &&promise) {

View File

@ -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<td_api::object_ptr<td_api::chatInviteLink>> &&promise);

View File

@ -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<ChannelId> 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()) {

View File

@ -354,6 +354,8 @@ class MessagesManager final : public Actor {
void on_update_delete_scheduled_messages(DialogId dialog_id, vector<ScheduledServerMessageId> &&server_message_ids);
void on_update_created_public_broadcasts(vector<ChannelId> 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<MessageId, DialogId, MessageIdHash> message_id_to_dialog_id_;
std::unordered_map<MessageId, DialogId, MessageIdHash> last_clear_history_message_id_to_dialog_id_;
bool created_public_broadcasts_inited_ = false;
vector<ChannelId> created_public_broadcasts_;
std::unordered_map<int64, DialogId> created_dialogs_; // random_id -> dialog_id
std::unordered_map<DialogId, Promise<Unit>, DialogIdHash> pending_created_dialogs_; // dialog_id -> promise