From 161d34fc15c13bdc6ba4c3c7ec6f19a3606a45c7 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 8 Apr 2022 15:35:21 +0300 Subject: [PATCH] Keep in chat list empty joined basic groups. --- td/telegram/ContactsManager.cpp | 8 ++++++ td/telegram/ContactsManager.h | 1 + td/telegram/MessagesManager.cpp | 47 ++++++++++++++++++++++----------- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 0be92755d..c0f39e6e7 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -14646,6 +14646,14 @@ void ContactsManager::send_get_chat_full_query(ChatId chat_id, Promise &&p get_chat_full_queries_.add_query(DialogId(chat_id).get(), std::move(send_query), std::move(promise)); } +int32 ContactsManager::get_chat_date(ChatId chat_id) const { + auto c = get_chat(chat_id); + if (c == nullptr) { + return 0; + } + return c->date; +} + int32 ContactsManager::get_chat_participant_count(ChatId chat_id) const { auto c = get_chat(chat_id); if (c == nullptr) { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index e70eb0e7f..6eeb5c887 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -496,6 +496,7 @@ class ContactsManager final : public Actor { FileSourceId get_chat_full_file_source_id(ChatId chat_id); void reload_chat_full(ChatId chat_id, Promise &&promise); + int32 get_chat_date(ChatId chat_id) const; int32 get_chat_participant_count(ChatId chat_id) const; bool get_chat_is_active(ChatId chat_id) const; ChannelId get_chat_migrated_to_channel_id(ChatId chat_id) const; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index a924828e6..df06f19e4 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -37139,24 +37139,39 @@ void MessagesManager::update_dialog_pos(Dialog *d, const char *source, bool need new_order = draft_order; } } - auto dialog_type = d->dialog_id.get_type(); - if (dialog_type == DialogType::Channel) { - auto date = td_->contacts_manager_->get_channel_date(d->dialog_id.get_channel_id()); - LOG(INFO) << "Join of channel at " << date << " found"; - int64 join_order = get_dialog_order(MessageId(), date); - if (join_order > new_order) { - new_order = join_order; - } - } - if (dialog_type == DialogType::SecretChat) { - auto date = td_->contacts_manager_->get_secret_chat_date(d->dialog_id.get_secret_chat_id()); - if (date != 0 && !is_deleted_secret_chat(d)) { - LOG(INFO) << "Creation of secret chat at " << date << " found"; - int64 creation_order = get_dialog_order(MessageId(), date); - if (creation_order > new_order) { - new_order = creation_order; + switch (d->dialog_id.get_type()) { + case DialogType::Chat: { + auto chat_id = d->dialog_id.get_chat_id(); + auto date = td_->contacts_manager_->get_chat_date(chat_id); + LOG(INFO) << "Creation at " << date << " found"; + int64 join_order = get_dialog_order(MessageId(), date); + if (join_order > new_order && td_->contacts_manager_->get_chat_status(chat_id).is_member()) { + new_order = join_order; } + break; } + case DialogType::Channel: { + auto date = td_->contacts_manager_->get_channel_date(d->dialog_id.get_channel_id()); + LOG(INFO) << "Join at " << date << " found"; + int64 join_order = get_dialog_order(MessageId(), date); + if (join_order > new_order) { + new_order = join_order; + } + break; + } + case DialogType::SecretChat: { + auto date = td_->contacts_manager_->get_secret_chat_date(d->dialog_id.get_secret_chat_id()); + if (date != 0 && !is_deleted_secret_chat(d)) { + LOG(INFO) << "Creation at " << date << " found"; + int64 creation_order = get_dialog_order(MessageId(), date); + if (creation_order > new_order) { + new_order = creation_order; + } + } + break; + } + default: + break; } if (new_order == DEFAULT_ORDER && !d->is_empty) { LOG(INFO) << "There are no known messages in the chat, just leave it where it is";