Merge remote-tracking branch 'td/master'

This commit is contained in:
Andrea Cavalli 2022-05-25 22:12:16 +02:00
commit 1b0b3829aa
9 changed files with 151 additions and 74 deletions

View File

@ -282,6 +282,7 @@ set(TDLIB_SOURCE
td/telegram/Account.cpp
td/telegram/AnimationsManager.cpp
td/telegram/Application.cpp
td/telegram/AttachMenuManager.cpp
td/telegram/AudiosManager.cpp
td/telegram/AuthManager.cpp
@ -477,6 +478,7 @@ set(TDLIB_SOURCE
td/telegram/Account.h
td/telegram/AffectedHistory.h
td/telegram/AnimationsManager.h
td/telegram/Application.h
td/telegram/AttachMenuManager.h
td/telegram/AudiosManager.h
td/telegram/AuthManager.h

View File

@ -0,0 +1,83 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// 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/Application.h"
#include "td/telegram/Global.h"
#include "td/telegram/Td.h"
#include "td/utils/buffer.h"
#include "td/utils/logging.h"
namespace td {
class GetInviteTextQuery final : public Td::ResultHandler {
Promise<string> promise_;
public:
explicit GetInviteTextQuery(Promise<string> &&promise) : promise_(std::move(promise)) {
}
void send() {
send_query(G()->net_query_creator().create(telegram_api::help_getInviteText()));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::help_getInviteText>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
promise_.set_value(std::move(result->message_));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class SaveAppLogQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit SaveAppLogQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const string &type, DialogId dialog_id, tl_object_ptr<telegram_api::JSONValue> &&data) {
CHECK(data != nullptr);
vector<telegram_api::object_ptr<telegram_api::inputAppEvent>> input_app_events;
input_app_events.push_back(
make_tl_object<telegram_api::inputAppEvent>(G()->server_time_cached(), type, dialog_id.get(), std::move(data)));
send_query(G()->net_query_creator().create_unauth(telegram_api::help_saveAppLog(std::move(input_app_events))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::help_saveAppLog>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
bool result = result_ptr.move_as_ok();
LOG_IF(ERROR, !result) << "Receive false from help.saveAppLog";
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
void get_invite_text(Td *td, Promise<string> &&promise) {
td->create_handler<GetInviteTextQuery>(std::move(promise))->send();
}
void save_app_log(Td *td, const string &type, DialogId dialog_id, tl_object_ptr<telegram_api::JSONValue> &&data,
Promise<Unit> &&promise) {
td->create_handler<SaveAppLogQuery>(std::move(promise))->send(type, dialog_id, std::move(data));
}
} // namespace td

25
td/telegram/Application.h Normal file
View File

@ -0,0 +1,25 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// 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)
//
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/telegram_api.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
namespace td {
class Td;
void get_invite_text(Td *td, Promise<string> &&promise);
void save_app_log(Td *td, const string &type, DialogId dialog_id, tl_object_ptr<telegram_api::JSONValue> &&data,
Promise<Unit> &&promise);
} // namespace td

View File

@ -11083,14 +11083,16 @@ void MessagesManager::on_failed_scheduled_message_deletion(DialogId dialog_id, c
}
MessagesManager::CanDeleteDialog MessagesManager::can_delete_dialog(const Dialog *d) const {
auto chat_source = sponsored_dialog_source_.get_chat_source_object();
if (chat_source != nullptr) {
switch (chat_source->get_id()) {
case td_api::chatSourcePublicServiceAnnouncement::ID:
// can delete for self (but only while removing from dialog list)
return {true, false};
default:
return {false, false};
if (is_dialog_sponsored(d)) {
auto chat_source = sponsored_dialog_source_.get_chat_source_object();
if (chat_source != nullptr) {
switch (chat_source->get_id()) {
case td_api::chatSourcePublicServiceAnnouncement::ID:
// can delete for self (but only while removing from dialog list)
return {true, false};
default:
return {false, false};
}
}
}
if (td_->auth_manager_->is_bot() || !have_input_peer(d->dialog_id, AccessRights::Read)) {

View File

@ -1773,7 +1773,7 @@ Status SecretChatActor::save_common_info(T &update) {
Status SecretChatActor::on_update_chat(telegram_api::encryptedChatRequested &update) {
if (auth_state_.state != State::Empty) {
LOG(WARNING) << "Unexpected ChatRequested ignored: " << to_string(update);
LOG(INFO) << "Unexpected encryptedChatRequested ignored: " << to_string(update);
return Status::OK();
}
auth_state_.state = State::SendAccept;
@ -1794,7 +1794,7 @@ Status SecretChatActor::on_update_chat(telegram_api::encryptedChatEmpty &update)
}
Status SecretChatActor::on_update_chat(telegram_api::encryptedChatWaiting &update) {
if (auth_state_.state != State::WaitRequestResponse && auth_state_.state != State::WaitAcceptResponse) {
LOG(WARNING) << "Unexpected ChatWaiting ignored";
LOG(INFO) << "Unexpected encryptedChatWaiting ignored";
return Status::OK();
}
TRY_STATUS(save_common_info(update));
@ -1803,7 +1803,7 @@ Status SecretChatActor::on_update_chat(telegram_api::encryptedChatWaiting &updat
}
Status SecretChatActor::on_update_chat(telegram_api::encryptedChat &update) {
if (auth_state_.state != State::WaitRequestResponse && auth_state_.state != State::WaitAcceptResponse) {
LOG(WARNING) << "Unexpected Chat ignored";
LOG(INFO) << "Unexpected encryptedChat ignored";
return Status::OK();
}
TRY_STATUS(save_common_info(update));

View File

@ -8,6 +8,7 @@
#include "td/telegram/Account.h"
#include "td/telegram/AnimationsManager.h"
#include "td/telegram/Application.h"
#include "td/telegram/AttachMenuManager.h"
#include "td/telegram/AudiosManager.h"
#include "td/telegram/AuthManager.h"
@ -417,63 +418,6 @@ class UpdateStatusQuery final : public Td::ResultHandler {
}
};
class GetInviteTextQuery final : public Td::ResultHandler {
Promise<string> promise_;
public:
explicit GetInviteTextQuery(Promise<string> &&promise) : promise_(std::move(promise)) {
}
void send() {
send_query(G()->net_query_creator().create(telegram_api::help_getInviteText()));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::help_getInviteText>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
promise_.set_value(std::move(result->message_));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class SaveAppLogQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit SaveAppLogQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const string &type, int64 peer_id, tl_object_ptr<telegram_api::JSONValue> &&data) {
CHECK(data != nullptr);
vector<telegram_api::object_ptr<telegram_api::inputAppEvent>> input_app_events;
input_app_events.push_back(
make_tl_object<telegram_api::inputAppEvent>(G()->server_time_cached(), type, peer_id, std::move(data)));
send_query(G()->net_query_creator().create_unauth(telegram_api::help_saveAppLog(std::move(input_app_events))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::help_saveAppLog>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
bool result = result_ptr.move_as_ok();
LOG_IF(ERROR, !result) << "Receive false from help.saveAppLog";
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class TestNetworkQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
@ -7897,7 +7841,7 @@ void Td::on_request(uint64 id, const td_api::getApplicationDownloadLink &request
promise.set_value(make_tl_object<td_api::httpUrl>(result.move_as_ok()));
}
});
create_handler<GetInviteTextQuery>(std::move(query_promise))->send();
get_invite_text(this, std::move(query_promise));
}
void Td::on_request(uint64 id, td_api::getDeepLinkInfo &request) {
@ -7915,9 +7859,9 @@ void Td::on_request(uint64 id, const td_api::getApplicationConfig &request) {
void Td::on_request(uint64 id, td_api::saveApplicationLogEvent &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.type_);
auto result = convert_json_value(std::move(request.data_));
CREATE_OK_REQUEST_PROMISE();
create_handler<SaveAppLogQuery>(std::move(promise))->send(request.type_, request.chat_id_, std::move(result));
save_app_log(this, request.type_, DialogId(request.chat_id_), convert_json_value(std::move(request.data_)),
std::move(promise));
}
void Td::on_request(uint64 id, td_api::addProxy &request) {

View File

@ -361,6 +361,10 @@ void UpdatesManager::before_get_difference(bool is_initial) {
drop_all_pending_pts_updates();
send_closure_later(td_->notification_manager_actor_, &NotificationManager::before_get_difference);
if (get_difference_start_time_ <= 0) {
get_difference_start_time_ = Time::now();
}
}
Promise<> UpdatesManager::add_pts(int32 pts) {
@ -1537,7 +1541,9 @@ void UpdatesManager::after_get_difference() {
}
if (!postponed_updates_.empty()) {
VLOG(get_difference) << "Begin to apply " << postponed_updates_.size() << " postponed update chunks";
auto begin_time = Time::now();
auto chunk_count = postponed_updates_.size();
VLOG(get_difference) << "Begin to apply " << chunk_count << " postponed update chunks";
size_t total_update_count = 0;
while (!postponed_updates_.empty()) {
auto it = postponed_updates_.begin();
@ -1559,13 +1565,21 @@ void UpdatesManager::after_get_difference() {
}
total_update_count += update_count;
}
VLOG(get_difference) << "Finish to apply " << total_update_count << " postponed updates";
VLOG(get_difference) << "Finished to apply " << total_update_count << " postponed updates";
auto passed_time = Time::now() - begin_time;
if (passed_time >= 1.0) {
LOG(WARNING) << "Applied " << total_update_count << " postponed for "
<< (Time::now() - get_difference_start_time_) << " updates in " << chunk_count << " chunks in "
<< passed_time;
}
}
if (!postponed_pts_updates_.empty()) { // must be before td_->messages_manager_->after_get_difference()
auto postponed_updates = std::move(postponed_pts_updates_);
postponed_pts_updates_.clear();
auto begin_time = Time::now();
auto update_count = postponed_updates.size();
VLOG(get_difference) << "Begin to apply " << postponed_updates.size()
<< " postponed pts updates with pts = " << get_pts();
for (auto &postponed_update : postponed_updates) {
@ -1577,6 +1591,11 @@ void UpdatesManager::after_get_difference() {
VLOG(get_difference) << "After applying postponed pts updates have pts = " << get_pts()
<< ", max_pts = " << accumulated_pts_ << " and " << pending_pts_updates_.size() << " + "
<< postponed_pts_updates_.size() << " pending pts updates";
auto passed_time = Time::now() - begin_time;
if (passed_time >= 1.0) {
LOG(WARNING) << "Applied " << update_count << " postponed for " << (Time::now() - get_difference_start_time_)
<< " pts updates in " << passed_time;
}
}
td_->download_manager_->after_get_difference();
@ -1585,6 +1604,7 @@ void UpdatesManager::after_get_difference() {
td_->notification_settings_manager_->after_get_difference();
send_closure_later(td_->notification_manager_actor_, &NotificationManager::after_get_difference);
send_closure(G()->state_manager(), &StateManager::on_synchronized, true);
get_difference_start_time_ = 0.0;
try_reload_data();
}

View File

@ -229,6 +229,7 @@ class UpdatesManager final : public Actor {
int32 last_get_difference_qts_ = 0;
int32 min_postponed_update_pts_ = 0;
int32 min_postponed_update_qts_ = 0;
double get_difference_start_time_ = 0; // time from which we started to get difference without success
void start_up() final;

View File

@ -657,7 +657,7 @@ void Binlog::do_reindex() {
event.realloc();
do_event(std::move(event)); // NB: no move is actually happens
});
need_sync_ = true; // must sync creation of the file
need_sync_ = start_size != 0; // must sync creation of the file if it is non-empty
sync();
// finish_reindex