Move is_dialog_info_received_from_server to DialogManager.

This commit is contained in:
levlam 2024-03-05 12:47:42 +03:00
parent d66e3657a3
commit 0e8f076bab
5 changed files with 35 additions and 22 deletions

View File

@ -4751,6 +4751,21 @@ void ContactsManager::apply_pending_user_photo(User *u, UserId user_id) {
}
}
bool ContactsManager::is_user_received_from_server(UserId user_id) const {
const auto *u = get_user(user_id);
return u != nullptr && u->is_received_from_server;
}
bool ContactsManager::is_chat_received_from_server(ChatId chat_id) const {
const auto *c = get_chat(chat_id);
return c != nullptr && c->is_received_from_server;
}
bool ContactsManager::is_channel_received_from_server(ChannelId channel_id) const {
const auto *c = get_channel(channel_id);
return c != nullptr && c->is_received_from_server;
}
const DialogPhoto *ContactsManager::get_user_dialog_photo(UserId user_id) {
auto u = get_user(user_id);
if (u == nullptr) {
@ -15115,25 +15130,6 @@ ContactsManager::User *ContactsManager::get_user(UserId user_id) {
return users_.get_pointer(user_id);
}
bool ContactsManager::is_dialog_info_received_from_server(DialogId dialog_id) const {
switch (dialog_id.get_type()) {
case DialogType::User: {
auto u = get_user(dialog_id.get_user_id());
return u != nullptr && u->is_received_from_server;
}
case DialogType::Chat: {
auto c = get_chat(dialog_id.get_chat_id());
return c != nullptr && c->is_received_from_server;
}
case DialogType::Channel: {
auto c = get_channel(dialog_id.get_channel_id());
return c != nullptr && c->is_received_from_server;
}
default:
return false;
}
}
void ContactsManager::send_get_me_query(Td *td, Promise<Unit> &&promise) {
vector<tl_object_ptr<telegram_api::InputUser>> users;
users.push_back(make_tl_object<telegram_api::inputUserSelf>());

View File

@ -110,6 +110,10 @@ class ContactsManager final : public Actor {
AccessRights access_rights) const;
bool have_input_encrypted_peer(SecretChatId secret_chat_id, AccessRights access_rights) const;
bool is_user_received_from_server(UserId user_id) const;
bool is_chat_received_from_server(ChatId chat_id) const;
bool is_channel_received_from_server(ChannelId channel_id) const;
const DialogPhoto *get_user_dialog_photo(UserId user_id);
const DialogPhoto *get_chat_dialog_photo(ChatId chat_id) const;
const DialogPhoto *get_channel_dialog_photo(ChannelId channel_id) const;
@ -575,8 +579,6 @@ class ContactsManager final : public Actor {
bool have_min_user(UserId user_id) const;
bool have_user_force(UserId user_id, const char *source);
bool is_dialog_info_received_from_server(DialogId dialog_id) const;
static void send_get_me_query(Td *td, Promise<Unit> &&promise);
UserId get_me(Promise<Unit> &&promise);
bool get_user(UserId user_id, int left_tries, Promise<Unit> &&promise);

View File

@ -682,6 +682,19 @@ bool DialogManager::have_dialog_info(DialogId dialog_id) const {
}
}
bool DialogManager::is_dialog_info_received_from_server(DialogId dialog_id) const {
switch (dialog_id.get_type()) {
case DialogType::User:
return td_->contacts_manager_->is_user_received_from_server(dialog_id.get_user_id());
case DialogType::Chat:
return td_->contacts_manager_->is_chat_received_from_server(dialog_id.get_chat_id());
case DialogType::Channel:
return td_->contacts_manager_->is_channel_received_from_server(dialog_id.get_channel_id());
default:
return false;
}
}
bool DialogManager::have_dialog_info_force(DialogId dialog_id, const char *source) const {
switch (dialog_id.get_type()) {
case DialogType::User: {

View File

@ -85,6 +85,8 @@ class DialogManager final : public Actor {
void reload_dialog_info(DialogId dialog_id, Promise<Unit> &&promise);
bool is_dialog_info_received_from_server(DialogId dialog_id) const;
void get_dialog_info_full(DialogId dialog_id, Promise<Unit> &&promise, const char *source);
void reload_dialog_info_full(DialogId dialog_id, const char *source);

View File

@ -34580,7 +34580,7 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<DraftMessage> &&draft
update_dialog_pos(d, "fix_new_dialog 7", true, is_loaded_from_database);
}
if (is_loaded_from_database && d->order != order && order < MAX_ORDINARY_DIALOG_ORDER &&
!td_->contacts_manager_->is_dialog_info_received_from_server(dialog_id) && !d->had_last_yet_unsent_message &&
!td_->dialog_manager_->is_dialog_info_received_from_server(dialog_id) && !d->had_last_yet_unsent_message &&
!td_->auth_manager_->is_bot()) {
LOG(ERROR) << dialog_id << " has order " << d->order << " instead of saved to database order " << order;
}