Make ContactsManager::get_service_notifications_user_id static.

GitOrigin-RevId: 28c9d570e1b9bfc7987dc299b87c0bb8ac33b38e
This commit is contained in:
levlam 2020-09-24 23:04:32 +03:00
parent 90ee4bd63c
commit b9e27e28b9
3 changed files with 17 additions and 12 deletions

View File

@ -4393,7 +4393,11 @@ ContactsManager::MyOnlineStatusInfo ContactsManager::get_my_online_status() cons
} }
UserId ContactsManager::get_service_notifications_user_id() { UserId ContactsManager::get_service_notifications_user_id() {
UserId user_id(777000); return UserId(777000);
}
UserId ContactsManager::add_service_notifications_user() {
auto user_id = get_service_notifications_user_id();
if (!have_user_force(user_id)) { if (!have_user_force(user_id)) {
LOG(FATAL) << "Failed to load service notification user"; LOG(FATAL) << "Failed to load service notification user";
} }
@ -7516,7 +7520,7 @@ bool ContactsManager::have_user_force(UserId user_id) {
ContactsManager::User *ContactsManager::get_user_force(UserId user_id) { ContactsManager::User *ContactsManager::get_user_force(UserId user_id) {
auto u = get_user_force_impl(user_id); auto u = get_user_force_impl(user_id);
if (user_id == UserId(777000) && (u == nullptr || !u->is_received)) { if (user_id == get_service_notifications_user_id() && (u == nullptr || !u->is_received)) {
int32 flags = telegram_api::user::ACCESS_HASH_MASK | telegram_api::user::FIRST_NAME_MASK | int32 flags = telegram_api::user::ACCESS_HASH_MASK | telegram_api::user::FIRST_NAME_MASK |
telegram_api::user::PHONE_MASK | telegram_api::user::PHOTO_MASK | telegram_api::user::VERIFIED_MASK | telegram_api::user::PHONE_MASK | telegram_api::user::PHOTO_MASK | telegram_api::user::VERIFIED_MASK |
telegram_api::user::SUPPORT_MASK | telegram_api::user::APPLY_MIN_PHOTO_MASK; telegram_api::user::SUPPORT_MASK | telegram_api::user::APPLY_MIN_PHOTO_MASK;
@ -7532,8 +7536,9 @@ ContactsManager::User *ContactsManager::get_user_force(UserId user_id) {
auto user = telegram_api::make_object<telegram_api::user>( auto user = telegram_api::make_object<telegram_api::user>(
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, 777000, 1, "Telegram", string(), false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
string(), "42777", std::move(profile_photo), nullptr, 0, Auto(), string(), string()); get_service_notifications_user_id().get(), 1, "Telegram", string(), string(), "42777", std::move(profile_photo),
nullptr, 0, Auto(), string(), string());
on_get_user(std::move(user), "get_user_force"); on_get_user(std::move(user), "get_user_force");
u = get_user(user_id); u = get_user(user_id);
CHECK(u != nullptr && u->is_received); CHECK(u != nullptr && u->is_received);

View File

@ -259,7 +259,9 @@ class ContactsManager : public Actor {
MyOnlineStatusInfo get_my_online_status() const; MyOnlineStatusInfo get_my_online_status() const;
UserId get_service_notifications_user_id(); static UserId get_service_notifications_user_id();
UserId add_service_notifications_user();
static UserId get_replies_bot_user_id(); static UserId get_replies_bot_user_id();

View File

@ -6106,7 +6106,7 @@ void MessagesManager::add_pending_update(tl_object_ptr<telegram_api::Update> &&u
} }
MessagesManager::Dialog *MessagesManager::get_service_notifications_dialog() { MessagesManager::Dialog *MessagesManager::get_service_notifications_dialog() {
UserId service_notifications_user_id = td_->contacts_manager_->get_service_notifications_user_id(); UserId service_notifications_user_id = td_->contacts_manager_->add_service_notifications_user();
DialogId service_notifications_dialog_id(service_notifications_user_id); DialogId service_notifications_dialog_id(service_notifications_user_id);
force_create_dialog(service_notifications_dialog_id, "get_service_notifications_dialog"); force_create_dialog(service_notifications_dialog_id, "get_service_notifications_dialog");
return get_dialog(service_notifications_dialog_id); return get_dialog(service_notifications_dialog_id);
@ -12546,7 +12546,7 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
sender_user_id = UserId(); sender_user_id = UserId();
} }
if (!is_broadcast_channel(dialog_id) && td_->auth_manager_->is_bot()) { if (!is_broadcast_channel(dialog_id) && td_->auth_manager_->is_bot()) {
sender_user_id = td_->contacts_manager_->get_service_notifications_user_id(); sender_user_id = td_->contacts_manager_->add_service_notifications_user();
} }
} }
if (sender_dialog_id.is_valid()) { if (sender_dialog_id.is_valid()) {
@ -24093,8 +24093,7 @@ bool MessagesManager::is_discussion_message(DialogId dialog_id, const Message *m
return false; return false;
} }
if (m->sender_user_id.is_valid()) { if (m->sender_user_id.is_valid()) {
if (!td_->auth_manager_->is_bot() || if (!td_->auth_manager_->is_bot() || m->sender_user_id != ContactsManager::get_service_notifications_user_id()) {
m->sender_user_id != td_->contacts_manager_->get_service_notifications_user_id()) {
return false; return false;
} }
} }
@ -28869,8 +28868,7 @@ vector<DialogListId> MessagesManager::get_dialog_lists_to_add_dialog(DialogId di
return result; return result;
} }
if (dialog_id != get_my_dialog_id() && if (dialog_id != get_my_dialog_id() && dialog_id != DialogId(ContactsManager::get_service_notifications_user_id())) {
dialog_id != DialogId(td_->contacts_manager_->get_service_notifications_user_id())) {
result.push_back(DialogListId(d->folder_id == FolderId::archive() ? FolderId::main() : FolderId::archive())); result.push_back(DialogListId(d->folder_id == FolderId::archive() ? FolderId::main() : FolderId::archive()));
} }
@ -28961,7 +28959,7 @@ void MessagesManager::add_dialog_to_list(DialogId dialog_id, DialogListId dialog
if (folder_id == FolderId::archive() && if (folder_id == FolderId::archive() &&
(dialog_id == get_my_dialog_id() || (dialog_id == get_my_dialog_id() ||
dialog_id == DialogId(td_->contacts_manager_->get_service_notifications_user_id()))) { dialog_id == DialogId(ContactsManager::get_service_notifications_user_id()))) {
return promise.set_error(Status::Error(400, "Chat can't be archived")); return promise.set_error(Status::Error(400, "Chat can't be archived"));
} }