2018-12-31 20:04:05 +01:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#include "td/telegram/UpdatesManager.h"
|
|
|
|
|
2023-09-11 21:03:01 +02:00
|
|
|
#include "td/telegram/AccountManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/AnimationsManager.h"
|
2022-03-25 14:00:06 +01:00
|
|
|
#include "td/telegram/AttachMenuManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/AuthManager.h"
|
2023-02-03 14:08:44 +01:00
|
|
|
#include "td/telegram/AutosaveManager.h"
|
2023-10-30 22:18:38 +01:00
|
|
|
#include "td/telegram/BoostManager.h"
|
2024-03-31 17:30:18 +02:00
|
|
|
#include "td/telegram/BusinessConnectionId.h"
|
2024-03-07 15:18:11 +01:00
|
|
|
#include "td/telegram/BusinessConnectionManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/CallbackQueriesManager.h"
|
|
|
|
#include "td/telegram/CallManager.h"
|
|
|
|
#include "td/telegram/ChannelId.h"
|
2023-10-30 17:04:14 +01:00
|
|
|
#include "td/telegram/ChannelType.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/ChatId.h"
|
2024-04-02 12:06:22 +02:00
|
|
|
#include "td/telegram/ChatManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/ConfigManager.h"
|
2020-10-01 18:28:10 +02:00
|
|
|
#include "td/telegram/DialogAction.h"
|
2024-01-06 22:46:36 +01:00
|
|
|
#include "td/telegram/DialogActionManager.h"
|
2023-03-27 16:44:13 +02:00
|
|
|
#include "td/telegram/DialogFilterManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/DialogId.h"
|
2021-02-25 13:56:26 +01:00
|
|
|
#include "td/telegram/DialogInviteLink.h"
|
2024-01-04 13:26:42 +01:00
|
|
|
#include "td/telegram/DialogManager.h"
|
2021-05-17 14:21:11 +02:00
|
|
|
#include "td/telegram/DialogParticipant.h"
|
2024-01-08 15:27:32 +01:00
|
|
|
#include "td/telegram/DialogParticipantManager.h"
|
2022-03-03 16:26:25 +01:00
|
|
|
#include "td/telegram/DownloadManager.h"
|
2022-08-30 17:03:57 +02:00
|
|
|
#include "td/telegram/EmojiStatus.h"
|
2019-08-27 16:54:09 +02:00
|
|
|
#include "td/telegram/FolderId.h"
|
2022-12-10 23:32:46 +01:00
|
|
|
#include "td/telegram/ForumTopicManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/Global.h"
|
2020-11-25 15:04:32 +01:00
|
|
|
#include "td/telegram/GroupCallManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/InlineQueriesManager.h"
|
2018-07-17 04:58:34 +02:00
|
|
|
#include "td/telegram/LanguagePackManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/Location.h"
|
|
|
|
#include "td/telegram/MessageId.h"
|
2023-12-14 17:55:53 +01:00
|
|
|
#include "td/telegram/MessageSender.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/MessagesManager.h"
|
2021-12-21 12:06:15 +01:00
|
|
|
#include "td/telegram/MessageTtl.h"
|
2022-09-22 18:33:43 +02:00
|
|
|
#include "td/telegram/misc.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/net/DcOptions.h"
|
|
|
|
#include "td/telegram/net/NetQuery.h"
|
2018-11-22 02:00:28 +01:00
|
|
|
#include "td/telegram/NotificationManager.h"
|
2022-04-11 11:45:52 +02:00
|
|
|
#include "td/telegram/NotificationSettingsManager.h"
|
2022-10-25 00:22:04 +02:00
|
|
|
#include "td/telegram/NotificationSettingsScope.h"
|
2022-08-18 16:00:18 +02:00
|
|
|
#include "td/telegram/OptionManager.h"
|
2022-09-22 18:28:39 +02:00
|
|
|
#include "td/telegram/OrderInfo.h"
|
2024-03-10 23:42:08 +01:00
|
|
|
#include "td/telegram/PeopleNearbyManager.h"
|
2019-02-22 21:15:43 +01:00
|
|
|
#include "td/telegram/PollId.h"
|
2019-02-19 14:45:32 +01:00
|
|
|
#include "td/telegram/PollManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/PrivacyManager.h"
|
2022-05-12 15:34:13 +02:00
|
|
|
#include "td/telegram/PublicDialogType.h"
|
2024-02-22 15:32:12 +01:00
|
|
|
#include "td/telegram/QuickReplyManager.h"
|
2024-02-29 12:43:32 +01:00
|
|
|
#include "td/telegram/QuickReplyShortcutId.h"
|
2024-01-18 18:53:43 +01:00
|
|
|
#include "td/telegram/ReactionListType.h"
|
2023-08-09 11:59:48 +02:00
|
|
|
#include "td/telegram/ReactionManager.h"
|
2023-08-15 16:45:16 +02:00
|
|
|
#include "td/telegram/ReactionType.h"
|
2024-02-04 21:06:48 +01:00
|
|
|
#include "td/telegram/SavedMessagesManager.h"
|
2019-12-02 17:20:54 +01:00
|
|
|
#include "td/telegram/ScheduledServerMessageId.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/SecretChatId.h"
|
|
|
|
#include "td/telegram/SecretChatsManager.h"
|
2019-11-26 17:33:18 +01:00
|
|
|
#include "td/telegram/ServerMessageId.h"
|
2022-05-12 15:34:13 +02:00
|
|
|
#include "td/telegram/SpecialStickerSetType.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/StateManager.h"
|
2023-10-19 14:12:26 +02:00
|
|
|
#include "td/telegram/StickerListType.h"
|
2019-10-22 19:01:15 +02:00
|
|
|
#include "td/telegram/StickerSetId.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/StickersManager.h"
|
2022-07-17 21:39:22 +02:00
|
|
|
#include "td/telegram/StickerType.h"
|
2023-07-01 15:22:01 +02:00
|
|
|
#include "td/telegram/StoryId.h"
|
2023-06-01 15:27:00 +02:00
|
|
|
#include "td/telegram/StoryManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/Td.h"
|
2021-10-27 16:32:09 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
2019-01-06 20:59:17 +01:00
|
|
|
#include "td/telegram/TdDb.h"
|
2023-07-01 13:53:04 +02:00
|
|
|
#include "td/telegram/telegram_api.h"
|
2021-10-27 16:32:09 +02:00
|
|
|
#include "td/telegram/telegram_api.hpp"
|
2021-09-12 21:29:40 +02:00
|
|
|
#include "td/telegram/ThemeManager.h"
|
2024-02-19 20:12:28 +01:00
|
|
|
#include "td/telegram/TimeZoneManager.h"
|
2023-11-21 18:32:23 +01:00
|
|
|
#include "td/telegram/TranscriptionManager.h"
|
2024-04-02 02:52:34 +02:00
|
|
|
#include "td/telegram/UserManager.h"
|
2022-10-12 20:04:18 +02:00
|
|
|
#include "td/telegram/Usernames.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/WebPagesManager.h"
|
|
|
|
|
2020-12-21 20:06:52 +01:00
|
|
|
#include "td/actor/MultiPromise.h"
|
2022-06-27 12:30:18 +02:00
|
|
|
#include "td/actor/PromiseFuture.h"
|
2020-12-21 20:06:52 +01:00
|
|
|
|
2021-01-01 13:59:53 +01:00
|
|
|
#include "td/utils/algorithm.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/buffer.h"
|
|
|
|
#include "td/utils/logging.h"
|
|
|
|
#include "td/utils/misc.h"
|
|
|
|
#include "td/utils/Random.h"
|
2022-06-23 21:00:48 +02:00
|
|
|
#include "td/utils/ScopeGuard.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Slice.h"
|
2021-05-17 14:21:11 +02:00
|
|
|
#include "td/utils/SliceBuilder.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Status.h"
|
|
|
|
#include "td/utils/StringBuilder.h"
|
2021-02-25 13:56:26 +01:00
|
|
|
#include "td/utils/Time.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2018-11-15 18:25:54 +01:00
|
|
|
int VERBOSITY_NAME(get_difference) = VERBOSITY_NAME(INFO);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class OnUpdate {
|
2021-08-20 13:18:11 +02:00
|
|
|
UpdatesManager *updates_manager_;
|
2018-12-31 20:04:05 +01:00
|
|
|
tl_object_ptr<telegram_api::Update> &update_;
|
2021-08-20 13:18:11 +02:00
|
|
|
mutable Promise<Unit> promise_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
public:
|
2021-08-20 13:18:11 +02:00
|
|
|
OnUpdate(UpdatesManager *updates_manager, tl_object_ptr<telegram_api::Update> &update, Promise<Unit> &&promise)
|
|
|
|
: updates_manager_(updates_manager), update_(update), promise_(std::move(promise)) {
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void operator()(T &obj) const {
|
|
|
|
CHECK(&*update_ == &obj);
|
2021-08-20 13:18:11 +02:00
|
|
|
updates_manager_->on_update(move_tl_object_as<T>(update_), std::move(promise_));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class GetUpdatesStateQuery final : public Td::ResultHandler {
|
2021-01-16 00:55:47 +01:00
|
|
|
Promise<tl_object_ptr<telegram_api::updates_state>> promise_;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2021-01-16 00:55:47 +01:00
|
|
|
explicit GetUpdatesStateQuery(Promise<tl_object_ptr<telegram_api::updates_state>> &&promise)
|
|
|
|
: promise_(std::move(promise)) {
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void send() {
|
2020-03-15 22:17:11 +01:00
|
|
|
send_query(G()->net_query_creator().create(telegram_api::updates_getState()));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-11-08 12:19:57 +01:00
|
|
|
void on_result(BufferSlice packet) final {
|
2018-12-31 20:04:05 +01:00
|
|
|
auto result_ptr = fetch_result<telegram_api::updates_getState>(packet);
|
|
|
|
if (result_ptr.is_error()) {
|
2021-11-08 12:19:57 +01:00
|
|
|
return on_error(result_ptr.move_as_error());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-16 00:55:47 +01:00
|
|
|
promise_.set_value(result_ptr.move_as_ok());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-11-08 12:19:57 +01:00
|
|
|
void on_error(Status status) final {
|
2021-01-16 00:55:47 +01:00
|
|
|
promise_.set_error(std::move(status));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class PingServerQuery final : public Td::ResultHandler {
|
2021-01-16 00:59:03 +01:00
|
|
|
Promise<tl_object_ptr<telegram_api::updates_state>> promise_;
|
|
|
|
|
2018-02-11 19:33:32 +01:00
|
|
|
public:
|
2021-01-16 00:59:03 +01:00
|
|
|
explicit PingServerQuery(Promise<tl_object_ptr<telegram_api::updates_state>> &&promise)
|
|
|
|
: promise_(std::move(promise)) {
|
|
|
|
}
|
|
|
|
|
2018-02-11 19:33:32 +01:00
|
|
|
void send() {
|
2020-03-15 22:17:11 +01:00
|
|
|
send_query(G()->net_query_creator().create(telegram_api::updates_getState()));
|
2018-02-11 19:33:32 +01:00
|
|
|
}
|
|
|
|
|
2021-11-08 12:19:57 +01:00
|
|
|
void on_result(BufferSlice packet) final {
|
2018-02-11 19:33:32 +01:00
|
|
|
auto result_ptr = fetch_result<telegram_api::updates_getState>(packet);
|
|
|
|
if (result_ptr.is_error()) {
|
2021-11-08 12:19:57 +01:00
|
|
|
return on_error(result_ptr.move_as_error());
|
2018-02-11 19:33:32 +01:00
|
|
|
}
|
|
|
|
|
2021-01-16 00:59:03 +01:00
|
|
|
promise_.set_value(result_ptr.move_as_ok());
|
2018-02-11 19:33:32 +01:00
|
|
|
}
|
|
|
|
|
2021-11-08 12:19:57 +01:00
|
|
|
void on_error(Status status) final {
|
2021-01-16 00:59:03 +01:00
|
|
|
promise_.set_error(std::move(status));
|
2018-02-11 19:33:32 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-07-12 20:08:01 +02:00
|
|
|
class InitSessionQuery final : public Td::ResultHandler {
|
|
|
|
public:
|
|
|
|
void send() {
|
|
|
|
send_query(G()->net_query_creator().create(telegram_api::help_getCdnConfig()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_result(BufferSlice) final {
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_error(Status) final {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class GetDifferenceQuery final : public Td::ResultHandler {
|
2021-01-16 00:44:58 +01:00
|
|
|
Promise<tl_object_ptr<telegram_api::updates_Difference>> promise_;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2021-01-16 00:44:58 +01:00
|
|
|
explicit GetDifferenceQuery(Promise<tl_object_ptr<telegram_api::updates_Difference>> &&promise)
|
|
|
|
: promise_(std::move(promise)) {
|
|
|
|
}
|
|
|
|
|
2021-01-15 23:42:06 +01:00
|
|
|
void send(int32 pts, int32 date, int32 qts) {
|
2023-04-25 13:27:58 +02:00
|
|
|
send_query(G()->net_query_creator().create(telegram_api::updates_getDifference(0, pts, 0, 0, date, qts, 0)));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-11-08 12:19:57 +01:00
|
|
|
void on_result(BufferSlice packet) final {
|
2018-11-21 15:14:35 +01:00
|
|
|
VLOG(get_difference) << "Receive getDifference result of size " << packet.size();
|
2018-12-31 20:04:05 +01:00
|
|
|
auto result_ptr = fetch_result<telegram_api::updates_getDifference>(packet);
|
|
|
|
if (result_ptr.is_error()) {
|
2021-11-08 12:19:57 +01:00
|
|
|
return on_error(result_ptr.move_as_error());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-16 00:44:58 +01:00
|
|
|
promise_.set_value(result_ptr.move_as_ok());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-11-08 12:19:57 +01:00
|
|
|
void on_error(Status status) final {
|
2023-04-27 21:01:10 +02:00
|
|
|
promise_.set_error(std::move(status));
|
2023-04-27 19:21:30 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConfirmPtsQtsQuery final : public Td::ResultHandler {
|
|
|
|
public:
|
|
|
|
void send(int32 pts, int32 qts) {
|
|
|
|
int32 flags =
|
|
|
|
telegram_api::updates_getDifference::PTS_LIMIT_MASK | telegram_api::updates_getDifference::QTS_LIMIT_MASK;
|
|
|
|
send_query(G()->net_query_creator().create(
|
|
|
|
telegram_api::updates_getDifference(flags, pts, 1, 0, std::numeric_limits<int32>::max(), qts, 1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_result(BufferSlice packet) final {
|
|
|
|
auto result_ptr = fetch_result<telegram_api::updates_getDifference>(packet);
|
|
|
|
if (result_ptr.is_error()) {
|
|
|
|
return on_error(result_ptr.move_as_error());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_error(Status status) final {
|
|
|
|
if (!G()->is_expected_error(status)) {
|
|
|
|
LOG(ERROR) << "Failed to confirm PTS/QTS: " << status;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-04-27 21:01:10 +02:00
|
|
|
class GetPtsUpdateQuery final : public Td::ResultHandler {
|
|
|
|
Promise<tl_object_ptr<telegram_api::updates_Difference>> promise_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit GetPtsUpdateQuery(Promise<tl_object_ptr<telegram_api::updates_Difference>> &&promise)
|
|
|
|
: promise_(std::move(promise)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void send(int32 pts) {
|
|
|
|
int32 flags =
|
|
|
|
telegram_api::updates_getDifference::PTS_LIMIT_MASK | telegram_api::updates_getDifference::QTS_LIMIT_MASK;
|
|
|
|
send_query(G()->net_query_creator().create(
|
|
|
|
telegram_api::updates_getDifference(flags, pts, 1, 0, std::numeric_limits<int32>::max(), 0, 0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_result(BufferSlice packet) final {
|
|
|
|
auto result_ptr = fetch_result<telegram_api::updates_getDifference>(packet);
|
|
|
|
if (result_ptr.is_error()) {
|
|
|
|
return on_error(result_ptr.move_as_error());
|
|
|
|
}
|
|
|
|
|
|
|
|
promise_.set_value(result_ptr.move_as_ok());
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_error(Status status) final {
|
|
|
|
promise_.set_error(std::move(status));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
UpdatesManager::UpdatesManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
2021-08-19 19:36:26 +02:00
|
|
|
last_pts_save_time_ = last_qts_save_time_ = Time::now() - 2 * MAX_PTS_SAVE_DELAY;
|
2022-10-20 16:52:32 +02:00
|
|
|
|
2023-10-14 02:00:54 +02:00
|
|
|
if (!td_->auth_manager_->is_authorized() || !td_->auth_manager_->is_bot()) {
|
|
|
|
skipped_postponed_updates_after_start_ = 0;
|
2023-01-29 23:29:33 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::tear_down() {
|
|
|
|
parent_.reset();
|
2022-04-25 19:52:44 +02:00
|
|
|
|
|
|
|
LOG(DEBUG) << "Have " << being_processed_updates_ << " unprocessed updates to apply";
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-05-12 15:40:53 +02:00
|
|
|
void UpdatesManager::start_up() {
|
2024-02-18 22:23:46 +01:00
|
|
|
if (td_->auth_manager_->is_bot()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-12 15:40:53 +02:00
|
|
|
class StateCallback final : public StateManager::Callback {
|
|
|
|
public:
|
|
|
|
explicit StateCallback(ActorId<UpdatesManager> parent) : parent_(std::move(parent)) {
|
|
|
|
}
|
|
|
|
bool on_online(bool is_online) final {
|
|
|
|
if (is_online) {
|
|
|
|
send_closure(parent_, &UpdatesManager::try_reload_data);
|
|
|
|
}
|
|
|
|
return parent_.is_alive();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ActorId<UpdatesManager> parent_;
|
|
|
|
};
|
|
|
|
send_closure(G()->state_manager(), &StateManager::add_callback, make_unique<StateCallback>(actor_id(this)));
|
2022-05-13 12:56:18 +02:00
|
|
|
|
|
|
|
next_data_reload_time_ = Time::now() - 1;
|
2022-05-12 15:40:53 +02:00
|
|
|
}
|
|
|
|
|
2021-11-05 01:31:48 +01:00
|
|
|
void UpdatesManager::hangup_shared() {
|
|
|
|
ref_cnt_--;
|
|
|
|
if (ref_cnt_ == 0) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::hangup() {
|
|
|
|
pending_pts_updates_.clear();
|
|
|
|
postponed_pts_updates_.clear();
|
|
|
|
postponed_updates_.clear();
|
|
|
|
pending_seq_updates_.clear();
|
|
|
|
pending_qts_updates_.clear();
|
|
|
|
|
|
|
|
hangup_shared();
|
|
|
|
}
|
|
|
|
|
|
|
|
ActorShared<UpdatesManager> UpdatesManager::create_reference() {
|
|
|
|
ref_cnt_++;
|
|
|
|
return actor_shared(this, 1);
|
|
|
|
}
|
|
|
|
|
2023-04-27 21:01:10 +02:00
|
|
|
void UpdatesManager::check_pts_gap(void *td) {
|
|
|
|
if (G()->close_flag()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(td != nullptr);
|
|
|
|
static_cast<Td *>(td)->updates_manager_.get()->repair_pts_gap();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::repair_pts_gap() {
|
2023-08-16 23:32:29 +02:00
|
|
|
if (!td_->auth_manager_->is_authorized() || running_get_difference_ || !postponed_pts_updates_.empty()) {
|
2023-04-27 21:01:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto pts = get_pts() + 1;
|
2023-07-26 21:04:57 +02:00
|
|
|
if (pending_pts_updates_.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto it = pending_pts_updates_.begin();
|
2024-01-26 12:59:07 +01:00
|
|
|
if (it->pts != pts + it->pts_count) {
|
2023-04-27 21:01:10 +02:00
|
|
|
return;
|
|
|
|
}
|
2024-01-26 12:01:44 +01:00
|
|
|
if (last_fetched_pts_ == pts) {
|
|
|
|
VLOG(get_difference) << "Don't fetch again update with PTS = " << pts;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
last_fetched_pts_ = pts;
|
|
|
|
|
2023-04-27 21:01:10 +02:00
|
|
|
VLOG(get_difference) << "Fetch update with PTS = " << pts;
|
2023-05-09 11:53:48 +02:00
|
|
|
pts_short_gap_++;
|
2023-04-27 21:01:10 +02:00
|
|
|
auto promise =
|
|
|
|
PromiseCreator::lambda([pts](Result<telegram_api::object_ptr<telegram_api::updates_Difference>> result) {
|
|
|
|
if (result.is_ok()) {
|
|
|
|
send_closure(G()->updates_manager(), &UpdatesManager::on_get_pts_update, pts, result.move_as_ok());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
td_->create_handler<GetPtsUpdateQuery>(std::move(promise))->send(pts - 1);
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void UpdatesManager::fill_pts_gap(void *td) {
|
2021-01-08 14:05:16 +01:00
|
|
|
if (G()->close_flag()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-10 12:57:41 +02:00
|
|
|
CHECK(td != nullptr);
|
2021-08-15 21:31:24 +02:00
|
|
|
auto updates_manager = static_cast<Td *>(td)->updates_manager_.get();
|
|
|
|
auto min_pts = std::numeric_limits<int32>::max();
|
2023-07-25 13:24:44 +02:00
|
|
|
auto min_pts_count = 0;
|
2023-07-28 17:10:24 +02:00
|
|
|
const telegram_api::Update *first_update = nullptr;
|
2021-08-15 21:31:24 +02:00
|
|
|
auto max_pts = 0;
|
|
|
|
if (!updates_manager->pending_pts_updates_.empty()) {
|
2024-01-26 12:59:07 +01:00
|
|
|
auto &min_update = *updates_manager->pending_pts_updates_.begin();
|
2023-07-25 13:24:44 +02:00
|
|
|
if (min_update.pts < min_pts) {
|
|
|
|
min_pts = min_update.pts;
|
|
|
|
min_pts_count = min_update.pts_count;
|
2023-07-28 17:10:24 +02:00
|
|
|
first_update = min_update.update.get();
|
2023-07-25 13:24:44 +02:00
|
|
|
}
|
2024-01-26 12:59:07 +01:00
|
|
|
max_pts = max(max_pts, updates_manager->pending_pts_updates_.rbegin()->pts);
|
2021-08-15 21:31:24 +02:00
|
|
|
}
|
|
|
|
if (!updates_manager->postponed_pts_updates_.empty()) {
|
2024-01-26 12:59:07 +01:00
|
|
|
auto &min_update = *updates_manager->postponed_pts_updates_.begin();
|
2023-07-25 13:24:44 +02:00
|
|
|
if (min_update.pts < min_pts) {
|
|
|
|
min_pts = min_update.pts;
|
|
|
|
min_pts_count = min_update.pts_count;
|
2023-07-28 17:10:24 +02:00
|
|
|
first_update = min_update.update.get();
|
2023-07-25 13:24:44 +02:00
|
|
|
}
|
2024-01-26 12:59:07 +01:00
|
|
|
max_pts = max(max_pts, updates_manager->postponed_pts_updates_.rbegin()->pts);
|
2021-08-15 21:31:24 +02:00
|
|
|
}
|
2023-07-25 13:24:44 +02:00
|
|
|
string source = PSTRING() << "PTS from " << updates_manager->get_pts() << " to " << min_pts << "(-" << min_pts_count
|
2023-07-28 17:10:24 +02:00
|
|
|
<< ")-" << max_pts << ' '
|
|
|
|
<< (first_update == nullptr ? string() : oneline(to_string(*first_update)));
|
2023-05-09 11:53:48 +02:00
|
|
|
updates_manager->pts_gap_++;
|
2021-01-08 14:05:16 +01:00
|
|
|
fill_gap(td, source.c_str());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::fill_seq_gap(void *td) {
|
2021-01-08 14:05:16 +01:00
|
|
|
if (G()->close_flag()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-10 12:57:41 +02:00
|
|
|
CHECK(td != nullptr);
|
2021-08-15 21:31:24 +02:00
|
|
|
auto updates_manager = static_cast<Td *>(td)->updates_manager_.get();
|
|
|
|
auto min_seq = std::numeric_limits<int32>::max();
|
|
|
|
auto max_seq = 0;
|
|
|
|
if (!updates_manager->pending_seq_updates_.empty()) {
|
2024-01-26 12:59:07 +01:00
|
|
|
min_seq = updates_manager->pending_seq_updates_.begin()->seq_begin;
|
|
|
|
max_seq = updates_manager->pending_seq_updates_.rbegin()->seq_end;
|
2021-01-08 14:05:16 +01:00
|
|
|
}
|
2021-08-15 21:31:24 +02:00
|
|
|
string source = PSTRING() << "seq from " << updates_manager->seq_ << " to " << min_seq << '-' << max_seq;
|
2021-01-08 14:05:16 +01:00
|
|
|
fill_gap(td, source.c_str());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2020-08-03 15:57:30 +02:00
|
|
|
void UpdatesManager::fill_qts_gap(void *td) {
|
2021-02-19 12:12:50 +01:00
|
|
|
if (G()->close_flag()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-10 12:57:41 +02:00
|
|
|
CHECK(td != nullptr);
|
2021-08-15 21:31:24 +02:00
|
|
|
auto updates_manager = static_cast<Td *>(td)->updates_manager_.get();
|
|
|
|
auto min_qts = std::numeric_limits<int32>::max();
|
|
|
|
auto max_qts = 0;
|
|
|
|
if (!updates_manager->pending_qts_updates_.empty()) {
|
|
|
|
min_qts = updates_manager->pending_qts_updates_.begin()->first;
|
|
|
|
max_qts = updates_manager->pending_qts_updates_.rbegin()->first;
|
2021-02-19 12:12:50 +01:00
|
|
|
}
|
2023-01-15 09:05:53 +01:00
|
|
|
string source = PSTRING() << "QTS from " << updates_manager->get_qts() << " to " << min_qts << '-' << max_qts;
|
2023-05-09 11:53:48 +02:00
|
|
|
updates_manager->qts_gap_++;
|
2021-02-19 12:12:50 +01:00
|
|
|
fill_gap(td, source.c_str());
|
2020-08-03 15:57:30 +02:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void UpdatesManager::fill_get_difference_gap(void *td) {
|
2021-03-14 03:19:07 +01:00
|
|
|
fill_gap(td, nullptr);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::fill_gap(void *td, const char *source) {
|
2022-08-10 12:57:41 +02:00
|
|
|
if (G()->close_flag()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
CHECK(td != nullptr);
|
2022-08-10 12:57:41 +02:00
|
|
|
if (!static_cast<Td *>(td)->auth_manager_->is_authorized()) {
|
2020-02-10 00:56:32 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
auto updates_manager = static_cast<Td *>(td)->updates_manager_.get();
|
|
|
|
|
2021-08-26 16:23:18 +02:00
|
|
|
if (source != nullptr && !updates_manager->running_get_difference_) {
|
2023-01-25 15:48:04 +01:00
|
|
|
auto auth_key_id = updates_manager->get_most_unused_auth_key_id();
|
|
|
|
uint64 update_count = 0;
|
|
|
|
double active_time = 0.0;
|
|
|
|
double delay_time = 0.0;
|
|
|
|
if (auth_key_id != 0) {
|
|
|
|
auto now = Time::now();
|
|
|
|
auto &info = updates_manager->session_infos_[auth_key_id];
|
|
|
|
update_count = info.update_count;
|
|
|
|
active_time = now - info.first_update_time;
|
|
|
|
delay_time = now - info.last_update_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(WARNING) << "Filling gap in " << source
|
|
|
|
<< " by running getDifference. Receive no updates from session with auth key " << auth_key_id
|
|
|
|
<< " for " << delay_time << " seconds, active for " << active_time << " seconds and having "
|
|
|
|
<< update_count << " received updates";
|
2021-03-14 03:19:07 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
updates_manager->get_difference("fill_gap");
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::get_difference(const char *source) {
|
2021-06-27 05:02:58 +02:00
|
|
|
if (G()->close_flag() || !td_->auth_manager_->is_authorized()) {
|
2021-01-18 13:54:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
if (get_pts() == -1) {
|
|
|
|
init_state();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (running_get_difference_) {
|
2018-11-15 18:25:54 +01:00
|
|
|
VLOG(get_difference) << "Skip running getDifference from " << source << " because it is already running";
|
2018-12-31 20:04:05 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-01-05 14:06:51 +01:00
|
|
|
|
|
|
|
run_get_difference(false, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::run_get_difference(bool is_recursive, const char *source) {
|
|
|
|
CHECK(get_pts() != -1);
|
|
|
|
CHECK(td_->auth_manager_->is_authorized());
|
|
|
|
CHECK(!running_get_difference_);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
running_get_difference_ = true;
|
|
|
|
|
2021-01-15 23:42:06 +01:00
|
|
|
int32 pts = get_pts();
|
|
|
|
int32 date = get_date();
|
|
|
|
int32 qts = get_qts();
|
|
|
|
if (pts < 0) {
|
|
|
|
pts = 0;
|
|
|
|
}
|
|
|
|
|
2023-01-15 09:05:53 +01:00
|
|
|
VLOG(get_difference) << "-----BEGIN GET DIFFERENCE----- from " << source << " with PTS = " << pts << ", QTS = " << qts
|
2021-01-15 23:42:06 +01:00
|
|
|
<< ", date = " << date;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-12-04 13:50:57 +01:00
|
|
|
before_get_difference(false);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-01-05 14:06:51 +01:00
|
|
|
if (!is_recursive) {
|
|
|
|
min_postponed_update_pts_ = 0;
|
|
|
|
min_postponed_update_qts_ = 0;
|
|
|
|
}
|
|
|
|
|
2021-01-16 00:44:58 +01:00
|
|
|
auto promise = PromiseCreator::lambda([](Result<tl_object_ptr<telegram_api::updates_Difference>> result) {
|
|
|
|
if (result.is_ok()) {
|
|
|
|
send_closure(G()->updates_manager(), &UpdatesManager::on_get_difference, result.move_as_ok());
|
|
|
|
} else {
|
|
|
|
send_closure(G()->updates_manager(), &UpdatesManager::on_failed_get_difference, result.move_as_error());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
td_->create_handler<GetDifferenceQuery>(std::move(promise))->send(pts, date, qts);
|
2023-04-25 15:51:08 +02:00
|
|
|
last_confirmed_pts_ = pts;
|
|
|
|
last_confirmed_qts_ = qts;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 13:50:57 +01:00
|
|
|
void UpdatesManager::before_get_difference(bool is_initial) {
|
2018-12-31 20:04:05 +01:00
|
|
|
// may be called many times before after_get_difference is called
|
|
|
|
send_closure(G()->state_manager(), &StateManager::on_synchronized, false);
|
|
|
|
|
2024-01-26 12:59:07 +01:00
|
|
|
vector<Promise<Unit>> promises;
|
2023-01-29 10:49:25 +01:00
|
|
|
if (can_postpone_updates()) {
|
2024-01-26 12:59:07 +01:00
|
|
|
for (auto &update : pending_pts_updates_) {
|
|
|
|
postponed_pts_updates_.emplace(std::move(update.update), update.pts, update.pts_count, update.receive_time,
|
|
|
|
std::move(update.promise));
|
|
|
|
}
|
2023-01-29 10:49:25 +01:00
|
|
|
} else {
|
|
|
|
for (auto &update : pending_pts_updates_) {
|
2024-01-26 12:59:07 +01:00
|
|
|
promises.push_back(std::move(update.promise));
|
2023-01-29 10:49:25 +01:00
|
|
|
}
|
|
|
|
}
|
2024-01-26 12:59:07 +01:00
|
|
|
set_promises(promises);
|
2021-01-15 23:17:35 +01:00
|
|
|
|
2021-08-16 11:19:30 +02:00
|
|
|
drop_all_pending_pts_updates();
|
2020-08-02 21:07:22 +02:00
|
|
|
|
2018-11-22 02:00:28 +01:00
|
|
|
send_closure_later(td_->notification_manager_actor_, &NotificationManager::before_get_difference);
|
2022-05-22 21:09:46 +02:00
|
|
|
|
|
|
|
if (get_difference_start_time_ <= 0) {
|
|
|
|
get_difference_start_time_ = Time::now();
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Promise<> UpdatesManager::add_pts(int32 pts) {
|
|
|
|
auto id = pts_manager_.add_pts(pts);
|
2022-06-27 01:57:56 +02:00
|
|
|
return create_event_promise(self_closure(this, &UpdatesManager::on_pts_ack, id));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2020-08-02 21:07:22 +02:00
|
|
|
Promise<> UpdatesManager::add_qts(int32 qts) {
|
|
|
|
auto id = qts_manager_.add_pts(qts);
|
2022-06-27 01:57:56 +02:00
|
|
|
return create_event_promise(self_closure(this, &UpdatesManager::on_qts_ack, id));
|
2020-08-02 21:07:22 +02:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void UpdatesManager::on_pts_ack(PtsManager::PtsId ack_token) {
|
|
|
|
auto old_pts = pts_manager_.db_pts();
|
|
|
|
auto new_pts = pts_manager_.finish(ack_token);
|
|
|
|
if (old_pts != new_pts) {
|
|
|
|
save_pts(new_pts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-02 21:07:22 +02:00
|
|
|
void UpdatesManager::on_qts_ack(PtsManager::PtsId ack_token) {
|
|
|
|
auto old_qts = qts_manager_.db_pts();
|
|
|
|
auto new_qts = qts_manager_.finish(ack_token);
|
|
|
|
if (old_qts != new_qts) {
|
|
|
|
save_qts(new_qts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void UpdatesManager::save_pts(int32 pts) {
|
|
|
|
if (pts == std::numeric_limits<int32>::max()) {
|
|
|
|
G()->td_db()->get_binlog_pmc()->erase("updates.pts");
|
2021-08-19 19:36:26 +02:00
|
|
|
last_pts_save_time_ -= 2 * MAX_PTS_SAVE_DELAY;
|
|
|
|
pending_pts_ = 0;
|
2023-03-13 19:13:59 +01:00
|
|
|
} else if (!td_->ignore_background_updates()) {
|
2021-08-19 19:36:26 +02:00
|
|
|
auto now = Time::now();
|
|
|
|
auto delay = last_pts_save_time_ + MAX_PTS_SAVE_DELAY - now;
|
|
|
|
if (delay <= 0 || !td_->auth_manager_->is_bot()) {
|
|
|
|
last_pts_save_time_ = now;
|
|
|
|
pending_pts_ = 0;
|
|
|
|
G()->td_db()->get_binlog_pmc()->set("updates.pts", to_string(pts));
|
|
|
|
} else {
|
|
|
|
pending_pts_ = pts;
|
|
|
|
if (!has_timeout()) {
|
|
|
|
set_timeout_in(delay);
|
|
|
|
}
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-02 21:07:22 +02:00
|
|
|
void UpdatesManager::save_qts(int32 qts) {
|
2023-03-13 19:13:59 +01:00
|
|
|
if (!td_->ignore_background_updates()) {
|
2021-08-19 19:36:26 +02:00
|
|
|
auto now = Time::now();
|
|
|
|
auto delay = last_qts_save_time_ + MAX_PTS_SAVE_DELAY - now;
|
|
|
|
if (delay <= 0 || !td_->auth_manager_->is_bot()) {
|
|
|
|
last_qts_save_time_ = now;
|
|
|
|
pending_qts_ = 0;
|
|
|
|
G()->td_db()->get_binlog_pmc()->set("updates.qts", to_string(qts));
|
|
|
|
} else {
|
|
|
|
pending_qts_ = qts;
|
|
|
|
if (!has_timeout()) {
|
|
|
|
set_timeout_in(delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::timeout_expired() {
|
|
|
|
if (pending_pts_ != 0) {
|
|
|
|
last_pts_save_time_ -= 2 * MAX_PTS_SAVE_DELAY;
|
|
|
|
save_pts(pending_pts_);
|
|
|
|
CHECK(pending_pts_ == 0);
|
|
|
|
}
|
|
|
|
if (pending_qts_ != 0) {
|
|
|
|
last_qts_save_time_ -= 2 * MAX_PTS_SAVE_DELAY;
|
|
|
|
save_qts(pending_qts_);
|
|
|
|
CHECK(pending_qts_ == 0);
|
2020-08-02 21:07:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
Promise<> UpdatesManager::set_pts(int32 pts, const char *source) {
|
|
|
|
if (pts == std::numeric_limits<int32>::max()) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(WARNING) << "Update PTS from " << get_pts() << " to -1 from " << source;
|
2023-07-11 15:10:56 +02:00
|
|
|
save_pts(pts); // drop saved PTS value
|
2021-08-19 19:36:26 +02:00
|
|
|
auto result = add_pts(pts);
|
2018-12-31 20:04:05 +01:00
|
|
|
init_state();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
Promise<> result;
|
2023-05-09 11:53:48 +02:00
|
|
|
auto old_pts = get_pts();
|
|
|
|
if (pts > old_pts || (0 < pts && pts < old_pts - 1000009)) { // PTS can only go up or drop cardinally
|
|
|
|
if (pts < old_pts - 1000009) {
|
|
|
|
LOG(WARNING) << "PTS decreases from " << old_pts << " to " << pts << " from " << source;
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2023-05-09 11:53:48 +02:00
|
|
|
LOG(INFO) << "Update PTS from " << old_pts << " to " << pts << " from " << source;
|
2023-10-19 10:51:33 +02:00
|
|
|
if (old_pts > 0) {
|
|
|
|
pts_diff_ += pts - old_pts;
|
|
|
|
if (pts_diff_ >= 1000000) {
|
|
|
|
LOG(WARNING) << "Fixed " << pts_gap_ << " PTS gaps and " << pts_fixed_short_gap_ << " short gaps by sending "
|
|
|
|
<< pts_short_gap_ << " requests";
|
|
|
|
pts_short_gap_ = 0;
|
|
|
|
pts_fixed_short_gap_ = 0;
|
|
|
|
pts_gap_ = 0;
|
|
|
|
pts_diff_ = 0;
|
|
|
|
}
|
2023-05-09 11:53:48 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
result = add_pts(pts);
|
2023-04-27 19:21:30 +02:00
|
|
|
if (last_confirmed_pts_ < get_pts() - FORCED_GET_DIFFERENCE_PTS_DIFF && last_confirmed_pts_ != 0) {
|
|
|
|
confirm_pts_qts(get_qts());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2022-08-28 21:57:19 +02:00
|
|
|
} else if (pts < get_pts() && (pts > 1 || td_->option_manager_->get_option_integer("session_count") <= 1)) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(ERROR) << "Receive wrong PTS = " << pts << " from " << source << ". Current PTS = " << get_pts();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::set_date(int32 date, bool from_update, string date_source) {
|
|
|
|
if (date > date_) {
|
|
|
|
LOG(INFO) << "Update date to " << date;
|
|
|
|
if (from_update && false) { // date in updates is decreased by the server
|
|
|
|
date--;
|
|
|
|
|
|
|
|
if (date == date_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-02-11 18:21:18 +01:00
|
|
|
auto now = G()->unix_time();
|
|
|
|
if (date_ > now + 1) {
|
2023-01-02 13:38:04 +01:00
|
|
|
LOG(ERROR) << "Receive wrong by " << (date_ - now) << " date = " << date_ << " from " << date_source;
|
2018-02-11 18:21:18 +01:00
|
|
|
date_ = now;
|
|
|
|
if (date_ <= date) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
date_ = date;
|
|
|
|
date_source_ = std::move(date_source);
|
2023-03-13 19:13:59 +01:00
|
|
|
if (!td_->ignore_background_updates()) {
|
2019-04-21 20:17:11 +02:00
|
|
|
G()->td_db()->get_binlog_pmc()->set("updates.date", to_string(date));
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (date < date_) {
|
|
|
|
if (from_update) {
|
|
|
|
date++;
|
|
|
|
|
|
|
|
if (date == date_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG(ERROR) << "Receive wrong by " << (date_ - date) << " date = " << date << " from " << date_source
|
2019-04-18 16:57:57 +02:00
|
|
|
<< ". Current date = " << date_ << " from " << date_source_;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-17 03:48:29 +02:00
|
|
|
bool UpdatesManager::is_acceptable_user(UserId user_id) const {
|
2024-04-02 02:52:34 +02:00
|
|
|
return td_->user_manager_->have_user_force(user_id, "is_acceptable_user") && td_->user_manager_->have_user(user_id);
|
2019-06-17 03:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool UpdatesManager::is_acceptable_chat(ChatId chat_id) const {
|
2024-04-02 12:06:22 +02:00
|
|
|
return td_->chat_manager_->have_chat_force(chat_id, "is_acceptable_chat");
|
2019-06-17 03:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool UpdatesManager::is_acceptable_channel(ChannelId channel_id) const {
|
2024-04-02 12:06:22 +02:00
|
|
|
return td_->chat_manager_->have_channel_force(channel_id, "is_acceptable_channel");
|
2019-06-17 03:48:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-11 16:56:17 +02:00
|
|
|
bool UpdatesManager::is_acceptable_peer(const tl_object_ptr<telegram_api::Peer> &peer) const {
|
|
|
|
if (peer == nullptr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogId dialog_id(peer);
|
2019-06-17 03:25:33 +02:00
|
|
|
switch (dialog_id.get_type()) {
|
|
|
|
case DialogType::User:
|
2019-06-17 03:48:29 +02:00
|
|
|
if (!is_acceptable_user(dialog_id.get_user_id())) {
|
2019-06-17 03:25:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DialogType::Chat:
|
2019-06-17 03:48:29 +02:00
|
|
|
if (!is_acceptable_chat(dialog_id.get_chat_id())) {
|
2019-06-17 03:25:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DialogType::Channel:
|
2019-06-17 03:48:29 +02:00
|
|
|
if (!is_acceptable_channel(dialog_id.get_channel_id())) {
|
2019-06-17 03:25:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DialogType::None:
|
|
|
|
return false;
|
|
|
|
case DialogType::SecretChat:
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool UpdatesManager::is_acceptable_message_entities(
|
|
|
|
const vector<tl_object_ptr<telegram_api::MessageEntity>> &message_entities) const {
|
|
|
|
for (auto &entity : message_entities) {
|
|
|
|
if (entity->get_id() == telegram_api::messageEntityMentionName::ID) {
|
|
|
|
auto entity_mention_name = static_cast<const telegram_api::messageEntityMentionName *>(entity.get());
|
|
|
|
UserId user_id(entity_mention_name->user_id_);
|
2024-04-02 02:52:34 +02:00
|
|
|
if (!is_acceptable_user(user_id) || td_->user_manager_->get_input_user(user_id).is_error()) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-11-10 15:14:00 +01:00
|
|
|
bool UpdatesManager::is_acceptable_reply_markup(const tl_object_ptr<telegram_api::ReplyMarkup> &reply_markup) const {
|
|
|
|
if (reply_markup == nullptr || reply_markup->get_id() != telegram_api::replyInlineMarkup::ID) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (const auto &row : static_cast<const telegram_api::replyInlineMarkup *>(reply_markup.get())->rows_) {
|
|
|
|
for (const auto &button : row->buttons_) {
|
|
|
|
if (button->get_id() == telegram_api::keyboardButtonUserProfile::ID) {
|
|
|
|
auto user_profile_button = static_cast<const telegram_api::keyboardButtonUserProfile *>(button.get());
|
|
|
|
UserId user_id(user_profile_button->user_id_);
|
2024-04-02 02:52:34 +02:00
|
|
|
if (!is_acceptable_user(user_id) || td_->user_manager_->get_input_user(user_id).is_error()) {
|
2021-11-10 15:14:00 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-10 15:28:25 +02:00
|
|
|
bool UpdatesManager::is_acceptable_message_reply_header(
|
2023-05-01 20:07:01 +02:00
|
|
|
const telegram_api::object_ptr<telegram_api::MessageReplyHeader> &header) const {
|
2023-06-05 18:29:38 +02:00
|
|
|
if (header == nullptr) {
|
2020-09-10 15:28:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-06-05 18:29:38 +02:00
|
|
|
switch (header->get_id()) {
|
|
|
|
case telegram_api::messageReplyHeader::ID: {
|
|
|
|
auto reply_header = static_cast<const telegram_api::messageReplyHeader *>(header.get());
|
2023-09-28 15:13:36 +02:00
|
|
|
return is_acceptable_peer(reply_header->reply_to_peer_id_) &&
|
|
|
|
is_acceptable_message_forward_header(reply_header->reply_from_) &&
|
|
|
|
is_acceptable_message_entities(reply_header->quote_entities_) &&
|
|
|
|
is_acceptable_message_media(reply_header->reply_media_);
|
2023-06-05 18:29:38 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageReplyStoryHeader::ID: {
|
|
|
|
auto reply_header = static_cast<const telegram_api::messageReplyStoryHeader *>(header.get());
|
2024-02-07 18:34:28 +01:00
|
|
|
return is_acceptable_peer(reply_header->peer_);
|
2023-06-05 18:29:38 +02:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return true;
|
2020-09-10 15:28:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-17 03:25:33 +02:00
|
|
|
bool UpdatesManager::is_acceptable_message_forward_header(
|
|
|
|
const telegram_api::object_ptr<telegram_api::messageFwdHeader> &header) const {
|
|
|
|
if (header == nullptr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-11 16:56:17 +02:00
|
|
|
if (!is_acceptable_peer(header->from_id_)) {
|
2020-09-11 16:51:01 +02:00
|
|
|
return false;
|
2019-06-17 03:25:33 +02:00
|
|
|
}
|
2020-09-11 16:56:17 +02:00
|
|
|
if (!is_acceptable_peer(header->saved_from_peer_)) {
|
2020-09-11 16:51:01 +02:00
|
|
|
return false;
|
2019-06-17 03:25:33 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-10-14 21:48:16 +02:00
|
|
|
bool UpdatesManager::is_acceptable_message_media(
|
|
|
|
const telegram_api::object_ptr<telegram_api::MessageMedia> &media_ptr) const {
|
|
|
|
if (media_ptr == nullptr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
switch (media_ptr->get_id()) {
|
|
|
|
case telegram_api::messageMediaContact::ID: {
|
|
|
|
auto message_media = static_cast<const telegram_api::messageMediaContact *>(media_ptr.get());
|
|
|
|
UserId user_id(message_media->user_id_);
|
|
|
|
return user_id == UserId() || is_acceptable_user(user_id);
|
|
|
|
}
|
|
|
|
case telegram_api::messageMediaStory::ID: {
|
|
|
|
auto message_media = static_cast<const telegram_api::messageMediaStory *>(media_ptr.get());
|
|
|
|
return is_acceptable_peer(message_media->peer_);
|
|
|
|
}
|
2023-09-28 15:13:36 +02:00
|
|
|
case telegram_api::messageMediaGiveaway::ID: {
|
|
|
|
auto message_media = static_cast<const telegram_api::messageMediaGiveaway *>(media_ptr.get());
|
|
|
|
for (auto channel_id : message_media->channels_) {
|
|
|
|
if (!is_acceptable_channel(ChannelId(channel_id))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2023-12-05 10:30:12 +01:00
|
|
|
case telegram_api::messageMediaGiveawayResults::ID: {
|
|
|
|
auto message_media = static_cast<const telegram_api::messageMediaGiveawayResults *>(media_ptr.get());
|
|
|
|
if (!is_acceptable_channel(ChannelId(message_media->channel_id_))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (auto user_id : message_media->winners_) {
|
|
|
|
if (!is_acceptable_user(UserId(user_id))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2023-10-14 21:48:16 +02:00
|
|
|
case telegram_api::messageMediaPoll::ID:
|
|
|
|
/*
|
|
|
|
// the users and chats are always min, so no need to check
|
|
|
|
auto message_media_poll = static_cast<const telegram_api::messageMediaPoll *>(media_ptr.get());
|
|
|
|
for (auto recent_voter : message_media_poll->results_->recent_voters_) {
|
|
|
|
if (!is_acceptable_peer(recent_voter)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
case telegram_api::messageMediaWebPage::ID:
|
|
|
|
/*
|
|
|
|
// the channel is always min, so no need to check
|
|
|
|
auto message_media_web_page = static_cast<const telegram_api::messageMediaWebPage *>(media_ptr.get());
|
|
|
|
if (message_media_web_page->webpage_->get_id() == telegram_api::webPage::ID) {
|
|
|
|
auto web_page = static_cast<const telegram_api::webPage *>(message_media_web_page->webpage_.get());
|
|
|
|
if (web_page->cached_page_ != nullptr) {
|
|
|
|
const vector<tl_object_ptr<telegram_api::PageBlock>> *page_blocks = nullptr;
|
|
|
|
downcast_call(*web_page->cached_page_, [&page_blocks](auto &page) { page_blocks = &page.blocks_; });
|
|
|
|
CHECK(page_blocks != nullptr);
|
|
|
|
for (auto &page_block : *page_blocks) {
|
|
|
|
if (page_block->get_id() == telegram_api::pageBlockChannel::ID) {
|
|
|
|
auto page_block_channel = static_cast<const telegram_api::pageBlockChannel *>(page_block.get());
|
2024-04-02 12:06:22 +02:00
|
|
|
auto channel_id = ChatManager::get_channel_id(page_block_channel->channel_);
|
2023-10-14 21:48:16 +02:00
|
|
|
if (channel_id.is_valid()) {
|
|
|
|
if (!is_acceptable_channel(channel_id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive wrong channel " << to_string(page_block_channel->channel_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool UpdatesManager::is_acceptable_message(const telegram_api::Message *message_ptr) const {
|
|
|
|
CHECK(message_ptr != nullptr);
|
|
|
|
int32 constructor_id = message_ptr->get_id();
|
|
|
|
|
|
|
|
switch (constructor_id) {
|
|
|
|
case telegram_api::messageEmpty::ID:
|
|
|
|
return true;
|
|
|
|
case telegram_api::message::ID: {
|
|
|
|
auto message = static_cast<const telegram_api::message *>(message_ptr);
|
|
|
|
|
2020-09-11 16:56:17 +02:00
|
|
|
if (!is_acceptable_peer(message->peer_id_)) {
|
2019-06-17 03:25:33 +02:00
|
|
|
return false;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-09-11 16:56:17 +02:00
|
|
|
if (!is_acceptable_peer(message->from_id_)) {
|
2020-09-10 15:28:25 +02:00
|
|
|
return false;
|
2019-06-17 03:25:33 +02:00
|
|
|
}
|
|
|
|
|
2020-09-10 15:28:25 +02:00
|
|
|
if (!is_acceptable_message_reply_header(message->reply_to_)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-17 03:25:33 +02:00
|
|
|
if (!is_acceptable_message_forward_header(message->fwd_from_)) {
|
|
|
|
return false;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2023-09-25 21:09:31 +02:00
|
|
|
if ((message->flags_ & telegram_api::message::VIA_BOT_ID_MASK) &&
|
2019-06-17 03:48:29 +02:00
|
|
|
!is_acceptable_user(UserId(message->via_bot_id_))) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_acceptable_message_entities(message->entities_)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-10-14 21:48:16 +02:00
|
|
|
if (!is_acceptable_message_media(message->media_)) {
|
|
|
|
return false;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2020-08-31 12:42:27 +02:00
|
|
|
/*
|
2020-09-10 13:54:34 +02:00
|
|
|
// the dialogs are always min, so no need to check
|
2020-08-30 21:12:43 +02:00
|
|
|
if (message->replies_ != nullptr) {
|
2020-09-10 13:54:34 +02:00
|
|
|
for (auto &peer : message->replies_->recent_repliers_) {
|
2020-09-11 16:56:17 +02:00
|
|
|
if (!is_acceptable_peer(peer)) {
|
2020-08-30 21:12:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-31 12:42:27 +02:00
|
|
|
*/
|
2020-08-30 21:12:43 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::messageService::ID: {
|
|
|
|
auto message = static_cast<const telegram_api::messageService *>(message_ptr);
|
|
|
|
|
2020-09-11 16:56:17 +02:00
|
|
|
if (!is_acceptable_peer(message->peer_id_)) {
|
2019-06-17 03:25:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-09-11 16:56:17 +02:00
|
|
|
if (!is_acceptable_peer(message->from_id_)) {
|
2020-09-11 16:51:01 +02:00
|
|
|
return false;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const telegram_api::MessageAction *action = message->action_.get();
|
|
|
|
CHECK(action != nullptr);
|
|
|
|
|
|
|
|
switch (action->get_id()) {
|
|
|
|
case telegram_api::messageActionEmpty::ID:
|
|
|
|
case telegram_api::messageActionChatEditTitle::ID:
|
|
|
|
case telegram_api::messageActionChatEditPhoto::ID:
|
|
|
|
case telegram_api::messageActionChatDeletePhoto::ID:
|
|
|
|
case telegram_api::messageActionCustomAction::ID:
|
2018-02-22 01:36:40 +01:00
|
|
|
case telegram_api::messageActionBotAllowed::ID:
|
2018-12-31 20:04:05 +01:00
|
|
|
case telegram_api::messageActionHistoryClear::ID:
|
|
|
|
case telegram_api::messageActionChannelCreate::ID:
|
|
|
|
case telegram_api::messageActionPinMessage::ID:
|
|
|
|
case telegram_api::messageActionGameScore::ID:
|
|
|
|
case telegram_api::messageActionPhoneCall::ID:
|
|
|
|
case telegram_api::messageActionPaymentSent::ID:
|
|
|
|
case telegram_api::messageActionPaymentSentMe::ID:
|
|
|
|
case telegram_api::messageActionScreenshotTaken::ID:
|
2018-03-27 15:11:15 +02:00
|
|
|
case telegram_api::messageActionSecureValuesSent::ID:
|
|
|
|
case telegram_api::messageActionSecureValuesSentMe::ID:
|
2019-02-13 17:05:34 +01:00
|
|
|
case telegram_api::messageActionContactSignUp::ID:
|
2020-11-23 23:36:20 +01:00
|
|
|
case telegram_api::messageActionGroupCall::ID:
|
2021-03-26 16:15:21 +01:00
|
|
|
case telegram_api::messageActionGroupCallScheduled::ID:
|
2021-08-18 15:03:10 +02:00
|
|
|
case telegram_api::messageActionSetChatTheme::ID:
|
2021-10-08 12:45:10 +02:00
|
|
|
case telegram_api::messageActionChatJoinedByRequest::ID:
|
2022-03-18 12:46:01 +01:00
|
|
|
case telegram_api::messageActionWebViewDataSentMe::ID:
|
|
|
|
case telegram_api::messageActionWebViewDataSent::ID:
|
2022-07-01 13:33:59 +02:00
|
|
|
case telegram_api::messageActionGiftPremium::ID:
|
2022-10-07 17:04:00 +02:00
|
|
|
case telegram_api::messageActionTopicCreate::ID:
|
|
|
|
case telegram_api::messageActionTopicEdit::ID:
|
2022-12-08 18:58:37 +01:00
|
|
|
case telegram_api::messageActionSuggestProfilePhoto::ID:
|
2023-03-21 12:11:43 +01:00
|
|
|
case telegram_api::messageActionSetChatWallPaper::ID:
|
2023-09-28 15:13:36 +02:00
|
|
|
case telegram_api::messageActionGiveawayLaunch::ID:
|
2023-11-09 17:37:26 +01:00
|
|
|
case telegram_api::messageActionGiveawayResults::ID:
|
2024-02-07 18:34:28 +01:00
|
|
|
case telegram_api::messageActionBoostApply::ID:
|
2024-03-07 13:24:28 +01:00
|
|
|
case telegram_api::messageActionRequestedPeerSentMe::ID:
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
case telegram_api::messageActionChatCreate::ID: {
|
|
|
|
auto chat_create = static_cast<const telegram_api::messageActionChatCreate *>(action);
|
|
|
|
for (auto &user : chat_create->users_) {
|
2019-06-17 03:48:29 +02:00
|
|
|
if (!is_acceptable_user(UserId(user))) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::messageActionChatAddUser::ID: {
|
|
|
|
auto chat_add_user = static_cast<const telegram_api::messageActionChatAddUser *>(action);
|
|
|
|
for (auto &user : chat_add_user->users_) {
|
2019-06-17 03:48:29 +02:00
|
|
|
if (!is_acceptable_user(UserId(user))) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-10-08 12:45:10 +02:00
|
|
|
case telegram_api::messageActionChatJoinedByLink::ID:
|
|
|
|
// inviter_id_ isn't used
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
case telegram_api::messageActionChatDeleteUser::ID: {
|
|
|
|
auto chat_delete_user = static_cast<const telegram_api::messageActionChatDeleteUser *>(action);
|
2019-06-17 03:48:29 +02:00
|
|
|
if (!is_acceptable_user(UserId(chat_delete_user->user_id_))) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::messageActionChatMigrateTo::ID: {
|
|
|
|
auto chat_migrate_to = static_cast<const telegram_api::messageActionChatMigrateTo *>(action);
|
2019-06-17 03:48:29 +02:00
|
|
|
if (!is_acceptable_channel(ChannelId(chat_migrate_to->channel_id_))) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::messageActionChannelMigrateFrom::ID: {
|
|
|
|
auto channel_migrate_from = static_cast<const telegram_api::messageActionChannelMigrateFrom *>(action);
|
2019-06-17 03:48:29 +02:00
|
|
|
if (!is_acceptable_chat(ChatId(channel_migrate_from->chat_id_))) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-10-19 19:44:09 +02:00
|
|
|
case telegram_api::messageActionGeoProximityReached::ID: {
|
|
|
|
auto geo_proximity_reached = static_cast<const telegram_api::messageActionGeoProximityReached *>(action);
|
|
|
|
if (!is_acceptable_peer(geo_proximity_reached->from_id_)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!is_acceptable_peer(geo_proximity_reached->to_id_)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-11-23 23:36:20 +01:00
|
|
|
case telegram_api::messageActionInviteToGroupCall::ID: {
|
|
|
|
auto invite_to_group_call = static_cast<const telegram_api::messageActionInviteToGroupCall *>(action);
|
2020-11-29 13:41:03 +01:00
|
|
|
for (auto &user : invite_to_group_call->users_) {
|
|
|
|
if (!is_acceptable_user(UserId(user))) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-23 23:36:20 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-11-29 12:02:05 +01:00
|
|
|
case telegram_api::messageActionSetMessagesTTL::ID: {
|
|
|
|
auto set_messages_ttl = static_cast<const telegram_api::messageActionSetMessagesTTL *>(action);
|
|
|
|
if (set_messages_ttl->auto_setting_from_ != 0 &&
|
|
|
|
!is_acceptable_user(UserId(set_messages_ttl->auto_setting_from_))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-01-06 10:42:16 +01:00
|
|
|
case telegram_api::messageActionRequestedPeer::ID: {
|
|
|
|
auto requested_peer = static_cast<const telegram_api::messageActionRequestedPeer *>(action);
|
2023-12-05 10:30:12 +01:00
|
|
|
if (!td_->auth_manager_->is_bot()) {
|
|
|
|
for (auto &peer : requested_peer->peers_) {
|
|
|
|
if (!is_acceptable_peer(peer)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-01-06 10:42:16 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-09-28 15:13:36 +02:00
|
|
|
case telegram_api::messageActionGiftCode::ID: {
|
|
|
|
auto gift_code = static_cast<const telegram_api::messageActionGiftCode *>(action);
|
|
|
|
if (!is_acceptable_peer(gift_code->boost_peer_)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UpdatesManager::is_acceptable_update(const telegram_api::Update *update) const {
|
|
|
|
if (update == nullptr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
int32 id = update->get_id();
|
|
|
|
const telegram_api::Message *message = nullptr;
|
|
|
|
if (id == telegram_api::updateNewMessage::ID) {
|
|
|
|
message = static_cast<const telegram_api::updateNewMessage *>(update)->message_.get();
|
|
|
|
}
|
|
|
|
if (id == telegram_api::updateNewChannelMessage::ID) {
|
|
|
|
message = static_cast<const telegram_api::updateNewChannelMessage *>(update)->message_.get();
|
|
|
|
}
|
2019-12-05 18:34:19 +01:00
|
|
|
if (id == telegram_api::updateNewScheduledMessage::ID) {
|
|
|
|
message = static_cast<const telegram_api::updateNewScheduledMessage *>(update)->message_.get();
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
if (id == telegram_api::updateEditMessage::ID) {
|
|
|
|
message = static_cast<const telegram_api::updateEditMessage *>(update)->message_.get();
|
|
|
|
}
|
|
|
|
if (id == telegram_api::updateEditChannelMessage::ID) {
|
|
|
|
message = static_cast<const telegram_api::updateEditChannelMessage *>(update)->message_.get();
|
|
|
|
}
|
|
|
|
if (message != nullptr) {
|
|
|
|
return is_acceptable_message(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-25 20:56:36 +02:00
|
|
|
int32 UpdatesManager::fix_short_message_flags(int32 flags) {
|
2023-09-25 21:09:31 +02:00
|
|
|
static constexpr int32 MESSAGE_FLAG_HAS_REPLY_MARKUP = 1 << 6;
|
|
|
|
static constexpr int32 MESSAGE_FLAG_HAS_MEDIA = 1 << 9;
|
|
|
|
static constexpr int32 MESSAGE_FLAG_HAS_REACTIONS = 1 << 20;
|
|
|
|
static constexpr int32 MESSAGE_FLAG_HAS_REPLY_INFO = 1 << 23;
|
2024-01-02 01:23:51 +01:00
|
|
|
static constexpr int32 MESSAGE_FLAG_HAS_SAVED_PEER_ID = 1 << 28;
|
|
|
|
auto disallowed_flags = MESSAGE_FLAG_HAS_REPLY_MARKUP | MESSAGE_FLAG_HAS_MEDIA | MESSAGE_FLAG_HAS_REACTIONS |
|
|
|
|
MESSAGE_FLAG_HAS_REPLY_INFO | MESSAGE_FLAG_HAS_SAVED_PEER_ID;
|
2023-09-25 20:56:36 +02:00
|
|
|
if ((flags & disallowed_flags) != 0) {
|
|
|
|
LOG(ERROR) << "Receive short message with flags " << flags;
|
|
|
|
flags = flags & ~disallowed_flags;
|
|
|
|
}
|
2023-09-25 21:48:35 +02:00
|
|
|
return flags;
|
2023-09-25 20:56:36 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 20:06:52 +01:00
|
|
|
void UpdatesManager::on_get_updates(tl_object_ptr<telegram_api::Updates> &&updates_ptr, Promise<Unit> &&promise) {
|
2023-07-20 20:03:05 +02:00
|
|
|
send_closure_later(actor_id(this), &UpdatesManager::on_get_updates_impl, std::move(updates_ptr), std::move(promise));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_get_updates_impl(tl_object_ptr<telegram_api::Updates> updates_ptr, Promise<Unit> promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
CHECK(updates_ptr != nullptr);
|
2022-08-02 20:12:05 +02:00
|
|
|
promise = PromiseCreator::lambda(
|
|
|
|
[promise = std::move(promise), update_ids = get_update_ids(updates_ptr.get())](Result<Unit> result) mutable {
|
|
|
|
if (!G()->close_flag() && result.is_error()) {
|
|
|
|
LOG(ERROR) << "Failed to process updates " << update_ids << ": " << result.error();
|
|
|
|
}
|
|
|
|
promise.set_value(Unit());
|
|
|
|
});
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
auto updates_type = updates_ptr->get_id();
|
|
|
|
if (updates_type != telegram_api::updateShort::ID) {
|
|
|
|
LOG(INFO) << "Receive " << to_string(updates_ptr);
|
|
|
|
}
|
|
|
|
if (!td_->auth_manager_->is_authorized()) {
|
2020-03-30 00:48:44 +02:00
|
|
|
if (updates_type == telegram_api::updateShort::ID && !G()->close_flag()) {
|
|
|
|
auto &update = static_cast<telegram_api::updateShort *>(updates_ptr.get())->update_;
|
|
|
|
auto update_id = update->get_id();
|
|
|
|
if (update_id == telegram_api::updateLoginToken::ID) {
|
2020-12-21 20:06:52 +01:00
|
|
|
td_->auth_manager_->on_update_login_token();
|
|
|
|
return promise.set_value(Unit());
|
2020-03-30 00:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (update_id) {
|
|
|
|
case telegram_api::updateServiceNotification::ID:
|
|
|
|
case telegram_api::updateDcOptions::ID:
|
|
|
|
case telegram_api::updateConfig::ID:
|
|
|
|
case telegram_api::updateLangPackTooLong::ID:
|
|
|
|
case telegram_api::updateLangPack::ID:
|
|
|
|
LOG(INFO) << "Apply without authorization " << to_string(updates_ptr);
|
2021-08-20 13:18:11 +02:00
|
|
|
downcast_call(*update, OnUpdate(this, update, std::move(promise)));
|
2020-03-30 00:48:44 +02:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-12-17 17:17:57 +01:00
|
|
|
}
|
|
|
|
LOG(INFO) << "Ignore received before authorization or after logout " << to_string(updates_ptr);
|
2020-12-21 20:06:52 +01:00
|
|
|
return promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-02-16 03:52:08 +01:00
|
|
|
switch (updates_type) {
|
2018-12-31 20:04:05 +01:00
|
|
|
case telegram_api::updatesTooLong::ID:
|
|
|
|
get_difference("updatesTooLong");
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
case telegram_api::updateShortMessage::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateShortMessage>(updates_ptr);
|
2024-04-02 02:52:34 +02:00
|
|
|
auto from_id = update->out_ ? td_->user_manager_->get_my_id().get() : update->user_id_;
|
2020-12-21 20:06:52 +01:00
|
|
|
auto message = make_tl_object<telegram_api::message>(
|
2023-09-25 20:56:36 +02:00
|
|
|
fix_short_message_flags(update->flags_), update->out_, update->mentioned_, update->media_unread_,
|
2024-03-07 13:24:28 +01:00
|
|
|
update->silent_, false, false, false, false, false, false, false, 0, false, update->id_,
|
2024-02-07 18:34:28 +01:00
|
|
|
make_tl_object<telegram_api::peerUser>(from_id), 0, make_tl_object<telegram_api::peerUser>(update->user_id_),
|
2024-03-07 13:24:28 +01:00
|
|
|
nullptr, std::move(update->fwd_from_), update->via_bot_id_, 0, std::move(update->reply_to_), update->date_,
|
2023-09-25 20:56:36 +02:00
|
|
|
update->message_, nullptr, nullptr, std::move(update->entities_), 0, 0, nullptr, 0, string(), 0, nullptr,
|
2024-02-19 12:07:10 +01:00
|
|
|
Auto(), update->ttl_period_, 0);
|
2020-10-20 01:08:56 +02:00
|
|
|
on_pending_update(
|
2020-12-21 20:06:52 +01:00
|
|
|
make_tl_object<telegram_api::updateNewMessage>(std::move(message), update->pts_, update->pts_count_), 0,
|
2023-07-01 18:13:17 +02:00
|
|
|
std::move(promise), "telegram_api::updateShortMessage");
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updateShortChatMessage::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateShortChatMessage>(updates_ptr);
|
2020-12-21 20:06:52 +01:00
|
|
|
auto message = make_tl_object<telegram_api::message>(
|
2023-09-25 20:56:36 +02:00
|
|
|
fix_short_message_flags(update->flags_), update->out_, update->mentioned_, update->media_unread_,
|
2024-03-07 13:24:28 +01:00
|
|
|
update->silent_, false, false, false, false, false, false, false, 0, false, update->id_,
|
2024-02-07 18:34:28 +01:00
|
|
|
make_tl_object<telegram_api::peerUser>(update->from_id_), 0,
|
2024-01-02 01:23:51 +01:00
|
|
|
make_tl_object<telegram_api::peerChat>(update->chat_id_), nullptr, std::move(update->fwd_from_),
|
2024-03-07 13:24:28 +01:00
|
|
|
update->via_bot_id_, 0, std::move(update->reply_to_), update->date_, update->message_, nullptr, nullptr,
|
2024-02-19 12:07:10 +01:00
|
|
|
std::move(update->entities_), 0, 0, nullptr, 0, string(), 0, nullptr, Auto(), update->ttl_period_, 0);
|
2020-09-08 21:08:10 +02:00
|
|
|
on_pending_update(
|
2020-12-21 20:06:52 +01:00
|
|
|
make_tl_object<telegram_api::updateNewMessage>(std::move(message), update->pts_, update->pts_count_), 0,
|
2023-07-01 18:13:17 +02:00
|
|
|
std::move(promise), "telegram_api::updateShortChatMessage");
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updateShort::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateShort>(updates_ptr);
|
2018-11-15 23:48:56 +01:00
|
|
|
LOG(DEBUG) << "Receive " << oneline(to_string(update));
|
2018-12-31 20:04:05 +01:00
|
|
|
if (!is_acceptable_update(update->update_.get())) {
|
2019-09-15 05:19:46 +02:00
|
|
|
LOG(ERROR) << "Receive unacceptable short update: " << oneline(to_string(update));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
return get_difference("unacceptable short update");
|
|
|
|
}
|
2019-03-15 01:16:44 +01:00
|
|
|
short_update_date_ = update->date_;
|
2021-08-20 13:18:11 +02:00
|
|
|
downcast_call(*update->update_, OnUpdate(this, update->update_, std::move(promise)));
|
2019-03-15 01:16:44 +01:00
|
|
|
short_update_date_ = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updatesCombined::ID: {
|
|
|
|
auto updates = move_tl_object_as<telegram_api::updatesCombined>(updates_ptr);
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_get_users(std::move(updates->users_), "updatesCombined");
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->on_get_chats(std::move(updates->chats_), "updatesCombined");
|
2021-08-15 11:46:38 +02:00
|
|
|
on_pending_updates(std::move(updates->updates_), updates->seq_start_, updates->seq_, updates->date_, Time::now(),
|
2020-12-21 20:06:52 +01:00
|
|
|
std::move(promise), "telegram_api::updatesCombined");
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updates::ID: {
|
|
|
|
auto updates = move_tl_object_as<telegram_api::updates>(updates_ptr);
|
2022-10-06 17:21:25 +02:00
|
|
|
string source_str;
|
|
|
|
const char *source = "updates";
|
|
|
|
if (updates->updates_.size() == 1 && updates->updates_[0] != nullptr) {
|
|
|
|
source_str = PSTRING() << "update " << updates->updates_[0]->get_id();
|
|
|
|
source = source_str.c_str();
|
|
|
|
}
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_get_users(std::move(updates->users_), source);
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->on_get_chats(std::move(updates->chats_), source);
|
2021-08-15 11:46:38 +02:00
|
|
|
on_pending_updates(std::move(updates->updates_), updates->seq_, updates->seq_, updates->date_, Time::now(),
|
|
|
|
std::move(promise), "telegram_api::updates");
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updateShortSentMessage::ID:
|
|
|
|
LOG(ERROR) << "Receive " << oneline(to_string(updates_ptr));
|
|
|
|
get_difference("updateShortSentMessage");
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-16 00:55:47 +01:00
|
|
|
void UpdatesManager::on_failed_get_updates_state(Status &&error) {
|
2021-06-27 05:02:58 +02:00
|
|
|
if (G()->close_flag() || !td_->auth_manager_->is_authorized()) {
|
2021-01-18 13:54:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-01-16 00:55:47 +01:00
|
|
|
if (error.code() != 401) {
|
|
|
|
LOG(ERROR) << "Receive updates.getState error: " << error;
|
|
|
|
}
|
|
|
|
|
|
|
|
running_get_difference_ = false;
|
|
|
|
schedule_get_difference("on_failed_get_updates_state");
|
|
|
|
}
|
|
|
|
|
2021-01-16 00:44:58 +01:00
|
|
|
void UpdatesManager::on_failed_get_difference(Status &&error) {
|
2021-06-27 05:02:58 +02:00
|
|
|
if (G()->close_flag() || !td_->auth_manager_->is_authorized()) {
|
2021-01-18 13:54:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-01-16 00:44:58 +01:00
|
|
|
if (error.code() != 401) {
|
|
|
|
LOG(ERROR) << "Receive updates.getDifference error: " << error;
|
|
|
|
}
|
|
|
|
|
|
|
|
running_get_difference_ = false;
|
2018-12-31 20:04:05 +01:00
|
|
|
schedule_get_difference("on_failed_get_difference");
|
2021-01-16 00:44:58 +01:00
|
|
|
|
|
|
|
if (error.message() == Slice("PERSISTENT_TIMESTAMP_INVALID")) {
|
|
|
|
set_pts(std::numeric_limits<int32>::max(), "PERSISTENT_TIMESTAMP_INVALID").set_value(Unit());
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::schedule_get_difference(const char *source) {
|
2021-06-27 05:02:58 +02:00
|
|
|
if (G()->close_flag() || !td_->auth_manager_->is_authorized()) {
|
2021-06-27 04:52:43 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
if (!retry_timeout_.has_timeout()) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(WARNING) << "Schedule getDifference in " << retry_time_ << " seconds with PTS = " << get_pts()
|
|
|
|
<< ", QTS = " << get_qts() << ", date = " << get_date() << " from " << source;
|
2018-12-31 20:04:05 +01:00
|
|
|
retry_timeout_.set_callback(std::move(fill_get_difference_gap));
|
|
|
|
retry_timeout_.set_callback_data(static_cast<void *>(td_));
|
|
|
|
retry_timeout_.set_timeout_in(retry_time_);
|
|
|
|
retry_time_ *= 2;
|
|
|
|
if (retry_time_ > 60) {
|
|
|
|
retry_time_ = Random::fast(60, 80);
|
|
|
|
}
|
2021-03-14 03:19:07 +01:00
|
|
|
} else {
|
|
|
|
VLOG(get_difference) << "Schedule getDifference from " << source;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_get_updates_state(tl_object_ptr<telegram_api::updates_state> &&state, const char *source) {
|
2021-01-16 00:55:47 +01:00
|
|
|
CHECK(state != nullptr);
|
|
|
|
|
2018-11-15 18:25:54 +01:00
|
|
|
VLOG(get_difference) << "Receive " << oneline(to_string(state)) << " from " << source;
|
2018-12-31 20:04:05 +01:00
|
|
|
// TODO use state->unread_count;
|
|
|
|
|
|
|
|
if (get_pts() == std::numeric_limits<int32>::max()) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(WARNING) << "Restore PTS to " << state->pts_;
|
|
|
|
// restoring right PTS
|
2022-08-21 07:22:58 +02:00
|
|
|
CHECK(pending_pts_updates_.empty());
|
2022-08-29 00:16:29 +02:00
|
|
|
auto real_running_get_difference = running_get_difference_;
|
|
|
|
running_get_difference_ = false;
|
2023-01-15 09:05:53 +01:00
|
|
|
process_postponed_pts_updates(); // drop all updates with old PTS
|
2022-08-29 00:16:29 +02:00
|
|
|
running_get_difference_ = real_running_get_difference;
|
2018-12-31 20:04:05 +01:00
|
|
|
pts_manager_.init(state->pts_);
|
2023-04-25 15:51:08 +02:00
|
|
|
last_confirmed_pts_ = get_pts();
|
2021-08-19 19:36:26 +02:00
|
|
|
last_pts_save_time_ = Time::now() - 2 * MAX_PTS_SAVE_DELAY;
|
|
|
|
save_pts(state->pts_);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
string full_source = "on_get_updates_state " + oneline(to_string(state)) + " from " + source;
|
|
|
|
set_pts(state->pts_, full_source.c_str()).set_value(Unit());
|
|
|
|
set_date(state->date_, false, std::move(full_source));
|
2020-08-03 15:57:30 +02:00
|
|
|
add_qts(state->qts_).set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
seq_ = state->seq_;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (running_get_difference_) { // called from getUpdatesState
|
|
|
|
running_get_difference_ = false;
|
|
|
|
after_get_difference();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-14 19:44:20 +01:00
|
|
|
const vector<tl_object_ptr<telegram_api::Update>> *UpdatesManager::get_updates(
|
|
|
|
const telegram_api::Updates *updates_ptr) {
|
2018-12-31 20:04:05 +01:00
|
|
|
switch (updates_ptr->get_id()) {
|
|
|
|
case telegram_api::updatesTooLong::ID:
|
|
|
|
case telegram_api::updateShortMessage::ID:
|
|
|
|
case telegram_api::updateShortChatMessage::ID:
|
|
|
|
case telegram_api::updateShort::ID:
|
|
|
|
case telegram_api::updateShortSentMessage::ID:
|
|
|
|
LOG(ERROR) << "Receive " << oneline(to_string(*updates_ptr)) << " instead of updates";
|
2019-02-14 19:44:20 +01:00
|
|
|
return nullptr;
|
|
|
|
case telegram_api::updatesCombined::ID:
|
|
|
|
return &static_cast<const telegram_api::updatesCombined *>(updates_ptr)->updates_;
|
|
|
|
case telegram_api::updates::ID:
|
|
|
|
return &static_cast<const telegram_api::updates *>(updates_ptr)->updates_;
|
2018-12-31 20:04:05 +01:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2019-02-14 19:44:20 +01:00
|
|
|
return nullptr;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2019-02-14 19:44:20 +01:00
|
|
|
}
|
|
|
|
|
2021-04-30 16:07:01 +02:00
|
|
|
vector<tl_object_ptr<telegram_api::Update>> *UpdatesManager::get_updates(telegram_api::Updates *updates_ptr) {
|
|
|
|
return const_cast<vector<tl_object_ptr<telegram_api::Update>> *>(
|
|
|
|
get_updates(static_cast<const telegram_api::Updates *>(updates_ptr)));
|
|
|
|
}
|
|
|
|
|
2023-03-23 14:53:11 +01:00
|
|
|
bool UpdatesManager::are_empty_updates(const telegram_api::Updates *updates_ptr) {
|
|
|
|
switch (updates_ptr->get_id()) {
|
|
|
|
case telegram_api::updatesTooLong::ID:
|
|
|
|
case telegram_api::updateShortSentMessage::ID:
|
|
|
|
return true;
|
|
|
|
case telegram_api::updateShortMessage::ID:
|
|
|
|
case telegram_api::updateShortChatMessage::ID:
|
|
|
|
case telegram_api::updateShort::ID:
|
|
|
|
return false;
|
|
|
|
case telegram_api::updatesCombined::ID:
|
|
|
|
return static_cast<const telegram_api::updatesCombined *>(updates_ptr)->updates_.empty();
|
|
|
|
case telegram_api::updates::ID:
|
|
|
|
return static_cast<const telegram_api::updates *>(updates_ptr)->updates_.empty();
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-11 19:38:48 +01:00
|
|
|
FlatHashSet<int64> UpdatesManager::get_sent_messages_random_ids(const telegram_api::Updates *updates_ptr) {
|
|
|
|
FlatHashSet<int64> random_ids;
|
2019-02-14 19:44:20 +01:00
|
|
|
auto updates = get_updates(updates_ptr);
|
|
|
|
if (updates != nullptr) {
|
2022-12-01 21:44:58 +01:00
|
|
|
auto new_messages = get_new_messages(updates_ptr);
|
2019-02-14 19:44:20 +01:00
|
|
|
for (auto &update : *updates) {
|
|
|
|
if (update->get_id() == telegram_api::updateMessageID::ID) {
|
2022-12-02 10:36:31 +01:00
|
|
|
auto update_message_id = static_cast<const telegram_api::updateMessageID *>(update.get());
|
|
|
|
int64 random_id = update_message_id->random_id_;
|
2022-12-01 21:44:58 +01:00
|
|
|
if (random_id != 0) {
|
2022-12-02 10:36:31 +01:00
|
|
|
bool found_message = false;
|
|
|
|
for (auto message : new_messages) {
|
2022-12-12 19:43:49 +01:00
|
|
|
MessageId message_id = MessageId::get_message_id(message.first, message.second);
|
2022-12-02 10:36:31 +01:00
|
|
|
if (message.second) {
|
|
|
|
found_message |= message_id.is_valid_scheduled() &&
|
|
|
|
message_id.get_scheduled_server_message_id().get() == update_message_id->id_;
|
|
|
|
} else {
|
|
|
|
found_message |=
|
|
|
|
message_id.is_valid() && message_id.get_server_message_id().get() == update_message_id->id_;
|
|
|
|
}
|
|
|
|
}
|
2022-12-01 21:44:58 +01:00
|
|
|
if (found_message && !random_ids.insert(random_id).second) {
|
|
|
|
LOG(ERROR) << "Receive twice updateMessageID for " << random_id;
|
|
|
|
}
|
2019-02-14 19:44:20 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return random_ids;
|
|
|
|
}
|
|
|
|
|
2022-10-25 15:10:15 +02:00
|
|
|
const telegram_api::Message *UpdatesManager::get_message_by_random_id(const telegram_api::Updates *updates_ptr,
|
|
|
|
DialogId dialog_id, int64 random_id) {
|
|
|
|
auto updates = get_updates(updates_ptr);
|
|
|
|
if (updates == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 message_id = 0;
|
|
|
|
for (auto &update : *updates) {
|
|
|
|
if (update->get_id() == telegram_api::updateMessageID::ID) {
|
|
|
|
auto update_message_id = static_cast<const telegram_api::updateMessageID *>(update.get());
|
|
|
|
if (update_message_id->random_id_ == random_id) {
|
|
|
|
if (message_id != 0 || update_message_id->id_ == 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
message_id = update_message_id->id_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (message_id == 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const telegram_api::Message *result = nullptr;
|
2023-09-21 18:11:17 +02:00
|
|
|
MessageFullId message_full_id(dialog_id, MessageId(ServerMessageId(message_id)));
|
2022-10-25 15:10:15 +02:00
|
|
|
for (auto &update : *updates) {
|
|
|
|
auto constructor_id = update->get_id();
|
|
|
|
const tl_object_ptr<telegram_api::Message> *message = nullptr;
|
|
|
|
if (constructor_id == telegram_api::updateNewMessage::ID) {
|
|
|
|
message = &static_cast<const telegram_api::updateNewMessage *>(update.get())->message_;
|
|
|
|
} else if (constructor_id == telegram_api::updateNewChannelMessage::ID) {
|
|
|
|
message = &static_cast<const telegram_api::updateNewChannelMessage *>(update.get())->message_;
|
|
|
|
}
|
2023-09-21 18:11:17 +02:00
|
|
|
if (message != nullptr && MessageFullId::get_message_full_id(*message, false) == message_full_id) {
|
2022-10-25 15:10:15 +02:00
|
|
|
if (result != nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
result = message->get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-12-01 21:44:58 +01:00
|
|
|
bool UpdatesManager::is_additional_service_message(const telegram_api::Message *message) {
|
|
|
|
if (message->get_id() != telegram_api::messageService::ID) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto action_id = static_cast<const telegram_api::messageService *>(message)->action_->get_id();
|
|
|
|
return action_id == telegram_api::messageActionSetMessagesTTL::ID;
|
|
|
|
}
|
|
|
|
|
2022-12-02 10:11:07 +01:00
|
|
|
vector<std::pair<const telegram_api::Message *, bool>> UpdatesManager::get_new_messages(
|
2018-12-31 20:04:05 +01:00
|
|
|
const telegram_api::Updates *updates_ptr) {
|
2022-12-02 10:11:07 +01:00
|
|
|
vector<std::pair<const telegram_api::Message *, bool>> messages;
|
2019-02-14 19:44:20 +01:00
|
|
|
auto updates = get_updates(updates_ptr);
|
|
|
|
if (updates != nullptr) {
|
|
|
|
for (auto &update : *updates) {
|
2022-12-02 10:11:07 +01:00
|
|
|
const telegram_api::Message *message = nullptr;
|
|
|
|
bool is_scheduled = false;
|
2019-02-14 19:44:20 +01:00
|
|
|
auto constructor_id = update->get_id();
|
|
|
|
if (constructor_id == telegram_api::updateNewMessage::ID) {
|
2022-12-02 10:11:07 +01:00
|
|
|
message = static_cast<const telegram_api::updateNewMessage *>(update.get())->message_.get();
|
2019-02-14 19:44:20 +01:00
|
|
|
} else if (constructor_id == telegram_api::updateNewChannelMessage::ID) {
|
2022-12-02 10:11:07 +01:00
|
|
|
message = static_cast<const telegram_api::updateNewChannelMessage *>(update.get())->message_.get();
|
2019-12-05 18:34:19 +01:00
|
|
|
} else if (constructor_id == telegram_api::updateNewScheduledMessage::ID) {
|
2022-12-02 10:11:07 +01:00
|
|
|
message = static_cast<const telegram_api::updateNewScheduledMessage *>(update.get())->message_.get();
|
|
|
|
is_scheduled = true;
|
2022-12-01 21:44:58 +01:00
|
|
|
}
|
|
|
|
|
2022-12-02 10:36:31 +01:00
|
|
|
if (message != nullptr && !is_additional_service_message(message)) {
|
2022-12-02 10:11:07 +01:00
|
|
|
messages.emplace_back(message, is_scheduled);
|
2019-02-14 19:44:20 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-14 19:44:20 +01:00
|
|
|
return messages;
|
|
|
|
}
|
|
|
|
|
2020-11-26 08:56:13 +01:00
|
|
|
vector<InputGroupCallId> UpdatesManager::get_update_new_group_call_ids(const telegram_api::Updates *updates_ptr) {
|
2020-12-03 17:52:50 +01:00
|
|
|
vector<InputGroupCallId> input_group_call_ids;
|
2020-11-26 08:56:13 +01:00
|
|
|
auto updates = get_updates(updates_ptr);
|
|
|
|
if (updates != nullptr) {
|
|
|
|
for (auto &update : *updates) {
|
2020-12-03 17:52:50 +01:00
|
|
|
InputGroupCallId input_group_call_id;
|
2020-11-26 08:56:13 +01:00
|
|
|
if (update->get_id() == telegram_api::updateGroupCall::ID) {
|
|
|
|
auto group_call_ptr = static_cast<const telegram_api::updateGroupCall *>(update.get())->call_.get();
|
|
|
|
if (group_call_ptr->get_id() == telegram_api::groupCall::ID) {
|
|
|
|
auto group_call = static_cast<const telegram_api::groupCall *>(group_call_ptr);
|
2020-12-03 17:52:50 +01:00
|
|
|
input_group_call_id = InputGroupCallId(group_call->id_, group_call->access_hash_);
|
2020-11-26 08:56:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 17:52:50 +01:00
|
|
|
if (input_group_call_id.is_valid()) {
|
|
|
|
input_group_call_ids.push_back(input_group_call_id);
|
2020-11-26 08:56:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-03 17:52:50 +01:00
|
|
|
return input_group_call_ids;
|
2020-11-26 08:56:13 +01:00
|
|
|
}
|
|
|
|
|
2021-04-30 18:53:39 +02:00
|
|
|
string UpdatesManager::extract_join_group_call_presentation_params(telegram_api::Updates *updates_ptr) {
|
|
|
|
auto updates = get_updates(updates_ptr);
|
|
|
|
for (auto it = updates->begin(); it != updates->end(); ++it) {
|
|
|
|
auto *update = it->get();
|
|
|
|
if (update->get_id() == telegram_api::updateGroupCallConnection::ID &&
|
|
|
|
static_cast<const telegram_api::updateGroupCallConnection *>(update)->presentation_) {
|
|
|
|
string result = std::move(static_cast<telegram_api::updateGroupCallConnection *>(update)->params_->data_);
|
|
|
|
updates->erase(it);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
2019-02-14 19:44:20 +01:00
|
|
|
vector<DialogId> UpdatesManager::get_update_notify_settings_dialog_ids(const telegram_api::Updates *updates_ptr) {
|
|
|
|
vector<DialogId> dialog_ids;
|
|
|
|
auto updates = get_updates(updates_ptr);
|
|
|
|
if (updates != nullptr) {
|
|
|
|
dialog_ids.reserve(updates->size());
|
|
|
|
for (auto &update : *updates) {
|
|
|
|
DialogId dialog_id;
|
|
|
|
if (update->get_id() == telegram_api::updateNotifySettings::ID) {
|
|
|
|
auto notify_peer = static_cast<const telegram_api::updateNotifySettings *>(update.get())->peer_.get();
|
|
|
|
if (notify_peer->get_id() == telegram_api::notifyPeer::ID) {
|
|
|
|
dialog_id = DialogId(static_cast<const telegram_api::notifyPeer *>(notify_peer)->peer_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog_id.is_valid()) {
|
|
|
|
dialog_ids.push_back(dialog_id);
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected " << to_string(update);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-14 19:44:20 +01:00
|
|
|
return dialog_ids;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-08-02 20:12:05 +02:00
|
|
|
vector<int32> UpdatesManager::get_update_ids(const telegram_api::Updates *updates_ptr) {
|
|
|
|
const vector<tl_object_ptr<telegram_api::Update>> *updates = nullptr;
|
|
|
|
auto updates_type = updates_ptr->get_id();
|
|
|
|
switch (updates_type) {
|
|
|
|
case telegram_api::updatesTooLong::ID:
|
|
|
|
case telegram_api::updateShortMessage::ID:
|
|
|
|
case telegram_api::updateShortChatMessage::ID:
|
|
|
|
case telegram_api::updateShortSentMessage::ID:
|
|
|
|
return {updates_type};
|
2023-03-06 19:01:00 +01:00
|
|
|
case telegram_api::updateShort::ID: {
|
|
|
|
const auto *update = static_cast<const telegram_api::updateShort *>(updates_ptr)->update_.get();
|
|
|
|
if (update != nullptr) {
|
|
|
|
return {update->get_id()};
|
|
|
|
}
|
|
|
|
return {updates_type};
|
|
|
|
}
|
2022-08-02 20:12:05 +02:00
|
|
|
case telegram_api::updatesCombined::ID:
|
|
|
|
updates = &static_cast<const telegram_api::updatesCombined *>(updates_ptr)->updates_;
|
|
|
|
break;
|
|
|
|
case telegram_api::updates::ID:
|
|
|
|
updates = &static_cast<const telegram_api::updates *>(updates_ptr)->updates_;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2023-03-06 19:01:00 +01:00
|
|
|
vector<int32> result;
|
|
|
|
result.reserve(updates->size());
|
|
|
|
for (auto &update : *updates) {
|
|
|
|
if (update != nullptr) {
|
|
|
|
result.push_back(update->get_id());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2022-08-02 20:12:05 +02:00
|
|
|
}
|
|
|
|
|
2019-02-14 19:44:20 +01:00
|
|
|
vector<DialogId> UpdatesManager::get_chat_dialog_ids(const telegram_api::Updates *updates_ptr) {
|
2018-02-28 23:08:45 +01:00
|
|
|
const vector<tl_object_ptr<telegram_api::Chat>> *chats = nullptr;
|
|
|
|
switch (updates_ptr->get_id()) {
|
|
|
|
case telegram_api::updatesTooLong::ID:
|
|
|
|
case telegram_api::updateShortMessage::ID:
|
|
|
|
case telegram_api::updateShortChatMessage::ID:
|
|
|
|
case telegram_api::updateShort::ID:
|
|
|
|
case telegram_api::updateShortSentMessage::ID:
|
|
|
|
LOG(ERROR) << "Receive " << oneline(to_string(*updates_ptr)) << " instead of updates";
|
|
|
|
break;
|
2022-08-02 20:12:05 +02:00
|
|
|
case telegram_api::updatesCombined::ID:
|
2018-02-28 23:08:45 +01:00
|
|
|
chats = &static_cast<const telegram_api::updatesCombined *>(updates_ptr)->chats_;
|
|
|
|
break;
|
2022-08-02 20:12:05 +02:00
|
|
|
case telegram_api::updates::ID:
|
2018-02-28 23:08:45 +01:00
|
|
|
chats = &static_cast<const telegram_api::updates *>(updates_ptr)->chats_;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chats == nullptr) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<DialogId> dialog_ids;
|
|
|
|
dialog_ids.reserve(chats->size());
|
|
|
|
for (const auto &chat : *chats) {
|
2024-04-02 12:06:22 +02:00
|
|
|
auto dialog_id = ChatManager::get_dialog_id(chat);
|
2022-04-30 20:13:01 +02:00
|
|
|
if (dialog_id.is_valid()) {
|
|
|
|
dialog_ids.push_back(dialog_id);
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Can't find identifier of " << oneline(to_string(chat));
|
2018-02-28 23:08:45 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-17 00:34:13 +02:00
|
|
|
if (dialog_ids.size() > 1) {
|
2024-04-02 12:06:22 +02:00
|
|
|
td::remove(dialog_ids, DialogId(ChatManager::get_unsupported_channel_id()));
|
2023-09-17 00:34:13 +02:00
|
|
|
}
|
2018-02-28 23:08:45 +01:00
|
|
|
return dialog_ids;
|
|
|
|
}
|
|
|
|
|
2022-02-16 19:18:36 +01:00
|
|
|
int32 UpdatesManager::get_update_edit_message_pts(const telegram_api::Updates *updates_ptr,
|
2023-09-21 18:11:17 +02:00
|
|
|
MessageFullId message_full_id) {
|
2020-12-25 14:12:09 +01:00
|
|
|
int32 pts = 0;
|
|
|
|
auto updates = get_updates(updates_ptr);
|
|
|
|
if (updates != nullptr) {
|
2022-05-18 20:11:28 +02:00
|
|
|
for (auto &update_ptr : *updates) {
|
2020-12-25 14:12:09 +01:00
|
|
|
int32 update_pts = [&] {
|
2022-05-18 20:11:28 +02:00
|
|
|
switch (update_ptr->get_id()) {
|
2022-02-16 19:18:36 +01:00
|
|
|
case telegram_api::updateEditMessage::ID: {
|
2022-05-18 20:11:28 +02:00
|
|
|
auto update = static_cast<const telegram_api::updateEditMessage *>(update_ptr.get());
|
2023-09-21 18:11:17 +02:00
|
|
|
if (MessageFullId::get_message_full_id(update->message_, false) == message_full_id) {
|
2022-05-18 20:11:28 +02:00
|
|
|
return update->pts_;
|
2022-02-16 19:18:36 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case telegram_api::updateEditChannelMessage::ID: {
|
2022-05-18 20:11:28 +02:00
|
|
|
auto update = static_cast<const telegram_api::updateEditChannelMessage *>(update_ptr.get());
|
2023-09-21 18:11:17 +02:00
|
|
|
if (MessageFullId::get_message_full_id(update->message_, false) == message_full_id) {
|
2022-05-18 20:11:28 +02:00
|
|
|
return update->pts_;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case telegram_api::updateNewScheduledMessage::ID: {
|
|
|
|
auto update = static_cast<const telegram_api::updateNewScheduledMessage *>(update_ptr.get());
|
2023-09-21 18:11:17 +02:00
|
|
|
auto new_message_full_id = MessageFullId::get_message_full_id(update->message_, true);
|
|
|
|
if (new_message_full_id.get_dialog_id() == message_full_id.get_dialog_id()) {
|
|
|
|
auto new_message_id = new_message_full_id.get_message_id();
|
|
|
|
auto old_message_id = message_full_id.get_message_id();
|
2022-05-18 20:11:28 +02:00
|
|
|
if (new_message_id.is_valid_scheduled() && new_message_id.is_scheduled_server() &&
|
|
|
|
old_message_id.is_valid_scheduled() && old_message_id.is_scheduled_server() &&
|
|
|
|
old_message_id.get_scheduled_server_message_id() ==
|
|
|
|
new_message_id.get_scheduled_server_message_id()) {
|
|
|
|
return -2;
|
|
|
|
}
|
2022-02-16 19:18:36 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2020-12-25 14:12:09 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
if (update_pts != 0) {
|
|
|
|
if (pts == 0) {
|
|
|
|
pts = update_pts;
|
|
|
|
} else {
|
|
|
|
pts = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pts == -1) {
|
|
|
|
LOG(ERROR) << "Receive multiple edit message updates in " << to_string(*updates_ptr);
|
|
|
|
pts = 0;
|
2022-02-16 19:21:37 +01:00
|
|
|
} else if (pts == 0) {
|
2023-09-21 18:11:17 +02:00
|
|
|
LOG(ERROR) << "Receive no edit message updates for " << message_full_id << " in " << to_string(*updates_ptr);
|
2020-12-25 14:12:09 +01:00
|
|
|
}
|
|
|
|
return pts;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void UpdatesManager::init_state() {
|
2021-06-27 05:02:58 +02:00
|
|
|
if (G()->close_flag() || !td_->auth_manager_->is_authorized()) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-11 14:23:35 +02:00
|
|
|
bool drop_state = get_pts() == -1 && td_->can_ignore_background_updates() && td_->auth_manager_->is_bot() &&
|
2023-01-29 23:29:33 +01:00
|
|
|
td_->option_manager_->get_option_integer("since_last_open") >= 2 * 86400;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
auto pmc = G()->td_db()->get_binlog_pmc();
|
2023-03-13 19:13:59 +01:00
|
|
|
if (td_->ignore_background_updates() || drop_state) {
|
2019-04-21 20:17:11 +02:00
|
|
|
// just in case
|
|
|
|
pmc->erase("updates.pts");
|
|
|
|
pmc->erase("updates.qts");
|
|
|
|
pmc->erase("updates.date");
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
string pts_str = pmc->get("updates.pts");
|
|
|
|
if (pts_str.empty()) {
|
|
|
|
if (!running_get_difference_) {
|
|
|
|
running_get_difference_ = true;
|
2018-12-04 13:50:57 +01:00
|
|
|
|
|
|
|
before_get_difference(true);
|
|
|
|
|
2021-01-16 00:55:47 +01:00
|
|
|
auto promise = PromiseCreator::lambda([](Result<tl_object_ptr<telegram_api::updates_state>> result) {
|
|
|
|
if (result.is_ok()) {
|
|
|
|
send_closure(G()->updates_manager(), &UpdatesManager::on_get_updates_state, result.move_as_ok(),
|
|
|
|
"GetUpdatesStateQuery");
|
|
|
|
} else {
|
|
|
|
send_closure(G()->updates_manager(), &UpdatesManager::on_failed_get_updates_state, result.move_as_error());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
td_->create_handler<GetUpdatesStateQuery>(std::move(promise))->send();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pts_manager_.init(to_integer<int32>(pts_str));
|
2023-04-25 15:51:08 +02:00
|
|
|
last_confirmed_pts_ = get_pts();
|
2020-08-02 21:07:22 +02:00
|
|
|
qts_manager_.init(to_integer<int32>(pmc->get("updates.qts")));
|
2023-04-25 15:51:08 +02:00
|
|
|
last_confirmed_qts_ = get_qts();
|
2018-12-31 20:04:05 +01:00
|
|
|
date_ = to_integer<int32>(pmc->get("updates.date"));
|
|
|
|
date_source_ = "database";
|
2020-08-02 21:07:22 +02:00
|
|
|
LOG(DEBUG) << "Init: " << get_pts() << " " << get_qts() << " " << date_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
get_difference("init_state");
|
|
|
|
}
|
|
|
|
|
2023-01-25 15:48:04 +01:00
|
|
|
uint64 UpdatesManager::get_most_unused_auth_key_id() {
|
|
|
|
uint64 min_auth_key_id = 0;
|
|
|
|
double min_time = Time::now();
|
|
|
|
for (auto &it : session_infos_) {
|
|
|
|
if (it.second.last_update_time < min_time) {
|
|
|
|
min_time = it.second.last_update_time;
|
|
|
|
min_auth_key_id = it.first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return min_auth_key_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update_from_auth_key_id(uint64 auth_key_id) {
|
|
|
|
if (auth_key_id == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &info = session_infos_[auth_key_id];
|
|
|
|
auto now = Time::now();
|
|
|
|
info.last_update_time = now;
|
|
|
|
if (info.update_count++ == 0) {
|
|
|
|
info.first_update_time = now;
|
|
|
|
while (session_infos_.size() >
|
|
|
|
static_cast<size_t>(max(narrow_cast<int32>(G()->get_option_integer("session_count")), 1))) {
|
|
|
|
auto unused_auth_key_id = get_most_unused_auth_key_id();
|
|
|
|
LOG(INFO) << "Delete statistics for auth key " << unused_auth_key_id;
|
|
|
|
session_infos_.erase(unused_auth_key_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-11 19:33:32 +01:00
|
|
|
void UpdatesManager::ping_server() {
|
2023-01-03 13:32:10 +01:00
|
|
|
if (is_ping_sent_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
is_ping_sent_ = true;
|
2021-01-16 00:59:03 +01:00
|
|
|
auto promise = PromiseCreator::lambda([](Result<tl_object_ptr<telegram_api::updates_state>> result) {
|
|
|
|
auto state = result.is_ok() ? result.move_as_ok() : nullptr;
|
|
|
|
send_closure(G()->updates_manager(), &UpdatesManager::on_server_pong, std::move(state));
|
|
|
|
});
|
|
|
|
td_->create_handler<PingServerQuery>(std::move(promise))->send();
|
2018-02-11 19:33:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_server_pong(tl_object_ptr<telegram_api::updates_state> &&state) {
|
|
|
|
LOG(INFO) << "Receive " << oneline(to_string(state));
|
2023-01-03 13:32:10 +01:00
|
|
|
is_ping_sent_ = false;
|
2018-02-11 19:33:32 +01:00
|
|
|
if (state == nullptr || state->pts_ > get_pts() || state->seq_ > seq_) {
|
|
|
|
get_difference("on server pong");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-08 19:18:48 +02:00
|
|
|
void UpdatesManager::notify_speed_limited(bool is_upload) {
|
|
|
|
if (Time::now() < next_notify_speed_limited_[is_upload]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
next_notify_speed_limited_[is_upload] =
|
2024-04-21 01:58:20 +02:00
|
|
|
Time::now() +
|
|
|
|
static_cast<double>(td_->option_manager_->get_option_integer("upload_premium_speedup_notify_period"));
|
2024-04-08 19:18:48 +02:00
|
|
|
send_closure(G()->td(), &Td::send_update, td_api::make_object<td_api::updateSpeedLimitNotification>(is_upload));
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void UpdatesManager::process_get_difference_updates(
|
|
|
|
vector<tl_object_ptr<telegram_api::Message>> &&new_messages,
|
2020-08-03 15:57:30 +02:00
|
|
|
vector<tl_object_ptr<telegram_api::EncryptedMessage>> &&new_encrypted_messages,
|
2018-12-31 20:04:05 +01:00
|
|
|
vector<tl_object_ptr<telegram_api::Update>> &&other_updates) {
|
2018-11-15 18:25:54 +01:00
|
|
|
VLOG(get_difference) << "In get difference receive " << new_messages.size() << " messages, "
|
|
|
|
<< new_encrypted_messages.size() << " encrypted messages and " << other_updates.size()
|
|
|
|
<< " other updates";
|
2018-12-31 20:04:05 +01:00
|
|
|
for (auto &update : other_updates) {
|
|
|
|
auto constructor_id = update->get_id();
|
|
|
|
if (constructor_id == telegram_api::updateMessageID::ID) {
|
2019-12-05 18:34:19 +01:00
|
|
|
// in getDifference updateMessageID can't be received for scheduled messages
|
2021-01-15 16:52:41 +01:00
|
|
|
LOG(INFO) << "Receive update about sent message " << to_string(update);
|
|
|
|
auto update_message_id = move_tl_object_as<telegram_api::updateMessageID>(update);
|
|
|
|
td_->messages_manager_->on_update_message_id(update_message_id->random_id_,
|
|
|
|
MessageId(ServerMessageId(update_message_id->id_)), "getDifference");
|
2018-12-31 20:04:05 +01:00
|
|
|
CHECK(!running_get_difference_);
|
|
|
|
}
|
|
|
|
|
2023-08-11 13:07:13 +02:00
|
|
|
if (constructor_id == telegram_api::updateStoryID::ID) {
|
|
|
|
LOG(INFO) << "Receive update about sent story " << to_string(update);
|
|
|
|
auto update_story_id = move_tl_object_as<telegram_api::updateStoryID>(update);
|
|
|
|
td_->story_manager_->on_update_story_id(update_story_id->random_id_, StoryId(update_story_id->id_),
|
|
|
|
"getDifference");
|
|
|
|
CHECK(!running_get_difference_);
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
if (constructor_id == telegram_api::updateEncryption::ID) {
|
2021-01-15 17:32:16 +01:00
|
|
|
on_update(move_tl_object_as<telegram_api::updateEncryption>(update), Promise<Unit>());
|
2018-12-31 20:04:05 +01:00
|
|
|
CHECK(!running_get_difference_);
|
|
|
|
}
|
|
|
|
|
2019-09-15 03:59:22 +02:00
|
|
|
if (constructor_id == telegram_api::updateFolderPeers::ID) {
|
2021-01-11 23:46:13 +01:00
|
|
|
auto update_folder_peers = move_tl_object_as<telegram_api::updateFolderPeers>(update);
|
|
|
|
if (update_folder_peers->pts_count_ != 0) {
|
|
|
|
LOG(ERROR) << "Receive updateFolderPeers with pts_count = " << update_folder_peers->pts_count_;
|
2021-01-15 16:45:26 +01:00
|
|
|
update_folder_peers->pts_count_ = 0;
|
2021-01-11 23:46:13 +01:00
|
|
|
}
|
|
|
|
update_folder_peers->pts_ = 0;
|
2021-01-15 17:32:16 +01:00
|
|
|
on_update(std::move(update_folder_peers), Promise<Unit>());
|
2019-09-15 03:59:22 +02:00
|
|
|
CHECK(!running_get_difference_);
|
|
|
|
}
|
|
|
|
|
2022-12-26 11:23:05 +01:00
|
|
|
if (constructor_id == telegram_api::updateUser::ID) {
|
|
|
|
update = nullptr;
|
|
|
|
}
|
|
|
|
|
2021-01-20 13:14:16 +01:00
|
|
|
if (constructor_id == telegram_api::updateChat::ID) {
|
|
|
|
update = nullptr;
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
if (constructor_id == telegram_api::updateChannel::ID) {
|
|
|
|
update = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
/*
|
|
|
|
// TODO can't apply it here, because dialog may not be created yet
|
|
|
|
// process updateReadHistoryInbox before new messages
|
|
|
|
if (constructor_id == telegram_api::updateReadHistoryInbox::ID) {
|
2021-01-15 16:45:26 +01:00
|
|
|
static_cast<telegram_api::updateReadHistoryInbox *>(update.get())->still_unread_count_ = -1;
|
2021-01-15 23:17:35 +01:00
|
|
|
process_pts_update(std::move(update));
|
2018-12-31 20:04:05 +01:00
|
|
|
CHECK(!running_get_difference_);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &message : new_messages) {
|
|
|
|
// channel messages must not be received in this vector
|
2023-05-11 19:27:00 +02:00
|
|
|
td_->messages_manager_->on_get_message(std::move(message), true, false, false, "get difference");
|
2018-12-31 20:04:05 +01:00
|
|
|
CHECK(!running_get_difference_);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &encrypted_message : new_encrypted_messages) {
|
2020-08-02 21:07:22 +02:00
|
|
|
send_closure(td_->secret_chats_manager_, &SecretChatsManager::on_new_message, std::move(encrypted_message),
|
|
|
|
Promise<Unit>());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2020-12-21 20:06:52 +01:00
|
|
|
process_updates(std::move(other_updates), true, Promise<Unit>());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_get_difference(tl_object_ptr<telegram_api::updates_Difference> &&difference_ptr) {
|
2023-08-16 23:32:29 +02:00
|
|
|
if (G()->close_flag() || !td_->auth_manager_->is_authorized()) {
|
2021-01-05 14:06:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-01 15:22:01 +02:00
|
|
|
VLOG(get_difference) << "----- END GET DIFFERENCE-----";
|
|
|
|
running_get_difference_ = false;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
LOG(DEBUG) << "Result of get difference: " << to_string(difference_ptr);
|
|
|
|
|
2021-01-16 00:44:58 +01:00
|
|
|
CHECK(difference_ptr != nullptr);
|
2018-12-31 20:04:05 +01:00
|
|
|
switch (difference_ptr->get_id()) {
|
|
|
|
case telegram_api::updates_differenceEmpty::ID: {
|
|
|
|
auto difference = move_tl_object_as<telegram_api::updates_differenceEmpty>(difference_ptr);
|
|
|
|
set_date(difference->date_, false, "on_get_difference_empty");
|
|
|
|
seq_ = difference->seq_;
|
2020-12-22 23:58:56 +01:00
|
|
|
|
2021-08-20 16:21:31 +02:00
|
|
|
process_pending_qts_updates();
|
2020-09-30 20:42:32 +02:00
|
|
|
if (!pending_qts_updates_.empty()) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(WARNING) << "Drop " << pending_qts_updates_.size() << " pending QTS updates after receive empty difference";
|
2020-12-22 23:58:56 +01:00
|
|
|
auto pending_qts_updates = std::move(pending_qts_updates_);
|
2020-10-31 10:01:13 +01:00
|
|
|
pending_qts_updates_.clear();
|
2020-12-22 23:58:56 +01:00
|
|
|
|
|
|
|
for (auto &pending_update : pending_qts_updates) {
|
2022-04-13 16:40:12 +02:00
|
|
|
set_promises(pending_update.second.promises);
|
2020-12-22 23:58:56 +01:00
|
|
|
}
|
2020-09-30 20:42:32 +02:00
|
|
|
}
|
2021-08-20 16:21:31 +02:00
|
|
|
|
|
|
|
process_pending_seq_updates();
|
|
|
|
if (!pending_seq_updates_.empty()) {
|
|
|
|
LOG(WARNING) << "Drop " << pending_seq_updates_.size() << " pending seq updates after receive empty difference";
|
|
|
|
auto pending_seq_updates = std::move(pending_seq_updates_);
|
|
|
|
pending_seq_updates_.clear();
|
|
|
|
|
|
|
|
for (auto &pending_update : pending_seq_updates) {
|
2024-01-26 12:59:07 +01:00
|
|
|
pending_update.promise.set_value(Unit());
|
2021-08-20 16:21:31 +02:00
|
|
|
}
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updates_difference::ID: {
|
|
|
|
auto difference = move_tl_object_as<telegram_api::updates_difference>(difference_ptr);
|
2018-11-21 15:14:35 +01:00
|
|
|
VLOG(get_difference) << "In get difference receive " << difference->users_.size() << " users and "
|
|
|
|
<< difference->chats_.size() << " chats";
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_get_users(std::move(difference->users_), "updates.difference");
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->on_get_chats(std::move(difference->chats_), "updates.difference");
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2023-07-24 18:42:09 +02:00
|
|
|
if (get_difference_retry_count_ <= 5) {
|
|
|
|
for (const auto &message : difference->new_messages_) {
|
|
|
|
if (MessagesManager::is_invalid_poll_message(message.get())) {
|
|
|
|
get_difference_retry_count_++;
|
|
|
|
LOG(ERROR) << "Receive invalid poll message in updates.difference after " << get_difference_retry_count_
|
|
|
|
<< " tries";
|
|
|
|
return run_get_difference(true, "reget difference");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
process_get_difference_updates(std::move(difference->new_messages_),
|
2020-08-03 15:57:30 +02:00
|
|
|
std::move(difference->new_encrypted_messages_),
|
2018-12-31 20:04:05 +01:00
|
|
|
std::move(difference->other_updates_));
|
|
|
|
if (running_get_difference_) {
|
|
|
|
LOG(ERROR) << "Get difference has run while processing get difference updates";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
on_get_updates_state(std::move(difference->state_), "get difference");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updates_differenceSlice::ID: {
|
|
|
|
auto difference = move_tl_object_as<telegram_api::updates_differenceSlice>(difference_ptr);
|
2021-01-05 14:06:51 +01:00
|
|
|
bool is_pts_changed = have_update_pts_changed(difference->other_updates_);
|
2018-11-21 15:14:35 +01:00
|
|
|
if (difference->intermediate_state_->pts_ >= get_pts() && get_pts() != std::numeric_limits<int32>::max() &&
|
2021-01-05 14:06:51 +01:00
|
|
|
difference->intermediate_state_->date_ >= date_ && difference->intermediate_state_->qts_ == get_qts() &&
|
|
|
|
!is_pts_changed) {
|
2018-11-21 15:14:35 +01:00
|
|
|
// TODO send new getDifference request and apply difference slice only after that
|
|
|
|
}
|
|
|
|
|
|
|
|
VLOG(get_difference) << "In get difference receive " << difference->users_.size() << " users and "
|
|
|
|
<< difference->chats_.size() << " chats";
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_get_users(std::move(difference->users_), "updates.differenceSlice");
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->on_get_chats(std::move(difference->chats_), "updates.differenceSlice");
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2023-07-24 18:42:09 +02:00
|
|
|
if (get_difference_retry_count_ <= 5) {
|
|
|
|
for (const auto &message : difference->new_messages_) {
|
|
|
|
if (MessagesManager::is_invalid_poll_message(message.get())) {
|
|
|
|
get_difference_retry_count_++;
|
|
|
|
LOG(ERROR) << "Receive invalid poll message in updates.differenceSlice after "
|
|
|
|
<< get_difference_retry_count_ << " tries";
|
|
|
|
return run_get_difference(true, "reget difference");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
process_get_difference_updates(std::move(difference->new_messages_),
|
|
|
|
std::move(difference->new_encrypted_messages_),
|
2020-08-03 15:57:30 +02:00
|
|
|
std::move(difference->other_updates_));
|
2018-12-31 20:04:05 +01:00
|
|
|
if (running_get_difference_) {
|
2021-01-05 14:06:51 +01:00
|
|
|
if (!is_pts_changed) {
|
|
|
|
LOG(ERROR) << "Get difference has run while processing get difference updates";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CHECK(!is_pts_changed);
|
|
|
|
|
2021-08-16 00:00:49 +02:00
|
|
|
auto old_pts = get_pts();
|
|
|
|
auto old_date = get_date();
|
|
|
|
auto old_qts = get_qts();
|
|
|
|
on_get_updates_state(std::move(difference->intermediate_state_), "get difference slice");
|
2021-08-16 12:35:30 +02:00
|
|
|
|
|
|
|
process_postponed_pts_updates();
|
|
|
|
process_pending_qts_updates();
|
|
|
|
|
2021-08-16 00:00:49 +02:00
|
|
|
auto new_pts = get_pts();
|
|
|
|
auto new_date = get_date();
|
|
|
|
auto new_qts = get_qts();
|
|
|
|
if (old_pts != std::numeric_limits<int32>::max() && new_date == old_date &&
|
|
|
|
(new_pts == old_pts || (min_postponed_update_pts_ != 0 && new_pts >= min_postponed_update_pts_)) &&
|
|
|
|
(new_qts == old_qts || (min_postponed_update_qts_ != 0 && new_qts >= min_postponed_update_qts_))) {
|
|
|
|
VLOG(get_difference) << "Switch back from getDifference to update processing";
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-08-16 00:00:49 +02:00
|
|
|
if (new_pts != -1) { // just in case
|
2021-01-05 14:06:51 +01:00
|
|
|
run_get_difference(true, "on updates_differenceSlice");
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updates_differenceTooLong::ID: {
|
2022-08-18 16:00:18 +02:00
|
|
|
if (td_->option_manager_->get_option_integer("session_count") <= 1) {
|
2022-08-08 18:20:19 +02:00
|
|
|
LOG(ERROR) << "Receive differenceTooLong";
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
// TODO
|
|
|
|
auto difference = move_tl_object_as<telegram_api::updates_differenceTooLong>(difference_ptr);
|
|
|
|
set_pts(difference->pts_, "differenceTooLong").set_value(Unit());
|
|
|
|
get_difference("on updates_differenceTooLong");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2023-07-24 18:42:09 +02:00
|
|
|
get_difference_retry_count_ = 0;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
if (!running_get_difference_) {
|
|
|
|
after_get_difference();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-27 21:01:10 +02:00
|
|
|
void UpdatesManager::on_get_pts_update(int32 pts,
|
|
|
|
telegram_api::object_ptr<telegram_api::updates_Difference> difference_ptr) {
|
2023-08-16 23:32:29 +02:00
|
|
|
if (G()->close_flag() || !td_->auth_manager_->is_authorized()) {
|
2023-04-27 21:01:10 +02:00
|
|
|
return;
|
|
|
|
}
|
2024-01-25 20:02:11 +01:00
|
|
|
LOG(DEBUG) << "Receive update with PTS " << pts << ": " << to_string(difference_ptr);
|
2023-04-27 21:01:10 +02:00
|
|
|
if (get_pts() != pts - 1 || running_get_difference_ || !postponed_pts_updates_.empty() ||
|
2024-01-26 12:59:07 +01:00
|
|
|
pending_pts_updates_.empty() || pending_pts_updates_.begin()->pts > pts + 1 ||
|
|
|
|
pending_pts_updates_.begin()->pts != pts + pending_pts_updates_.begin()->pts_count) {
|
2023-04-27 21:01:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (difference_ptr->get_id()) {
|
2023-04-27 21:47:45 +02:00
|
|
|
case telegram_api::updates_difference::ID: {
|
|
|
|
auto difference = move_tl_object_as<telegram_api::updates_difference>(difference_ptr);
|
|
|
|
difference_ptr = telegram_api::make_object<telegram_api::updates_differenceSlice>(
|
|
|
|
std::move(difference->new_messages_), std::move(difference->new_encrypted_messages_),
|
|
|
|
std::move(difference->other_updates_), std::move(difference->chats_), std::move(difference->users_),
|
|
|
|
std::move(difference->state_));
|
|
|
|
}
|
2023-07-01 18:54:22 +02:00
|
|
|
// fallthrough
|
2023-04-27 21:01:10 +02:00
|
|
|
case telegram_api::updates_differenceSlice::ID: {
|
|
|
|
auto difference = move_tl_object_as<telegram_api::updates_differenceSlice>(difference_ptr);
|
|
|
|
|
|
|
|
if (have_update_pts_changed(difference->other_updates_)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_get_users(std::move(difference->users_), "on_get_pts_update");
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->on_get_chats(std::move(difference->chats_), "on_get_pts_update");
|
2023-04-27 21:01:10 +02:00
|
|
|
|
|
|
|
for (auto &message : difference->new_messages_) {
|
|
|
|
difference->other_updates_.push_back(
|
|
|
|
telegram_api::make_object<telegram_api::updateNewMessage>(std::move(message), pts, 1));
|
|
|
|
}
|
|
|
|
telegram_api::object_ptr<telegram_api::Update> *update_ptr = nullptr;
|
|
|
|
size_t update_count = 0;
|
|
|
|
for (auto &update : difference->other_updates_) {
|
|
|
|
auto constructor_id = update->get_id();
|
|
|
|
if (constructor_id == telegram_api::updateMessageID::ID) {
|
|
|
|
// in getDifference updateMessageID can't be received for scheduled messages
|
|
|
|
LOG(INFO) << "Receive update about sent message " << to_string(update);
|
|
|
|
auto update_message_id = move_tl_object_as<telegram_api::updateMessageID>(update);
|
|
|
|
td_->messages_manager_->on_update_message_id(
|
|
|
|
update_message_id->random_id_, MessageId(ServerMessageId(update_message_id->id_)), "on_get_pts_update");
|
|
|
|
continue;
|
|
|
|
}
|
2024-01-25 20:02:11 +01:00
|
|
|
if (constructor_id == telegram_api::updateDeleteMessages::ID) {
|
|
|
|
auto *update_delete_messages = static_cast<const telegram_api::updateDeleteMessages *>(update.get());
|
|
|
|
if (update_delete_messages->pts_count_ != 0 || update_delete_messages->messages_.size() != 1) {
|
|
|
|
LOG(ERROR) << "Receive in getDifference " << to_string(update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-27 21:01:10 +02:00
|
|
|
update_ptr = &update;
|
|
|
|
update_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!difference->new_encrypted_messages_.empty() || update_count != 1) {
|
2023-11-08 23:46:02 +01:00
|
|
|
LOG(ERROR) << "Receive unexpected updates with PTS " << pts << ": " << to_string(difference);
|
2023-04-27 21:01:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(update_ptr != nullptr);
|
2023-05-09 11:53:48 +02:00
|
|
|
VLOG(get_difference) << "Repair update with PTS " << pts;
|
|
|
|
pts_fixed_short_gap_++;
|
2023-04-27 21:01:10 +02:00
|
|
|
add_pending_pts_update(std::move(*update_ptr), pts, 1, Time::now(), Promise<Unit>(), "on_get_pts_update");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updates_differenceEmpty::ID:
|
|
|
|
case telegram_api::updates_differenceTooLong::ID: {
|
2024-01-28 22:55:37 +01:00
|
|
|
LOG(ERROR) << "Receive " << oneline(to_string(difference_ptr)) << " for request with PTS = " << pts - 1
|
|
|
|
<< ", but have pending " << oneline(to_string(pending_pts_updates_.begin()->update))
|
|
|
|
<< " with PTS = " << pending_pts_updates_.begin()->pts;
|
2023-04-27 21:01:10 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-27 19:21:30 +02:00
|
|
|
void UpdatesManager::confirm_pts_qts(int32 qts) {
|
|
|
|
int32 pts = get_pts();
|
|
|
|
if (pts < 0) {
|
|
|
|
pts = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
td_->create_handler<ConfirmPtsQtsQuery>()->send(pts, qts);
|
|
|
|
|
|
|
|
last_confirmed_pts_ = pts;
|
|
|
|
last_confirmed_qts_ = qts;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void UpdatesManager::after_get_difference() {
|
|
|
|
CHECK(!running_get_difference_);
|
|
|
|
|
|
|
|
retry_timeout_.cancel_timeout();
|
|
|
|
retry_time_ = 1;
|
|
|
|
|
2023-10-14 02:00:54 +02:00
|
|
|
skipped_postponed_updates_after_start_ = 0;
|
2023-01-29 23:29:33 +01:00
|
|
|
td_->option_manager_->set_option_empty("since_last_open");
|
2023-01-29 10:49:25 +01:00
|
|
|
|
2021-08-16 00:30:38 +02:00
|
|
|
// cancels qts_gap_timeout_ if needed, can apply some updates received during getDifference,
|
|
|
|
// but missed in getDifference
|
2020-08-03 16:37:08 +02:00
|
|
|
process_pending_qts_updates();
|
|
|
|
|
2021-08-16 00:30:38 +02:00
|
|
|
// cancels seq_gap_timeout_ if needed, can apply some updates received during getDifference,
|
|
|
|
// but missed in getDifference
|
|
|
|
process_pending_seq_updates();
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
if (running_get_difference_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-15 12:52:00 +02:00
|
|
|
if (!postponed_updates_.empty()) {
|
2022-05-22 21:09:46 +02:00
|
|
|
auto begin_time = Time::now();
|
|
|
|
auto chunk_count = postponed_updates_.size();
|
|
|
|
VLOG(get_difference) << "Begin to apply " << chunk_count << " postponed update chunks";
|
2021-01-05 14:06:51 +01:00
|
|
|
size_t total_update_count = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
while (!postponed_updates_.empty()) {
|
|
|
|
auto it = postponed_updates_.begin();
|
2024-01-26 12:59:07 +01:00
|
|
|
auto updates = std::move(it->updates);
|
|
|
|
auto updates_seq_begin = it->seq_begin;
|
|
|
|
auto updates_seq_end = it->seq_end;
|
|
|
|
auto receive_time = it->receive_time;
|
|
|
|
auto promise = std::move(it->promise);
|
|
|
|
// ignore it->date, because it may be too old
|
2018-12-31 20:04:05 +01:00
|
|
|
postponed_updates_.erase(it);
|
2021-01-05 14:06:51 +01:00
|
|
|
auto update_count = updates.size();
|
2021-08-15 11:46:38 +02:00
|
|
|
on_pending_updates(std::move(updates), updates_seq_begin, updates_seq_end, 0, receive_time, std::move(promise),
|
2020-12-21 20:06:52 +01:00
|
|
|
"postponed updates");
|
2020-02-08 21:31:27 +01:00
|
|
|
if (running_get_difference_) {
|
|
|
|
VLOG(get_difference) << "Finish to apply postponed updates with " << postponed_updates_.size()
|
2021-01-05 14:06:51 +01:00
|
|
|
<< " updates left after applied " << total_update_count
|
|
|
|
<< " updates, because forced to run getDifference";
|
2020-02-08 21:31:27 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-01-05 14:06:51 +01:00
|
|
|
total_update_count += update_count;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2022-05-22 21:09:46 +02:00
|
|
|
VLOG(get_difference) << "Finished to apply " << total_update_count << " postponed updates";
|
|
|
|
auto passed_time = Time::now() - begin_time;
|
2022-11-20 20:41:50 +01:00
|
|
|
if (passed_time >= UPDATE_APPLY_WARNING_TIME) {
|
2022-12-10 23:32:46 +01:00
|
|
|
LOG(WARNING) << "Applied " << total_update_count << " updates in " << chunk_count << " chunks in " << passed_time
|
|
|
|
<< " seconds after postponing them for " << (Time::now() - get_difference_start_time_) << " seconds";
|
2022-05-22 21:09:46 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-08-15 12:52:00 +02:00
|
|
|
if (!postponed_pts_updates_.empty()) { // must be before td_->messages_manager_->after_get_difference()
|
2021-01-15 23:17:35 +01:00
|
|
|
auto postponed_updates = std::move(postponed_pts_updates_);
|
|
|
|
postponed_pts_updates_.clear();
|
|
|
|
|
2022-05-22 21:09:46 +02:00
|
|
|
auto begin_time = Time::now();
|
|
|
|
auto update_count = postponed_updates.size();
|
2024-01-17 14:50:08 +01:00
|
|
|
auto old_pts = get_pts();
|
2021-08-15 21:54:18 +02:00
|
|
|
VLOG(get_difference) << "Begin to apply " << postponed_updates.size()
|
2023-01-15 09:05:53 +01:00
|
|
|
<< " postponed PTS updates with PTS = " << get_pts();
|
2021-01-15 23:17:35 +01:00
|
|
|
for (auto &postponed_update : postponed_updates) {
|
2024-01-26 12:59:07 +01:00
|
|
|
auto &update = postponed_update;
|
2021-08-15 11:46:38 +02:00
|
|
|
add_pending_pts_update(std::move(update.update), update.pts, update.pts_count, update.receive_time,
|
2022-08-08 18:01:50 +02:00
|
|
|
std::move(update.promise), AFTER_GET_DIFFERENCE_SOURCE);
|
2021-01-15 23:17:35 +01:00
|
|
|
CHECK(!running_get_difference_);
|
|
|
|
}
|
2023-01-15 09:05:53 +01:00
|
|
|
VLOG(get_difference) << "After applying postponed PTS updates have PTS = " << get_pts()
|
2021-08-15 23:11:48 +02:00
|
|
|
<< ", max_pts = " << accumulated_pts_ << " and " << pending_pts_updates_.size() << " + "
|
2023-01-15 09:05:53 +01:00
|
|
|
<< postponed_pts_updates_.size() << " pending PTS updates";
|
2022-05-22 21:09:46 +02:00
|
|
|
auto passed_time = Time::now() - begin_time;
|
2022-11-20 20:41:50 +01:00
|
|
|
if (passed_time >= UPDATE_APPLY_WARNING_TIME) {
|
2024-01-17 14:50:08 +01:00
|
|
|
LOG(WARNING) << "Updated PTS from " << old_pts << " to " << get_pts() << " and applied " << update_count
|
|
|
|
<< " PTS updates in " << passed_time << " seconds after postponing them for "
|
|
|
|
<< (Time::now() - get_difference_start_time_) << " seconds";
|
2022-05-22 21:09:46 +02:00
|
|
|
}
|
2021-01-15 23:17:35 +01:00
|
|
|
}
|
|
|
|
|
2022-07-23 15:41:03 +02:00
|
|
|
send_closure(td_->download_manager_actor_, &DownloadManager::after_get_difference);
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->inline_queries_manager_->after_get_difference();
|
|
|
|
td_->messages_manager_->after_get_difference();
|
2018-11-22 02:00:28 +01:00
|
|
|
send_closure_later(td_->notification_manager_actor_, &NotificationManager::after_get_difference);
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(G()->state_manager(), &StateManager::on_synchronized, true);
|
2022-05-22 21:09:46 +02:00
|
|
|
get_difference_start_time_ = 0.0;
|
2022-05-12 15:34:13 +02:00
|
|
|
|
|
|
|
try_reload_data();
|
|
|
|
}
|
|
|
|
|
2022-05-13 12:56:18 +02:00
|
|
|
void UpdatesManager::schedule_data_reload() {
|
|
|
|
if (data_reload_timeout_.has_timeout()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto timeout = next_data_reload_time_ - Time::now();
|
|
|
|
LOG(INFO) << "Schedule data reload in " << timeout;
|
|
|
|
data_reload_timeout_.set_callback(std::move(try_reload_data_static));
|
|
|
|
data_reload_timeout_.set_callback_data(static_cast<void *>(td_));
|
|
|
|
data_reload_timeout_.set_timeout_in(timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::try_reload_data_static(void *td) {
|
|
|
|
if (G()->close_flag()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-10 12:57:41 +02:00
|
|
|
CHECK(td != nullptr);
|
2022-05-13 12:56:18 +02:00
|
|
|
static_cast<Td *>(td)->updates_manager_->try_reload_data();
|
|
|
|
}
|
|
|
|
|
2022-05-12 15:34:13 +02:00
|
|
|
void UpdatesManager::try_reload_data() {
|
2022-05-20 15:59:14 +02:00
|
|
|
if (!td_->auth_manager_->is_authorized() || td_->auth_manager_->is_bot() || running_get_difference_ ||
|
|
|
|
!td_->is_online()) {
|
2022-05-12 15:34:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-13 12:56:18 +02:00
|
|
|
auto now = Time::now();
|
|
|
|
if (now < next_data_reload_time_) {
|
|
|
|
schedule_data_reload();
|
|
|
|
return;
|
|
|
|
}
|
2023-02-06 18:31:17 +01:00
|
|
|
next_data_reload_time_ = now + 365 * 86400;
|
|
|
|
|
|
|
|
auto promise = PromiseCreator::lambda([actor_id = actor_id(this)](Result<td_api::object_ptr<td_api::chats>>) {
|
|
|
|
send_closure(actor_id, &UpdatesManager::on_data_reloaded);
|
|
|
|
});
|
2022-05-13 12:56:18 +02:00
|
|
|
|
|
|
|
LOG(INFO) << "Reload data";
|
2023-02-06 18:31:17 +01:00
|
|
|
td_->animations_manager_->reload_saved_animations(true);
|
2023-02-06 18:10:27 +01:00
|
|
|
td_->autosave_manager_->reload_autosave_settings();
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->reload_created_public_dialogs(PublicDialogType::HasUsername, std::move(promise));
|
|
|
|
td_->chat_manager_->reload_created_public_dialogs(PublicDialogType::IsLocationBased, Auto());
|
|
|
|
td_->chat_manager_->reload_created_public_dialogs(PublicDialogType::ForPersonalDialog, Auto());
|
2022-08-30 17:03:57 +02:00
|
|
|
get_default_emoji_statuses(td_, Auto());
|
2023-12-22 10:29:12 +01:00
|
|
|
get_default_channel_emoji_statuses(td_, Auto());
|
2022-05-12 15:34:13 +02:00
|
|
|
td_->notification_settings_manager_->reload_saved_ringtones(Auto());
|
2022-05-31 16:18:27 +02:00
|
|
|
td_->notification_settings_manager_->send_get_scope_notification_settings_query(NotificationSettingsScope::Private,
|
|
|
|
Auto());
|
|
|
|
td_->notification_settings_manager_->send_get_scope_notification_settings_query(NotificationSettingsScope::Group,
|
|
|
|
Auto());
|
|
|
|
td_->notification_settings_manager_->send_get_scope_notification_settings_query(NotificationSettingsScope::Channel,
|
|
|
|
Auto());
|
2024-02-22 15:32:12 +01:00
|
|
|
td_->quick_reply_manager_->reload_quick_reply_shortcuts();
|
2023-08-09 11:59:48 +02:00
|
|
|
td_->reaction_manager_->reload_reactions();
|
2024-01-18 18:53:43 +01:00
|
|
|
|
|
|
|
for (int32 type = 0; type < MAX_REACTION_LIST_TYPE; type++) {
|
|
|
|
auto reaction_list_type = static_cast<ReactionListType>(type);
|
2024-03-22 13:57:46 +01:00
|
|
|
td_->reaction_manager_->reload_reaction_list(reaction_list_type, "try_reload_data");
|
2024-01-18 18:53:43 +01:00
|
|
|
}
|
|
|
|
|
2022-07-17 21:39:22 +02:00
|
|
|
for (int32 type = 0; type < MAX_STICKER_TYPE; type++) {
|
|
|
|
auto sticker_type = static_cast<StickerType>(type);
|
|
|
|
td_->stickers_manager_->get_installed_sticker_sets(sticker_type, Auto());
|
|
|
|
td_->stickers_manager_->get_featured_sticker_sets(sticker_type, 0, 1000, Auto());
|
|
|
|
}
|
2022-05-12 15:34:13 +02:00
|
|
|
td_->stickers_manager_->get_recent_stickers(false, Auto());
|
|
|
|
td_->stickers_manager_->get_recent_stickers(true, Auto());
|
|
|
|
td_->stickers_manager_->get_favorite_stickers(Auto());
|
|
|
|
td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::animated_emoji());
|
|
|
|
td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::animated_emoji_click());
|
2022-07-15 14:24:08 +02:00
|
|
|
td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::premium_gifts());
|
2022-09-02 12:59:49 +02:00
|
|
|
td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::generic_animations());
|
|
|
|
td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::default_statuses());
|
2023-12-21 20:44:59 +01:00
|
|
|
td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::default_channel_statuses());
|
2022-10-27 09:06:13 +02:00
|
|
|
td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::default_topic_icons());
|
2023-10-19 14:12:26 +02:00
|
|
|
td_->stickers_manager_->get_default_custom_emoji_stickers(StickerListType::DialogPhoto, true, Auto());
|
|
|
|
td_->stickers_manager_->get_default_custom_emoji_stickers(StickerListType::UserProfilePhoto, true, Auto());
|
2023-12-24 00:30:49 +01:00
|
|
|
td_->stickers_manager_->get_default_custom_emoji_stickers(StickerListType::Background, true, Auto());
|
|
|
|
td_->stickers_manager_->get_sticker_list_emoji_statuses(StickerListType::DisallowedChannelEmojiStatus, true, Auto());
|
2023-07-06 17:22:20 +02:00
|
|
|
td_->story_manager_->reload_active_stories();
|
2023-07-07 16:41:30 +02:00
|
|
|
td_->story_manager_->reload_all_read_stories();
|
2023-11-27 14:35:27 +01:00
|
|
|
td_->theme_manager_->reload_accent_colors();
|
2023-11-27 11:34:14 +01:00
|
|
|
td_->theme_manager_->reload_chat_themes();
|
2023-11-27 16:08:45 +01:00
|
|
|
td_->theme_manager_->reload_profile_accent_colors();
|
2024-02-19 20:12:28 +01:00
|
|
|
td_->time_zone_manager_->reload_time_zones(Auto());
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->reload_contact_birthdates(false);
|
2022-05-13 12:56:18 +02:00
|
|
|
|
|
|
|
schedule_data_reload();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2023-02-06 18:31:17 +01:00
|
|
|
void UpdatesManager::on_data_reloaded() {
|
|
|
|
if (G()->close_flag()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
next_data_reload_time_ = Time::now() + Random::fast(3000, 4200);
|
|
|
|
data_reload_timeout_.cancel_timeout();
|
|
|
|
schedule_data_reload();
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void UpdatesManager::on_pending_updates(vector<tl_object_ptr<telegram_api::Update>> &&updates, int32 seq_begin,
|
2021-08-15 11:46:38 +02:00
|
|
|
int32 seq_end, int32 date, double receive_time, Promise<Unit> &&promise,
|
|
|
|
const char *source) {
|
2018-12-31 20:04:05 +01:00
|
|
|
if (get_pts() == -1) {
|
|
|
|
init_state();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!td_->auth_manager_->is_authorized()) {
|
|
|
|
LOG(INFO) << "Ignore updates received before authorization or after logout";
|
2020-12-21 20:06:52 +01:00
|
|
|
return promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// for (auto &update : updates) {
|
|
|
|
// LOG(WARNING) << "Receive update " << to_string(update.get());
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (seq_begin < 0 || seq_end < 0 || date < 0 || seq_end < seq_begin) {
|
|
|
|
LOG(ERROR) << "Wrong updates parameters seq_begin = " << seq_begin << ", seq_end = " << seq_end
|
|
|
|
<< ", date = " << date << " from " << source;
|
|
|
|
get_difference("on wrong updates in on_pending_updates");
|
2020-12-21 20:06:52 +01:00
|
|
|
return promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-08-20 13:18:11 +02:00
|
|
|
for (auto &update : updates) {
|
|
|
|
if (update != nullptr) {
|
|
|
|
switch (update->get_id()) {
|
|
|
|
case telegram_api::updateUserTyping::ID:
|
|
|
|
case telegram_api::updateChatUserTyping::ID:
|
|
|
|
case telegram_api::updateChannelUserTyping::ID:
|
|
|
|
case telegram_api::updateEncryptedChatTyping::ID:
|
|
|
|
case telegram_api::updateLoginToken::ID:
|
|
|
|
case telegram_api::updateDcOptions::ID:
|
|
|
|
case telegram_api::updateConfig::ID:
|
|
|
|
case telegram_api::updateServiceNotification::ID:
|
|
|
|
case telegram_api::updateLangPackTooLong::ID:
|
|
|
|
case telegram_api::updateLangPack::ID:
|
2022-06-23 13:06:06 +02:00
|
|
|
short_update_date_ = date == 0 ? G()->unix_time() : date;
|
2021-08-20 13:18:11 +02:00
|
|
|
LOG(INFO) << "Process short " << oneline(to_string(update));
|
|
|
|
// don't need promise for short update
|
|
|
|
downcast_call(*update, OnUpdate(this, update, Promise<Unit>()));
|
|
|
|
short_update_date_ = 0;
|
|
|
|
update = nullptr;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool need_postpone = running_get_difference_ /*|| string(source) != string("postponed updates")*/;
|
2023-01-29 10:49:25 +01:00
|
|
|
bool can_postpone = can_postpone_updates();
|
2021-08-20 16:21:31 +02:00
|
|
|
if (!need_postpone) {
|
2021-01-05 14:06:51 +01:00
|
|
|
for (auto &update : updates) {
|
2021-08-20 16:21:31 +02:00
|
|
|
if (!is_acceptable_update(update.get())) {
|
|
|
|
CHECK(update != nullptr);
|
|
|
|
int32 id = update->get_id();
|
|
|
|
const tl_object_ptr<telegram_api::Message> *message_ptr = nullptr;
|
|
|
|
int32 pts = 0;
|
|
|
|
if (id == telegram_api::updateNewChannelMessage::ID) {
|
|
|
|
auto update_new_channel_message = static_cast<const telegram_api::updateNewChannelMessage *>(update.get());
|
|
|
|
message_ptr = &update_new_channel_message->message_;
|
|
|
|
pts = update_new_channel_message->pts_;
|
|
|
|
}
|
|
|
|
if (id == telegram_api::updateEditChannelMessage::ID) {
|
|
|
|
auto update_edit_channel_message = static_cast<const telegram_api::updateEditChannelMessage *>(update.get());
|
|
|
|
message_ptr = &update_edit_channel_message->message_;
|
|
|
|
pts = update_edit_channel_message->pts_;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-08-20 16:21:31 +02:00
|
|
|
// for channels we can try to replace unacceptable update with updateChannelTooLong
|
|
|
|
if (message_ptr != nullptr) {
|
2022-12-12 19:43:49 +01:00
|
|
|
auto dialog_id = DialogId::get_message_dialog_id(*message_ptr);
|
2021-08-20 16:21:31 +02:00
|
|
|
if (dialog_id.get_type() == DialogType::Channel) {
|
|
|
|
auto channel_id = dialog_id.get_channel_id();
|
2024-04-02 12:06:22 +02:00
|
|
|
if (td_->chat_manager_->have_channel_force(channel_id, source)) {
|
2021-08-20 16:21:31 +02:00
|
|
|
if (td_->messages_manager_->is_old_channel_update(dialog_id, pts)) {
|
|
|
|
// the update will be ignored anyway, so there is no reason to replace it or force get_difference
|
|
|
|
LOG(INFO) << "Allow an outdated unacceptable update from " << source;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((*message_ptr)->get_id() != telegram_api::messageService::ID) {
|
|
|
|
// don't replace service messages, because they can be about bot's kicking
|
|
|
|
LOG(INFO) << "Replace update about new message with updateChannelTooLong in " << dialog_id;
|
|
|
|
update = telegram_api::make_object<telegram_api::updateChannelTooLong>(
|
|
|
|
telegram_api::updateChannelTooLong::PTS_MASK, channel_id.get(), pts);
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-04 02:06:20 +01:00
|
|
|
}
|
2021-08-20 16:21:31 +02:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Update is not from a channel: " << to_string(update);
|
2018-04-04 22:03:35 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-08-20 16:21:31 +02:00
|
|
|
get_difference("on unacceptable updates in on_pending_updates");
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-12-13 20:12:49 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-12-13 20:12:49 +01:00
|
|
|
if (date > 0 && updates.size() == 1 && updates[0] != nullptr &&
|
|
|
|
updates[0]->get_id() == telegram_api::updateReadHistoryOutbox::ID) {
|
|
|
|
auto update = static_cast<const telegram_api::updateReadHistoryOutbox *>(updates[0].get());
|
|
|
|
DialogId dialog_id(update->peer_);
|
|
|
|
if (dialog_id.get_type() == DialogType::User) {
|
|
|
|
auto user_id = dialog_id.get_user_id();
|
|
|
|
if (user_id.is_valid()) {
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_update_user_local_was_online(user_id, date);
|
2019-03-15 20:09:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-05 18:34:19 +01:00
|
|
|
size_t ordinary_new_message_count = 0;
|
|
|
|
size_t scheduled_new_message_count = 0;
|
2022-05-26 14:21:56 +02:00
|
|
|
size_t update_message_id_count = 0;
|
2022-06-23 16:05:43 +02:00
|
|
|
size_t update_count = 0;
|
2019-12-05 18:34:19 +01:00
|
|
|
for (auto &update : updates) {
|
|
|
|
if (update != nullptr) {
|
|
|
|
auto constructor_id = update->get_id();
|
2022-06-23 16:05:43 +02:00
|
|
|
if (constructor_id == telegram_api::updateMessageID::ID) {
|
2022-05-26 14:21:56 +02:00
|
|
|
update_message_id_count++;
|
2022-06-23 16:05:43 +02:00
|
|
|
} else {
|
|
|
|
update_count++;
|
|
|
|
if (constructor_id == telegram_api::updateNewMessage::ID ||
|
|
|
|
constructor_id == telegram_api::updateNewChannelMessage::ID) {
|
|
|
|
ordinary_new_message_count++;
|
|
|
|
} else if (constructor_id == telegram_api::updateNewScheduledMessage::ID) {
|
|
|
|
scheduled_new_message_count++;
|
|
|
|
}
|
2019-12-05 18:34:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-26 14:21:56 +02:00
|
|
|
if (update_message_id_count != 0 && ordinary_new_message_count != 0 && scheduled_new_message_count != 0) {
|
2019-12-05 18:34:19 +01:00
|
|
|
LOG(ERROR) << "Receive mixed message types in updates:";
|
|
|
|
for (auto &update : updates) {
|
|
|
|
LOG(ERROR) << "Update: " << oneline(to_string(update));
|
|
|
|
}
|
2021-08-20 16:21:31 +02:00
|
|
|
if (!running_get_difference_) {
|
|
|
|
schedule_get_difference("on_get_wrong_updates");
|
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
return promise.set_value(Unit());
|
2019-12-05 18:34:19 +01:00
|
|
|
}
|
|
|
|
|
2020-12-21 20:06:52 +01:00
|
|
|
MultiPromiseActorSafe mpas{"OnPendingUpdatesMultiPromiseActor"};
|
2022-06-23 21:00:48 +02:00
|
|
|
Promise<Unit> lock;
|
|
|
|
auto use_mpas = need_postpone || update_count != 1;
|
|
|
|
auto get_promise = [&] {
|
|
|
|
if (use_mpas) {
|
|
|
|
return mpas.get_promise();
|
|
|
|
} else {
|
|
|
|
CHECK(update_count != 0);
|
|
|
|
update_count--;
|
|
|
|
return std::move(promise);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (use_mpas) {
|
|
|
|
being_processed_updates_++;
|
|
|
|
mpas.add_promise([actor_id = create_reference(), promise = std::move(promise)](Result<Unit> &&result) mutable {
|
|
|
|
send_closure(actor_id, &UpdatesManager::on_pending_updates_processed, std::move(result), std::move(promise));
|
|
|
|
});
|
|
|
|
lock = get_promise();
|
|
|
|
}
|
|
|
|
SCOPE_EXIT {
|
|
|
|
if (!use_mpas && update_count == 1) {
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
};
|
2020-12-21 20:06:52 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
for (auto &update : updates) {
|
|
|
|
if (update != nullptr) {
|
|
|
|
LOG(INFO) << "Receive from " << source << " pending " << to_string(update);
|
|
|
|
int32 id = update->get_id();
|
|
|
|
if (id == telegram_api::updateMessageID::ID) {
|
|
|
|
auto sent_message_update = move_tl_object_as<telegram_api::updateMessageID>(update);
|
2022-06-23 16:05:43 +02:00
|
|
|
MessageId message_id;
|
2019-12-05 18:34:19 +01:00
|
|
|
if (ordinary_new_message_count != 0) {
|
2022-06-23 16:05:43 +02:00
|
|
|
message_id = MessageId(ServerMessageId(sent_message_update->id_));
|
2019-12-05 18:34:19 +01:00
|
|
|
} else if (scheduled_new_message_count != 0) {
|
2022-06-23 16:05:43 +02:00
|
|
|
message_id = MessageId(ScheduledServerMessageId(sent_message_update->id_), std::numeric_limits<int32>::max());
|
2019-12-05 18:34:19 +01:00
|
|
|
}
|
2022-06-23 16:05:43 +02:00
|
|
|
if (!td_->messages_manager_->on_update_message_id(sent_message_update->random_id_, message_id, source)) {
|
2018-12-31 20:04:05 +01:00
|
|
|
for (auto &debug_update : updates) {
|
|
|
|
LOG(ERROR) << "Update: " << oneline(to_string(debug_update));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
update = nullptr;
|
|
|
|
}
|
2023-08-11 13:07:13 +02:00
|
|
|
if (id == telegram_api::updateStoryID::ID) {
|
|
|
|
auto update_story_id = move_tl_object_as<telegram_api::updateStoryID>(update);
|
|
|
|
td_->story_manager_->on_update_story_id(update_story_id->random_id_, StoryId(update_story_id->id_), source);
|
|
|
|
update = nullptr;
|
|
|
|
}
|
2019-09-15 03:59:22 +02:00
|
|
|
if (id == telegram_api::updateFolderPeers::ID) {
|
2022-06-23 21:00:48 +02:00
|
|
|
on_update(move_tl_object_as<telegram_api::updateFolderPeers>(update), get_promise());
|
2019-09-15 03:59:22 +02:00
|
|
|
update = nullptr;
|
|
|
|
}
|
2020-08-03 00:51:57 +02:00
|
|
|
if (id == telegram_api::updateEncryption::ID) {
|
2022-06-23 21:00:48 +02:00
|
|
|
on_update(move_tl_object_as<telegram_api::updateEncryption>(update), get_promise());
|
2020-08-03 00:51:57 +02:00
|
|
|
update = nullptr;
|
|
|
|
}
|
2023-01-29 10:49:25 +01:00
|
|
|
// check that if getDifference wasn't run than it isn't run still
|
2021-08-20 16:21:31 +02:00
|
|
|
CHECK(need_postpone || !running_get_difference_);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &update : updates) {
|
|
|
|
if (update != nullptr) {
|
2021-08-20 16:21:31 +02:00
|
|
|
if (is_pts_update(update.get())) {
|
2023-01-29 10:49:25 +01:00
|
|
|
if (running_get_difference_ && can_postpone) {
|
2021-08-20 16:21:31 +02:00
|
|
|
auto pts = get_update_pts(update.get());
|
|
|
|
if (pts != 0 && (min_postponed_update_pts_ == 0 || pts < min_postponed_update_pts_)) {
|
|
|
|
min_postponed_update_pts_ = pts;
|
|
|
|
}
|
|
|
|
}
|
2022-06-23 21:00:48 +02:00
|
|
|
downcast_call(*update, OnUpdate(this, update, get_promise()));
|
2021-08-20 16:21:31 +02:00
|
|
|
update = nullptr;
|
|
|
|
} else if (is_qts_update(update.get())) {
|
2023-01-29 10:49:25 +01:00
|
|
|
if (running_get_difference_ && can_postpone) {
|
2021-08-20 16:21:31 +02:00
|
|
|
auto qts = get_update_qts(update.get());
|
|
|
|
if (qts != 0 && (min_postponed_update_qts_ == 0 || qts < min_postponed_update_qts_)) {
|
|
|
|
min_postponed_update_qts_ = qts;
|
|
|
|
}
|
|
|
|
}
|
2022-06-23 21:00:48 +02:00
|
|
|
downcast_call(*update, OnUpdate(this, update, get_promise()));
|
2018-12-31 20:04:05 +01:00
|
|
|
update = nullptr;
|
2022-06-28 15:39:32 +02:00
|
|
|
} else if (is_channel_pts_update(update.get())) {
|
|
|
|
downcast_call(*update, OnUpdate(this, update, get_promise()));
|
|
|
|
update = nullptr;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-20 14:04:24 +02:00
|
|
|
if (seq_begin == 0 && seq_end == 0) {
|
|
|
|
bool have_updates = false;
|
|
|
|
for (auto &update : updates) {
|
|
|
|
if (update != nullptr) {
|
|
|
|
have_updates = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!have_updates) {
|
2021-08-20 16:21:31 +02:00
|
|
|
LOG(INFO) << "All updates were processed";
|
2021-08-20 14:04:24 +02:00
|
|
|
return lock.set_value(Unit());
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-06-25 20:15:03 +02:00
|
|
|
if (!use_mpas && update_count == 1) {
|
|
|
|
// still need to process the only update
|
2022-06-27 01:57:56 +02:00
|
|
|
lock = std::move(promise); // now we can use lock as the last promise
|
2022-06-25 20:15:03 +02:00
|
|
|
update_count = 0;
|
|
|
|
}
|
2021-08-20 16:21:31 +02:00
|
|
|
if (need_postpone || running_get_difference_) {
|
|
|
|
LOG(INFO) << "Postpone " << updates.size() << " updates [" << seq_begin << ", " << seq_end
|
|
|
|
<< "] with date = " << date << " from " << source;
|
|
|
|
if (!need_postpone) {
|
|
|
|
LOG(ERROR) << "Run get difference while applying updates from " << source;
|
|
|
|
}
|
2023-01-29 10:49:25 +01:00
|
|
|
if (can_postpone) {
|
2024-01-26 12:59:07 +01:00
|
|
|
postponed_updates_.emplace(seq_begin, seq_end, date, receive_time, std::move(updates), std::move(lock));
|
2023-01-29 10:49:25 +01:00
|
|
|
} else {
|
|
|
|
lock.set_value(Unit());
|
|
|
|
}
|
2022-06-25 08:26:30 +02:00
|
|
|
return;
|
2021-08-20 16:21:31 +02:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
if (seq_begin == 0 || seq_begin == seq_ + 1) {
|
|
|
|
LOG(INFO) << "Process " << updates.size() << " updates [" << seq_begin << ", " << seq_end
|
|
|
|
<< "] with date = " << date << " from " << source;
|
2022-06-25 08:26:30 +02:00
|
|
|
process_seq_updates(seq_end, date, std::move(updates), std::move(lock));
|
2018-12-31 20:04:05 +01:00
|
|
|
process_pending_seq_updates();
|
2022-06-25 08:26:30 +02:00
|
|
|
return;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (seq_begin <= seq_) {
|
2021-08-26 17:05:27 +02:00
|
|
|
if (seq_ >= (1 << 30) && seq_begin < seq_ - (1 << 30)) {
|
2020-10-04 12:01:53 +02:00
|
|
|
set_seq_gap_timeout(0.001);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
if (seq_end > seq_) {
|
2021-08-16 00:30:38 +02:00
|
|
|
LOG(ERROR) << "Receive updates with seq_begin = " << seq_begin << ", seq_end = " << seq_end
|
|
|
|
<< ", but seq = " << seq_ << " from " << source;
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2021-08-16 00:30:38 +02:00
|
|
|
LOG(INFO) << "Receive old updates with seq_begin = " << seq_begin << ", seq_end = " << seq_end
|
|
|
|
<< ", but seq = " << seq_ << " from " << source;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
return lock.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LOG(INFO) << "Gap in seq has found. Receive " << updates.size() << " updates [" << seq_begin << ", " << seq_end
|
|
|
|
<< "] from " << source << ", but seq = " << seq_;
|
|
|
|
|
2023-01-29 10:49:25 +01:00
|
|
|
if (can_postpone_updates()) {
|
2024-01-26 12:59:07 +01:00
|
|
|
pending_seq_updates_.emplace(seq_begin, seq_end, date, receive_time, std::move(updates), std::move(lock));
|
2023-01-29 10:49:25 +01:00
|
|
|
} else {
|
|
|
|
lock.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2021-08-15 11:46:38 +02:00
|
|
|
set_seq_gap_timeout(receive_time + MAX_UNFILLED_GAP_TIME - Time::now());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-11-05 01:31:48 +01:00
|
|
|
void UpdatesManager::on_pending_updates_processed(Result<Unit> result, Promise<Unit> promise) {
|
2022-04-25 19:52:44 +02:00
|
|
|
being_processed_updates_--;
|
2021-10-07 14:28:52 +02:00
|
|
|
promise.set_result(std::move(result));
|
|
|
|
}
|
|
|
|
|
2020-12-21 20:06:52 +01:00
|
|
|
void UpdatesManager::add_pending_qts_update(tl_object_ptr<telegram_api::Update> &&update, int32 qts,
|
|
|
|
Promise<Unit> &&promise) {
|
2020-08-03 15:57:30 +02:00
|
|
|
CHECK(update != nullptr);
|
|
|
|
if (qts <= 1) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(ERROR) << "Receive wrong QTS " << qts << " in " << oneline(to_string(update));
|
|
|
|
schedule_get_difference("wrong QTS");
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2020-08-03 15:57:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 old_qts = get_qts();
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(INFO) << "Process update with QTS = " << qts << ", current QTS = " << old_qts;
|
2023-05-09 11:53:48 +02:00
|
|
|
if (qts < old_qts - 1000009) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(WARNING) << "Restore QTS after QTS overflow from " << old_qts << " to " << qts << " by "
|
2020-08-03 15:57:30 +02:00
|
|
|
<< oneline(to_string(update));
|
|
|
|
add_qts(qts - 1).set_value(Unit());
|
|
|
|
CHECK(get_qts() == qts - 1);
|
|
|
|
old_qts = qts - 1;
|
2023-04-25 15:51:08 +02:00
|
|
|
last_confirmed_qts_ = get_qts();
|
2020-08-03 15:57:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (qts <= old_qts) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(INFO) << "Skip already applied update with QTS = " << qts;
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2020-08-03 15:57:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:21:31 +02:00
|
|
|
if (running_get_difference_ || (qts - 1 > old_qts && old_qts > 0)) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(INFO) << "Postpone update with QTS = " << qts;
|
2021-08-20 16:21:31 +02:00
|
|
|
if (!running_get_difference_ && pending_qts_updates_.empty()) {
|
2020-08-03 15:57:30 +02:00
|
|
|
set_qts_gap_timeout(MAX_UNFILLED_GAP_TIME);
|
|
|
|
}
|
2023-01-29 10:49:25 +01:00
|
|
|
if (!can_postpone_updates()) {
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
auto &pending_update = pending_qts_updates_[qts];
|
|
|
|
if (pending_update.update != nullptr) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(WARNING) << "Receive duplicate update with QTS = " << qts;
|
2021-08-15 11:46:38 +02:00
|
|
|
} else {
|
|
|
|
pending_update.receive_time = Time::now();
|
2020-08-03 15:57:30 +02:00
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
pending_update.update = std::move(update);
|
2020-12-22 23:58:56 +01:00
|
|
|
pending_update.promises.push_back(std::move(promise));
|
2020-08-03 15:57:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-21 20:06:52 +01:00
|
|
|
process_qts_update(std::move(update), qts, std::move(promise));
|
2020-08-03 15:57:30 +02:00
|
|
|
process_pending_qts_updates();
|
|
|
|
}
|
|
|
|
|
2020-12-21 20:06:52 +01:00
|
|
|
void UpdatesManager::process_updates(vector<tl_object_ptr<telegram_api::Update>> &&updates, bool force_apply,
|
|
|
|
Promise<Unit> &&promise) {
|
2022-06-23 21:00:48 +02:00
|
|
|
int32 update_count = 0;
|
|
|
|
for (auto &update : updates) {
|
|
|
|
if (update != nullptr) {
|
|
|
|
update_count++;
|
|
|
|
}
|
|
|
|
}
|
2022-06-28 15:43:51 +02:00
|
|
|
if (update_count == 0) {
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
2022-06-23 21:00:48 +02:00
|
|
|
|
2021-01-15 23:17:35 +01:00
|
|
|
MultiPromiseActorSafe mpas{"OnProcessUpdatesMultiPromiseActor"};
|
2022-06-23 21:00:48 +02:00
|
|
|
Promise<Unit> lock;
|
|
|
|
auto use_mpas = update_count != 1;
|
|
|
|
auto get_promise = [&] {
|
|
|
|
if (use_mpas) {
|
|
|
|
return mpas.get_promise();
|
|
|
|
} else {
|
|
|
|
CHECK(update_count != 0);
|
|
|
|
update_count--;
|
|
|
|
return std::move(promise);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (use_mpas) {
|
|
|
|
mpas.add_promise(std::move(promise));
|
|
|
|
lock = get_promise();
|
|
|
|
}
|
|
|
|
SCOPE_EXIT {
|
|
|
|
if (!use_mpas && update_count == 1) {
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
};
|
2020-12-21 20:06:52 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
/*
|
|
|
|
for (auto &update : updates) {
|
|
|
|
if (update != nullptr) {
|
|
|
|
// TODO can't apply it here, because dialog may not be created yet
|
|
|
|
// process updateReadChannelInbox before updateNewChannelMessage
|
|
|
|
auto constructor_id = update->get_id();
|
|
|
|
if (constructor_id == telegram_api::updateReadChannelInbox::ID) {
|
2022-06-23 21:00:48 +02:00
|
|
|
on_update(move_tl_object_as<telegram_api::updateReadChannelInbox>(update), get_promise());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2022-06-28 15:43:51 +02:00
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::updatePtsChanged> update_pts_changed;
|
2018-12-31 20:04:05 +01:00
|
|
|
for (auto &update : updates) {
|
|
|
|
if (update != nullptr) {
|
|
|
|
// process updateNewChannelMessage first
|
|
|
|
auto constructor_id = update->get_id();
|
|
|
|
if (constructor_id == telegram_api::updateNewChannelMessage::ID) {
|
2022-06-23 21:00:48 +02:00
|
|
|
on_update(move_tl_object_as<telegram_api::updateNewChannelMessage>(update), get_promise());
|
2021-01-15 16:45:26 +01:00
|
|
|
continue;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-12-05 18:34:19 +01:00
|
|
|
// process updateNewScheduledMessage first
|
|
|
|
if (constructor_id == telegram_api::updateNewScheduledMessage::ID) {
|
2022-06-23 21:00:48 +02:00
|
|
|
on_update(move_tl_object_as<telegram_api::updateNewScheduledMessage>(update), get_promise());
|
2021-01-15 16:45:26 +01:00
|
|
|
continue;
|
2019-12-05 18:34:19 +01:00
|
|
|
}
|
|
|
|
|
2021-04-30 16:07:01 +02:00
|
|
|
// updateGroupCallConnection must be processed before updateGroupCall
|
|
|
|
if (constructor_id == telegram_api::updateGroupCallConnection::ID) {
|
2022-06-23 21:00:48 +02:00
|
|
|
on_update(move_tl_object_as<telegram_api::updateGroupCallConnection>(update), get_promise());
|
2021-04-30 16:07:01 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
// updatePtsChanged forces get difference, so process it last
|
|
|
|
if (constructor_id == telegram_api::updatePtsChanged::ID) {
|
|
|
|
update_pts_changed = move_tl_object_as<telegram_api::updatePtsChanged>(update);
|
2021-01-15 16:45:26 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (force_apply) {
|
|
|
|
for (auto &update : updates) {
|
2021-10-19 17:11:16 +02:00
|
|
|
if (update != nullptr) {
|
|
|
|
if (is_pts_update(update.get())) {
|
|
|
|
auto constructor_id = update->get_id();
|
|
|
|
if (constructor_id == telegram_api::updateWebPage::ID) {
|
|
|
|
auto update_web_page = move_tl_object_as<telegram_api::updateWebPage>(update);
|
|
|
|
td_->web_pages_manager_->on_get_web_page(std::move(update_web_page->webpage_), DialogId());
|
|
|
|
continue;
|
|
|
|
}
|
2021-01-15 16:45:26 +01:00
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
CHECK(constructor_id != telegram_api::updateFolderPeers::ID);
|
2021-01-15 16:45:26 +01:00
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
if (constructor_id == telegram_api::updateReadHistoryInbox::ID) {
|
|
|
|
static_cast<telegram_api::updateReadHistoryInbox *>(update.get())->still_unread_count_ = -1;
|
|
|
|
}
|
2021-01-15 16:45:26 +01:00
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
process_pts_update(std::move(update));
|
2023-01-09 11:27:28 +01:00
|
|
|
CHECK(update == nullptr);
|
2021-10-19 17:11:16 +02:00
|
|
|
} else if (is_qts_update(update.get())) {
|
2022-06-23 21:00:48 +02:00
|
|
|
process_qts_update(std::move(update), 0, get_promise());
|
2023-01-09 11:27:28 +01:00
|
|
|
CHECK(update == nullptr);
|
2021-10-19 17:11:16 +02:00
|
|
|
} else if (update->get_id() == telegram_api::updateChannelTooLong::ID) {
|
|
|
|
td_->messages_manager_->on_update_channel_too_long(
|
|
|
|
move_tl_object_as<telegram_api::updateChannelTooLong>(update), true);
|
|
|
|
}
|
2021-01-15 17:32:16 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto &update : updates) {
|
|
|
|
if (update != nullptr) {
|
|
|
|
LOG(INFO) << "Process update " << to_string(update);
|
2022-06-23 21:00:48 +02:00
|
|
|
downcast_call(*update, OnUpdate(this, update, get_promise()));
|
2018-12-31 20:04:05 +01:00
|
|
|
CHECK(!running_get_difference_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (update_pts_changed != nullptr) {
|
2022-06-23 21:00:48 +02:00
|
|
|
on_update(std::move(update_pts_changed), get_promise());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
lock.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 23:17:35 +01:00
|
|
|
void UpdatesManager::process_pts_update(tl_object_ptr<telegram_api::Update> &&update) {
|
|
|
|
CHECK(update != nullptr);
|
|
|
|
|
2023-01-15 09:05:53 +01:00
|
|
|
// TODO need to save all updates that can change result of running queries not associated with PTS (for example
|
2021-01-15 23:17:35 +01:00
|
|
|
// getHistory) and apply the updates to results of the queries
|
|
|
|
|
|
|
|
if (!check_pts_update(update)) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(ERROR) << "Receive wrong PTS update: " << oneline(to_string(update));
|
2023-01-09 11:27:28 +01:00
|
|
|
update = nullptr;
|
2021-01-15 23:17:35 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// must be called only during getDifference
|
|
|
|
CHECK(pending_pts_updates_.empty());
|
|
|
|
CHECK(accumulated_pts_ == -1);
|
|
|
|
|
|
|
|
td_->messages_manager_->process_pts_update(std::move(update));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::add_pending_pts_update(tl_object_ptr<telegram_api::Update> &&update, int32 new_pts,
|
2021-08-15 11:46:38 +02:00
|
|
|
int32 pts_count, double receive_time, Promise<Unit> &&promise,
|
|
|
|
const char *source) {
|
2021-01-15 23:17:35 +01:00
|
|
|
// do not try to run getDifference from this function
|
|
|
|
CHECK(update != nullptr);
|
|
|
|
CHECK(source != nullptr);
|
2024-01-26 09:25:09 +01:00
|
|
|
LOG(INFO) << "Receive from " << source << " with pts_count = " << pts_count << " pending " << to_string(update);
|
2021-01-15 23:17:35 +01:00
|
|
|
if (pts_count < 0 || new_pts <= pts_count) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(ERROR) << "Receive update with wrong PTS = " << new_pts << " or pts_count = " << pts_count << " from " << source
|
2021-01-15 23:17:35 +01:00
|
|
|
<< ": " << oneline(to_string(update));
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2023-01-15 09:05:53 +01:00
|
|
|
// TODO need to save all updates that can change result of running queries not associated with PTS (for example
|
2021-01-15 23:17:35 +01:00
|
|
|
// getHistory) and apply them to result of this queries
|
|
|
|
|
|
|
|
if (!check_pts_update(update)) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(ERROR) << "Receive wrong PTS update from " << source << ": " << oneline(to_string(update));
|
2021-01-15 23:17:35 +01:00
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2023-04-27 21:01:10 +02:00
|
|
|
if (DROP_PTS_UPDATES && Slice(source) != Slice("on_get_pts_update")) {
|
2021-01-15 23:17:35 +01:00
|
|
|
set_pts_gap_timeout(1.0);
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 old_pts = get_pts();
|
2022-08-08 18:01:50 +02:00
|
|
|
if (new_pts < old_pts - 99 && source != AFTER_GET_DIFFERENCE_SOURCE) {
|
2021-01-15 23:17:35 +01:00
|
|
|
bool need_restore_pts = new_pts < old_pts - 19999;
|
|
|
|
auto now = Time::now();
|
2023-07-11 15:20:35 +02:00
|
|
|
if (old_pts == 2100000000 && new_pts < 1100000000 && pts_count <= 10000 &&
|
|
|
|
td_->option_manager_->get_option_integer("session_count") > 1) {
|
2023-07-13 18:17:16 +02:00
|
|
|
set_pts(1, "restore PTS").set_value(Unit());
|
2023-07-11 14:50:50 +02:00
|
|
|
old_pts = get_pts();
|
2023-07-11 15:20:35 +02:00
|
|
|
set_pts_gap_timeout(0.001);
|
|
|
|
return promise.set_value(Unit());
|
2023-07-29 14:37:15 +02:00
|
|
|
} else if (now > last_pts_jump_warning_time_ + 1 && need_restore_pts &&
|
2023-07-11 14:50:50 +02:00
|
|
|
!(old_pts == std::numeric_limits<int32>::max() && running_get_difference_)) {
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(ERROR) << "Restore PTS after delete_first_messages from " << old_pts << " to " << new_pts
|
2021-01-15 23:17:35 +01:00
|
|
|
<< " is disabled, pts_count = " << pts_count << ", update is from " << source << ": "
|
|
|
|
<< oneline(to_string(update));
|
|
|
|
last_pts_jump_warning_time_ = now;
|
|
|
|
}
|
|
|
|
if (need_restore_pts) {
|
|
|
|
set_pts_gap_timeout(0.001);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-26 17:05:27 +02:00
|
|
|
if (new_pts <= old_pts || (old_pts >= 1 && new_pts - (1 << 30) > old_pts)) {
|
2021-01-15 23:17:35 +01:00
|
|
|
td_->messages_manager_->skip_old_pending_pts_update(std::move(update), new_pts, old_pts, pts_count, source);
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
2022-12-20 10:42:03 +01:00
|
|
|
if (source == AFTER_GET_DIFFERENCE_SOURCE && old_pts >= 1 && new_pts - (1 << 21) > old_pts) {
|
|
|
|
LOG(ERROR) << "Ignore update " << oneline(to_string(update)) << ", because current PTS is " << old_pts;
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
2021-01-15 23:17:35 +01:00
|
|
|
|
|
|
|
if (running_get_difference_ || !postponed_pts_updates_.empty()) {
|
2023-02-26 12:22:31 +01:00
|
|
|
LOG(INFO) << "Save pending update received while running getDifference from " << source;
|
2021-08-15 11:46:38 +02:00
|
|
|
postpone_pts_update(std::move(update), new_pts, pts_count, receive_time, std::move(promise));
|
2021-01-15 23:17:35 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-15 09:05:53 +01:00
|
|
|
// is_acceptable_update check was skipped for postponed PTS updates
|
2022-08-08 18:01:50 +02:00
|
|
|
if (source == AFTER_GET_DIFFERENCE_SOURCE && !is_acceptable_update(update.get())) {
|
2021-12-13 20:30:42 +01:00
|
|
|
LOG(INFO) << "Postpone again unacceptable pending update";
|
|
|
|
postpone_pts_update(std::move(update), new_pts, pts_count, receive_time, std::move(promise));
|
|
|
|
set_pts_gap_timeout(0.001);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-03 13:10:00 +01:00
|
|
|
if (old_pts > new_pts - pts_count) {
|
2021-01-15 23:17:35 +01:00
|
|
|
LOG(WARNING) << "Have old_pts (= " << old_pts << ") + pts_count (= " << pts_count << ") > new_pts (= " << new_pts
|
2022-08-18 16:00:18 +02:00
|
|
|
<< "). Logged in " << td_->option_manager_->get_option_integer("authorization_date")
|
|
|
|
<< ". Update from " << source << " = " << oneline(to_string(update));
|
2021-08-15 11:46:38 +02:00
|
|
|
postpone_pts_update(std::move(update), new_pts, pts_count, receive_time, std::move(promise));
|
2021-01-15 23:17:35 +01:00
|
|
|
set_pts_gap_timeout(0.001);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
accumulated_pts_count_ += pts_count;
|
|
|
|
if (new_pts > accumulated_pts_) {
|
|
|
|
accumulated_pts_ = new_pts;
|
|
|
|
}
|
|
|
|
|
2021-03-03 13:10:00 +01:00
|
|
|
if (old_pts > accumulated_pts_ - accumulated_pts_count_) {
|
2021-01-15 23:17:35 +01:00
|
|
|
LOG(WARNING) << "Have old_pts (= " << old_pts << ") + accumulated_pts_count (= " << accumulated_pts_count_
|
|
|
|
<< ") > accumulated_pts (= " << accumulated_pts_ << "). new_pts = " << new_pts
|
2022-08-18 16:00:18 +02:00
|
|
|
<< ", pts_count = " << pts_count << ". Logged in "
|
|
|
|
<< td_->option_manager_->get_option_integer("authorization_date") << ". Update from " << source
|
|
|
|
<< " = " << oneline(to_string(update));
|
2021-08-15 11:46:38 +02:00
|
|
|
postpone_pts_update(std::move(update), new_pts, pts_count, receive_time, std::move(promise));
|
2021-01-15 23:17:35 +01:00
|
|
|
set_pts_gap_timeout(0.001);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_IF(INFO, pts_count == 0 && update->get_id() != dummyUpdate::ID) << "Skip useless update " << to_string(update);
|
|
|
|
|
2021-03-03 13:10:00 +01:00
|
|
|
if (pending_pts_updates_.empty() && old_pts == accumulated_pts_ - accumulated_pts_count_ &&
|
2021-01-15 23:17:35 +01:00
|
|
|
!pts_gap_timeout_.has_timeout()) {
|
|
|
|
if (pts_count > 0) {
|
|
|
|
td_->messages_manager_->process_pts_update(std::move(update));
|
|
|
|
|
|
|
|
set_pts(accumulated_pts_, "process pending updates fast path")
|
2021-08-16 12:35:30 +02:00
|
|
|
.set_value(Unit()); // TODO can't set until data are really stored on persistent storage
|
2021-01-15 23:17:35 +01:00
|
|
|
accumulated_pts_count_ = 0;
|
|
|
|
accumulated_pts_ = -1;
|
2024-01-26 09:25:09 +01:00
|
|
|
} else {
|
|
|
|
LOG(DEBUG) << "There is no need to process the update";
|
2021-01-15 23:17:35 +01:00
|
|
|
}
|
|
|
|
promise.set_value(Unit());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-26 12:59:07 +01:00
|
|
|
pending_pts_updates_.emplace(std::move(update), new_pts, pts_count, receive_time, std::move(promise));
|
2021-01-15 23:17:35 +01:00
|
|
|
|
2021-03-03 13:10:00 +01:00
|
|
|
if (old_pts < accumulated_pts_ - accumulated_pts_count_) {
|
2021-08-16 11:19:30 +02:00
|
|
|
if (old_pts == new_pts - pts_count) {
|
|
|
|
// can't apply all updates, but can apply this and probably some other updates
|
|
|
|
process_pending_pts_updates();
|
|
|
|
} else {
|
2024-01-26 09:25:09 +01:00
|
|
|
LOG(DEBUG) << "Can't process PTS updates, because current PTS = " << old_pts << ", new PTS = " << new_pts
|
|
|
|
<< ", pts_count = " << pts_count << ", maximum known PTS = " << accumulated_pts_
|
|
|
|
<< ", accumulated_pts_count = " << accumulated_pts_count_;
|
2024-01-25 22:30:49 +01:00
|
|
|
set_pts_gap_timeout(max(receive_time + MAX_UNFILLED_GAP_TIME - Time::now(), 0.001));
|
2021-08-16 11:19:30 +02:00
|
|
|
}
|
2021-01-15 23:17:35 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-03 13:10:00 +01:00
|
|
|
CHECK(old_pts == accumulated_pts_ - accumulated_pts_count_);
|
2021-08-16 11:19:30 +02:00
|
|
|
process_all_pending_pts_updates();
|
2021-01-15 23:17:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::postpone_pts_update(tl_object_ptr<telegram_api::Update> &&update, int32 pts, int32 pts_count,
|
2021-08-15 11:46:38 +02:00
|
|
|
double receive_time, Promise<Unit> &&promise) {
|
2024-01-25 20:28:07 +01:00
|
|
|
if (!can_postpone_updates() || (pts_count > 1 && td_->option_manager_->get_option_integer("session_count") <= 1)) {
|
2023-01-29 10:49:25 +01:00
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
2024-01-26 12:59:07 +01:00
|
|
|
postponed_pts_updates_.emplace(std::move(update), pts, pts_count, receive_time, std::move(promise));
|
2021-01-15 23:17:35 +01:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void UpdatesManager::process_seq_updates(int32 seq_end, int32 date,
|
2020-12-21 20:06:52 +01:00
|
|
|
vector<tl_object_ptr<telegram_api::Update>> &&updates,
|
|
|
|
Promise<Unit> &&promise) {
|
2022-06-28 15:50:22 +02:00
|
|
|
string serialized_updates;
|
|
|
|
if (date && seq_end) {
|
|
|
|
serialized_updates = PSTRING() << "process_seq_updates [seq_ = " << seq_ << ", seq_end = " << seq_end << "]: ";
|
|
|
|
// TODO remove after bugs will be fixed
|
|
|
|
for (auto &update : updates) {
|
|
|
|
if (update != nullptr) {
|
|
|
|
serialized_updates += oneline(to_string(update));
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
process_updates(std::move(updates), false, std::move(promise));
|
2018-12-31 20:04:05 +01:00
|
|
|
if (seq_end) {
|
|
|
|
seq_ = seq_end;
|
|
|
|
}
|
|
|
|
if (date && seq_end) {
|
|
|
|
set_date(date, true, std::move(serialized_updates));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-21 20:06:52 +01:00
|
|
|
void UpdatesManager::process_qts_update(tl_object_ptr<telegram_api::Update> &&update_ptr, int32 qts,
|
|
|
|
Promise<Unit> &&promise) {
|
2020-08-03 20:54:28 +02:00
|
|
|
LOG(DEBUG) << "Process " << to_string(update_ptr);
|
2023-04-27 19:21:30 +02:00
|
|
|
if (last_confirmed_qts_ < qts - FORCED_GET_DIFFERENCE_PTS_DIFF && last_confirmed_qts_ != 0) {
|
|
|
|
confirm_pts_qts(qts);
|
2021-01-05 14:29:45 +01:00
|
|
|
}
|
2023-05-09 11:53:48 +02:00
|
|
|
qts_diff_++;
|
|
|
|
if (qts_diff_ >= 1000000) {
|
|
|
|
LOG(WARNING) << "Fixed " << qts_gap_ << " QTS gaps";
|
|
|
|
qts_gap_ = 0;
|
|
|
|
qts_diff_ = 0;
|
|
|
|
}
|
2023-12-14 21:27:46 +01:00
|
|
|
auto constructor_id = update_ptr->get_id();
|
|
|
|
if (constructor_id == telegram_api::updateNewEncryptedMessage::ID) {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateNewEncryptedMessage>(update_ptr);
|
|
|
|
send_closure(td_->secret_chats_manager_, &SecretChatsManager::on_new_message, std::move(update->message_),
|
|
|
|
add_qts(qts));
|
|
|
|
} else if (td_->auth_manager_->is_bot()) {
|
|
|
|
switch (constructor_id) {
|
|
|
|
case telegram_api::updateMessagePollVote::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateMessagePollVote>(update_ptr);
|
|
|
|
td_->poll_manager_->on_get_poll_vote(PollId(update->poll_id_), DialogId(update->peer_),
|
|
|
|
std::move(update->options_));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updateBotStopped::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateBotStopped>(update_ptr);
|
2024-01-08 15:27:32 +01:00
|
|
|
td_->dialog_participant_manager_->on_update_bot_stopped(UserId(update->user_id_), update->date_,
|
|
|
|
update->stopped_);
|
2023-12-14 21:27:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updateChatParticipant::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateChatParticipant>(update_ptr);
|
2024-01-08 15:27:32 +01:00
|
|
|
td_->dialog_participant_manager_->on_update_chat_participant(
|
2023-12-14 21:27:46 +01:00
|
|
|
ChatId(update->chat_id_), UserId(update->actor_id_), update->date_,
|
|
|
|
DialogInviteLink(std::move(update->invite_), true, "updateChatParticipant"),
|
|
|
|
std::move(update->prev_participant_), std::move(update->new_participant_));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updateChannelParticipant::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateChannelParticipant>(update_ptr);
|
2024-01-08 15:27:32 +01:00
|
|
|
td_->dialog_participant_manager_->on_update_channel_participant(
|
2023-12-14 21:27:46 +01:00
|
|
|
ChannelId(update->channel_id_), UserId(update->actor_id_), update->date_,
|
|
|
|
DialogInviteLink(std::move(update->invite_), true, "updateChannelParticipant"), update->via_chatlist_,
|
|
|
|
std::move(update->prev_participant_), std::move(update->new_participant_));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updateBotChatInviteRequester::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateBotChatInviteRequester>(update_ptr);
|
2024-01-08 15:27:32 +01:00
|
|
|
td_->dialog_participant_manager_->on_update_chat_invite_requester(
|
2023-12-14 21:27:46 +01:00
|
|
|
DialogId(update->peer_), UserId(update->user_id_), std::move(update->about_), update->date_,
|
|
|
|
DialogInviteLink(std::move(update->invite_), true, "updateBotChatInviteRequester"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updateBotChatBoost::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateBotChatBoost>(update_ptr);
|
|
|
|
td_->boost_manager_->on_update_dialog_boost(DialogId(update->peer_), std::move(update->boost_));
|
|
|
|
break;
|
|
|
|
}
|
2023-12-14 17:55:53 +01:00
|
|
|
case telegram_api::updateBotMessageReaction::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateBotMessageReaction>(update_ptr);
|
|
|
|
auto dialog_id = DialogId(update->peer_);
|
|
|
|
auto message_id = MessageId(ServerMessageId(update->msg_id_));
|
|
|
|
auto date = update->date_;
|
|
|
|
auto actor_dialog_id = DialogId(update->actor_);
|
|
|
|
auto old_reaction_types = ReactionType::get_reaction_types(update->old_reactions_);
|
|
|
|
auto new_reaction_types = ReactionType::get_reaction_types(update->new_reactions_);
|
|
|
|
if (!dialog_id.is_valid() || !message_id.is_valid() || !actor_dialog_id.is_valid() || date <= 0 ||
|
|
|
|
old_reaction_types == new_reaction_types) {
|
|
|
|
LOG(ERROR) << "Receive invalid updateBotMessageReaction for " << MessageFullId{dialog_id, message_id}
|
|
|
|
<< " by " << actor_dialog_id << " at " << date << ": " << old_reaction_types << " -> "
|
|
|
|
<< new_reaction_types;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-01-04 13:38:01 +01:00
|
|
|
td_->dialog_manager_->force_create_dialog(dialog_id, "on_update_bot_message_reaction", true);
|
2023-12-14 17:55:53 +01:00
|
|
|
send_closure(G()->td(), &Td::send_update,
|
|
|
|
td_api::make_object<td_api::updateMessageReaction>(
|
2024-01-04 14:13:20 +01:00
|
|
|
td_->dialog_manager_->get_chat_id_object(dialog_id, "updateMessageReaction"), message_id.get(),
|
|
|
|
get_message_sender_object(td_, actor_dialog_id, "updateMessageReaction"), date,
|
|
|
|
ReactionType::get_reaction_types_object(old_reaction_types),
|
2023-12-14 17:55:53 +01:00
|
|
|
ReactionType::get_reaction_types_object(new_reaction_types)));
|
|
|
|
break;
|
|
|
|
}
|
2023-12-14 21:44:31 +01:00
|
|
|
case telegram_api::updateBotMessageReactions::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateBotMessageReactions>(update_ptr);
|
|
|
|
auto dialog_id = DialogId(update->peer_);
|
|
|
|
auto message_id = MessageId(ServerMessageId(update->msg_id_));
|
|
|
|
auto date = update->date_;
|
|
|
|
if (!dialog_id.is_valid() || !message_id.is_valid() || date <= 0) {
|
|
|
|
LOG(ERROR) << "Receive invalid " << to_string(update->reactions_);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
vector<td_api::object_ptr<td_api::messageReaction>> message_reactions;
|
|
|
|
for (const auto &reaction_count : update->reactions_) {
|
|
|
|
auto reaction_type = ReactionType(reaction_count->reaction_);
|
|
|
|
if (reaction_type.is_empty() || reaction_count->count_ <= 0) {
|
|
|
|
LOG(ERROR) << "Receive invalid reaction in updateBotMessageReactions for "
|
|
|
|
<< MessageFullId{dialog_id, message_id} << " at " << date << ": " << to_string(reaction_count);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
message_reactions.push_back(td_api::make_object<td_api::messageReaction>(
|
|
|
|
reaction_type.get_reaction_type_object(), reaction_count->count_, false, nullptr, Auto()));
|
|
|
|
}
|
2024-01-04 13:38:01 +01:00
|
|
|
td_->dialog_manager_->force_create_dialog(dialog_id, "on_update_bot_message_reactions", true);
|
2023-12-14 21:44:31 +01:00
|
|
|
send_closure(G()->td(), &Td::send_update,
|
|
|
|
td_api::make_object<td_api::updateMessageReactions>(
|
2024-01-04 14:13:20 +01:00
|
|
|
td_->dialog_manager_->get_chat_id_object(dialog_id, "updateMessageReactions"),
|
2023-12-14 21:44:31 +01:00
|
|
|
message_id.get(), date, std::move(message_reactions)));
|
|
|
|
break;
|
|
|
|
}
|
2024-03-07 14:41:30 +01:00
|
|
|
case telegram_api::updateBotBusinessConnect::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateBotBusinessConnect>(update_ptr);
|
2024-03-07 15:18:11 +01:00
|
|
|
td_->business_connection_manager_->on_update_bot_business_connect(std::move(update->connection_));
|
2024-03-07 14:41:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updateBotNewBusinessMessage::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateBotNewBusinessMessage>(update_ptr);
|
2024-03-09 00:14:02 +01:00
|
|
|
td_->business_connection_manager_->on_update_bot_new_business_message(
|
2024-03-16 22:19:24 +01:00
|
|
|
BusinessConnectionId(std::move(update->connection_id_)), std::move(update->message_),
|
|
|
|
std::move(update->reply_to_message_));
|
2024-03-07 14:41:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updateBotEditBusinessMessage::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateBotEditBusinessMessage>(update_ptr);
|
2024-03-09 00:17:00 +01:00
|
|
|
td_->business_connection_manager_->on_update_bot_edit_business_message(
|
2024-03-16 22:19:24 +01:00
|
|
|
BusinessConnectionId(std::move(update->connection_id_)), std::move(update->message_),
|
|
|
|
std::move(update->reply_to_message_));
|
2024-03-07 14:41:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::updateBotDeleteBusinessMessage::ID: {
|
|
|
|
auto update = move_tl_object_as<telegram_api::updateBotDeleteBusinessMessage>(update_ptr);
|
2024-03-11 14:41:19 +01:00
|
|
|
td_->business_connection_manager_->on_update_bot_delete_business_messages(
|
|
|
|
BusinessConnectionId(std::move(update->connection_id_)), DialogId(update->peer_),
|
|
|
|
std::move(update->messages_));
|
2024-03-07 14:41:30 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-12-14 21:27:46 +01:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
2023-10-30 22:18:38 +01:00
|
|
|
}
|
2023-12-14 21:27:46 +01:00
|
|
|
add_qts(qts).set_value(Unit());
|
|
|
|
} else {
|
|
|
|
add_qts(qts).set_value(Unit());
|
|
|
|
LOG(ERROR) << "Receive " << to_string(update_ptr);
|
2020-08-03 15:57:30 +02:00
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2020-08-03 15:57:30 +02:00
|
|
|
}
|
|
|
|
|
2021-08-16 11:19:30 +02:00
|
|
|
void UpdatesManager::process_all_pending_pts_updates() {
|
2021-08-15 21:54:18 +02:00
|
|
|
auto begin_time = Time::now();
|
2021-01-15 23:17:35 +01:00
|
|
|
for (auto &update : pending_pts_updates_) {
|
2024-01-26 12:59:07 +01:00
|
|
|
td_->messages_manager_->process_pts_update(std::move(update.update));
|
|
|
|
update.promise.set_value(Unit());
|
2021-01-15 23:17:35 +01:00
|
|
|
}
|
|
|
|
|
2021-02-01 11:06:38 +01:00
|
|
|
if (last_pts_gap_time_ != 0) {
|
2021-08-15 21:54:18 +02:00
|
|
|
auto begin_diff = begin_time - last_pts_gap_time_;
|
2021-02-01 11:06:38 +01:00
|
|
|
auto diff = Time::now() - last_pts_gap_time_;
|
|
|
|
last_pts_gap_time_ = 0;
|
|
|
|
if (diff > 0.1) {
|
2023-01-15 09:05:53 +01:00
|
|
|
VLOG(get_difference) << "Gap in PTS from " << accumulated_pts_ - accumulated_pts_count_ << " to "
|
2021-08-15 21:54:18 +02:00
|
|
|
<< accumulated_pts_ << " has been filled in " << begin_diff << '-' << diff << " seconds";
|
2021-02-01 11:06:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-16 11:19:30 +02:00
|
|
|
set_pts(accumulated_pts_, "process_all_pending_pts_updates")
|
2021-02-01 11:06:38 +01:00
|
|
|
.set_value(Unit()); // TODO can't set until updates are stored on persistent storage
|
2021-08-16 11:19:30 +02:00
|
|
|
drop_all_pending_pts_updates();
|
2021-01-15 23:17:35 +01:00
|
|
|
}
|
|
|
|
|
2021-08-16 11:19:30 +02:00
|
|
|
void UpdatesManager::drop_all_pending_pts_updates() {
|
2021-01-15 23:17:35 +01:00
|
|
|
accumulated_pts_count_ = 0;
|
|
|
|
accumulated_pts_ = -1;
|
2023-04-27 21:01:10 +02:00
|
|
|
min_pts_gap_timeout_.cancel_timeout();
|
2021-01-15 23:17:35 +01:00
|
|
|
pts_gap_timeout_.cancel_timeout();
|
|
|
|
pending_pts_updates_.clear();
|
|
|
|
}
|
|
|
|
|
2021-08-16 12:35:30 +02:00
|
|
|
void UpdatesManager::process_postponed_pts_updates() {
|
|
|
|
if (postponed_pts_updates_.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-20 14:25:29 +02:00
|
|
|
auto begin_time = Time::now();
|
2021-08-16 12:35:30 +02:00
|
|
|
auto initial_pts = get_pts();
|
|
|
|
auto old_pts = initial_pts;
|
|
|
|
int32 skipped_update_count = 0;
|
|
|
|
int32 applied_update_count = 0;
|
2021-08-18 16:40:28 +02:00
|
|
|
auto update_it = postponed_pts_updates_.begin();
|
|
|
|
while (update_it != postponed_pts_updates_.end()) {
|
2024-01-26 12:59:07 +01:00
|
|
|
auto new_pts = update_it->pts;
|
|
|
|
auto pts_count = update_it->pts_count;
|
2021-08-26 17:05:27 +02:00
|
|
|
if (new_pts <= old_pts || (old_pts >= 1 && new_pts - (1 << 30) > old_pts)) {
|
2021-08-16 12:35:30 +02:00
|
|
|
skipped_update_count++;
|
2024-01-26 12:59:07 +01:00
|
|
|
td_->messages_manager_->skip_old_pending_pts_update(std::move(update_it->update), new_pts, old_pts, pts_count,
|
|
|
|
"process_postponed_pts_updates");
|
|
|
|
update_it->promise.set_value(Unit());
|
2021-08-18 16:40:28 +02:00
|
|
|
update_it = postponed_pts_updates_.erase(update_it);
|
2021-08-16 12:35:30 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-01-17 14:50:08 +01:00
|
|
|
if (Time::now() - begin_time >= 0.1) {
|
2022-11-26 22:59:09 +01:00
|
|
|
// the updates will be applied or skipped later; reget the remaining updates through getDifference
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-08-20 09:29:57 +02:00
|
|
|
auto last_update_it = update_it;
|
2021-08-18 16:40:28 +02:00
|
|
|
for (int32 i = 1; true; i++) {
|
2021-08-20 09:29:57 +02:00
|
|
|
++last_update_it;
|
2021-08-18 16:40:28 +02:00
|
|
|
if (old_pts == new_pts - pts_count) {
|
|
|
|
// the updates can be applied
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (old_pts > new_pts - pts_count || last_update_it == postponed_pts_updates_.end() ||
|
|
|
|
i == GAP_TIMEOUT_UPDATE_COUNT) {
|
|
|
|
// the updates can't be applied
|
2024-01-26 12:59:07 +01:00
|
|
|
VLOG(get_difference) << "Can't apply " << i << " next postponed updates with PTS " << update_it->pts << '-'
|
|
|
|
<< new_pts << ", because their pts_count is " << pts_count << " instead of expected "
|
|
|
|
<< new_pts - old_pts;
|
2021-08-18 16:40:28 +02:00
|
|
|
last_update_it = update_it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-01-26 12:59:07 +01:00
|
|
|
new_pts = last_update_it->pts;
|
|
|
|
pts_count += last_update_it->pts_count;
|
2021-08-18 16:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (last_update_it == update_it) {
|
2021-08-16 12:35:30 +02:00
|
|
|
// the updates will be applied or skipped later
|
|
|
|
break;
|
|
|
|
}
|
2021-08-18 16:40:28 +02:00
|
|
|
CHECK(old_pts == new_pts - pts_count);
|
2021-08-16 12:35:30 +02:00
|
|
|
|
2021-08-18 16:40:28 +02:00
|
|
|
while (update_it != last_update_it) {
|
2024-01-26 12:59:07 +01:00
|
|
|
if (update_it->pts_count > 0) {
|
2021-08-18 16:40:28 +02:00
|
|
|
applied_update_count++;
|
2024-01-26 12:59:07 +01:00
|
|
|
td_->messages_manager_->process_pts_update(std::move(update_it->update));
|
2021-08-18 16:40:28 +02:00
|
|
|
}
|
2024-01-26 12:59:07 +01:00
|
|
|
update_it->promise.set_value(Unit());
|
2021-08-18 16:40:28 +02:00
|
|
|
update_it = postponed_pts_updates_.erase(update_it);
|
2021-08-16 12:35:30 +02:00
|
|
|
}
|
2021-08-18 16:40:28 +02:00
|
|
|
old_pts = new_pts;
|
2021-08-16 12:35:30 +02:00
|
|
|
}
|
|
|
|
if (old_pts != initial_pts) {
|
|
|
|
set_pts(old_pts, "process_postponed_pts_updates")
|
|
|
|
.set_value(Unit()); // TODO can't set until data are really stored on persistent storage
|
|
|
|
}
|
|
|
|
CHECK(!running_get_difference_);
|
|
|
|
if (skipped_update_count + applied_update_count > 0) {
|
2022-11-23 14:32:09 +01:00
|
|
|
VLOG(get_difference) << "PTS has changed from " << initial_pts << " to " << old_pts << " after skipping "
|
2021-08-20 09:57:19 +02:00
|
|
|
<< skipped_update_count << ", applying " << applied_update_count << " and keeping "
|
|
|
|
<< postponed_pts_updates_.size() << " postponed updates";
|
2021-08-16 12:35:30 +02:00
|
|
|
}
|
2022-08-20 14:25:29 +02:00
|
|
|
|
|
|
|
auto passed_time = Time::now() - begin_time;
|
2022-11-20 20:41:50 +01:00
|
|
|
if (passed_time >= UPDATE_APPLY_WARNING_TIME) {
|
2022-11-23 14:32:09 +01:00
|
|
|
LOG(WARNING) << "PTS has changed from " << initial_pts << " to " << old_pts << " after skipping "
|
2022-08-20 14:25:29 +02:00
|
|
|
<< skipped_update_count << ", applying " << applied_update_count << " and keeping "
|
|
|
|
<< postponed_pts_updates_.size() << " postponed for " << (Time::now() - get_difference_start_time_)
|
2022-12-10 23:32:46 +01:00
|
|
|
<< " seconds updates in " << passed_time << " seconds";
|
2022-08-20 14:25:29 +02:00
|
|
|
}
|
2021-08-16 12:35:30 +02:00
|
|
|
}
|
|
|
|
|
2021-08-16 11:19:30 +02:00
|
|
|
void UpdatesManager::process_pending_pts_updates() {
|
|
|
|
if (pending_pts_updates_.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-20 20:41:50 +01:00
|
|
|
auto begin_time = Time::now();
|
|
|
|
auto initial_pts = get_pts();
|
|
|
|
int32 applied_update_count = 0;
|
2021-08-16 11:19:30 +02:00
|
|
|
while (!pending_pts_updates_.empty()) {
|
|
|
|
auto update_it = pending_pts_updates_.begin();
|
2024-01-26 12:59:07 +01:00
|
|
|
auto &update = *update_it;
|
2021-08-16 11:19:30 +02:00
|
|
|
if (get_pts() != update.pts - update.pts_count) {
|
|
|
|
// the updates will be applied or skipped later
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-11-20 20:41:50 +01:00
|
|
|
applied_update_count++;
|
2021-08-16 11:19:30 +02:00
|
|
|
if (update.pts_count > 0) {
|
|
|
|
td_->messages_manager_->process_pts_update(std::move(update.update));
|
|
|
|
set_pts(update.pts, "process_pending_pts_updates")
|
2021-08-16 12:35:30 +02:00
|
|
|
.set_value(Unit()); // TODO can't set until data are really stored on persistent storage
|
2021-08-16 13:02:15 +02:00
|
|
|
|
|
|
|
if (accumulated_pts_ != -1) {
|
|
|
|
CHECK(update.pts <= accumulated_pts_);
|
|
|
|
CHECK(accumulated_pts_count_ >= update.pts_count);
|
|
|
|
accumulated_pts_count_ -= update.pts_count;
|
|
|
|
}
|
2024-01-26 13:08:16 +01:00
|
|
|
} else {
|
|
|
|
LOG(INFO) << "Skip because of pts_count == 0 " << to_string(update.update);
|
2021-08-16 11:19:30 +02:00
|
|
|
}
|
|
|
|
update.promise.set_value(Unit());
|
|
|
|
pending_pts_updates_.erase(update_it);
|
|
|
|
}
|
2022-11-20 20:41:50 +01:00
|
|
|
if (applied_update_count > 0) {
|
2023-04-27 21:01:10 +02:00
|
|
|
min_pts_gap_timeout_.cancel_timeout();
|
2021-08-16 11:19:30 +02:00
|
|
|
pts_gap_timeout_.cancel_timeout();
|
|
|
|
}
|
|
|
|
if (!pending_pts_updates_.empty()) {
|
|
|
|
// if still have a gap, reset timeout
|
|
|
|
auto update_it = pending_pts_updates_.begin();
|
2024-01-26 12:59:07 +01:00
|
|
|
double receive_time = update_it->receive_time;
|
2021-08-16 11:19:30 +02:00
|
|
|
for (size_t i = 0; i < GAP_TIMEOUT_UPDATE_COUNT; i++) {
|
|
|
|
if (++update_it == pending_pts_updates_.end()) {
|
|
|
|
break;
|
|
|
|
}
|
2024-01-26 12:59:07 +01:00
|
|
|
receive_time = min(receive_time, update_it->receive_time);
|
2021-08-16 11:19:30 +02:00
|
|
|
}
|
2024-01-25 22:30:49 +01:00
|
|
|
set_pts_gap_timeout(max(receive_time + MAX_UNFILLED_GAP_TIME - Time::now(), 0.001));
|
2021-08-16 11:19:30 +02:00
|
|
|
}
|
2022-11-20 20:41:50 +01:00
|
|
|
|
|
|
|
auto passed_time = Time::now() - begin_time;
|
|
|
|
if (passed_time >= UPDATE_APPLY_WARNING_TIME) {
|
2022-11-23 14:32:09 +01:00
|
|
|
LOG(WARNING) << "PTS has changed from " << initial_pts << " to " << get_pts() << " after applying "
|
2022-11-20 20:41:50 +01:00
|
|
|
<< applied_update_count << " and keeping " << pending_pts_updates_.size() << " pending updates in "
|
2022-12-10 23:32:46 +01:00
|
|
|
<< passed_time << " seconds";
|
2022-11-20 20:41:50 +01:00
|
|
|
}
|
2021-08-16 11:19:30 +02:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void UpdatesManager::process_pending_seq_updates() {
|
2020-10-31 14:33:06 +01:00
|
|
|
if (!pending_seq_updates_.empty()) {
|
|
|
|
LOG(DEBUG) << "Trying to process " << pending_seq_updates_.size() << " pending seq updates";
|
2021-08-16 07:38:29 +02:00
|
|
|
// must not return, because in case of seq overflow there are no pending seq updates
|
2020-10-31 14:33:06 +01:00
|
|
|
}
|
2021-08-16 07:38:29 +02:00
|
|
|
|
2022-11-20 20:41:50 +01:00
|
|
|
auto begin_time = Time::now();
|
2022-11-23 14:32:09 +01:00
|
|
|
int32 initial_seq = seq_;
|
2022-11-20 20:41:50 +01:00
|
|
|
int32 applied_update_count = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
while (!pending_seq_updates_.empty() && !running_get_difference_) {
|
|
|
|
auto update_it = pending_seq_updates_.begin();
|
2024-01-26 12:59:07 +01:00
|
|
|
auto &update = *update_it;
|
2021-08-16 00:30:38 +02:00
|
|
|
auto seq_begin = update.seq_begin;
|
2021-08-26 17:05:27 +02:00
|
|
|
if (seq_begin - 1 > seq_ && seq_begin - (1 << 30) <= seq_) {
|
2021-08-15 12:52:00 +02:00
|
|
|
// the updates will be applied later
|
2018-12-31 20:04:05 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-08-16 07:38:29 +02:00
|
|
|
|
2022-11-20 20:41:50 +01:00
|
|
|
applied_update_count++;
|
2021-08-16 00:30:38 +02:00
|
|
|
auto seq_end = update.seq_end;
|
2021-08-15 12:52:00 +02:00
|
|
|
if (seq_begin - 1 == seq_) {
|
2021-08-16 00:30:38 +02:00
|
|
|
process_seq_updates(seq_end, update.date, std::move(update.updates), std::move(update.promise));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
// old update
|
|
|
|
CHECK(seq_begin != 0);
|
2021-08-16 00:30:38 +02:00
|
|
|
if (seq_begin <= seq_ && seq_ < seq_end) {
|
|
|
|
LOG(ERROR) << "Receive updates with seq_begin = " << seq_begin << ", seq_end = " << seq_end
|
|
|
|
<< ", but seq = " << seq_;
|
|
|
|
}
|
|
|
|
update.promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
pending_seq_updates_.erase(update_it);
|
|
|
|
}
|
2022-11-20 20:41:50 +01:00
|
|
|
if (pending_seq_updates_.empty() || applied_update_count > 0) {
|
2018-12-31 20:04:05 +01:00
|
|
|
seq_gap_timeout_.cancel_timeout();
|
2021-08-16 07:38:29 +02:00
|
|
|
}
|
|
|
|
if (!pending_seq_updates_.empty()) {
|
|
|
|
// if still have a gap, reset timeout
|
2021-08-15 11:46:38 +02:00
|
|
|
auto update_it = pending_seq_updates_.begin();
|
2024-01-26 12:59:07 +01:00
|
|
|
double receive_time = update_it->receive_time;
|
2021-08-16 11:19:30 +02:00
|
|
|
for (size_t i = 0; i < GAP_TIMEOUT_UPDATE_COUNT; i++) {
|
2021-08-15 11:46:38 +02:00
|
|
|
if (++update_it == pending_seq_updates_.end()) {
|
|
|
|
break;
|
|
|
|
}
|
2024-01-26 12:59:07 +01:00
|
|
|
receive_time = min(receive_time, update_it->receive_time);
|
2021-08-15 11:46:38 +02:00
|
|
|
}
|
|
|
|
set_seq_gap_timeout(receive_time + MAX_UNFILLED_GAP_TIME - Time::now());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2022-11-20 20:41:50 +01:00
|
|
|
|
|
|
|
auto passed_time = Time::now() - begin_time;
|
|
|
|
if (passed_time >= UPDATE_APPLY_WARNING_TIME) {
|
2022-11-23 14:32:09 +01:00
|
|
|
LOG(WARNING) << "Seq has changed from " << initial_seq << " to " << seq_ << " after applying "
|
2022-11-20 20:41:50 +01:00
|
|
|
<< applied_update_count << " and keeping " << pending_seq_updates_.size() << " pending updates in "
|
2022-12-10 23:32:46 +01:00
|
|
|
<< passed_time << " seconds";
|
2022-11-20 20:41:50 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2020-08-03 15:57:30 +02:00
|
|
|
void UpdatesManager::process_pending_qts_updates() {
|
|
|
|
if (pending_qts_updates_.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-08-15 12:52:00 +02:00
|
|
|
|
2023-01-15 09:05:53 +01:00
|
|
|
LOG(DEBUG) << "Process " << pending_qts_updates_.size() << " pending QTS updates";
|
2022-11-20 20:41:50 +01:00
|
|
|
auto begin_time = Time::now();
|
|
|
|
auto initial_qts = get_qts();
|
|
|
|
int32 applied_update_count = 0;
|
2020-08-03 15:57:30 +02:00
|
|
|
while (!pending_qts_updates_.empty()) {
|
|
|
|
CHECK(!running_get_difference_);
|
|
|
|
auto update_it = pending_qts_updates_.begin();
|
|
|
|
auto qts = update_it->first;
|
2021-08-15 12:52:00 +02:00
|
|
|
auto old_qts = get_qts();
|
2021-08-26 17:05:27 +02:00
|
|
|
if (qts - 1 > old_qts && qts - (1 << 30) <= old_qts) {
|
2021-08-15 12:52:00 +02:00
|
|
|
// the update will be applied later
|
2020-08-03 16:37:08 +02:00
|
|
|
break;
|
2020-08-03 15:57:30 +02:00
|
|
|
}
|
2022-04-13 16:40:12 +02:00
|
|
|
auto promise = PromiseCreator::lambda(
|
|
|
|
[promises = std::move(update_it->second.promises)](Unit) mutable { set_promises(promises); });
|
2022-11-20 20:41:50 +01:00
|
|
|
applied_update_count++;
|
2021-08-15 12:52:00 +02:00
|
|
|
if (qts == old_qts + 1) {
|
2020-12-22 23:58:56 +01:00
|
|
|
process_qts_update(std::move(update_it->second.update), qts, std::move(promise));
|
2020-12-23 00:06:45 +01:00
|
|
|
} else {
|
|
|
|
promise.set_value(Unit());
|
2020-08-03 15:57:30 +02:00
|
|
|
}
|
|
|
|
pending_qts_updates_.erase(update_it);
|
|
|
|
}
|
2021-08-15 12:52:00 +02:00
|
|
|
|
2022-11-20 20:41:50 +01:00
|
|
|
if (applied_update_count > 0) {
|
2020-08-03 15:57:30 +02:00
|
|
|
qts_gap_timeout_.cancel_timeout();
|
2021-08-16 07:38:29 +02:00
|
|
|
}
|
|
|
|
if (!pending_qts_updates_.empty()) {
|
|
|
|
// if still have a gap, reset timeout
|
2021-08-15 11:46:38 +02:00
|
|
|
auto update_it = pending_qts_updates_.begin();
|
|
|
|
double receive_time = update_it->second.receive_time;
|
2021-08-16 11:19:30 +02:00
|
|
|
for (size_t i = 0; i < GAP_TIMEOUT_UPDATE_COUNT; i++) {
|
2021-08-15 11:46:38 +02:00
|
|
|
if (++update_it == pending_qts_updates_.end()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
receive_time = min(receive_time, update_it->second.receive_time);
|
|
|
|
}
|
|
|
|
set_qts_gap_timeout(receive_time + MAX_UNFILLED_GAP_TIME - Time::now());
|
2020-08-03 15:57:30 +02:00
|
|
|
}
|
2021-08-20 16:21:31 +02:00
|
|
|
CHECK(!running_get_difference_);
|
2022-11-20 20:41:50 +01:00
|
|
|
|
|
|
|
auto passed_time = Time::now() - begin_time;
|
|
|
|
if (passed_time >= UPDATE_APPLY_WARNING_TIME) {
|
2022-11-23 14:32:09 +01:00
|
|
|
LOG(WARNING) << "QTS has changed from " << initial_qts << " to " << get_qts() << " after applying "
|
2022-11-20 20:41:50 +01:00
|
|
|
<< applied_update_count << " and keeping " << pending_qts_updates_.size() << " pending updates in "
|
2022-12-10 23:32:46 +01:00
|
|
|
<< passed_time << " seconds";
|
2022-11-20 20:41:50 +01:00
|
|
|
}
|
2020-08-03 15:57:30 +02:00
|
|
|
}
|
|
|
|
|
2021-01-15 23:17:35 +01:00
|
|
|
void UpdatesManager::set_pts_gap_timeout(double timeout) {
|
2021-08-15 10:43:00 +02:00
|
|
|
if (!pts_gap_timeout_.has_timeout() || timeout < pts_gap_timeout_.get_timeout()) {
|
2024-01-26 13:08:16 +01:00
|
|
|
LOG(DEBUG) << "Set PTS gap timeout in " << timeout;
|
2023-04-27 21:01:10 +02:00
|
|
|
if (timeout > 2 * MIN_UNFILLED_GAP_TIME) {
|
|
|
|
min_pts_gap_timeout_.set_callback(std::move(check_pts_gap));
|
|
|
|
min_pts_gap_timeout_.set_callback_data(static_cast<void *>(td_));
|
|
|
|
min_pts_gap_timeout_.set_timeout_in(MIN_UNFILLED_GAP_TIME);
|
|
|
|
}
|
|
|
|
|
2021-01-15 23:17:35 +01:00
|
|
|
pts_gap_timeout_.set_callback(std::move(fill_pts_gap));
|
|
|
|
pts_gap_timeout_.set_callback_data(static_cast<void *>(td_));
|
|
|
|
pts_gap_timeout_.set_timeout_in(timeout);
|
2021-08-15 11:51:57 +02:00
|
|
|
last_pts_gap_time_ = Time::now();
|
2021-01-15 23:17:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void UpdatesManager::set_seq_gap_timeout(double timeout) {
|
2021-08-15 10:43:00 +02:00
|
|
|
if (!seq_gap_timeout_.has_timeout() || timeout < seq_gap_timeout_.get_timeout()) {
|
2024-01-26 13:08:16 +01:00
|
|
|
LOG(DEBUG) << "Set seq gap timeout in " << timeout;
|
2018-12-31 20:04:05 +01:00
|
|
|
seq_gap_timeout_.set_callback(std::move(fill_seq_gap));
|
|
|
|
seq_gap_timeout_.set_callback_data(static_cast<void *>(td_));
|
|
|
|
seq_gap_timeout_.set_timeout_in(timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 15:57:30 +02:00
|
|
|
void UpdatesManager::set_qts_gap_timeout(double timeout) {
|
2021-08-15 10:43:00 +02:00
|
|
|
if (!qts_gap_timeout_.has_timeout() || timeout < qts_gap_timeout_.get_timeout()) {
|
2024-01-26 13:08:16 +01:00
|
|
|
LOG(DEBUG) << "Set QTS gap timeout in " << timeout;
|
2020-08-03 16:37:08 +02:00
|
|
|
qts_gap_timeout_.set_callback(std::move(fill_qts_gap));
|
|
|
|
qts_gap_timeout_.set_callback_data(static_cast<void *>(td_));
|
|
|
|
qts_gap_timeout_.set_timeout_in(timeout);
|
|
|
|
}
|
2020-08-03 15:57:30 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 20:06:52 +01:00
|
|
|
void UpdatesManager::on_pending_update(tl_object_ptr<telegram_api::Update> update, int32 seq, Promise<Unit> &&promise,
|
|
|
|
const char *source) {
|
2020-06-24 13:33:20 +02:00
|
|
|
vector<tl_object_ptr<telegram_api::Update>> updates;
|
|
|
|
updates.push_back(std::move(update));
|
2021-08-15 11:46:38 +02:00
|
|
|
on_pending_updates(std::move(updates), seq, seq, 0, Time::now(), std::move(promise), source);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewMessage> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
int new_pts = update->pts_;
|
|
|
|
int pts_count = update->pts_count_;
|
2021-08-15 11:46:38 +02:00
|
|
|
add_pending_pts_update(std::move(update), new_pts, pts_count, Time::now(), std::move(promise), "updateNewMessage");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewChannelMessage> update, Promise<Unit> &&promise) {
|
2022-12-12 19:43:49 +01:00
|
|
|
DialogId dialog_id = DialogId::get_message_dialog_id(update->message_);
|
2020-12-25 00:53:00 +01:00
|
|
|
int new_pts = update->pts_;
|
|
|
|
int pts_count = update->pts_count_;
|
|
|
|
td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count,
|
|
|
|
std::move(promise), "updateNewChannelMessage");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessageID> update, Promise<Unit> &&promise) {
|
2021-01-15 16:52:41 +01:00
|
|
|
LOG(ERROR) << "Receive not in getDifference and not in on_pending_updates " << to_string(update);
|
2023-08-11 13:07:13 +02:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadMessagesContents> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
int new_pts = update->pts_;
|
|
|
|
int pts_count = update->pts_count_;
|
2021-08-15 11:46:38 +02:00
|
|
|
add_pending_pts_update(std::move(update), new_pts, pts_count, Time::now(), std::move(promise),
|
|
|
|
"updateReadMessagesContents");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEditMessage> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
int new_pts = update->pts_;
|
|
|
|
int pts_count = update->pts_count_;
|
2021-08-15 11:46:38 +02:00
|
|
|
add_pending_pts_update(std::move(update), new_pts, pts_count, Time::now(), std::move(promise), "updateEditMessage");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteMessages> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
int new_pts = update->pts_;
|
|
|
|
int pts_count = update->pts_count_;
|
|
|
|
if (update->messages_.empty()) {
|
2021-08-15 11:46:38 +02:00
|
|
|
add_pending_pts_update(make_tl_object<dummyUpdate>(), new_pts, pts_count, Time::now(), Promise<Unit>(),
|
|
|
|
"updateDeleteMessages");
|
2020-12-24 19:56:15 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2021-08-15 11:46:38 +02:00
|
|
|
add_pending_pts_update(std::move(update), new_pts, pts_count, Time::now(), std::move(promise),
|
|
|
|
"updateDeleteMessages");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadHistoryInbox> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
int new_pts = update->pts_;
|
|
|
|
int pts_count = update->pts_count_;
|
2021-08-15 11:46:38 +02:00
|
|
|
add_pending_pts_update(std::move(update), new_pts, pts_count, Time::now(), std::move(promise),
|
|
|
|
"updateReadHistoryInbox");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadHistoryOutbox> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
int new_pts = update->pts_;
|
|
|
|
int pts_count = update->pts_count_;
|
2021-08-15 11:46:38 +02:00
|
|
|
add_pending_pts_update(std::move(update), new_pts, pts_count, Time::now(), std::move(promise),
|
|
|
|
"updateReadHistoryOutbox");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateServiceNotification> update, Promise<Unit> &&promise) {
|
2019-04-02 21:24:54 +02:00
|
|
|
td_->messages_manager_->on_update_service_notification(std::move(update), true, Promise<Unit>());
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChat> update, Promise<Unit> &&promise) {
|
2024-01-04 17:52:31 +01:00
|
|
|
td_->dialog_manager_->on_dialog_info_full_invalidated(DialogId(ChatId(update->chat_id_)));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2020-12-14 14:52:25 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadChannelInbox> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->messages_manager_->on_update_read_channel_inbox(std::move(update));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadChannelOutbox> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->messages_manager_->on_update_read_channel_outbox(std::move(update));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelReadMessagesContents> update,
|
2021-01-15 17:32:16 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->messages_manager_->on_update_read_channel_messages_contents(std::move(update));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelTooLong> update, Promise<Unit> &&promise) {
|
|
|
|
td_->messages_manager_->on_update_channel_too_long(std::move(update), false);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannel> update, Promise<Unit> &&promise) {
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->invalidate_channel_full(ChannelId(update->channel_id_), false, "updateChannel");
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEditChannelMessage> update, Promise<Unit> &&promise) {
|
2022-12-12 19:43:49 +01:00
|
|
|
DialogId dialog_id = DialogId::get_message_dialog_id(update->message_);
|
2020-12-25 00:53:00 +01:00
|
|
|
int new_pts = update->pts_;
|
|
|
|
int pts_count = update->pts_count_;
|
|
|
|
td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count,
|
|
|
|
std::move(promise), "updateEditChannelMessage");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteChannelMessages> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2020-12-25 00:37:14 +01:00
|
|
|
DialogId dialog_id(ChannelId(update->channel_id_));
|
|
|
|
int new_pts = update->pts_;
|
|
|
|
int pts_count = update->pts_count_;
|
|
|
|
td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count,
|
2020-12-25 00:53:00 +01:00
|
|
|
std::move(promise), "updateDeleteChannelMessages");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelMessageViews> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
ChannelId channel_id(update->channel_id_);
|
|
|
|
if (!channel_id.is_valid()) {
|
|
|
|
LOG(ERROR) << "Receive invalid " << channel_id;
|
2020-12-21 20:06:52 +01:00
|
|
|
} else {
|
|
|
|
DialogId dialog_id(channel_id);
|
|
|
|
td_->messages_manager_->on_update_message_view_count({dialog_id, MessageId(ServerMessageId(update->id_))},
|
|
|
|
update->views_);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2020-07-31 04:50:11 +02:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelMessageForwards> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2020-07-31 04:50:11 +02:00
|
|
|
ChannelId channel_id(update->channel_id_);
|
|
|
|
if (!channel_id.is_valid()) {
|
|
|
|
LOG(ERROR) << "Receive invalid " << channel_id;
|
2020-12-21 20:06:52 +01:00
|
|
|
} else {
|
|
|
|
DialogId dialog_id(channel_id);
|
|
|
|
td_->messages_manager_->on_update_message_forward_count({dialog_id, MessageId(ServerMessageId(update->id_))},
|
|
|
|
update->forwards_);
|
2020-07-31 04:50:11 +02:00
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelAvailableMessages> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->messages_manager_->on_update_channel_max_unavailable_message_id(
|
2023-07-22 21:40:26 +02:00
|
|
|
ChannelId(update->channel_id_), MessageId(ServerMessageId(update->available_min_id_)),
|
|
|
|
"updateChannelAvailableMessages");
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2023-11-16 15:11:36 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelViewForumAsMessages> update,
|
|
|
|
Promise<Unit> &&promise) {
|
|
|
|
td_->messages_manager_->on_update_dialog_view_as_messages(DialogId(ChannelId(update->channel_id_)), update->enabled_);
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2020-09-18 17:32:59 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadChannelDiscussionInbox> update,
|
2021-01-15 17:32:16 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2022-11-19 09:21:41 +01:00
|
|
|
auto last_read_inbox_message_id = MessageId(ServerMessageId(update->read_max_id_));
|
|
|
|
if (!last_read_inbox_message_id.is_valid()) {
|
|
|
|
LOG(ERROR) << "Receive " << to_string(update);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
td_->messages_manager_->on_update_read_message_comments(DialogId(ChannelId(update->channel_id_)),
|
|
|
|
MessageId(ServerMessageId(update->top_msg_id_)), MessageId(),
|
2022-12-14 12:25:04 +01:00
|
|
|
last_read_inbox_message_id, MessageId(), -1);
|
2020-09-19 21:01:28 +02:00
|
|
|
if ((update->flags_ & telegram_api::updateReadChannelDiscussionInbox::BROADCAST_ID_MASK) != 0) {
|
2022-11-19 09:21:41 +01:00
|
|
|
td_->messages_manager_->on_update_read_message_comments(DialogId(ChannelId(update->broadcast_id_)),
|
|
|
|
MessageId(ServerMessageId(update->broadcast_post_)),
|
2022-12-14 12:25:04 +01:00
|
|
|
MessageId(), last_read_inbox_message_id, MessageId(), -1);
|
2020-09-19 21:01:28 +02:00
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2020-09-18 17:32:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadChannelDiscussionOutbox> update,
|
2021-01-15 17:32:16 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2022-11-19 09:21:41 +01:00
|
|
|
auto last_read_outbox_message_id = MessageId(ServerMessageId(update->read_max_id_));
|
|
|
|
if (!last_read_outbox_message_id.is_valid()) {
|
|
|
|
LOG(ERROR) << "Receive " << to_string(update);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
td_->messages_manager_->on_update_read_message_comments(DialogId(ChannelId(update->channel_id_)),
|
|
|
|
MessageId(ServerMessageId(update->top_msg_id_)), MessageId(),
|
2022-12-14 12:25:04 +01:00
|
|
|
MessageId(), last_read_outbox_message_id, -1);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2020-09-18 17:32:59 +02:00
|
|
|
}
|
|
|
|
|
2022-12-29 23:06:05 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelPinnedTopic> update, Promise<Unit> &&promise) {
|
|
|
|
td_->forum_topic_manager_->on_update_forum_topic_is_pinned(
|
|
|
|
DialogId(ChannelId(update->channel_id_)), MessageId(ServerMessageId(update->topic_id_)), update->pinned_);
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelPinnedTopics> update, Promise<Unit> &&promise) {
|
|
|
|
vector<MessageId> top_thread_message_ids;
|
|
|
|
for (auto &server_message_id : update->order_) {
|
|
|
|
auto message_id = MessageId(ServerMessageId(server_message_id));
|
|
|
|
if (!message_id.is_valid()) {
|
|
|
|
LOG(ERROR) << "Receive " << to_string(update);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
top_thread_message_ids.push_back(message_id);
|
|
|
|
}
|
|
|
|
td_->forum_topic_manager_->on_update_pinned_forum_topics(DialogId(ChannelId(update->channel_id_)),
|
|
|
|
std::move(top_thread_message_ids));
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePinnedMessages> update, Promise<Unit> &&promise) {
|
2020-10-20 14:08:36 +02:00
|
|
|
int new_pts = update->pts_;
|
|
|
|
int pts_count = update->pts_count_;
|
2021-08-15 11:46:38 +02:00
|
|
|
add_pending_pts_update(std::move(update), new_pts, pts_count, Time::now(), std::move(promise),
|
|
|
|
"updatePinnedMessages");
|
2019-02-01 13:19:32 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePinnedChannelMessages> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2020-12-25 00:37:14 +01:00
|
|
|
DialogId dialog_id(ChannelId(update->channel_id_));
|
|
|
|
int new_pts = update->pts_;
|
|
|
|
int pts_count = update->pts_count_;
|
|
|
|
td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count,
|
2020-12-25 00:53:00 +01:00
|
|
|
std::move(promise), "updatePinnedChannelMessages");
|
2019-02-01 13:19:32 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNotifySettings> update, Promise<Unit> &&promise) {
|
2018-04-09 18:30:27 +02:00
|
|
|
switch (update->peer_->get_id()) {
|
|
|
|
case telegram_api::notifyPeer::ID: {
|
2022-12-06 14:48:32 +01:00
|
|
|
auto notify_peer = static_cast<const telegram_api::notifyPeer *>(update->peer_.get());
|
|
|
|
DialogId dialog_id(notify_peer->peer_);
|
2018-04-09 18:30:27 +02:00
|
|
|
if (dialog_id.is_valid()) {
|
2019-02-20 02:30:22 +01:00
|
|
|
td_->messages_manager_->on_update_dialog_notify_settings(dialog_id, std::move(update->notify_settings_),
|
|
|
|
"updateNotifySettings");
|
2018-04-09 18:30:27 +02:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive wrong " << to_string(update);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::notifyUsers::ID:
|
2022-04-11 11:45:52 +02:00
|
|
|
td_->notification_settings_manager_->on_update_scope_notify_settings(NotificationSettingsScope::Private,
|
|
|
|
std::move(update->notify_settings_));
|
2020-12-21 20:06:52 +01:00
|
|
|
break;
|
2018-04-09 18:30:27 +02:00
|
|
|
case telegram_api::notifyChats::ID:
|
2022-04-11 11:45:52 +02:00
|
|
|
td_->notification_settings_manager_->on_update_scope_notify_settings(NotificationSettingsScope::Group,
|
|
|
|
std::move(update->notify_settings_));
|
2020-12-21 20:06:52 +01:00
|
|
|
break;
|
2019-01-29 12:40:56 +01:00
|
|
|
case telegram_api::notifyBroadcasts::ID:
|
2022-04-11 11:45:52 +02:00
|
|
|
td_->notification_settings_manager_->on_update_scope_notify_settings(NotificationSettingsScope::Channel,
|
|
|
|
std::move(update->notify_settings_));
|
2020-12-21 20:06:52 +01:00
|
|
|
break;
|
2022-12-06 14:48:32 +01:00
|
|
|
case telegram_api::notifyForumTopic::ID: {
|
|
|
|
auto notify_peer = static_cast<const telegram_api::notifyForumTopic *>(update->peer_.get());
|
|
|
|
DialogId dialog_id(notify_peer->peer_);
|
|
|
|
auto top_thread_message_id = MessageId(ServerMessageId(notify_peer->top_msg_id_));
|
|
|
|
if (dialog_id.is_valid() && top_thread_message_id.is_valid()) {
|
|
|
|
td_->forum_topic_manager_->on_update_forum_topic_notify_settings(
|
|
|
|
dialog_id, top_thread_message_id, std::move(update->notify_settings_), "updateNotifySettings");
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive wrong " << to_string(update);
|
|
|
|
}
|
2022-10-07 17:04:00 +02:00
|
|
|
break;
|
2022-12-06 14:48:32 +01:00
|
|
|
}
|
2018-04-09 18:30:27 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePeerSettings> update, Promise<Unit> &&promise) {
|
2019-10-10 18:07:49 +02:00
|
|
|
td_->messages_manager_->on_get_peer_settings(DialogId(update->peer_), std::move(update->settings_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2019-10-10 18:07:49 +02:00
|
|
|
}
|
|
|
|
|
2021-02-09 15:35:48 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePeerHistoryTTL> update, Promise<Unit> &&promise) {
|
2022-12-18 20:15:57 +01:00
|
|
|
td_->messages_manager_->on_update_dialog_message_ttl(DialogId(update->peer_), MessageTtl(update->ttl_period_));
|
2021-02-09 15:35:48 +01:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePeerLocated> update, Promise<Unit> &&promise) {
|
2024-03-10 23:42:08 +01:00
|
|
|
td_->people_nearby_manager_->on_update_peer_located(std::move(update->peers_), true);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2019-10-16 20:55:16 +02:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateWebPage> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->web_pages_manager_->on_get_web_page(std::move(update->webpage_), DialogId());
|
2021-08-15 11:46:38 +02:00
|
|
|
add_pending_pts_update(make_tl_object<dummyUpdate>(), update->pts_, update->pts_count_, Time::now(), Promise<Unit>(),
|
2021-01-15 23:17:35 +01:00
|
|
|
"updateWebPage");
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelWebPage> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->web_pages_manager_->on_get_web_page(std::move(update->webpage_), DialogId());
|
2020-12-25 00:37:14 +01:00
|
|
|
DialogId dialog_id(ChannelId(update->channel_id_));
|
|
|
|
td_->messages_manager_->add_pending_channel_update(dialog_id, make_tl_object<dummyUpdate>(), update->pts_,
|
2020-12-25 00:53:00 +01:00
|
|
|
update->pts_count_, Promise<Unit>(), "updateChannelWebPage");
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-01-21 09:53:18 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessageReactions> update, Promise<Unit> &&promise) {
|
|
|
|
td_->messages_manager_->on_update_message_reactions(
|
2022-02-08 16:48:09 +01:00
|
|
|
{DialogId(update->peer_), MessageId(ServerMessageId(update->msg_id_))}, std::move(update->reactions_),
|
|
|
|
std::move(promise));
|
2022-01-21 09:53:18 +01:00
|
|
|
}
|
|
|
|
|
2022-09-12 18:52:08 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateRecentReactions> update, Promise<Unit> &&promise) {
|
2024-03-22 13:57:46 +01:00
|
|
|
td_->reaction_manager_->reload_reaction_list(ReactionListType::Recent, "updateRecentReactions");
|
2022-09-12 18:52:08 +02:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2024-01-23 14:39:15 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateSavedReactionTags> update, Promise<Unit> &&promise) {
|
2024-01-23 17:04:31 +01:00
|
|
|
td_->reaction_manager_->on_update_saved_reaction_tags(Promise<Unit>());
|
2024-01-23 14:39:15 +01:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2022-03-25 14:00:06 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateAttachMenuBots> update, Promise<Unit> &&promise) {
|
2022-03-29 14:42:57 +02:00
|
|
|
td_->attach_menu_manager_->reload_attach_menu_bots(std::move(promise));
|
2022-03-25 14:00:06 +01:00
|
|
|
}
|
|
|
|
|
2022-03-31 21:02:19 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateWebViewResultSent> update, Promise<Unit> &&promise) {
|
|
|
|
td_->attach_menu_manager_->close_web_view(update->query_id_, std::move(promise));
|
|
|
|
send_closure(G()->td(), &Td::send_update, td_api::make_object<td_api::updateWebAppMessageSent>(update->query_id_));
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateFolderPeers> update, Promise<Unit> &&promise) {
|
2019-08-27 16:54:09 +02:00
|
|
|
for (auto &folder_peer : update->folder_peers_) {
|
|
|
|
DialogId dialog_id(folder_peer->peer_);
|
|
|
|
FolderId folder_id(folder_peer->folder_id_);
|
|
|
|
td_->messages_manager_->on_update_dialog_folder_id(dialog_id, folder_id);
|
|
|
|
}
|
|
|
|
|
2021-01-11 23:46:13 +01:00
|
|
|
if (update->pts_ > 0) {
|
2021-08-15 11:46:38 +02:00
|
|
|
add_pending_pts_update(make_tl_object<dummyUpdate>(), update->pts_, update->pts_count_, Time::now(),
|
|
|
|
Promise<Unit>(), "updateFolderPeers");
|
2021-01-11 23:46:13 +01:00
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2019-08-27 16:54:09 +02:00
|
|
|
}
|
|
|
|
|
2019-03-15 01:16:44 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-01-05 14:06:51 +01:00
|
|
|
bool UpdatesManager::have_update_pts_changed(const vector<tl_object_ptr<telegram_api::Update>> &updates) {
|
|
|
|
for (auto &update : updates) {
|
|
|
|
CHECK(update != nullptr);
|
|
|
|
if (update->get_id() == telegram_api::updatePtsChanged::ID) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-15 21:39:34 +01:00
|
|
|
bool UpdatesManager::check_pts_update_dialog_id(DialogId dialog_id) {
|
|
|
|
switch (dialog_id.get_type()) {
|
|
|
|
case DialogType::User:
|
|
|
|
case DialogType::Chat:
|
|
|
|
return true;
|
|
|
|
case DialogType::Channel:
|
|
|
|
case DialogType::SecretChat:
|
|
|
|
case DialogType::None:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UpdatesManager::check_pts_update(const tl_object_ptr<telegram_api::Update> &update) {
|
|
|
|
CHECK(update != nullptr);
|
|
|
|
switch (update->get_id()) {
|
|
|
|
case dummyUpdate::ID:
|
|
|
|
case updateSentMessage::ID:
|
|
|
|
case telegram_api::updateReadMessagesContents::ID:
|
|
|
|
case telegram_api::updateDeleteMessages::ID:
|
|
|
|
return true;
|
|
|
|
case telegram_api::updateNewMessage::ID: {
|
|
|
|
auto update_new_message = static_cast<const telegram_api::updateNewMessage *>(update.get());
|
2022-12-12 19:43:49 +01:00
|
|
|
return check_pts_update_dialog_id(DialogId::get_message_dialog_id(update_new_message->message_));
|
2021-01-15 21:39:34 +01:00
|
|
|
}
|
|
|
|
case telegram_api::updateReadHistoryInbox::ID: {
|
|
|
|
auto update_read_history_inbox = static_cast<const telegram_api::updateReadHistoryInbox *>(update.get());
|
|
|
|
return check_pts_update_dialog_id(DialogId(update_read_history_inbox->peer_));
|
|
|
|
}
|
|
|
|
case telegram_api::updateReadHistoryOutbox::ID: {
|
|
|
|
auto update_read_history_outbox = static_cast<const telegram_api::updateReadHistoryOutbox *>(update.get());
|
|
|
|
return check_pts_update_dialog_id(DialogId(update_read_history_outbox->peer_));
|
|
|
|
}
|
|
|
|
case telegram_api::updateEditMessage::ID: {
|
|
|
|
auto update_edit_message = static_cast<const telegram_api::updateEditMessage *>(update.get());
|
2022-12-12 19:43:49 +01:00
|
|
|
return check_pts_update_dialog_id(DialogId::get_message_dialog_id(update_edit_message->message_));
|
2021-01-15 21:39:34 +01:00
|
|
|
}
|
|
|
|
case telegram_api::updatePinnedMessages::ID: {
|
|
|
|
auto update_pinned_messages = static_cast<const telegram_api::updatePinnedMessages *>(update.get());
|
|
|
|
return check_pts_update_dialog_id(DialogId(update_pinned_messages->peer_));
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-11 21:58:03 +01:00
|
|
|
bool UpdatesManager::is_pts_update(const telegram_api::Update *update) {
|
|
|
|
switch (update->get_id()) {
|
|
|
|
case telegram_api::updateNewMessage::ID:
|
|
|
|
case telegram_api::updateReadMessagesContents::ID:
|
|
|
|
case telegram_api::updateEditMessage::ID:
|
|
|
|
case telegram_api::updateDeleteMessages::ID:
|
|
|
|
case telegram_api::updateReadHistoryInbox::ID:
|
|
|
|
case telegram_api::updateReadHistoryOutbox::ID:
|
|
|
|
case telegram_api::updateWebPage::ID:
|
|
|
|
case telegram_api::updatePinnedMessages::ID:
|
|
|
|
case telegram_api::updateFolderPeers::ID:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-05 10:41:35 +01:00
|
|
|
int32 UpdatesManager::get_update_pts(const telegram_api::Update *update) {
|
|
|
|
switch (update->get_id()) {
|
|
|
|
case telegram_api::updateNewMessage::ID:
|
|
|
|
return static_cast<const telegram_api::updateNewMessage *>(update)->pts_;
|
|
|
|
case telegram_api::updateReadMessagesContents::ID:
|
|
|
|
return static_cast<const telegram_api::updateReadMessagesContents *>(update)->pts_;
|
|
|
|
case telegram_api::updateEditMessage::ID:
|
|
|
|
return static_cast<const telegram_api::updateEditMessage *>(update)->pts_;
|
|
|
|
case telegram_api::updateDeleteMessages::ID:
|
|
|
|
return static_cast<const telegram_api::updateDeleteMessages *>(update)->pts_;
|
|
|
|
case telegram_api::updateReadHistoryInbox::ID:
|
|
|
|
return static_cast<const telegram_api::updateReadHistoryInbox *>(update)->pts_;
|
|
|
|
case telegram_api::updateReadHistoryOutbox::ID:
|
|
|
|
return static_cast<const telegram_api::updateReadHistoryOutbox *>(update)->pts_;
|
|
|
|
case telegram_api::updateWebPage::ID:
|
|
|
|
return static_cast<const telegram_api::updateWebPage *>(update)->pts_;
|
|
|
|
case telegram_api::updatePinnedMessages::ID:
|
|
|
|
return static_cast<const telegram_api::updatePinnedMessages *>(update)->pts_;
|
2021-01-11 21:14:41 +01:00
|
|
|
case telegram_api::updateFolderPeers::ID:
|
|
|
|
return static_cast<const telegram_api::updateFolderPeers *>(update)->pts_;
|
2021-01-05 10:41:35 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-11 21:58:03 +01:00
|
|
|
bool UpdatesManager::is_qts_update(const telegram_api::Update *update) {
|
|
|
|
switch (update->get_id()) {
|
|
|
|
case telegram_api::updateNewEncryptedMessage::ID:
|
2021-05-18 18:33:18 +02:00
|
|
|
case telegram_api::updateMessagePollVote::ID:
|
2021-02-19 00:16:50 +01:00
|
|
|
case telegram_api::updateBotStopped::ID:
|
|
|
|
case telegram_api::updateChatParticipant::ID:
|
2021-01-11 21:58:03 +01:00
|
|
|
case telegram_api::updateChannelParticipant::ID:
|
2021-10-28 21:49:56 +02:00
|
|
|
case telegram_api::updateBotChatInviteRequester::ID:
|
2023-10-30 22:18:38 +01:00
|
|
|
case telegram_api::updateBotChatBoost::ID:
|
2023-12-14 17:55:53 +01:00
|
|
|
case telegram_api::updateBotMessageReaction::ID:
|
2023-12-14 21:44:31 +01:00
|
|
|
case telegram_api::updateBotMessageReactions::ID:
|
2024-03-07 14:41:30 +01:00
|
|
|
case telegram_api::updateBotBusinessConnect::ID:
|
|
|
|
case telegram_api::updateBotNewBusinessMessage::ID:
|
|
|
|
case telegram_api::updateBotEditBusinessMessage::ID:
|
|
|
|
case telegram_api::updateBotDeleteBusinessMessage::ID:
|
2021-01-11 21:58:03 +01:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-05 10:41:35 +01:00
|
|
|
int32 UpdatesManager::get_update_qts(const telegram_api::Update *update) {
|
|
|
|
switch (update->get_id()) {
|
|
|
|
case telegram_api::updateNewEncryptedMessage::ID:
|
|
|
|
return static_cast<const telegram_api::updateNewEncryptedMessage *>(update)->qts_;
|
2021-05-18 18:33:18 +02:00
|
|
|
case telegram_api::updateMessagePollVote::ID:
|
|
|
|
return static_cast<const telegram_api::updateMessagePollVote *>(update)->qts_;
|
2021-02-19 00:16:50 +01:00
|
|
|
case telegram_api::updateBotStopped::ID:
|
|
|
|
return static_cast<const telegram_api::updateBotStopped *>(update)->qts_;
|
|
|
|
case telegram_api::updateChatParticipant::ID:
|
|
|
|
return static_cast<const telegram_api::updateChatParticipant *>(update)->qts_;
|
2021-01-05 10:41:35 +01:00
|
|
|
case telegram_api::updateChannelParticipant::ID:
|
|
|
|
return static_cast<const telegram_api::updateChannelParticipant *>(update)->qts_;
|
2021-10-28 21:49:56 +02:00
|
|
|
case telegram_api::updateBotChatInviteRequester::ID:
|
|
|
|
return static_cast<const telegram_api::updateBotChatInviteRequester *>(update)->qts_;
|
2023-10-30 22:18:38 +01:00
|
|
|
case telegram_api::updateBotChatBoost::ID:
|
|
|
|
return static_cast<const telegram_api::updateBotChatBoost *>(update)->qts_;
|
2023-12-14 17:55:53 +01:00
|
|
|
case telegram_api::updateBotMessageReaction::ID:
|
|
|
|
return static_cast<const telegram_api::updateBotMessageReaction *>(update)->qts_;
|
2023-12-14 21:44:31 +01:00
|
|
|
case telegram_api::updateBotMessageReactions::ID:
|
|
|
|
return static_cast<const telegram_api::updateBotMessageReactions *>(update)->qts_;
|
2024-03-07 14:41:30 +01:00
|
|
|
case telegram_api::updateBotBusinessConnect::ID:
|
|
|
|
return static_cast<const telegram_api::updateBotBusinessConnect *>(update)->qts_;
|
|
|
|
case telegram_api::updateBotNewBusinessMessage::ID:
|
|
|
|
return static_cast<const telegram_api::updateBotNewBusinessMessage *>(update)->qts_;
|
|
|
|
case telegram_api::updateBotEditBusinessMessage::ID:
|
|
|
|
return static_cast<const telegram_api::updateBotEditBusinessMessage *>(update)->qts_;
|
|
|
|
case telegram_api::updateBotDeleteBusinessMessage::ID:
|
|
|
|
return static_cast<const telegram_api::updateBotDeleteBusinessMessage *>(update)->qts_;
|
2021-01-05 10:41:35 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-28 15:39:32 +02:00
|
|
|
bool UpdatesManager::is_channel_pts_update(const telegram_api::Update *update) {
|
|
|
|
switch (update->get_id()) {
|
|
|
|
case telegram_api::updateNewChannelMessage::ID:
|
|
|
|
case telegram_api::updateEditChannelMessage::ID:
|
|
|
|
case telegram_api::updateDeleteChannelMessages::ID:
|
|
|
|
case telegram_api::updatePinnedChannelMessages::ID:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateUserTyping> update, Promise<Unit> &&promise) {
|
2021-03-02 15:27:44 +01:00
|
|
|
DialogId dialog_id(UserId(update->user_id_));
|
2024-01-06 22:46:36 +01:00
|
|
|
td_->dialog_action_manager_->on_dialog_action(dialog_id, MessageId(), dialog_id,
|
|
|
|
DialogAction(std::move(update->action_)), get_short_update_date());
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatUserTyping> update, Promise<Unit> &&promise) {
|
2024-01-06 22:46:36 +01:00
|
|
|
td_->dialog_action_manager_->on_dialog_action(DialogId(ChatId(update->chat_id_)), MessageId(),
|
|
|
|
DialogId(update->from_id_), DialogAction(std::move(update->action_)),
|
|
|
|
get_short_update_date());
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2020-09-18 17:32:59 +02:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelUserTyping> update, Promise<Unit> &&promise) {
|
2024-01-06 22:46:36 +01:00
|
|
|
td_->dialog_action_manager_->on_dialog_action(
|
|
|
|
DialogId(ChannelId(update->channel_id_)), MessageId(ServerMessageId(update->top_msg_id_)),
|
|
|
|
DialogId(update->from_id_), DialogAction(std::move(update->action_)), get_short_update_date());
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEncryptedChatTyping> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
SecretChatId secret_chat_id(update->chat_id_);
|
2024-04-02 02:52:34 +02:00
|
|
|
UserId user_id = td_->user_manager_->get_secret_chat_user_id(secret_chat_id);
|
2024-01-06 22:46:36 +01:00
|
|
|
td_->dialog_action_manager_->on_dialog_action(DialogId(secret_chat_id), MessageId(), DialogId(user_id),
|
|
|
|
DialogAction::get_typing_action(), get_short_update_date());
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateUserStatus> update, Promise<Unit> &&promise) {
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_update_user_online(UserId(update->user_id_), std::move(update->status_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateUserName> update, Promise<Unit> &&promise) {
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_update_user_name(UserId(update->user_id_), std::move(update->first_name_),
|
|
|
|
std::move(update->last_name_),
|
|
|
|
Usernames{string(), std::move(update->usernames_)});
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateUserPhone> update, Promise<Unit> &&promise) {
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_update_user_phone_number(UserId(update->user_id_), std::move(update->phone_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-12-08 18:58:37 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateUser> update, Promise<Unit> &&promise) {
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->invalidate_user_full(UserId(update->user_id_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-08-23 17:14:46 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateUserEmojiStatus> update, Promise<Unit> &&promise) {
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_update_user_emoji_status(UserId(update->user_id_), std::move(update->emoji_status_));
|
2022-08-23 17:14:46 +02:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2022-08-31 15:56:40 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateRecentEmojiStatuses> update, Promise<Unit> &&promise) {
|
|
|
|
get_recent_emoji_statuses(td_, Auto());
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePeerBlocked> update, Promise<Unit> &&promise) {
|
2023-07-28 15:19:05 +02:00
|
|
|
td_->messages_manager_->on_update_dialog_is_blocked(DialogId(update->peer_id_), update->blocked_,
|
|
|
|
update->blocked_my_stories_from_);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-06-28 14:55:11 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotCommands> update, Promise<Unit> &&promise) {
|
2024-03-09 21:35:12 +01:00
|
|
|
td_->dialog_manager_->on_update_dialog_bot_commands(DialogId(update->peer_), UserId(update->bot_id_),
|
|
|
|
std::move(update->commands_));
|
2021-06-28 14:55:11 +02:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2022-03-18 12:46:01 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotMenuButton> update, Promise<Unit> &&promise) {
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_update_bot_menu_button(UserId(update->bot_id_), std::move(update->button_));
|
2022-03-18 12:46:01 +01:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatParticipants> update, Promise<Unit> &&promise) {
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->on_get_chat_participants(std::move(update->participants_), true);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatParticipantAdd> update, Promise<Unit> &&promise) {
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->on_update_chat_add_user(ChatId(update->chat_id_), UserId(update->inviter_id_),
|
|
|
|
UserId(update->user_id_), update->date_, update->version_);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatParticipantAdmin> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->on_update_chat_edit_administrator(ChatId(update->chat_id_), UserId(update->user_id_),
|
|
|
|
update->is_admin_, update->version_);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatParticipantDelete> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->on_update_chat_delete_user(ChatId(update->chat_id_), UserId(update->user_id_), update->version_);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatDefaultBannedRights> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2019-03-20 14:32:27 +01:00
|
|
|
DialogId dialog_id(update->peer_);
|
|
|
|
auto version = update->version_;
|
|
|
|
switch (dialog_id.get_type()) {
|
2020-12-21 20:06:52 +01:00
|
|
|
case DialogType::Chat:
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->on_update_chat_default_permissions(
|
2023-10-19 21:37:44 +02:00
|
|
|
dialog_id.get_chat_id(), RestrictedRights(update->default_banned_rights_, ChannelType::Unknown), version);
|
2020-12-21 20:06:52 +01:00
|
|
|
break;
|
|
|
|
case DialogType::Channel:
|
|
|
|
LOG_IF(ERROR, version != 0) << "Receive version " << version << " in " << dialog_id;
|
2024-04-02 12:06:22 +02:00
|
|
|
td_->chat_manager_->on_update_channel_default_permissions(
|
2023-10-19 21:37:44 +02:00
|
|
|
dialog_id.get_channel_id(), RestrictedRights(update->default_banned_rights_, ChannelType::Megagroup));
|
2020-12-21 20:06:52 +01:00
|
|
|
break;
|
2019-03-20 14:32:27 +01:00
|
|
|
case DialogType::None:
|
|
|
|
case DialogType::User:
|
|
|
|
case DialogType::SecretChat:
|
|
|
|
default:
|
2021-05-17 14:21:11 +02:00
|
|
|
LOG(ERROR) << "Receive updateChatDefaultBannedRights in " << dialog_id;
|
2020-12-21 20:06:52 +01:00
|
|
|
break;
|
2019-03-20 14:32:27 +01:00
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2019-03-20 14:32:27 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDraftMessage> update, Promise<Unit> &&promise) {
|
2022-12-18 20:15:57 +01:00
|
|
|
td_->messages_manager_->on_update_dialog_draft_message(
|
|
|
|
DialogId(update->peer_), MessageId(ServerMessageId(update->top_msg_id_)), std::move(update->draft_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDialogPinned> update, Promise<Unit> &&promise) {
|
2021-11-01 19:53:23 +01:00
|
|
|
td_->messages_manager_->on_update_dialog_is_pinned(FolderId(update->folder_id_), DialogId(update->peer_),
|
|
|
|
update->pinned_);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePinnedDialogs> update, Promise<Unit> &&promise) {
|
2022-12-18 20:15:57 +01:00
|
|
|
td_->messages_manager_->on_update_pinned_dialogs(FolderId(update->folder_id_)); // TODO use update->order_
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2024-01-18 16:51:34 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateSavedDialogPinned> update, Promise<Unit> &&promise) {
|
2024-02-06 13:12:03 +01:00
|
|
|
td_->saved_messages_manager_->reload_pinned_saved_messages_topics();
|
2024-01-18 16:51:34 +01:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePinnedSavedDialogs> update, Promise<Unit> &&promise) {
|
2024-02-06 13:12:03 +01:00
|
|
|
td_->saved_messages_manager_->reload_pinned_saved_messages_topics();
|
2024-01-18 16:51:34 +01:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDialogUnreadMark> update, Promise<Unit> &&promise) {
|
2021-11-01 19:53:23 +01:00
|
|
|
td_->messages_manager_->on_update_dialog_is_marked_as_unread(DialogId(update->peer_), update->unread_);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-06-25 23:10:53 +02:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDialogFilter> update, Promise<Unit> &&promise) {
|
2023-04-02 10:53:25 +02:00
|
|
|
td_->dialog_filter_manager_->on_update_dialog_filters(std::move(promise));
|
2020-05-15 01:14:06 +02:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDialogFilters> update, Promise<Unit> &&promise) {
|
2023-04-02 10:53:25 +02:00
|
|
|
td_->dialog_filter_manager_->on_update_dialog_filters(std::move(promise));
|
2020-05-15 00:44:52 +02:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDialogFilterOrder> update, Promise<Unit> &&promise) {
|
2023-04-02 10:53:25 +02:00
|
|
|
td_->dialog_filter_manager_->on_update_dialog_filters(std::move(promise));
|
2020-05-15 01:14:06 +02:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDcOptions> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(G()->config_manager(), &ConfigManager::on_dc_options_update, DcOptions(update->dc_options_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotInlineQuery> update, Promise<Unit> &&promise) {
|
2023-06-28 18:01:00 +02:00
|
|
|
td_->inline_queries_manager_->on_new_query(update->query_id_, UserId(update->user_id_), Location(td_, update->geo_),
|
2020-12-07 21:08:18 +01:00
|
|
|
std::move(update->peer_type_), update->query_, update->offset_);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotInlineSend> update, Promise<Unit> &&promise) {
|
2023-06-28 18:01:00 +02:00
|
|
|
td_->inline_queries_manager_->on_chosen_result(UserId(update->user_id_), Location(td_, update->geo_), update->query_,
|
2018-12-31 20:04:05 +01:00
|
|
|
update->id_, std::move(update->msg_id_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotCallbackQuery> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->callback_queries_manager_->on_new_query(update->flags_, update->query_id_, UserId(update->user_id_),
|
|
|
|
DialogId(update->peer_), MessageId(ServerMessageId(update->msg_id_)),
|
|
|
|
std::move(update->data_), update->chat_instance_,
|
|
|
|
std::move(update->game_short_name_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateInlineBotCallbackQuery> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->callback_queries_manager_->on_new_inline_query(update->flags_, update->query_id_, UserId(update->user_id_),
|
|
|
|
std::move(update->msg_id_), std::move(update->data_),
|
|
|
|
update->chat_instance_, std::move(update->game_short_name_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateFavedStickers> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->stickers_manager_->reload_favorite_stickers(true);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateSavedGifs> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->animations_manager_->reload_saved_animations(true);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateConfig> update, Promise<Unit> &&promise) {
|
2022-06-06 19:36:15 +02:00
|
|
|
send_closure(td_->config_manager_, &ConfigManager::request_config, false);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePtsChanged> update, Promise<Unit> &&promise) {
|
2023-07-11 15:10:56 +02:00
|
|
|
if (td_->option_manager_->get_option_integer("session_count") > 1) {
|
|
|
|
auto old_pts = get_pts();
|
|
|
|
auto new_pts = 1;
|
|
|
|
if (old_pts != new_pts) {
|
|
|
|
LOG(WARNING) << "PTS changes from " << old_pts << " from updatePtsChanged";
|
|
|
|
save_pts(new_pts);
|
|
|
|
add_pts(new_pts).set_value(Unit());
|
|
|
|
get_difference("updatePtsChanged");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set_pts(std::numeric_limits<int32>::max(), "updatePtsChanged").set_value(Unit());
|
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEncryption> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(td_->secret_chats_manager_, &SecretChatsManager::on_update_chat, std::move(update));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewEncryptedMessage> update, Promise<Unit> &&promise) {
|
2020-08-03 15:57:30 +02:00
|
|
|
auto qts = update->qts_;
|
2020-12-21 20:06:52 +01:00
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEncryptedMessagesRead> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->messages_manager_->read_secret_chat_outbox(SecretChatId(update->chat_id_), update->max_date_, update->date_);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePrivacy> update, Promise<Unit> &&promise) {
|
2023-05-08 14:23:57 +02:00
|
|
|
td_->privacy_manager_->on_update_privacy(std::move(update));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewStickerSet> update, Promise<Unit> &&promise) {
|
2019-12-29 02:59:34 +01:00
|
|
|
td_->stickers_manager_->on_get_messages_sticker_set(StickerSetId(), std::move(update->stickerset_), true,
|
|
|
|
"updateNewStickerSet");
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStickerSets> update, Promise<Unit> &&promise) {
|
2022-09-02 17:18:18 +02:00
|
|
|
auto sticker_type = get_sticker_type(update->masks_, update->emojis_);
|
2022-08-23 17:24:21 +02:00
|
|
|
td_->stickers_manager_->on_update_sticker_sets(sticker_type);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStickerSetsOrder> update, Promise<Unit> &&promise) {
|
2022-09-02 17:18:18 +02:00
|
|
|
auto sticker_type = get_sticker_type(update->masks_, update->emojis_);
|
2022-07-14 15:17:19 +02:00
|
|
|
td_->stickers_manager_->on_update_sticker_sets_order(sticker_type,
|
2019-09-18 05:55:43 +02:00
|
|
|
StickersManager::convert_sticker_set_ids(update->order_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-09-02 17:35:57 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMoveStickerSetToTop> update, Promise<Unit> &&promise) {
|
|
|
|
auto sticker_type = get_sticker_type(update->masks_, update->emojis_);
|
|
|
|
td_->stickers_manager_->on_update_move_sticker_set_to_top(sticker_type, StickerSetId(update->stickerset_));
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadFeaturedStickers> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2022-07-17 21:39:22 +02:00
|
|
|
td_->stickers_manager_->reload_featured_sticker_sets(StickerType::Regular, true);
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadFeaturedEmojiStickers> update,
|
|
|
|
Promise<Unit> &&promise) {
|
2022-07-19 13:51:29 +02:00
|
|
|
td_->stickers_manager_->reload_featured_sticker_sets(StickerType::CustomEmoji, true);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateRecentStickers> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
td_->stickers_manager_->reload_recent_stickers(false, true);
|
|
|
|
td_->stickers_manager_->reload_recent_stickers(true, true);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotShippingQuery> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
UserId user_id(update->user_id_);
|
|
|
|
if (!user_id.is_valid()) {
|
|
|
|
LOG(ERROR) << "Receive shipping query from invalid " << user_id;
|
2020-12-21 20:06:52 +01:00
|
|
|
} else {
|
|
|
|
CHECK(update->shipping_address_ != nullptr);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-12-21 20:06:52 +01:00
|
|
|
send_closure(
|
|
|
|
G()->td(), &Td::send_update,
|
|
|
|
make_tl_object<td_api::updateNewShippingQuery>(
|
2024-04-02 02:52:34 +02:00
|
|
|
update->query_id_, td_->user_manager_->get_user_id_object(user_id, "updateNewShippingQuery"),
|
2020-12-21 20:06:52 +01:00
|
|
|
update->payload_.as_slice().str(),
|
|
|
|
get_address_object(get_address(std::move(update->shipping_address_))))); // TODO use convert_address
|
|
|
|
}
|
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotPrecheckoutQuery> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
UserId user_id(update->user_id_);
|
|
|
|
if (!user_id.is_valid()) {
|
|
|
|
LOG(ERROR) << "Receive pre-checkout query from invalid " << user_id;
|
2022-07-30 02:58:46 +02:00
|
|
|
} else if (update->total_amount_ <= 0 || !check_currency_amount(update->total_amount_)) {
|
|
|
|
LOG(ERROR) << "Receive pre-checkout query with invalid total amount " << update->total_amount_;
|
2020-12-21 20:06:52 +01:00
|
|
|
} else {
|
2024-04-02 02:52:34 +02:00
|
|
|
send_closure(G()->td(), &Td::send_update,
|
|
|
|
make_tl_object<td_api::updateNewPreCheckoutQuery>(
|
|
|
|
update->query_id_, td_->user_manager_->get_user_id_object(user_id, "updateNewPreCheckoutQuery"),
|
|
|
|
update->currency_, update->total_amount_, update->payload_.as_slice().str(),
|
|
|
|
update->shipping_option_id_, get_order_info_object(get_order_info(std::move(update->info_)))));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotWebhookJSON> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(G()->td(), &Td::send_update, make_tl_object<td_api::updateNewCustomEvent>(update->data_->data_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotWebhookJSONQuery> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(G()->td(), &Td::send_update,
|
|
|
|
make_tl_object<td_api::updateNewCustomQuery>(update->query_id_, update->data_->data_, update->timeout_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePhoneCall> update, Promise<Unit> &&promise) {
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(G()->call_manager(), &CallManager::update_call, std::move(update));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePhoneCallSignalingData> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2020-05-29 10:26:08 +02:00
|
|
|
send_closure(G()->call_manager(), &CallManager::update_call_signaling_data, update->phone_call_id_,
|
|
|
|
update->data_.as_slice().str());
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2020-05-29 10:26:08 +02:00
|
|
|
}
|
|
|
|
|
2021-04-30 16:07:01 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateGroupCallConnection> update, Promise<Unit> &&promise) {
|
2021-04-30 18:53:39 +02:00
|
|
|
if (update->presentation_) {
|
|
|
|
LOG(ERROR) << "Receive unexpected updateGroupCallConnection";
|
|
|
|
} else {
|
|
|
|
send_closure(G()->group_call_manager(), &GroupCallManager::on_update_group_call_connection,
|
|
|
|
std::move(update->params_->data_));
|
|
|
|
}
|
2021-04-30 16:07:01 +02:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateGroupCall> update, Promise<Unit> &&promise) {
|
2020-12-14 14:52:25 +01:00
|
|
|
DialogId dialog_id(ChatId(update->chat_id_));
|
2024-01-04 13:26:42 +01:00
|
|
|
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "updateGroupCall")) {
|
2020-12-14 14:52:25 +01:00
|
|
|
dialog_id = DialogId(ChannelId(update->chat_id_));
|
2024-01-04 13:26:42 +01:00
|
|
|
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "updateGroupCall")) {
|
2020-12-14 14:52:25 +01:00
|
|
|
dialog_id = DialogId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
send_closure(G()->group_call_manager(), &GroupCallManager::on_update_group_call, std::move(update->call_), dialog_id);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2020-11-25 15:04:32 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateGroupCallParticipants> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2020-12-11 16:12:07 +01:00
|
|
|
send_closure(G()->group_call_manager(), &GroupCallManager::on_update_group_call_participants,
|
2021-03-18 20:36:59 +01:00
|
|
|
InputGroupCallId(update->call_), std::move(update->participants_), update->version_, false);
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2020-12-11 16:12:07 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateContactsReset> update, Promise<Unit> &&promise) {
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_update_contacts_reset();
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateLangPackTooLong> update, Promise<Unit> &&promise) {
|
2019-02-10 23:12:42 +01:00
|
|
|
send_closure(G()->language_pack_manager(), &LanguagePackManager::on_language_pack_too_long,
|
|
|
|
std::move(update->lang_code_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateLangPack> update, Promise<Unit> &&promise) {
|
2018-07-17 04:58:34 +02:00
|
|
|
send_closure(G()->language_pack_manager(), &LanguagePackManager::on_update_language_pack,
|
|
|
|
std::move(update->difference_));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateGeoLiveViewed> update, Promise<Unit> &&promise) {
|
2019-12-13 19:05:10 +01:00
|
|
|
td_->messages_manager_->on_update_live_location_viewed(
|
|
|
|
{DialogId(update->peer_), MessageId(ServerMessageId(update->msg_id_))});
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2019-12-13 19:05:10 +01:00
|
|
|
}
|
|
|
|
|
2022-09-23 11:07:07 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessageExtendedMedia> update,
|
|
|
|
Promise<Unit> &&promise) {
|
|
|
|
td_->messages_manager_->on_update_message_extended_media(
|
|
|
|
{DialogId(update->peer_), MessageId(ServerMessageId(update->msg_id_))}, std::move(update->extended_media_));
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessagePoll> update, Promise<Unit> &&promise) {
|
2022-05-29 18:31:36 +02:00
|
|
|
td_->poll_manager_->on_get_poll(PollId(update->poll_id_), std::move(update->poll_), std::move(update->results_),
|
|
|
|
"updateMessagePoll");
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2019-02-18 01:27:35 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessagePollVote> update, Promise<Unit> &&promise) {
|
2021-05-18 18:33:18 +02:00
|
|
|
auto qts = update->qts_;
|
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
2020-01-13 20:56:59 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewScheduledMessage> update, Promise<Unit> &&promise) {
|
2023-05-11 19:27:00 +02:00
|
|
|
td_->messages_manager_->on_get_message(std::move(update->message_), true, false, true, "updateNewScheduledMessage");
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2019-12-02 17:30:35 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteScheduledMessages> update,
|
2020-12-21 20:06:52 +01:00
|
|
|
Promise<Unit> &&promise) {
|
2019-12-02 17:20:54 +01:00
|
|
|
vector<ScheduledServerMessageId> message_ids = transform(update->messages_, [](int32 scheduled_server_message_id) {
|
|
|
|
return ScheduledServerMessageId(scheduled_server_message_id);
|
|
|
|
});
|
2019-02-19 14:45:32 +01:00
|
|
|
|
2019-12-02 17:20:54 +01:00
|
|
|
td_->messages_manager_->on_update_delete_scheduled_messages(DialogId(update->peer_), std::move(message_ids));
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2019-11-21 20:57:20 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateLoginToken> update, Promise<Unit> &&promise) {
|
2020-08-03 20:54:28 +02:00
|
|
|
LOG(INFO) << "Ignore updateLoginToken after authorization";
|
2020-12-21 20:06:52 +01:00
|
|
|
promise.set_value(Unit());
|
2019-12-17 17:17:57 +01:00
|
|
|
}
|
|
|
|
|
2021-02-19 00:16:50 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotStopped> update, Promise<Unit> &&promise) {
|
2020-08-03 20:54:28 +02:00
|
|
|
auto qts = update->qts_;
|
2020-12-21 20:06:52 +01:00
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
2019-11-21 20:57:20 +01:00
|
|
|
}
|
|
|
|
|
2021-02-19 00:16:50 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatParticipant> update, Promise<Unit> &&promise) {
|
|
|
|
auto qts = update->qts_;
|
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
2021-02-02 00:00:28 +01:00
|
|
|
}
|
|
|
|
|
2021-02-19 00:16:50 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelParticipant> update, Promise<Unit> &&promise) {
|
|
|
|
auto qts = update->qts_;
|
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
2021-02-02 00:00:28 +01:00
|
|
|
}
|
|
|
|
|
2021-10-28 21:49:56 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotChatInviteRequester> update,
|
|
|
|
Promise<Unit> &&promise) {
|
|
|
|
auto qts = update->qts_;
|
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
|
|
|
}
|
|
|
|
|
2023-10-30 22:18:38 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotChatBoost> update, Promise<Unit> &&promise) {
|
|
|
|
auto qts = update->qts_;
|
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
|
|
|
}
|
|
|
|
|
2023-12-14 17:55:53 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotMessageReaction> update, Promise<Unit> &&promise) {
|
|
|
|
auto qts = update->qts_;
|
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
|
|
|
}
|
|
|
|
|
2023-12-14 21:44:31 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotMessageReactions> update, Promise<Unit> &&promise) {
|
|
|
|
auto qts = update->qts_;
|
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:32:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateTheme> update, Promise<Unit> &&promise) {
|
2021-09-12 21:29:40 +02:00
|
|
|
td_->theme_manager_->on_update_theme(std::move(update->theme_), std::move(promise));
|
2020-06-24 10:45:36 +02:00
|
|
|
}
|
|
|
|
|
2023-11-10 12:08:46 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePeerWallpaper> update, Promise<Unit> &&promise) {
|
2023-11-23 21:12:59 +01:00
|
|
|
auto dialog_id = DialogId(update->peer_);
|
|
|
|
if (dialog_id.get_type() == DialogType::User) {
|
2024-04-02 02:52:34 +02:00
|
|
|
td_->user_manager_->on_update_user_wallpaper_overridden(dialog_id.get_user_id(), update->wallpaper_overridden_);
|
2023-11-23 21:12:59 +01:00
|
|
|
}
|
|
|
|
td_->messages_manager_->on_update_dialog_background(dialog_id, std::move(update->wallpaper_));
|
2023-11-10 12:08:46 +01:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2021-10-08 12:45:10 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePendingJoinRequests> update, Promise<Unit> &&promise) {
|
2021-10-26 19:51:06 +02:00
|
|
|
td_->messages_manager_->on_update_dialog_pending_join_requests(DialogId(update->peer_), update->requests_pending_,
|
|
|
|
std::move(update->recent_requesters_));
|
2021-10-12 17:11:17 +02:00
|
|
|
promise.set_value(Unit());
|
2021-10-08 12:45:10 +02:00
|
|
|
}
|
|
|
|
|
2022-03-18 12:46:01 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateSavedRingtones> update, Promise<Unit> &&promise) {
|
2022-04-13 21:14:40 +02:00
|
|
|
td_->notification_settings_manager_->reload_saved_ringtones(std::move(promise));
|
2022-03-18 12:46:01 +01:00
|
|
|
}
|
|
|
|
|
2022-04-19 16:43:24 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateTranscribedAudio> update, Promise<Unit> &&promise) {
|
2023-11-21 18:32:23 +01:00
|
|
|
td_->transcription_manager_->on_update_transcribed_audio(std::move(update));
|
2022-05-25 20:48:31 +02:00
|
|
|
promise.set_value(Unit());
|
2022-04-19 16:43:24 +02:00
|
|
|
}
|
|
|
|
|
2023-01-06 10:42:16 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateAutoSaveSettings> update, Promise<Unit> &&promise) {
|
2023-02-06 17:53:21 +01:00
|
|
|
td_->autosave_manager_->reload_autosave_settings();
|
2023-01-06 10:42:16 +01:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2023-05-01 20:07:01 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStory> update, Promise<Unit> &&promise) {
|
2023-08-15 21:45:37 +02:00
|
|
|
td_->story_manager_->on_get_story(DialogId(update->peer_), std::move(update->story_));
|
2023-05-01 20:07:01 +02:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadStories> update, Promise<Unit> &&promise) {
|
2023-08-15 21:45:37 +02:00
|
|
|
td_->story_manager_->on_update_read_stories(DialogId(update->peer_), StoryId(update->max_id_));
|
2023-05-01 20:07:01 +02:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2023-08-04 13:51:39 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStoriesStealthMode> update, Promise<Unit> &&promise) {
|
|
|
|
td_->story_manager_->on_update_story_stealth_mode(std::move(update->stealth_mode_));
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2023-07-21 14:41:44 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateSentStoryReaction> update, Promise<Unit> &&promise) {
|
2023-08-15 21:45:37 +02:00
|
|
|
td_->story_manager_->on_update_story_chosen_reaction_type(DialogId(update->peer_), StoryId(update->story_id_),
|
|
|
|
ReactionType(update->reaction_));
|
2023-07-21 14:41:44 +02:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2023-05-01 20:07:01 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStoryID> update, Promise<Unit> &&promise) {
|
2023-08-11 13:07:13 +02:00
|
|
|
LOG(ERROR) << "Receive not in getDifference and not in on_pending_updates " << to_string(update);
|
2023-05-01 20:07:01 +02:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2023-09-06 18:02:17 +02:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewAuthorization> update, Promise<Unit> &&promise) {
|
2023-09-11 21:03:01 +02:00
|
|
|
if (update->unconfirmed_) {
|
|
|
|
td_->account_manager_->on_new_unconfirmed_authorization(update->hash_, update->date_, std::move(update->device_),
|
|
|
|
std::move(update->location_));
|
|
|
|
} else {
|
|
|
|
td_->account_manager_->on_confirm_authorization(update->hash_);
|
|
|
|
}
|
2023-09-06 18:02:17 +02:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2024-02-19 12:07:10 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateSmsJob> update, Promise<Unit> &&promise) {
|
|
|
|
LOG(ERROR) << "Receive " << to_string(update);
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateQuickReplies> update, Promise<Unit> &&promise) {
|
2024-02-22 18:12:06 +01:00
|
|
|
td_->quick_reply_manager_->reload_quick_reply_shortcuts();
|
2024-02-19 12:07:10 +01:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewQuickReply> update, Promise<Unit> &&promise) {
|
2024-02-22 21:14:08 +01:00
|
|
|
td_->quick_reply_manager_->reload_quick_reply_shortcuts();
|
2024-02-19 12:07:10 +01:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteQuickReply> update, Promise<Unit> &&promise) {
|
2024-02-22 21:17:02 +01:00
|
|
|
td_->quick_reply_manager_->reload_quick_reply_shortcuts();
|
2024-02-19 12:07:10 +01:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2024-02-29 14:39:38 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateQuickReplyMessage> update, Promise<Unit> &&promise) {
|
|
|
|
td_->quick_reply_manager_->update_quick_reply_message(std::move(update->message_));
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2024-02-29 12:43:32 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteQuickReplyMessages> update,
|
|
|
|
Promise<Unit> &&promise) {
|
|
|
|
vector<MessageId> message_ids;
|
|
|
|
for (auto message : update->messages_) {
|
|
|
|
message_ids.push_back(MessageId(ServerMessageId(message)));
|
|
|
|
}
|
2024-02-29 19:59:53 +01:00
|
|
|
td_->quick_reply_manager_->delete_quick_reply_messages_from_updates(QuickReplyShortcutId(update->shortcut_id_),
|
|
|
|
std::move(message_ids));
|
2024-02-19 12:07:10 +01:00
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
2024-03-07 13:24:28 +01:00
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotBusinessConnect> update, Promise<Unit> &&promise) {
|
2024-03-07 14:41:30 +01:00
|
|
|
auto qts = update->qts_;
|
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
2024-03-07 13:24:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotNewBusinessMessage> update,
|
|
|
|
Promise<Unit> &&promise) {
|
2024-03-07 14:41:30 +01:00
|
|
|
auto qts = update->qts_;
|
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
2024-03-07 13:24:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotEditBusinessMessage> update,
|
|
|
|
Promise<Unit> &&promise) {
|
2024-03-07 14:41:30 +01:00
|
|
|
auto qts = update->qts_;
|
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
2024-03-07 13:24:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotDeleteBusinessMessage> update,
|
|
|
|
Promise<Unit> &&promise) {
|
2024-03-07 14:41:30 +01:00
|
|
|
auto qts = update->qts_;
|
|
|
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
2024-03-07 13:24:28 +01:00
|
|
|
}
|
|
|
|
|
2024-03-07 14:41:30 +01:00
|
|
|
// unsupported updates
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|