Better removing of reply markup after bot has left.

GitOrigin-RevId: 11971b4485fc89fc663afaf5f30ef0f4a88e6d2e
This commit is contained in:
levlam 2019-01-07 19:30:09 +03:00
parent b4c0d1b876
commit ccb2649306
4 changed files with 45 additions and 7 deletions

View File

@ -6386,12 +6386,18 @@ void ContactsManager::update_chat_full(ChatFull *chat_full, ChatId chat_id) {
CHECK(chat_full != nullptr);
if (chat_full->is_changed) {
vector<UserId> administrator_user_ids;
vector<UserId> bot_user_ids;
for (auto &participant : chat_full->participants) {
auto user_id = participant.user_id;
if (participant.status.is_administrator()) {
administrator_user_ids.push_back(participant.user_id);
administrator_user_ids.push_back(user_id);
}
if (is_user_bot(user_id)) {
bot_user_ids.push_back(user_id);
}
}
on_update_dialog_administrators(DialogId(chat_id), std::move(administrator_user_ids), chat_full->version != -1);
td_->messages_manager_->on_dialog_bots_updated(DialogId(chat_id), std::move(bot_user_ids));
chat_full->is_changed = false;
send_closure(
@ -7281,10 +7287,15 @@ void ContactsManager::on_get_channel_participants_success(
result.push_back(get_dialog_participant(channel_id, std::move(participant_ptr)));
}
if (filter.is_administrators() && offset == 0 && static_cast<int32>(participants.size()) < limit) {
on_update_dialog_administrators(
DialogId(channel_id),
transform(result, [](const DialogParticipant &participant) { return participant.user_id; }), true);
if (offset == 0 && static_cast<int32>(participants.size()) < limit) {
if (filter.is_administrators() || filter.is_bots()) {
auto user_ids = transform(result, [](const DialogParticipant &participant) { return participant.user_id; });
if (filter.is_administrators()) {
on_update_dialog_administrators(DialogId(channel_id), std::move(user_ids), true);
} else {
td_->messages_manager_->on_dialog_bots_updated(DialogId(channel_id), std::move(user_ids));
}
}
}
}

View File

@ -258,6 +258,10 @@ class ChannelParticipantsFilter {
bool is_administrators() const {
return type == Type::Administrators;
}
bool is_bots() const {
return type == Type::Bots;
}
};
enum class DialogParticipantsFilter : int32 { Administrators, Members, Restricted, Banned, Bots };

View File

@ -10474,13 +10474,15 @@ bool MessagesManager::can_unload_message(const Dialog *d, const Message *m) cons
// don't want to unload messages from opened dialogs
// don't want to unload messages to which there are replies in yet unsent messages
// don't want to unload messages with pending web pages
// don't want to unload message with active reply markup
// can't unload from memory last dialog, last database messages, yet unsent messages, being edited media messages and active live locations
// can't unload messages in dialog with active suffix load query
FullMessageId full_message_id{d->dialog_id, m->message_id};
return !d->is_opened && m->message_id != d->last_message_id && m->message_id != d->last_database_message_id &&
!m->message_id.is_yet_unsent() && active_live_location_full_message_ids_.count(full_message_id) == 0 &&
replied_by_yet_unsent_messages_.count(full_message_id) == 0 && m->edited_content == nullptr &&
waiting_for_web_page_messages_.count(full_message_id) == 0 && d->suffix_load_queries_.empty();
waiting_for_web_page_messages_.count(full_message_id) == 0 && d->suffix_load_queries_.empty() &&
m->message_id != d->reply_markup_message_id;
}
void MessagesManager::unload_message(Dialog *d, MessageId message_id) {
@ -19273,6 +19275,23 @@ void MessagesManager::on_create_new_dialog_fail(int64 random_id, Status error, P
td_->updates_manager_->get_difference("on_create_new_dialog_fail");
}
void MessagesManager::on_dialog_bots_updated(DialogId dialog_id, vector<UserId> bot_user_ids) {
if (td_->auth_manager_->is_bot()) {
return;
}
auto d = get_dialog_force(dialog_id);
if (d->reply_markup_message_id == MessageId()) {
return;
}
const Message *m = get_message_force(d, d->reply_markup_message_id);
if (m == nullptr || std::find(bot_user_ids.begin(), bot_user_ids.end(), m->sender_user_id) == bot_user_ids.end()) {
LOG(INFO) << "Remove reply markup in " << dialog_id << ", because bot " << m->sender_user_id
<< " isn't a member of the chat";
set_dialog_reply_markup(d, MessageId());
}
}
void MessagesManager::on_dialog_photo_updated(DialogId dialog_id) {
auto d = get_dialog(dialog_id); // called from update_user, must not create the dialog
if (d != nullptr && d->is_update_new_chat_sent) {
@ -21265,9 +21284,11 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
if (!td_->auth_manager_->is_bot() && from_update && d->reply_markup_message_id != MessageId()) {
auto deleted_user_id = get_message_content_deleted_user_id(m->content.get());
if (deleted_user_id.is_valid() && td_->contacts_manager_->is_user_bot(deleted_user_id)) {
if (deleted_user_id.is_valid()) { // do not check for is_user_bot to allow deleted bots
const Message *old_message = get_message_force(d, d->reply_markup_message_id);
if (old_message == nullptr || old_message->sender_user_id == deleted_user_id) {
LOG(INFO) << "Remove reply markup in " << dialog_id << ", because bot " << deleted_user_id
<< " isn't a member of the chat";
set_dialog_reply_markup(d, MessageId());
}
}

View File

@ -581,6 +581,8 @@ class MessagesManager : public Actor {
bool is_update_about_username_change_received(DialogId dialog_id) const;
void on_dialog_bots_updated(DialogId dialog_id, vector<UserId> bot_user_ids);
void on_dialog_photo_updated(DialogId dialog_id);
void on_dialog_title_updated(DialogId dialog_id);
void on_dialog_username_updated(DialogId dialog_id, const string &old_username, const string &new_username);