From 30e96aa8c8ec52e7271fa91540dd33115b10dc51 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 13 Jun 2019 00:21:30 +0300 Subject: [PATCH] Improve applying chat full participants. GitOrigin-RevId: 4280f3daa15b4120e81eb3891adced8ff5f97c1c --- td/telegram/ContactsManager.cpp | 14 +++++++++----- td/telegram/ContactsManager.h | 4 ++-- td/telegram/UpdatesManager.cpp | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 845e4cd15..a20cf9424 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -6751,7 +6751,7 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c chat->is_changed = true; } - on_get_chat_participants(std::move(chat_full->participants_)); + on_get_chat_participants(std::move(chat_full->participants_), false); td_->messages_manager_->on_update_dialog_notify_settings(DialogId(chat_id), std::move(chat_full->notify_settings_), "on_get_chat_full"); @@ -7380,7 +7380,8 @@ void ContactsManager::update_dialog_online_member_count(const vectormessages_manager_->on_update_dialog_online_member_count(dialog_id, online_member_count, is_from_server); } -void ContactsManager::on_get_chat_participants(tl_object_ptr &&participants_ptr) { +void ContactsManager::on_get_chat_participants(tl_object_ptr &&participants_ptr, + bool from_update) { switch (participants_ptr->get_id()) { case telegram_api::chatParticipantsForbidden::ID: { auto participants = move_tl_object_as(participants_ptr); @@ -7474,7 +7475,8 @@ void ContactsManager::on_get_chat_participants(tl_object_ptris_changed = true; } - on_update_chat_full_participants(chat_full, chat_id, std::move(new_participants), participants->version_); + on_update_chat_full_participants(chat_full, chat_id, std::move(new_participants), participants->version_, + from_update); update_chat_full(chat_full, chat_id); break; } @@ -8546,7 +8548,8 @@ bool ContactsManager::on_update_chat_full_participants_short(ChatFull *chat_full } void ContactsManager::on_update_chat_full_participants(ChatFull *chat_full, ChatId chat_id, - vector participants, int32 version) { + vector participants, int32 version, + bool from_update) { if (version <= -1) { LOG(ERROR) << "Receive members with wrong version " << version << " in " << chat_id; return; @@ -8559,7 +8562,8 @@ void ContactsManager::on_update_chat_full_participants(ChatFull *chat_full, Chat return; } - if (chat_full->participants.size() != participants.size() && version == chat_full->version) { + if ((chat_full->participants.size() != participants.size() && version == chat_full->version) || + (from_update && version != chat_full->version + 1)) { LOG(INFO) << "Members of " << chat_id << " has changed"; // this is possible in very rare situations repair_chat_participants(chat_id); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 8729685a3..806325ac9 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -166,7 +166,7 @@ class ContactsManager : public Actor { void on_delete_profile_photo(int64 profile_photo_id, Promise promise); - void on_get_chat_participants(tl_object_ptr &&participants); + void on_get_chat_participants(tl_object_ptr &&participants, bool from_update); void on_update_chat_add_user(ChatId chat_id, UserId inviter_user_id, UserId user_id, int32 date, int32 version); void on_update_chat_description(ChatId chat_id, string &&description); void on_update_chat_edit_administrator(ChatId chat_id, UserId user_id, bool is_administrator, int32 version); @@ -905,7 +905,7 @@ class ContactsManager : public Actor { bool on_update_chat_full_participants_short(ChatFull *chat_full, ChatId chat_id, int32 version); void on_update_chat_full_participants(ChatFull *chat_full, ChatId chat_id, vector participants, - int32 version); + int32 version, bool from_update); void on_update_chat_full_invite_link(ChatFull *chat_full, tl_object_ptr &&invite_link_ptr); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 23ff20336..52f4944af 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1660,7 +1660,7 @@ void UpdatesManager::on_update(tl_object_ptr up } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { - td_->contacts_manager_->on_get_chat_participants(std::move(update->participants_)); + td_->contacts_manager_->on_get_chat_participants(std::move(update->participants_), true); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) {