Don't store copy of created public broadcasts in MessagesManager.

This commit is contained in:
levlam 2024-04-30 14:07:06 +03:00
parent d35f26e2ac
commit 0e1600ac7d
4 changed files with 18 additions and 47 deletions

View File

@ -3721,10 +3721,6 @@ void ChatManager::get_created_public_dialogs(PublicDialogType type,
}
created_public_channels_inited_[index] = true;
if (type == PublicDialogType::ForPersonalDialog) {
update_created_public_broadcasts();
}
if (from_binlog) {
return_created_public_dialogs(std::move(promise), created_public_channels_[index]);
promise = {};
@ -3782,10 +3778,6 @@ void ChatManager::update_created_public_channels(Channel *c, ChannelId channel_i
}
}
if (was_changed) {
if (type == PublicDialogType::ForPersonalDialog) {
update_created_public_broadcasts();
}
save_created_public_channels(type);
reload_created_public_dialogs(type, Promise<td_api::object_ptr<td_api::chats>>());
@ -3809,10 +3801,6 @@ void ChatManager::on_get_created_public_channels(PublicDialogType type,
}
created_public_channels_inited_[index] = true;
if (type == PublicDialogType::ForPersonalDialog) {
update_created_public_broadcasts();
}
save_created_public_channels(type);
}
@ -3828,15 +3816,18 @@ void ChatManager::save_created_public_channels(PublicDialogType type) {
}
}
void ChatManager::update_created_public_broadcasts() {
send_closure_later(G()->messages_manager(), &MessagesManager::on_update_created_public_broadcasts,
created_public_channels_[2]);
}
void ChatManager::check_created_public_dialogs_limit(PublicDialogType type, Promise<Unit> &&promise) {
td_->create_handler<GetCreatedPublicChannelsQuery>(std::move(promise))->send(type, true);
}
bool ChatManager::are_created_public_broadcasts_inited() const {
return created_public_channels_inited_[2];
}
const vector<ChannelId> &ChatManager::get_created_public_broadcasts() const {
return created_public_channels_[2];
}
vector<DialogId> ChatManager::get_dialogs_for_discussion(Promise<Unit> &&promise) {
if (dialogs_for_discussion_inited_) {
promise.set_value(Unit());

View File

@ -190,6 +190,10 @@ class ChatManager final : public Actor {
void on_get_created_public_channels(PublicDialogType type, vector<tl_object_ptr<telegram_api::Chat>> &&chats);
bool are_created_public_broadcasts_inited() const;
const vector<ChannelId> &get_created_public_broadcasts() const;
void on_get_dialogs_for_discussion(vector<tl_object_ptr<telegram_api::Chat>> &&chats);
void on_get_inactive_channels(vector<tl_object_ptr<telegram_api::Chat>> &&chats, Promise<Unit> &&promise);
@ -833,8 +837,6 @@ class ChatManager final : public Actor {
void save_created_public_channels(PublicDialogType type);
void update_created_public_broadcasts();
bool update_permanent_invite_link(DialogInviteLink &invite_link, DialogInviteLink new_invite_link);
static const DialogParticipant *get_chat_full_participant(const ChatFull *chat_full, DialogId dialog_id);

View File

@ -6806,25 +6806,6 @@ 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;
}
LOG(INFO) << "Update create public channels to " << channel_ids;
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_speaking_action(DialogId dialog_id, DialogId speaking_dialog_id, int32 date) {
const Dialog *d = get_dialog_force(dialog_id, "on_dialog_speaking_action");
if (d != nullptr && d->active_group_call_id.is_valid()) {
@ -23368,9 +23349,10 @@ void MessagesManager::get_dialog_send_message_as_dialog_ids(
}
CHECK(dialog_id.get_type() == DialogType::Channel);
if (created_public_broadcasts_inited_) {
if (td_->chat_manager_->are_created_public_broadcasts_inited()) {
auto senders = td_api::make_object<td_api::chatMessageSenders>();
if (!created_public_broadcasts_.empty()) {
const auto &created_public_broadcasts = td_->chat_manager_->get_created_public_broadcasts();
if (!created_public_broadcasts.empty()) {
auto add_sender = [&senders, td = td_](DialogId dialog_id, bool needs_premium) {
auto sender = get_message_sender_object(td, dialog_id, "add_sender");
senders->senders_.push_back(td_api::make_object<td_api::chatMessageSender>(std::move(sender), needs_premium));
@ -23390,7 +23372,7 @@ void MessagesManager::get_dialog_send_message_as_dialog_ids(
bool is_premium = td_->option_manager_->get_option_boolean("is_premium");
auto linked_channel_id = td_->chat_manager_->get_channel_linked_channel_id(
dialog_id.get_channel_id(), "get_dialog_send_message_as_dialog_ids");
for (auto channel_id : created_public_broadcasts_) {
for (auto channel_id : created_public_broadcasts) {
int64 score = td_->chat_manager_->get_channel_participant_count(channel_id);
bool needs_premium =
!is_premium && channel_id != linked_channel_id && !td_->chat_manager_->get_channel_is_verified(channel_id);
@ -30622,7 +30604,8 @@ void MessagesManager::on_update_dialog_default_send_message_as_dialog_id(DialogI
if (d->default_send_message_as_dialog_id != default_send_as_dialog_id) {
if (force || default_send_as_dialog_id.is_valid() ||
(created_public_broadcasts_inited_ && created_public_broadcasts_.empty())) {
(td_->chat_manager_->are_created_public_broadcasts_inited() &&
td_->chat_manager_->get_created_public_broadcasts().empty())) {
LOG(INFO) << "Set message sender in " << dialog_id << " to " << default_send_as_dialog_id;
d->need_drop_default_send_message_as_dialog_id = false;
d->default_send_message_as_dialog_id = default_send_as_dialog_id;

View File

@ -352,8 +352,6 @@ 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_speaking_action(DialogId dialog_id, DialogId speaking_dialog_id, int32 date);
void on_message_animated_emoji_clicked(MessageFullId message_full_id, string &&emoji, string &&data);
@ -3218,9 +3216,6 @@ class MessagesManager final : public Actor {
WaitFreeHashMap<MessageId, DialogId, MessageIdHash> message_id_to_dialog_id_;
FlatHashMap<MessageId, DialogId, MessageIdHash> last_clear_history_message_id_to_dialog_id_;
bool created_public_broadcasts_inited_ = false;
vector<ChannelId> created_public_broadcasts_;
struct PendingCreatedDialog {
td_api::object_ptr<td_api::failedToAddMembers> failed_to_add_members_;
Promise<td_api::object_ptr<td_api::createdBasicGroupChat>> chat_promise_;