From 0c89d3400752f7ef4ca77f5070560190d51b7226 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 15 Mar 2019 03:16:44 +0300 Subject: [PATCH] Use correct update date for typings; ignore too old typings. GitOrigin-RevId: a1dc65a74bfbc8519591b0ca6739cf04ad58b2bc --- td/telegram/ContactsManager.cpp | 5 +++-- td/telegram/MessagesManager.cpp | 4 ++++ td/telegram/Td.cpp | 10 +++++----- td/telegram/UpdatesManager.cpp | 18 +++++++++++++----- td/telegram/UpdatesManager.h | 4 ++++ 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 5a297963..e2b557a2 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -3460,7 +3460,7 @@ int32 ContactsManager::get_user_was_online(const User *u, UserId user_id) const was_online = my_was_online_local_; } } else { - if (u->local_was_online != 0 && u->local_was_online > was_online) { + if (u->local_was_online > 0 && u->local_was_online > was_online && u->local_was_online > G()->unix_time_cached()) { was_online = u->local_was_online; } } @@ -7058,7 +7058,8 @@ void ContactsManager::on_update_user_local_was_online(User *u, UserId user_id, i // bring users with inaccessible status online for 5 minutes local_was_online += 5 * 60; } - if (local_was_online < G()->unix_time_cached() + 2 || local_was_online <= u->local_was_online) { + if (local_was_online < G()->unix_time_cached() + 2 || local_was_online <= u->local_was_online || + local_was_online <= u->was_online) { return; } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index b9c35dd4..ca7a8d39 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5347,6 +5347,10 @@ void MessagesManager::on_user_dialog_action(DialogId dialog_id, UserId user_id, action = make_tl_object(); } } else { + if (date < G()->unix_time_cached() - DIALOG_ACTION_TIMEOUT - 60) { + LOG(DEBUG) << "Ignore too old action of " << user_id << " in " << dialog_id << " sent at " << date; + return; + } auto &active_actions = active_dialog_actions_[dialog_id]; auto it = std::find_if(active_actions.begin(), active_actions.end(), [user_id](const ActiveDialogAction &action) { return action.user_id == user_id; }); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 4dec2677..174a2bfc 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4329,11 +4329,11 @@ void Td::send_update(tl_object_ptr &&object) { case td_api::updateTrendingStickerSets::ID: VLOG(td_requests) << "Sending update: updateTrendingStickerSets { ... }"; break; - case td_api::updateChatReadInbox::ID * 2: - case td_api::updateUnreadMessageCount::ID * 2: - case td_api::updateUnreadChatCount::ID * 2: - case td_api::updateChatOnlineMemberCount::ID * 2: - case td_api::updateUserChatAction::ID * 2: + case td_api::updateChatReadInbox::ID / 2: + case td_api::updateUnreadMessageCount::ID / 2: + case td_api::updateUnreadChatCount::ID / 2: + case td_api::updateChatOnlineMemberCount::ID / 2: + case td_api::updateUserChatAction::ID / 2: LOG(ERROR) << "Sending update: " << oneline(to_string(object)); break; default: diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 73e72f68..bf365083 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -705,10 +705,11 @@ void UpdatesManager::on_get_updates(tl_object_ptr &&updat LOG(ERROR) << "Receive unacceptable short update: " << td::oneline(to_string(update)); return get_difference("unacceptable short update"); } - + short_update_date_ = update->date_; if (!downcast_call(*update->update_, OnUpdate(this, update->update_, false))) { LOG(ERROR) << "Can't call on some update"; } + short_update_date_ = 0; break; } case telegram_api::updatesCombined::ID: { @@ -1566,6 +1567,14 @@ void UpdatesManager::on_update(tl_object_ptr update->pts_count_, "on_updateChannelWebPage"); } +int32 UpdatesManager::get_short_update_date() const { + int32 now = G()->unix_time(); + if (short_update_date_ > 0) { + return min(short_update_date_, now); + } + return now; +} + tl_object_ptr UpdatesManager::convert_send_message_action( tl_object_ptr action) { auto fix_progress = [](int32 progress) { return progress <= 0 || progress > 100 ? 0 : progress; }; @@ -1624,9 +1633,8 @@ void UpdatesManager::on_update(tl_object_ptr upd LOG(DEBUG) << "Ignore user typing in unknown " << dialog_id; return; } - // TODO date td_->messages_manager_->on_user_dialog_action( - dialog_id, user_id, convert_send_message_action(std::move(update->action_)), G()->unix_time_cached()); + dialog_id, user_id, convert_send_message_action(std::move(update->action_)), get_short_update_date()); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { @@ -1646,7 +1654,7 @@ void UpdatesManager::on_update(tl_object_ptr } } td_->messages_manager_->on_user_dialog_action( - dialog_id, user_id, convert_send_message_action(std::move(update->action_)), G()->unix_time_cached()); + dialog_id, user_id, convert_send_message_action(std::move(update->action_)), get_short_update_date()); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { @@ -1665,7 +1673,7 @@ void UpdatesManager::on_update(tl_object_ptrmessages_manager_->on_user_dialog_action(dialog_id, user_id, make_tl_object(), - G()->unix_time_cached()); + get_short_update_date()); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index b67da3ae..4bcb05c0 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -107,6 +107,8 @@ class UpdatesManager : public Actor { int32 seq_ = 0; string date_source_ = "nowhere"; + int32 short_update_date_ = 0; + std::multimap postponed_updates_; // updates received during getDifference std::multimap pending_seq_updates_; // updates with too big seq @@ -147,6 +149,8 @@ class UpdatesManager : public Actor { void set_date(int32 date, bool from_update, string date_source); + int32 get_short_update_date() const; + static tl_object_ptr convert_send_message_action( tl_object_ptr action);