Merge remote-tracking branch 'td/master'

This commit is contained in:
Andrea Cavalli 2021-11-14 22:46:37 +01:00
commit 48e3660d2c
109 changed files with 3203 additions and 3257 deletions

View File

@ -306,6 +306,7 @@ set(TDLIB_SOURCE
td/telegram/DialogAction.cpp
td/telegram/DialogAdministrator.cpp
td/telegram/DialogDb.cpp
td/telegram/DialogEventLog.cpp
td/telegram/DialogFilter.cpp
td/telegram/DialogId.cpp
td/telegram/DialogInviteLink.cpp
@ -456,6 +457,7 @@ set(TDLIB_SOURCE
td/mtproto/utils.h
td/telegram/AccessRights.h
td/telegram/AffectedHistory.h
td/telegram/AnimationsManager.h
td/telegram/AudiosManager.h
td/telegram/AuthManager.h
@ -488,6 +490,7 @@ set(TDLIB_SOURCE
td/telegram/DialogAdministrator.h
td/telegram/DialogDate.h
td/telegram/DialogDb.h
td/telegram/DialogEventLog.h
td/telegram/DialogFilter.h
td/telegram/DialogFilterId.h
td/telegram/DialogId.h

View File

@ -10,7 +10,6 @@
#include "td/utils/base64.h"
#include "td/utils/benchmark.h"
#include "td/utils/common.h"
#include "td/utils/logging.h"
#include "td/utils/Slice.h"
#include <map>

View File

@ -61,7 +61,7 @@ class HttpClient final : public td::HttpOutboundConnection::Callback {
}
td::ActorOwn<td::HttpOutboundConnection> connection_;
int cnt_;
int cnt_ = 0;
};
int main() {

View File

@ -4163,7 +4163,7 @@ getMessage chat_id:int53 message_id:int53 = Message;
getMessageLocally chat_id:int53 message_id:int53 = Message;
//@description Returns information about a message that is replied by a given message. Also returns the pinned message, the game message, and the invoice message for messages of the types messagePinMessage, messageGameScore, and messagePaymentSuccessful respectively
//@chat_id Identifier of the chat the message belongs to @message_id Identifier of the message reply to which to get
//@chat_id Identifier of the chat the message belongs to @message_id Identifier of the reply message
getRepliedMessage chat_id:int53 message_id:int53 = Message;
//@description Returns information about a newest pinned message in the chat @chat_id Identifier of the chat the message belongs to

View File

@ -242,7 +242,7 @@ class TlWriterCCommon final : public tl::TL_writer {
"TDC_VECTOR(Int,int)\n"
"TDC_VECTOR(Long,long long)\n"
"TDC_VECTOR(String,char *)\n"
"TDC_VECTOR(Bytes,TdBytes)\n"
"TDC_VECTOR(Bytes,struct TdBytes)\n"
"struct TdStackStorerMethods {\n"
" void (*pack_string)(const char *s);\n"
" void (*pack_bytes)(const unsigned char *s, int len);\n"

View File

@ -49,7 +49,7 @@ class Transport final : public IStreamTransport {
string secret_;
HttpReader reader_;
HttpQuery http_query_;
ChainBufferWriter *output_;
ChainBufferWriter *output_ = nullptr;
enum { Write, Read } turn_ = Write;
};

View File

@ -14,17 +14,17 @@ namespace mtproto {
struct PacketInfo {
enum { Common, EndToEnd } type = Common;
uint64 auth_key_id;
uint32 message_ack;
UInt128 message_key;
uint64 auth_key_id{0};
uint32 message_ack{0};
UInt128 message_key{};
uint64 salt;
uint64 session_id;
uint64 salt{0};
uint64 session_id{0};
uint64 message_id;
int32 seq_no;
uint64 message_id{0};
int32 seq_no{0};
int32 version{1};
bool no_crypto_flag;
bool no_crypto_flag{false};
bool is_creator{false};
bool check_mod4{true};
bool use_random_padding{false};

View File

@ -188,8 +188,8 @@ class SessionConnection final
uint64 last_ping_message_id_ = 0;
uint64 last_ping_container_id_ = 0;
bool need_destroy_auth_key_{false};
bool sent_destroy_auth_key_{false};
bool need_destroy_auth_key_ = false;
bool sent_destroy_auth_key_ = false;
double wakeup_at_ = 0;
double flush_packet_at_ = 0;
@ -206,7 +206,7 @@ class SessionConnection final
unique_ptr<RawConnection> raw_connection_;
AuthData *auth_data_;
SessionConnection::Callback *callback_ = nullptr;
BufferSlice *current_buffer_slice_;
BufferSlice *current_buffer_slice_ = nullptr;
BufferSlice as_buffer_slice(Slice packet);
auto set_buffer_slice(BufferSlice *buffer_slice) TD_WARN_UNUSED_RESULT {

View File

@ -122,8 +122,8 @@ class OldTransport final : public IStreamTransport {
private:
TransportImpl impl_{false};
ChainBufferReader *input_;
ChainBufferWriter *output_;
ChainBufferReader *input_{nullptr};
ChainBufferWriter *output_{nullptr};
};
class ObfuscatedTransport final : public IStreamTransport {
@ -193,9 +193,9 @@ class ObfuscatedTransport final : public IStreamTransport {
// TODO: use ByteFlow?
// One problem is that BufferedFd owns output_buffer_
// The other problem is that first 56 bytes must be sent unencrypted.
UInt256 output_key_;
UInt256 output_key_{};
AesCtrState output_state_;
ChainBufferWriter *output_;
ChainBufferWriter *output_ = nullptr;
void do_write_tls(BufferWriter &&message);
void do_write_tls(BufferBuilder &&builder);

View File

@ -128,7 +128,6 @@ class TlsHello {
Op::string("\x03\x04\x03\x03\x03\x02\x03\x01"),
Op::grease(3),
Op::string("\x00\x01\x00\x00\x15")};
res.grease_size_ = 7;
#else
res.ops_ = {
Op::string("\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03"),
@ -163,7 +162,6 @@ class TlsHello {
Op::string("\x03\x04\x03\x03\x03\x02\x03\x01\x00\x1b\x00\x03\x02\x00\x02"),
Op::grease(3),
Op::string("\x00\x01\x00\x00\x15")};
res.grease_size_ = 7;
#endif
return res;
}();
@ -180,7 +178,7 @@ class TlsHello {
private:
std::vector<Op> ops_;
size_t grease_size_;
size_t grease_size_ = 7;
};
class TlsHelloContext {

View File

@ -0,0 +1,33 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
//
// 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/telegram_api.h"
#include "td/utils/common.h"
namespace td {
struct AffectedHistory {
int32 pts_;
int32 pts_count_;
bool is_final_;
explicit AffectedHistory(tl_object_ptr<telegram_api::messages_affectedHistory> &&affected_history)
: pts_(affected_history->pts_)
, pts_count_(affected_history->pts_count_)
, is_final_(affected_history->offset_ <= 0) {
}
explicit AffectedHistory(tl_object_ptr<telegram_api::messages_affectedFoundMessages> &&affected_history)
: pts_(affected_history->pts_)
, pts_count_(affected_history->pts_count_)
, is_final_(affected_history->offset_ <= 0) {
}
};
} // namespace td

View File

@ -46,25 +46,24 @@ class GetSavedGifsQuery final : public Td::ResultHandler {
public:
void send(bool is_repair, int64 hash) {
is_repair_ = is_repair;
LOG(INFO) << "Send get saved animations request with hash = " << hash;
send_query(G()->net_query_creator().create(telegram_api::messages_getSavedGifs(hash)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getSavedGifs>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
td->animations_manager_->on_get_saved_animations(is_repair_, std::move(ptr));
td_->animations_manager_->on_get_saved_animations(is_repair_, std::move(ptr));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (!G()->is_expected_error(status)) {
LOG(ERROR) << "Receive error for get saved animations: " << status;
}
td->animations_manager_->on_get_saved_animations_failed(is_repair_, std::move(status));
td_->animations_manager_->on_get_saved_animations_failed(is_repair_, std::move(status));
}
};
@ -88,26 +87,26 @@ class SaveGifQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::messages_saveGif(std::move(input_document), unsave)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_saveGif>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
bool result = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for save GIF: " << result;
if (!result) {
td->animations_manager_->reload_saved_animations(true);
td_->animations_manager_->reload_saved_animations(true);
}
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
if (!td->auth_manager_->is_bot() && FileReferenceManager::is_file_reference_error(status)) {
void on_error(Status status) final {
if (!td_->auth_manager_->is_bot() && FileReferenceManager::is_file_reference_error(status)) {
VLOG(file_references) << "Receive " << status << " for " << file_id_;
td->file_manager_->delete_file_reference(file_id_, file_reference_);
td->file_reference_manager_->repair_file_reference(
td_->file_manager_->delete_file_reference(file_id_, file_reference_);
td_->file_reference_manager_->repair_file_reference(
file_id_, PromiseCreator::lambda([animation_id = file_id_, unsave = unsave_,
promise = std::move(promise_)](Result<Unit> result) mutable {
if (result.is_error()) {
@ -123,7 +122,7 @@ class SaveGifQuery final : public Td::ResultHandler {
if (!G()->is_expected_error(status)) {
LOG(ERROR) << "Receive error for save GIF: " << status;
}
td->animations_manager_->reload_saved_animations(true);
td_->animations_manager_->reload_saved_animations(true);
promise_.set_error(std::move(status));
}
};

View File

@ -56,7 +56,7 @@ AuthManager::AuthManager(int32 api_id, const string &api_hash, ActorShared<> par
} else {
LOG(ERROR) << "Restore unknown my_id";
ContactsManager::send_get_me_query(
td, PromiseCreator::lambda([this](Result<Unit> result) { update_state(State::Ok); }));
td_, PromiseCreator::lambda([this](Result<Unit> result) { update_state(State::Ok); }));
}
} else if (auth_str == "logout") {
LOG(WARNING) << "Continue to log out";
@ -208,11 +208,14 @@ void AuthManager::set_login_token_expires_at(double login_token_expires_at) {
login_token_expires_at_ = login_token_expires_at;
poll_export_login_code_timeout_.cancel_timeout();
poll_export_login_code_timeout_.set_callback(std::move(on_update_login_token_static));
poll_export_login_code_timeout_.set_callback_data(static_cast<void *>(td));
poll_export_login_code_timeout_.set_callback_data(static_cast<void *>(td_));
poll_export_login_code_timeout_.set_timeout_at(login_token_expires_at_);
}
void AuthManager::on_update_login_token_static(void *td) {
if (G()->close_flag()) {
return;
}
static_cast<Td *>(td)->auth_manager_->on_update_login_token();
}
@ -763,9 +766,9 @@ void AuthManager::on_get_authorization(tl_object_ptr<telegram_api::auth_Authoriz
new_password_.clear();
new_hint_.clear();
state_ = State::Ok;
td->contacts_manager_->on_get_user(std::move(auth->user_), "on_get_authorization", true);
td_->contacts_manager_->on_get_user(std::move(auth->user_), "on_get_authorization", true);
update_state(State::Ok, true);
if (!td->contacts_manager_->get_my_id().is_valid()) {
if (!td_->contacts_manager_->get_my_id().is_valid()) {
LOG(ERROR) << "Server doesn't send proper authorization";
if (query_id_ != 0) {
on_query_error(Status::Error(500, "Server doesn't send proper authorization"));
@ -776,19 +779,19 @@ void AuthManager::on_get_authorization(tl_object_ptr<telegram_api::auth_Authoriz
if ((auth->flags_ & telegram_api::auth_authorization::TMP_SESSIONS_MASK) != 0) {
G()->shared_config().set_option_integer("session_count", auth->tmp_sessions_);
}
td->messages_manager_->on_authorization_success();
td->notification_manager_->init();
td->stickers_manager_->init();
td->theme_manager_->init();
td->top_dialog_manager_->init();
td->updates_manager_->get_difference("on_get_authorization");
td->on_online_updated(false, true);
td_->messages_manager_->on_authorization_success();
td_->notification_manager_->init();
td_->stickers_manager_->init();
td_->theme_manager_->init();
td_->top_dialog_manager_->init();
td_->updates_manager_->get_difference("on_get_authorization");
td_->on_online_updated(false, true);
if (!is_bot()) {
td->schedule_get_terms_of_service(0);
td->schedule_get_promo_data(0);
td_->schedule_get_terms_of_service(0);
td_->schedule_get_promo_data(0);
G()->td_db()->get_binlog_pmc()->set("fetched_marks_as_unread", "1");
} else {
td->set_is_bot_online(true);
td_->set_is_bot_online(true);
}
send_closure(G()->config_manager(), &ConfigManager::request_config);
if (query_id_ != 0) {

View File

@ -211,7 +211,7 @@ class AuthManager final : public NetActor {
bool was_check_bot_token_ = false;
bool is_bot_ = false;
uint64 net_query_id_ = 0;
NetQueryType net_query_type_;
NetQueryType net_query_type_ = NetQueryType::None;
vector<uint64> pending_get_authorization_state_requests_;

View File

@ -42,10 +42,10 @@ class GetAutoDownloadSettingsQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::account_getAutoDownloadSettings()));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_getAutoDownloadSettings>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto settings = result_ptr.move_as_ok();
@ -54,7 +54,7 @@ class GetAutoDownloadSettingsQuery final : public Td::ResultHandler {
convert_auto_download_settings(settings->high_)));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -98,17 +98,17 @@ class SaveAutoDownloadSettingsQuery final : public Td::ResultHandler {
flags, false /*ignored*/, false /*ignored*/, get_input_auto_download_settings(settings))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_saveAutoDownloadSettings>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
LOG(INFO) << "SaveAutoDownloadSettingsQuery returned " << result_ptr.ok();
LOG(INFO) << "Receive result for SaveAutoDownloadSettingsQuery: " << result_ptr.ok();
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};

View File

@ -50,22 +50,21 @@ class GetBackgroundQuery final : public Td::ResultHandler {
telegram_api::object_ptr<telegram_api::InputWallPaper> &&input_wallpaper) {
background_id_ = background_id;
background_name_ = background_name;
LOG(INFO) << "Load " << background_id_ << "/" << background_name_ << " from server";
send_query(G()->net_query_creator().create(telegram_api::account_getWallPaper(std::move(input_wallpaper))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_getWallPaper>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
td->background_manager_->on_get_background(background_id_, background_name_, result_ptr.move_as_ok(), true);
td_->background_manager_->on_get_background(background_id_, background_name_, result_ptr.move_as_ok(), true);
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
LOG(INFO) << "Receive error for GetBackgroundQuery for " << background_id_ << "/" << background_name_ << ": "
<< status;
promise_.set_error(std::move(status));
@ -84,16 +83,16 @@ class GetBackgroundsQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::account_getWallPapers(0)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_getWallPapers>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -110,17 +109,17 @@ class InstallBackgroundQuery final : public Td::ResultHandler {
telegram_api::account_installWallPaper(std::move(input_wallpaper), type.get_input_wallpaper_settings())));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_installWallPaper>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
LOG_IF(INFO, !result_ptr.ok()) << "Receive false from account.installWallPaper";
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -145,28 +144,28 @@ class UploadBackgroundQuery final : public Td::ResultHandler {
std::move(input_file), type_.get_mime_type(), type_.get_input_wallpaper_settings())));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_uploadWallPaper>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
td->background_manager_->on_uploaded_background_file(file_id_, type_, for_dark_theme_, result_ptr.move_as_ok(),
std::move(promise_));
td_->background_manager_->on_uploaded_background_file(file_id_, type_, for_dark_theme_, result_ptr.move_as_ok(),
std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
CHECK(status.is_error());
CHECK(file_id_.is_valid());
if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) {
// TODO td->background_manager_->on_upload_background_file_part_missing(file_id_, to_integer<int32>(status.message().substr(10)));
// TODO td_->background_manager_->on_upload_background_file_part_missing(file_id_, to_integer<int32>(status.message().substr(10)));
// return;
} else {
if (status.code() != 429 && status.code() < 500 && !G()->close_flag()) {
td->file_manager_->delete_partial_remote_location(file_id_);
td_->file_manager_->delete_partial_remote_location(file_id_);
}
}
td->file_manager_->cancel_upload(file_id_);
td_->file_manager_->cancel_upload(file_id_);
promise_.set_error(std::move(status));
}
};
@ -183,10 +182,10 @@ class UnsaveBackgroundQuery final : public Td::ResultHandler {
std::move(input_wallpaper), true, telegram_api::make_object<telegram_api::wallPaperSettings>())));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_saveWallPaper>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
bool result = result_ptr.move_as_ok();
@ -194,7 +193,7 @@ class UnsaveBackgroundQuery final : public Td::ResultHandler {
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (!G()->is_expected_error(status)) {
LOG(ERROR) << "Receive error for save background: " << status;
}
@ -213,10 +212,10 @@ class ResetBackgroundsQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::account_resetWallPapers()));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_resetWallPapers>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
bool result = result_ptr.move_as_ok();
@ -224,7 +223,7 @@ class ResetBackgroundsQuery final : public Td::ResultHandler {
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (!G()->is_expected_error(status)) {
LOG(ERROR) << "Receive error for reset backgrounds: " << status;
}
@ -810,8 +809,9 @@ void BackgroundManager::save_local_backgrounds(bool for_dark_theme) {
void BackgroundManager::upload_background_file(FileId file_id, const BackgroundType &type, bool for_dark_theme,
Promise<Unit> &&promise) {
auto upload_file_id = td_->file_manager_->dup_file_id(file_id);
being_uploaded_files_[upload_file_id] = {type, for_dark_theme, std::move(promise)};
bool is_inserted =
being_uploaded_files_.emplace(upload_file_id, UploadedFileInfo(type, for_dark_theme, std::move(promise))).second;
CHECK(is_inserted);
LOG(INFO) << "Ask to upload background file " << upload_file_id;
td_->file_manager_->upload(upload_file_id, upload_background_file_callback_, 1, 0);
}
@ -822,9 +822,9 @@ void BackgroundManager::on_upload_background_file(FileId file_id, tl_object_ptr<
auto it = being_uploaded_files_.find(file_id);
CHECK(it != being_uploaded_files_.end());
auto type = it->second.type;
auto for_dark_theme = it->second.for_dark_theme;
auto promise = std::move(it->second.promise);
auto type = it->second.type_;
auto for_dark_theme = it->second.for_dark_theme_;
auto promise = std::move(it->second.promise_);
being_uploaded_files_.erase(it);
@ -843,7 +843,7 @@ void BackgroundManager::on_upload_background_file_error(FileId file_id, Status s
auto it = being_uploaded_files_.find(file_id);
CHECK(it != being_uploaded_files_.end());
auto promise = std::move(it->second.promise);
auto promise = std::move(it->second.promise_);
being_uploaded_files_.erase(it);

View File

@ -184,9 +184,13 @@ class BackgroundManager final : public Actor {
std::shared_ptr<UploadBackgroundFileCallback> upload_background_file_callback_;
struct UploadedFileInfo {
BackgroundType type;
bool for_dark_theme;
Promise<Unit> promise;
BackgroundType type_;
bool for_dark_theme_;
Promise<Unit> promise_;
UploadedFileInfo(BackgroundType type, bool for_dark_theme, Promise<Unit> &&promise)
: type_(type), for_dark_theme_(for_dark_theme), promise_(std::move(promise)) {
}
};
std::unordered_map<FileId, UploadedFileInfo, FileIdHash> being_uploaded_files_;

View File

@ -31,14 +31,14 @@ class SetBotCommandsQuery final : public Td::ResultHandler {
void send(BotCommandScope scope, const string &language_code, vector<BotCommand> &&commands) {
send_query(G()->net_query_creator().create(telegram_api::bots_setBotCommands(
scope.get_input_bot_command_scope(td), language_code,
scope.get_input_bot_command_scope(td_), language_code,
transform(commands, [](const BotCommand &command) { return command.get_input_bot_command(); }))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::bots_setBotCommands>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
if (!result_ptr.ok()) {
@ -47,7 +47,7 @@ class SetBotCommandsQuery final : public Td::ResultHandler {
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -61,19 +61,19 @@ class ResetBotCommandsQuery final : public Td::ResultHandler {
void send(BotCommandScope scope, const string &language_code) {
send_query(G()->net_query_creator().create(
telegram_api::bots_resetBotCommands(scope.get_input_bot_command_scope(td), language_code)));
telegram_api::bots_resetBotCommands(scope.get_input_bot_command_scope(td_), language_code)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::bots_resetBotCommands>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -88,20 +88,20 @@ class GetBotCommandsQuery final : public Td::ResultHandler {
void send(BotCommandScope scope, const string &language_code) {
send_query(G()->net_query_creator().create(
telegram_api::bots_getBotCommands(scope.get_input_bot_command_scope(td), language_code)));
telegram_api::bots_getBotCommands(scope.get_input_bot_command_scope(td_), language_code)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::bots_getBotCommands>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
BotCommands commands(td->contacts_manager_->get_my_id(), result_ptr.move_as_ok());
promise_.set_value(commands.get_bot_commands_object(td));
BotCommands commands(td_->contacts_manager_->get_my_id(), result_ptr.move_as_ok());
promise_.set_value(commands.get_bot_commands_object(td_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};

View File

@ -41,7 +41,7 @@ class GetBotCallbackAnswerQuery final : public Td::ResultHandler {
dialog_id_ = dialog_id;
message_id_ = message_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
CHECK(input_peer != nullptr);
int32 flags = 0;
@ -72,10 +72,10 @@ class GetBotCallbackAnswerQuery final : public Td::ResultHandler {
send_query(std::move(net_query));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getBotCallbackAnswer>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto answer = result_ptr.move_as_ok();
@ -83,17 +83,17 @@ class GetBotCallbackAnswerQuery final : public Td::ResultHandler {
td_api::make_object<td_api::callbackQueryAnswer>(answer->message_, answer->alert_, answer->url_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (status.message() == "DATA_INVALID" || status.message() == "MESSAGE_ID_INVALID") {
td->messages_manager_->get_message_from_server({dialog_id_, message_id_}, Auto(), "GetBotCallbackAnswerQuery");
td_->messages_manager_->get_message_from_server({dialog_id_, message_id_}, Auto(), "GetBotCallbackAnswerQuery");
} else if (status.message() == "BOT_RESPONSE_TIMEOUT") {
status = Status::Error(502, "The bot is not responding");
}
if (status.code() == 502 && td->messages_manager_->is_message_edited_recently({dialog_id_, message_id_}, 31)) {
if (status.code() == 502 && td_->messages_manager_->is_message_edited_recently({dialog_id_, message_id_}, 31)) {
return promise_.set_value(td_api::make_object<td_api::callbackQueryAnswer>());
}
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetBotCallbackAnswerQuery");
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetBotCallbackAnswerQuery");
promise_.set_error(std::move(status));
}
};
@ -110,10 +110,10 @@ class SetBotCallbackAnswerQuery final : public Td::ResultHandler {
flags, false /*ignored*/, callback_query_id, text, url, cache_time)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_setBotCallbackAnswer>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
bool result = result_ptr.ok();
@ -123,7 +123,7 @@ class SetBotCallbackAnswerQuery final : public Td::ResultHandler {
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};

View File

@ -728,7 +728,7 @@ class ConfigRecoverer final : public Actor {
DcOptions dc_options_; // dc_options_update_ + simple_config_
double dc_options_at_{0};
size_t dc_options_i_;
size_t dc_options_i_{0};
size_t date_option_i_{0};
@ -1604,11 +1604,9 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
auto current_value = get_json_value_string(std::move(sound_key_value->value_), Slice());
if (sound_key_value->key_ == "id") {
id = std::move(current_value);
}
if (sound_key_value->key_ == "access_hash") {
} else if (sound_key_value->key_ == "access_hash") {
access_hash = std::move(current_value);
}
if (sound_key_value->key_ == "file_reference_base64") {
} else if (sound_key_value->key_ == "file_reference_base64") {
file_reference_base64 = std::move(current_value);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -127,8 +127,7 @@ class ContactsManager final : public Actor {
int32 get_secret_chat_layer(SecretChatId secret_chat_id) const;
FolderId get_secret_chat_initial_folder_id(SecretChatId secret_chat_id) const;
void on_imported_contacts(int64 random_id, vector<UserId> imported_contact_user_ids,
vector<int32> unimported_contact_invites);
void on_imported_contacts(int64 random_id, Result<tl_object_ptr<telegram_api::contacts_importedContacts>> result);
void on_deleted_contacts(const vector<UserId> &deleted_contact_user_ids);
@ -909,7 +908,7 @@ class ContactsManager final : public Actor {
struct SecretChat {
int64 access_hash = 0;
UserId user_id;
SecretChatState state;
SecretChatState state = SecretChatState::Unknown;
string key_hash;
int32 ttl = 0;
int32 date = 0;
@ -1374,6 +1373,11 @@ class ContactsManager final : public Actor {
void on_get_contacts_finished(size_t expected_contact_count);
void do_import_contacts(vector<Contact> contacts, int64 random_id, Promise<Unit> &&promise);
void on_import_contacts_finished(int64 random_id, vector<UserId> imported_contact_user_ids,
vector<int32> unimported_contact_invites);
void load_imported_contacts(Promise<Unit> &&promise);
void on_load_imported_contacts_from_database(string value);
@ -1690,6 +1694,14 @@ class ContactsManager final : public Actor {
};
std::unordered_map<FileId, UploadedProfilePhoto, FileIdHash> uploaded_profile_photos_; // file_id -> promise
struct ImportContactsTask {
Promise<Unit> promise_;
vector<Contact> input_contacts_;
vector<UserId> imported_user_ids_;
vector<int32> unimported_contact_invites_;
};
std::unordered_map<int64, unique_ptr<ImportContactsTask>> import_contact_tasks_;
std::unordered_map<int64, std::pair<vector<UserId>, vector<int32>>> imported_contacts_;
std::unordered_map<ChannelId, vector<DialogParticipant>, ChannelIdHash> cached_channel_participants_;

View File

@ -34,17 +34,17 @@ class GetNearestDcQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create_unauth(telegram_api::help_getNearestDc()));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::help_getNearestDc>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
promise_.set_value(std::move(result->country_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (!G()->is_expected_error(status) && status.message() != "BOT_METHOD_INVALID") {
LOG(ERROR) << "GetNearestDc returned " << status;
}
@ -64,17 +64,17 @@ class GetCountriesListQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create_unauth(telegram_api::help_getCountriesList(language_code, hash)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
// LOG(ERROR) << base64url_encode(gzencode(packet, 0.9));
auto result_ptr = fetch_result<telegram_api::help_getCountriesList>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (!G()->is_expected_error(status)) {
LOG(ERROR) << "GetCountriesList returned " << status;
}

View File

@ -79,7 +79,7 @@ class DialogAction {
string get_watching_animations_emoji() const;
struct ClickingAnimateEmojiInfo {
int32 message_id;
int32 message_id = 0;
string emoji;
string data;
};

View File

@ -0,0 +1,501 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
//
// 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/DialogEventLog.h"
#include "td/telegram/ChannelId.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogInviteLink.h"
#include "td/telegram/DialogLocation.h"
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/Global.h"
#include "td/telegram/GroupCallManager.h"
#include "td/telegram/GroupCallParticipant.h"
#include "td/telegram/InputGroupCallId.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/MessageTtlSetting.h"
#include "td/telegram/StickersManager.h"
#include "td/telegram/Td.h"
#include "td/telegram/telegram_api.h"
#include "td/utils/buffer.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/Status.h"
namespace td {
static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
Td *td, ChannelId channel_id, tl_object_ptr<telegram_api::ChannelAdminLogEventAction> &&action_ptr) {
CHECK(action_ptr != nullptr);
switch (action_ptr->get_id()) {
case telegram_api::channelAdminLogEventActionParticipantJoin::ID:
return td_api::make_object<td_api::chatEventMemberJoined>();
case telegram_api::channelAdminLogEventActionParticipantJoinByInvite::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantJoinByInvite>(action_ptr);
DialogInviteLink invite_link(std::move(action->invite_));
if (!invite_link.is_valid()) {
LOG(ERROR) << "Wrong invite link: " << invite_link;
return nullptr;
}
return td_api::make_object<td_api::chatEventMemberJoinedByInviteLink>(
invite_link.get_chat_invite_link_object(td->contacts_manager_.get()));
}
case telegram_api::channelAdminLogEventActionParticipantJoinByRequest::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantJoinByRequest>(action_ptr);
DialogInviteLink invite_link(std::move(action->invite_));
if (!invite_link.is_valid()) {
LOG(ERROR) << "Wrong invite link: " << invite_link;
return nullptr;
}
UserId approver_user_id(action->approved_by_);
if (!approver_user_id.is_valid()) {
return nullptr;
}
return td_api::make_object<td_api::chatEventMemberJoinedByRequest>(
td->contacts_manager_->get_user_id_object(approver_user_id, "chatEventMemberJoinedByRequest"),
invite_link.get_chat_invite_link_object(td->contacts_manager_.get()));
}
case telegram_api::channelAdminLogEventActionParticipantLeave::ID:
return td_api::make_object<td_api::chatEventMemberLeft>();
case telegram_api::channelAdminLogEventActionParticipantInvite::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantInvite>(action_ptr);
DialogParticipant dialog_participant(std::move(action->participant_));
if (!dialog_participant.is_valid() || dialog_participant.dialog_id_.get_type() != DialogType::User) {
LOG(ERROR) << "Wrong invite: " << dialog_participant;
return nullptr;
}
return td_api::make_object<td_api::chatEventMemberInvited>(
td->contacts_manager_->get_user_id_object(dialog_participant.dialog_id_.get_user_id(),
"chatEventMemberInvited"),
dialog_participant.status_.get_chat_member_status_object());
}
case telegram_api::channelAdminLogEventActionParticipantToggleBan::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantToggleBan>(action_ptr);
DialogParticipant old_dialog_participant(std::move(action->prev_participant_));
DialogParticipant new_dialog_participant(std::move(action->new_participant_));
if (old_dialog_participant.dialog_id_ != new_dialog_participant.dialog_id_) {
LOG(ERROR) << old_dialog_participant.dialog_id_ << " VS " << new_dialog_participant.dialog_id_;
return nullptr;
}
if (!old_dialog_participant.is_valid() || !new_dialog_participant.is_valid()) {
LOG(ERROR) << "Wrong restrict: " << old_dialog_participant << " -> " << new_dialog_participant;
return nullptr;
}
return td_api::make_object<td_api::chatEventMemberRestricted>(
td->messages_manager_->get_message_sender_object(old_dialog_participant.dialog_id_,
"chatEventMemberRestricted"),
old_dialog_participant.status_.get_chat_member_status_object(),
new_dialog_participant.status_.get_chat_member_status_object());
}
case telegram_api::channelAdminLogEventActionParticipantToggleAdmin::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantToggleAdmin>(action_ptr);
DialogParticipant old_dialog_participant(std::move(action->prev_participant_));
DialogParticipant new_dialog_participant(std::move(action->new_participant_));
if (old_dialog_participant.dialog_id_ != new_dialog_participant.dialog_id_) {
LOG(ERROR) << old_dialog_participant.dialog_id_ << " VS " << new_dialog_participant.dialog_id_;
return nullptr;
}
if (!old_dialog_participant.is_valid() || !new_dialog_participant.is_valid() ||
old_dialog_participant.dialog_id_.get_type() != DialogType::User) {
LOG(ERROR) << "Wrong edit administrator: " << old_dialog_participant << " -> " << new_dialog_participant;
return nullptr;
}
return td_api::make_object<td_api::chatEventMemberPromoted>(
td->contacts_manager_->get_user_id_object(old_dialog_participant.dialog_id_.get_user_id(),
"chatEventMemberPromoted"),
old_dialog_participant.status_.get_chat_member_status_object(),
new_dialog_participant.status_.get_chat_member_status_object());
}
case telegram_api::channelAdminLogEventActionChangeTitle::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeTitle>(action_ptr);
return td_api::make_object<td_api::chatEventTitleChanged>(std::move(action->prev_value_),
std::move(action->new_value_));
}
case telegram_api::channelAdminLogEventActionChangeAbout::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeAbout>(action_ptr);
return td_api::make_object<td_api::chatEventDescriptionChanged>(std::move(action->prev_value_),
std::move(action->new_value_));
}
case telegram_api::channelAdminLogEventActionChangeUsername::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeUsername>(action_ptr);
return td_api::make_object<td_api::chatEventUsernameChanged>(std::move(action->prev_value_),
std::move(action->new_value_));
}
case telegram_api::channelAdminLogEventActionChangePhoto::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangePhoto>(action_ptr);
auto file_manager = td->file_manager_.get();
auto old_photo = get_photo(file_manager, std::move(action->prev_photo_), DialogId(channel_id));
auto new_photo = get_photo(file_manager, std::move(action->new_photo_), DialogId(channel_id));
return td_api::make_object<td_api::chatEventPhotoChanged>(get_chat_photo_object(file_manager, old_photo),
get_chat_photo_object(file_manager, new_photo));
}
case telegram_api::channelAdminLogEventActionDefaultBannedRights::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionDefaultBannedRights>(action_ptr);
auto old_permissions = get_restricted_rights(std::move(action->prev_banned_rights_));
auto new_permissions = get_restricted_rights(std::move(action->new_banned_rights_));
return td_api::make_object<td_api::chatEventPermissionsChanged>(old_permissions.get_chat_permissions_object(),
new_permissions.get_chat_permissions_object());
}
case telegram_api::channelAdminLogEventActionToggleInvites::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionToggleInvites>(action_ptr);
return td_api::make_object<td_api::chatEventInvitesToggled>(action->new_value_);
}
case telegram_api::channelAdminLogEventActionToggleSignatures::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionToggleSignatures>(action_ptr);
return td_api::make_object<td_api::chatEventSignMessagesToggled>(action->new_value_);
}
case telegram_api::channelAdminLogEventActionUpdatePinned::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionUpdatePinned>(action_ptr);
auto message =
td->messages_manager_->get_dialog_event_log_message_object(DialogId(channel_id), std::move(action->message_));
if (message == nullptr) {
return nullptr;
}
if (message->is_pinned_) {
return td_api::make_object<td_api::chatEventMessagePinned>(std::move(message));
} else {
return td_api::make_object<td_api::chatEventMessageUnpinned>(std::move(message));
}
}
case telegram_api::channelAdminLogEventActionEditMessage::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionEditMessage>(action_ptr);
auto old_message = td->messages_manager_->get_dialog_event_log_message_object(DialogId(channel_id),
std::move(action->prev_message_));
auto new_message = td->messages_manager_->get_dialog_event_log_message_object(DialogId(channel_id),
std::move(action->new_message_));
if (old_message == nullptr || new_message == nullptr) {
return nullptr;
}
return td_api::make_object<td_api::chatEventMessageEdited>(std::move(old_message), std::move(new_message));
}
case telegram_api::channelAdminLogEventActionStopPoll::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionStopPoll>(action_ptr);
auto message =
td->messages_manager_->get_dialog_event_log_message_object(DialogId(channel_id), std::move(action->message_));
if (message == nullptr) {
return nullptr;
}
return td_api::make_object<td_api::chatEventPollStopped>(std::move(message));
}
case telegram_api::channelAdminLogEventActionDeleteMessage::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionDeleteMessage>(action_ptr);
auto message =
td->messages_manager_->get_dialog_event_log_message_object(DialogId(channel_id), std::move(action->message_));
if (message == nullptr) {
return nullptr;
}
return td_api::make_object<td_api::chatEventMessageDeleted>(std::move(message));
}
case telegram_api::channelAdminLogEventActionChangeStickerSet::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeStickerSet>(action_ptr);
auto old_sticker_set_id = td->stickers_manager_->add_sticker_set(std::move(action->prev_stickerset_));
auto new_sticker_set_id = td->stickers_manager_->add_sticker_set(std::move(action->new_stickerset_));
return td_api::make_object<td_api::chatEventStickerSetChanged>(old_sticker_set_id.get(),
new_sticker_set_id.get());
}
case telegram_api::channelAdminLogEventActionTogglePreHistoryHidden::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionTogglePreHistoryHidden>(action_ptr);
return td_api::make_object<td_api::chatEventIsAllHistoryAvailableToggled>(!action->new_value_);
}
case telegram_api::channelAdminLogEventActionChangeLinkedChat::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeLinkedChat>(action_ptr);
auto get_dialog_from_channel_id = [messages_manager = td->messages_manager_.get()](int64 channel_id_int) {
ChannelId channel_id(channel_id_int);
if (!channel_id.is_valid()) {
return DialogId();
}
DialogId dialog_id(channel_id);
messages_manager->force_create_dialog(dialog_id, "get_dialog_from_channel_id");
return dialog_id;
};
auto old_linked_dialog_id = get_dialog_from_channel_id(action->prev_value_);
auto new_linked_dialog_id = get_dialog_from_channel_id(action->new_value_);
if (old_linked_dialog_id == new_linked_dialog_id) {
LOG(ERROR) << "Receive the same linked " << new_linked_dialog_id;
return nullptr;
}
return td_api::make_object<td_api::chatEventLinkedChatChanged>(old_linked_dialog_id.get(),
new_linked_dialog_id.get());
}
case telegram_api::channelAdminLogEventActionChangeLocation::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeLocation>(action_ptr);
auto old_location = DialogLocation(std::move(action->prev_value_));
auto new_location = DialogLocation(std::move(action->new_value_));
return td_api::make_object<td_api::chatEventLocationChanged>(old_location.get_chat_location_object(),
new_location.get_chat_location_object());
}
case telegram_api::channelAdminLogEventActionToggleSlowMode::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionToggleSlowMode>(action_ptr);
auto old_slow_mode_delay = clamp(action->prev_value_, 0, 86400 * 366);
auto new_slow_mode_delay = clamp(action->new_value_, 0, 86400 * 366);
return td_api::make_object<td_api::chatEventSlowModeDelayChanged>(old_slow_mode_delay, new_slow_mode_delay);
}
case telegram_api::channelAdminLogEventActionExportedInviteEdit::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionExportedInviteEdit>(action_ptr);
DialogInviteLink old_invite_link(std::move(action->prev_invite_));
DialogInviteLink new_invite_link(std::move(action->new_invite_));
if (!old_invite_link.is_valid() || !new_invite_link.is_valid()) {
LOG(ERROR) << "Wrong edited invite link: " << old_invite_link << " -> " << new_invite_link;
return nullptr;
}
return td_api::make_object<td_api::chatEventInviteLinkEdited>(
old_invite_link.get_chat_invite_link_object(td->contacts_manager_.get()),
new_invite_link.get_chat_invite_link_object(td->contacts_manager_.get()));
}
case telegram_api::channelAdminLogEventActionExportedInviteRevoke::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionExportedInviteRevoke>(action_ptr);
DialogInviteLink invite_link(std::move(action->invite_));
if (!invite_link.is_valid()) {
LOG(ERROR) << "Wrong revoked invite link: " << invite_link;
return nullptr;
}
return td_api::make_object<td_api::chatEventInviteLinkRevoked>(
invite_link.get_chat_invite_link_object(td->contacts_manager_.get()));
}
case telegram_api::channelAdminLogEventActionExportedInviteDelete::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionExportedInviteDelete>(action_ptr);
DialogInviteLink invite_link(std::move(action->invite_));
if (!invite_link.is_valid()) {
LOG(ERROR) << "Wrong deleted invite link: " << invite_link;
return nullptr;
}
return td_api::make_object<td_api::chatEventInviteLinkDeleted>(
invite_link.get_chat_invite_link_object(td->contacts_manager_.get()));
}
case telegram_api::channelAdminLogEventActionStartGroupCall::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionStartGroupCall>(action_ptr);
auto input_group_call_id = InputGroupCallId(action->call_);
if (!input_group_call_id.is_valid()) {
return nullptr;
}
return td_api::make_object<td_api::chatEventVideoChatCreated>(
td->group_call_manager_->get_group_call_id(input_group_call_id, DialogId(channel_id)).get());
}
case telegram_api::channelAdminLogEventActionDiscardGroupCall::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionDiscardGroupCall>(action_ptr);
auto input_group_call_id = InputGroupCallId(action->call_);
if (!input_group_call_id.is_valid()) {
return nullptr;
}
return td_api::make_object<td_api::chatEventVideoChatDiscarded>(
td->group_call_manager_->get_group_call_id(input_group_call_id, DialogId(channel_id)).get());
}
case telegram_api::channelAdminLogEventActionParticipantMute::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantMute>(action_ptr);
GroupCallParticipant participant(action->participant_, 0);
if (!participant.is_valid()) {
return nullptr;
}
return td_api::make_object<td_api::chatEventVideoChatParticipantIsMutedToggled>(
td->messages_manager_->get_message_sender_object(participant.dialog_id,
"chatEventVideoChatParticipantIsMutedToggled"),
true);
}
case telegram_api::channelAdminLogEventActionParticipantUnmute::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantUnmute>(action_ptr);
GroupCallParticipant participant(action->participant_, 0);
if (!participant.is_valid()) {
return nullptr;
}
return td_api::make_object<td_api::chatEventVideoChatParticipantIsMutedToggled>(
td->messages_manager_->get_message_sender_object(participant.dialog_id,
"chatEventVideoChatParticipantIsMutedToggled"),
false);
}
case telegram_api::channelAdminLogEventActionParticipantVolume::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantVolume>(action_ptr);
GroupCallParticipant participant(action->participant_, 0);
if (!participant.is_valid()) {
return nullptr;
}
return td_api::make_object<td_api::chatEventVideoChatParticipantVolumeLevelChanged>(
td->messages_manager_->get_message_sender_object(participant.dialog_id,
"chatEventVideoChatParticipantVolumeLevelChanged"),
participant.volume_level);
}
case telegram_api::channelAdminLogEventActionToggleGroupCallSetting::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionToggleGroupCallSetting>(action_ptr);
return td_api::make_object<td_api::chatEventVideoChatMuteNewParticipantsToggled>(action->join_muted_);
}
case telegram_api::channelAdminLogEventActionChangeHistoryTTL::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeHistoryTTL>(action_ptr);
auto old_value = MessageTtlSetting(clamp(action->prev_value_, 0, 86400 * 366));
auto new_value = MessageTtlSetting(clamp(action->new_value_, 0, 86400 * 366));
return td_api::make_object<td_api::chatEventMessageTtlSettingChanged>(old_value.get_message_ttl_setting_object(),
new_value.get_message_ttl_setting_object());
}
default:
UNREACHABLE();
return nullptr;
}
}
class GetChannelAdminLogQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::chatEvents>> promise_;
ChannelId channel_id_;
public:
explicit GetChannelAdminLogQuery(Promise<td_api::object_ptr<td_api::chatEvents>> &&promise)
: promise_(std::move(promise)) {
}
void send(ChannelId channel_id, const string &query, int64 from_event_id, int32 limit,
tl_object_ptr<telegram_api::channelAdminLogEventsFilter> filter,
vector<tl_object_ptr<telegram_api::InputUser>> input_users) {
channel_id_ = channel_id;
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
CHECK(input_channel != nullptr);
int32 flags = 0;
if (filter != nullptr) {
flags |= telegram_api::channels_getAdminLog::EVENTS_FILTER_MASK;
}
if (!input_users.empty()) {
flags |= telegram_api::channels_getAdminLog::ADMINS_MASK;
}
send_query(G()->net_query_creator().create(telegram_api::channels_getAdminLog(
flags, std::move(input_channel), query, std::move(filter), std::move(input_users), from_event_id, 0, limit)));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::channels_getAdminLog>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto events = result_ptr.move_as_ok();
LOG(INFO) << "Receive in " << channel_id_ << ' ' << to_string(events);
td_->contacts_manager_->on_get_users(std::move(events->users_), "on_get_event_log");
td_->contacts_manager_->on_get_chats(std::move(events->chats_), "on_get_event_log");
auto result = td_api::make_object<td_api::chatEvents>();
result->events_.reserve(events->events_.size());
for (auto &event : events->events_) {
if (event->date_ <= 0) {
LOG(ERROR) << "Receive wrong event date = " << event->date_;
event->date_ = 0;
}
UserId user_id(event->user_id_);
if (!user_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << user_id;
continue;
}
LOG_IF(ERROR, !td_->contacts_manager_->have_user(user_id)) << "Have no info about " << user_id;
auto action = get_chat_event_action_object(td_, channel_id_, std::move(event->action_));
if (action == nullptr) {
continue;
}
result->events_.push_back(td_api::make_object<td_api::chatEvent>(
event->id_, event->date_, td_->contacts_manager_->get_user_id_object(user_id, "chatEvent"),
std::move(action)));
}
promise_.set_value(std::move(result));
}
void on_error(Status status) final {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "GetChannelAdminLogQuery");
promise_.set_error(std::move(status));
}
};
static telegram_api::object_ptr<telegram_api::channelAdminLogEventsFilter> get_input_channel_admin_log_events_filter(
const td_api::object_ptr<td_api::chatEventLogFilters> &filters) {
if (filters == nullptr) {
return nullptr;
}
int32 flags = 0;
if (filters->message_edits_) {
flags |= telegram_api::channelAdminLogEventsFilter::EDIT_MASK;
}
if (filters->message_deletions_) {
flags |= telegram_api::channelAdminLogEventsFilter::DELETE_MASK;
}
if (filters->message_pins_) {
flags |= telegram_api::channelAdminLogEventsFilter::PINNED_MASK;
}
if (filters->member_joins_) {
flags |= telegram_api::channelAdminLogEventsFilter::JOIN_MASK;
}
if (filters->member_leaves_) {
flags |= telegram_api::channelAdminLogEventsFilter::LEAVE_MASK;
}
if (filters->member_invites_) {
flags |= telegram_api::channelAdminLogEventsFilter::INVITE_MASK;
}
if (filters->member_promotions_) {
flags |= telegram_api::channelAdminLogEventsFilter::PROMOTE_MASK;
flags |= telegram_api::channelAdminLogEventsFilter::DEMOTE_MASK;
}
if (filters->member_restrictions_) {
flags |= telegram_api::channelAdminLogEventsFilter::BAN_MASK;
flags |= telegram_api::channelAdminLogEventsFilter::UNBAN_MASK;
flags |= telegram_api::channelAdminLogEventsFilter::KICK_MASK;
flags |= telegram_api::channelAdminLogEventsFilter::UNKICK_MASK;
}
if (filters->info_changes_) {
flags |= telegram_api::channelAdminLogEventsFilter::INFO_MASK;
}
if (filters->setting_changes_) {
flags |= telegram_api::channelAdminLogEventsFilter::SETTINGS_MASK;
}
if (filters->invite_link_changes_) {
flags |= telegram_api::channelAdminLogEventsFilter::INVITES_MASK;
}
if (filters->video_chat_changes_) {
flags |= telegram_api::channelAdminLogEventsFilter::GROUP_CALL_MASK;
}
return telegram_api::make_object<telegram_api::channelAdminLogEventsFilter>(
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/);
}
void get_dialog_event_log(Td *td, DialogId dialog_id, const string &query, int64 from_event_id, int32 limit,
const td_api::object_ptr<td_api::chatEventLogFilters> &filters,
const vector<UserId> &user_ids, Promise<td_api::object_ptr<td_api::chatEvents>> &&promise) {
if (!td->messages_manager_->have_dialog_force(dialog_id, "get_dialog_event_log")) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (dialog_id.get_type() != DialogType::Channel) {
return promise.set_error(Status::Error(400, "Chat is not a supergroup chat"));
}
auto channel_id = dialog_id.get_channel_id();
if (!td->contacts_manager_->have_channel(channel_id)) {
return promise.set_error(Status::Error(400, "Chat info not found"));
}
if (!td->contacts_manager_->get_channel_status(channel_id).is_administrator()) {
return promise.set_error(Status::Error(400, "Not enough rights to get event log"));
}
vector<tl_object_ptr<telegram_api::InputUser>> input_users;
for (auto user_id : user_ids) {
auto input_user = td->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(400, "User not found"));
}
input_users.push_back(std::move(input_user));
}
td->create_handler<GetChannelAdminLogQuery>(std::move(promise))
->send(channel_id, query, from_event_id, limit, get_input_channel_admin_log_events_filter(filters),
std::move(input_users));
}
} // namespace td

View File

@ -0,0 +1,25 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
//
// 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/td_api.h"
#include "td/telegram/UserId.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
namespace td {
class Td;
void get_dialog_event_log(Td *td, DialogId dialog_id, const string &query, int64 from_event_id, int32 limit,
const td_api::object_ptr<td_api::chatEventLogFilters> &filters,
const vector<UserId> &user_ids, Promise<td_api::object_ptr<td_api::chatEvents>> &&promise);
} // namespace td

View File

@ -273,27 +273,27 @@ unique_ptr<DialogFilter> DialogFilter::merge_dialog_filter_changes(const DialogF
// merge additions and deletions from other clients to the local changes
std::unordered_set<DialogId, DialogIdHash> deleted_dialog_ids;
for (auto old_dialog_id : old_server_dialog_ids) {
for (const auto &old_dialog_id : old_server_dialog_ids) {
deleted_dialog_ids.insert(old_dialog_id.get_dialog_id());
}
std::unordered_set<DialogId, DialogIdHash> added_dialog_ids;
for (auto new_dialog_id : new_server_dialog_ids) {
for (const auto &new_dialog_id : new_server_dialog_ids) {
auto dialog_id = new_dialog_id.get_dialog_id();
if (deleted_dialog_ids.erase(dialog_id) == 0) {
added_dialog_ids.insert(dialog_id);
}
}
vector<InputDialogId> result;
for (auto input_dialog_id : new_dialog_ids) {
for (const auto &input_dialog_id : new_dialog_ids) {
// do not add dialog twice
added_dialog_ids.erase(input_dialog_id.get_dialog_id());
}
for (auto new_dialog_id : new_server_dialog_ids) {
for (const auto &new_dialog_id : new_server_dialog_ids) {
if (added_dialog_ids.count(new_dialog_id.get_dialog_id()) == 1) {
result.push_back(new_dialog_id);
}
}
for (auto input_dialog_id : new_dialog_ids) {
for (const auto &input_dialog_id : new_dialog_ids) {
if (deleted_dialog_ids.count(input_dialog_id.get_dialog_id()) == 0) {
result.push_back(input_dialog_id);
}

View File

@ -21,7 +21,7 @@ class ContactsManager;
class DraftMessage {
public:
int32 date;
int32 date = 0;
MessageId reply_to_message_id;
InputMessageText input_message_text;
};

View File

@ -363,7 +363,7 @@ void FileReferenceManager::repair_file_reference(NodeId node_id, Promise<> promi
}
void FileReferenceManager::reload_photo(PhotoSizeSource source, Promise<Unit> promise) {
switch (source.get_type()) {
switch (source.get_type("reload_photo")) {
case PhotoSizeSource::Type::DialogPhotoBig:
case PhotoSizeSource::Type::DialogPhotoSmall:
case PhotoSizeSource::Type::DialogPhotoBigLegacy:

View File

@ -82,13 +82,13 @@ class FileReferenceManager final : public Actor {
return node_id.empty();
}
NodeId node_id;
int64 generation;
int64 generation{0};
};
struct Query {
std::vector<Promise<>> promises;
int32 active_queries{0};
Destination proxy;
int64 generation;
int64 generation{0};
};
struct Node {

View File

@ -37,7 +37,7 @@ Game::Game(Td *td, string title, string description, tl_object_ptr<telegram_api:
CHECK(photo != nullptr);
photo_ = get_photo(td->file_manager_.get(), std::move(photo), owner_dialog_id);
if (photo_.is_empty()) {
LOG(ERROR) << "Receive empty photo for game " << title;
LOG(ERROR) << "Receive empty photo for game " << title_;
photo_.id = 0; // to prevent null photo in td_api
}
if (document != nullptr) {

View File

@ -48,9 +48,9 @@ class SetGameScoreActor final : public NetActorOnce {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Edit);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Edit);
if (input_peer == nullptr) {
on_error(0, Status::Error(400, "Can't access the chat"));
on_error(Status::Error(400, "Can't access the chat"));
stop();
return;
}
@ -60,27 +60,25 @@ class SetGameScoreActor final : public NetActorOnce {
telegram_api::messages_setGameScore(flags, false /*ignored*/, false /*ignored*/, std::move(input_peer),
message_id.get_server_message_id().get(), std::move(input_user), score));
LOG(INFO) << "Set game score to " << score;
query->debug("send to MultiSequenceDispatcher");
send_closure(td->messages_manager_->sequence_dispatcher_, &MultiSequenceDispatcher::send_with_callback,
send_closure(td_->messages_manager_->sequence_dispatcher_, &MultiSequenceDispatcher::send_with_callback,
std::move(query), actor_shared(this), sequence_dispatcher_id);
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_setGameScore>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for SetGameScore: " << to_string(ptr);
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
LOG(INFO) << "Receive error for SetGameScore: " << status;
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "SetGameScoreActor");
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "SetGameScoreActor");
promise_.set_error(std::move(status));
}
};
@ -112,10 +110,10 @@ class SetInlineGameScoreQuery final : public Td::ResultHandler {
dc_id));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_setInlineGameScore>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
LOG_IF(ERROR, !result_ptr.ok()) << "Receive false in result of setInlineGameScore";
@ -123,7 +121,7 @@ class SetInlineGameScoreQuery final : public Td::ResultHandler {
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
LOG(INFO) << "Receive error for SetInlineGameScoreQuery: " << status;
promise_.set_error(std::move(status));
}
@ -141,7 +139,7 @@ class GetGameHighScoresQuery final : public Td::ResultHandler {
void send(DialogId dialog_id, MessageId message_id, tl_object_ptr<telegram_api::InputUser> input_user) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
CHECK(input_peer != nullptr);
CHECK(input_user != nullptr);
@ -149,17 +147,17 @@ class GetGameHighScoresQuery final : public Td::ResultHandler {
std::move(input_peer), message_id.get_server_message_id().get(), std::move(input_user))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getGameHighScores>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(td->game_manager_->get_game_high_scores_object(result_ptr.move_as_ok()));
promise_.set_value(td_->game_manager_->get_game_high_scores_object(result_ptr.move_as_ok()));
}
void on_error(uint64 id, Status status) final {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetGameHighScoresQuery");
void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetGameHighScoresQuery");
promise_.set_error(std::move(status));
}
};
@ -183,16 +181,16 @@ class GetInlineGameHighScoresQuery final : public Td::ResultHandler {
dc_id));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getInlineGameHighScores>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(td->game_manager_->get_game_high_scores_object(result_ptr.move_as_ok()));
promise_.set_value(td_->game_manager_->get_game_high_scores_object(result_ptr.move_as_ok()));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};

View File

@ -461,8 +461,8 @@ class Global final : public ActorContext {
unique_ptr<MtprotoHeader> mtproto_header_;
TdParameters parameters_;
int32 gc_scheduler_id_;
int32 slow_net_scheduler_id_;
int32 gc_scheduler_id_ = 0;
int32 slow_net_scheduler_id_ = 0;
std::atomic<bool> store_all_files_in_files_directory_{false};
@ -505,7 +505,8 @@ class Global final : public ActorContext {
inline Global *G_impl(const char *file, int line) {
ActorContext *context = Scheduler::context();
LOG_CHECK(context != nullptr && context->get_id() == Global::ID) << "In " << file << " at " << line;
LOG_CHECK(context != nullptr && context->get_id() == Global::ID)
<< "Context = " << context << " in " << file << " at " << line;
return static_cast<Global *>(context);
}

View File

@ -55,22 +55,22 @@ class GetGroupCallStreamQuery final : public Td::ResultHandler {
send_query(std::move(query));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::upload_getFile>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
if (ptr->get_id() != telegram_api::upload_file::ID) {
return on_error(id, Status::Error(500, "Receive unexpected server response"));
return on_error(Status::Error(500, "Receive unexpected server response"));
}
auto file = move_tl_object_as<telegram_api::upload_file>(ptr);
promise_.set_value(file->bytes_.as_slice().str());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -87,23 +87,23 @@ class GetGroupCallJoinAsQuery final : public Td::ResultHandler {
void send(DialogId dialog_id) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
CHECK(input_peer != nullptr);
send_query(G()->net_query_creator().create(telegram_api::phone_getGroupCallJoinAs(std::move(input_peer))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_getGroupCallJoinAs>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetGroupCallJoinAsQuery: " << to_string(ptr);
td->contacts_manager_->on_get_users(std::move(ptr->users_), "GetGroupCallJoinAsQuery");
td->contacts_manager_->on_get_chats(std::move(ptr->chats_), "GetGroupCallJoinAsQuery");
td_->contacts_manager_->on_get_users(std::move(ptr->users_), "GetGroupCallJoinAsQuery");
td_->contacts_manager_->on_get_chats(std::move(ptr->chats_), "GetGroupCallJoinAsQuery");
vector<td_api::object_ptr<td_api::MessageSender>> participant_aliaces;
for (auto &peer : ptr->peers_) {
@ -113,19 +113,19 @@ class GetGroupCallJoinAsQuery final : public Td::ResultHandler {
continue;
}
if (dialog_id.get_type() != DialogType::User) {
td->messages_manager_->force_create_dialog(dialog_id, "GetGroupCallJoinAsQuery");
td_->messages_manager_->force_create_dialog(dialog_id, "GetGroupCallJoinAsQuery");
}
participant_aliaces.push_back(
td->messages_manager_->get_message_sender_object(dialog_id, "GetGroupCallJoinAsQuery"));
td_->messages_manager_->get_message_sender_object(dialog_id, "GetGroupCallJoinAsQuery"));
}
promise_.set_value(td_api::make_object<td_api::messageSenders>(static_cast<int32>(participant_aliaces.size()),
std::move(participant_aliaces)));
}
void on_error(uint64 id, Status status) final {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetGroupCallJoinAsQuery");
void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetGroupCallJoinAsQuery");
promise_.set_error(std::move(status));
}
};
@ -138,20 +138,20 @@ class SaveDefaultGroupCallJoinAsQuery final : public Td::ResultHandler {
}
void send(DialogId dialog_id, DialogId as_dialog_id) {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
CHECK(input_peer != nullptr);
auto as_input_peer = td->messages_manager_->get_input_peer(as_dialog_id, AccessRights::Read);
auto as_input_peer = td_->messages_manager_->get_input_peer(as_dialog_id, AccessRights::Read);
CHECK(as_input_peer != nullptr);
send_query(G()->net_query_creator().create(
telegram_api::phone_saveDefaultGroupCallJoinAs(std::move(input_peer), std::move(as_input_peer))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_saveDefaultGroupCallJoinAs>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto success = result_ptr.move_as_ok();
@ -160,8 +160,8 @@ class SaveDefaultGroupCallJoinAsQuery final : public Td::ResultHandler {
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
// td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetGroupCallJoinAsQuery");
void on_error(Status status) final {
// td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetGroupCallJoinAsQuery");
promise_.set_error(std::move(status));
}
};
@ -177,7 +177,7 @@ class CreateGroupCallQuery final : public Td::ResultHandler {
void send(DialogId dialog_id, const string &title, int32 start_date) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
CHECK(input_peer != nullptr);
int32 flags = 0;
@ -191,36 +191,36 @@ class CreateGroupCallQuery final : public Td::ResultHandler {
telegram_api::phone_createGroupCall(flags, std::move(input_peer), Random::secure_int32(), title, start_date)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_createGroupCall>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for CreateGroupCallQuery: " << to_string(ptr);
auto group_call_ids = td->updates_manager_->get_update_new_group_call_ids(ptr.get());
auto group_call_ids = td_->updates_manager_->get_update_new_group_call_ids(ptr.get());
if (group_call_ids.empty()) {
LOG(ERROR) << "Receive wrong CreateGroupCallQuery response " << to_string(ptr);
return on_error(id, Status::Error(500, "Receive wrong response"));
return on_error(Status::Error(500, "Receive wrong response"));
}
auto group_call_id = group_call_ids[0];
for (auto other_group_call_id : group_call_ids) {
for (const auto &other_group_call_id : group_call_ids) {
if (group_call_id != other_group_call_id) {
LOG(ERROR) << "Receive wrong CreateGroupCallQuery response " << to_string(ptr);
return on_error(id, Status::Error(500, "Receive wrong response"));
return on_error(Status::Error(500, "Receive wrong response"));
}
}
td->updates_manager_->on_get_updates(
td_->updates_manager_->on_get_updates(
std::move(ptr), PromiseCreator::lambda([promise = std::move(promise_), group_call_id](Unit) mutable {
promise.set_value(std::move(group_call_id));
}));
}
void on_error(uint64 id, Status status) final {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "CreateGroupCallQuery");
void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "CreateGroupCallQuery");
promise_.set_error(std::move(status));
}
};
@ -238,10 +238,10 @@ class GetGroupCallQuery final : public Td::ResultHandler {
telegram_api::phone_getGroupCall(input_group_call_id.get_input_group_call(), limit)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_getGroupCall>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
@ -250,7 +250,7 @@ class GetGroupCallQuery final : public Td::ResultHandler {
promise_.set_value(std::move(ptr));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -271,19 +271,19 @@ class GetGroupCallParticipantQuery final : public Td::ResultHandler {
input_group_call_id.get_input_group_call(), std::move(input_peers), std::move(source_ids), string(), limit)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_getGroupParticipants>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
td->group_call_manager_->on_get_group_call_participants(input_group_call_id_, result_ptr.move_as_ok(), false,
string());
td_->group_call_manager_->on_get_group_call_participants(input_group_call_id_, result_ptr.move_as_ok(), false,
string());
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -305,19 +305,19 @@ class GetGroupCallParticipantsQuery final : public Td::ResultHandler {
offset_, limit)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_getGroupParticipants>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
td->group_call_manager_->on_get_group_call_participants(input_group_call_id_, result_ptr.move_as_ok(), true,
offset_);
td_->group_call_manager_->on_get_group_call_participants(input_group_call_id_, result_ptr.move_as_ok(), true,
offset_);
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -334,18 +334,18 @@ class StartScheduledGroupCallQuery final : public Td::ResultHandler {
telegram_api::phone_startScheduledGroupCall(input_group_call_id.get_input_group_call())));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_startScheduledGroupCall>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for StartScheduledGroupCallQuery: " << to_string(ptr);
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (status.message() == "GROUPCALL_NOT_MODIFIED") {
promise_.set_value(Unit());
return;
@ -372,7 +372,7 @@ class JoinGroupCallQuery final : public Td::ResultHandler {
tl_object_ptr<telegram_api::InputPeer> join_as_input_peer;
if (as_dialog_id.is_valid()) {
join_as_input_peer = td->messages_manager_->get_input_peer(as_dialog_id, AccessRights::Read);
join_as_input_peer = td_->messages_manager_->get_input_peer(as_dialog_id, AccessRights::Read);
} else {
join_as_input_peer = make_tl_object<telegram_api::inputPeerSelf>();
}
@ -396,19 +396,19 @@ class JoinGroupCallQuery final : public Td::ResultHandler {
return join_query_ref;
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_joinGroupCall>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for JoinGroupCallQuery with generation " << generation_ << ": " << to_string(ptr);
td->group_call_manager_->process_join_group_call_response(input_group_call_id_, generation_, std::move(ptr),
std::move(promise_));
td_->group_call_manager_->process_join_group_call_response(input_group_call_id_, generation_, std::move(ptr),
std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -429,22 +429,22 @@ class JoinGroupCallPresentationQuery final : public Td::ResultHandler {
return join_query_ref;
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_joinGroupCallPresentation>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for JoinGroupCallPresentationQuery with generation " << generation_ << ": "
<< to_string(ptr);
td->group_call_manager_->process_join_group_call_presentation_response(input_group_call_id_, generation_,
std::move(ptr), Status::OK());
td_->group_call_manager_->process_join_group_call_presentation_response(input_group_call_id_, generation_,
std::move(ptr), Status::OK());
}
void on_error(uint64 id, Status status) final {
td->group_call_manager_->process_join_group_call_presentation_response(input_group_call_id_, generation_, nullptr,
std::move(status));
void on_error(Status status) final {
td_->group_call_manager_->process_join_group_call_presentation_response(input_group_call_id_, generation_, nullptr,
std::move(status));
}
};
@ -460,18 +460,18 @@ class LeaveGroupCallPresentationQuery final : public Td::ResultHandler {
telegram_api::phone_leaveGroupCallPresentation(input_group_call_id.get_input_group_call())));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_editGroupCallTitle>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for LeaveGroupCallPresentationQuery: " << to_string(ptr);
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (status.message() == "PARTICIPANT_PRESENTATION_MISSING") {
promise_.set_value(Unit());
return;
@ -492,18 +492,18 @@ class EditGroupCallTitleQuery final : public Td::ResultHandler {
telegram_api::phone_editGroupCallTitle(input_group_call_id.get_input_group_call(), title)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_editGroupCallTitle>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for EditGroupCallTitleQuery: " << to_string(ptr);
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (status.message() == "GROUPCALL_NOT_MODIFIED") {
promise_.set_value(Unit());
return;
@ -524,18 +524,18 @@ class ToggleGroupCallStartSubscriptionQuery final : public Td::ResultHandler {
input_group_call_id.get_input_group_call(), start_subscribed)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_toggleGroupCallStartSubscription>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for ToggleGroupCallStartSubscriptionQuery: " << to_string(ptr);
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (status.message() == "GROUPCALL_NOT_MODIFIED") {
promise_.set_value(Unit());
return;
@ -556,18 +556,18 @@ class ToggleGroupCallSettingsQuery final : public Td::ResultHandler {
flags, false /*ignored*/, input_group_call_id.get_input_group_call(), join_muted)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_toggleGroupCallSettings>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for ToggleGroupCallSettingsQuery: " << to_string(ptr);
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (status.message() == "GROUPCALL_NOT_MODIFIED") {
promise_.set_value(Unit());
return;
@ -588,18 +588,18 @@ class InviteToGroupCallQuery final : public Td::ResultHandler {
telegram_api::phone_inviteToGroupCall(input_group_call_id.get_input_group_call(), std::move(input_users))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_inviteToGroupCall>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for InviteToGroupCallQuery: " << to_string(ptr);
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -620,17 +620,17 @@ class ExportGroupCallInviteQuery final : public Td::ResultHandler {
flags, false /*ignored*/, input_group_call_id.get_input_group_call())));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_exportGroupCallInvite>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
promise_.set_value(std::move(ptr->link_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -659,18 +659,18 @@ class ToggleGroupCallRecordQuery final : public Td::ResultHandler {
use_portrait_orientation)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_toggleGroupCallRecord>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for ToggleGroupCallRecordQuery: " << to_string(ptr);
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (status.message() == "GROUPCALL_NOT_MODIFIED") {
promise_.set_value(Unit());
return;
@ -690,9 +690,9 @@ class EditGroupCallParticipantQuery final : public Td::ResultHandler {
int32 volume_level, bool set_raise_hand, bool raise_hand, bool set_video_is_stopped, bool video_is_stopped,
bool set_video_is_paused, bool video_is_paused, bool set_presentation_is_paused,
bool presentation_is_paused) {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Know);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Know);
if (input_peer == nullptr) {
return on_error(0, Status::Error(400, "Can't access the chat"));
return on_error(Status::Error(400, "Can't access the chat"));
}
int32 flags = 0;
@ -715,18 +715,18 @@ class EditGroupCallParticipantQuery final : public Td::ResultHandler {
video_is_stopped, video_is_paused, presentation_is_paused)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_editGroupCallParticipant>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for EditGroupCallParticipantQuery: " << to_string(ptr);
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -746,10 +746,10 @@ class CheckGroupCallQuery final : public Td::ResultHandler {
telegram_api::phone_checkGroupCall(input_group_call_id.get_input_group_call(), std::move(audio_sources))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_checkGroupCall>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
vector<int32> active_audio_sources = result_ptr.move_as_ok();
@ -762,7 +762,7 @@ class CheckGroupCallQuery final : public Td::ResultHandler {
}
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -779,18 +779,18 @@ class LeaveGroupCallQuery final : public Td::ResultHandler {
telegram_api::phone_leaveGroupCall(input_group_call_id.get_input_group_call(), audio_source)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_leaveGroupCall>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for LeaveGroupCallQuery: " << to_string(ptr);
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -807,18 +807,18 @@ class DiscardGroupCallQuery final : public Td::ResultHandler {
telegram_api::phone_discardGroupCall(input_group_call_id.get_input_group_call())));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::phone_discardGroupCall>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for DiscardGroupCallQuery: " << to_string(ptr);
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -2304,7 +2304,7 @@ void GroupCallManager::on_update_dialog_about(DialogId dialog_id, const string &
}
CHECK(!it->second.empty());
for (auto input_group_call_id : it->second) {
for (const auto &input_group_call_id : it->second) {
auto participant = get_group_call_participant(input_group_call_id, dialog_id);
CHECK(participant != nullptr);
if ((from_server || participant->is_fake) && participant->about != about) {
@ -3935,7 +3935,7 @@ void GroupCallManager::leave_group_call(GroupCallId group_call_id, Promise<Unit>
process_group_call_after_join_requests(input_group_call_id, "leave_group_call 1");
return promise.set_value(Unit());
}
if (group_call->need_rejoin) {
if (group_call != nullptr && group_call->need_rejoin) {
group_call->need_rejoin = false;
send_update_group_call(group_call, "leave_group_call");
if (try_clear_group_call_participants(input_group_call_id)) {

View File

@ -90,26 +90,26 @@ class GetInlineBotResultsQuery final : public Td::ResultHandler {
return result;
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getInlineBotResults>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
td->inline_queries_manager_->on_get_inline_query_results(dialog_id_, bot_user_id_, query_hash_,
result_ptr.move_as_ok());
td_->inline_queries_manager_->on_get_inline_query_results(dialog_id_, bot_user_id_, query_hash_,
result_ptr.move_as_ok());
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (status.code() == NetQuery::Canceled) {
status = Status::Error(406, "Request canceled");
} else if (status.message() == "BOT_RESPONSE_TIMEOUT") {
status = Status::Error(502, "The bot is not responding");
}
LOG(INFO) << "Inline query returned error " << status;
LOG(INFO) << "Receive error for GetInlineBotResultsQuery: " << status;
td->inline_queries_manager_->on_get_inline_query_results(dialog_id_, bot_user_id_, query_hash_, nullptr);
td_->inline_queries_manager_->on_get_inline_query_results(dialog_id_, bot_user_id_, query_hash_, nullptr);
promise_.set_error(std::move(status));
}
};
@ -144,10 +144,10 @@ class SetInlineBotResultsQuery final : public Td::ResultHandler {
std::move(inline_bot_switch_pm))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_setInlineBotResults>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
bool result = result_ptr.ok();
@ -157,7 +157,7 @@ class SetInlineBotResultsQuery final : public Td::ResultHandler {
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -174,6 +174,9 @@ void InlineQueriesManager::tear_down() {
void InlineQueriesManager::on_drop_inline_query_result_timeout_callback(void *inline_queries_manager_ptr,
int64 query_hash) {
if (G()->close_flag()) {
return;
}
auto inline_queries_manager = static_cast<InlineQueriesManager *>(inline_queries_manager_ptr);
auto it = inline_queries_manager->inline_query_results_.find(query_hash);
CHECK(it != inline_queries_manager->inline_query_results_.end());

View File

@ -74,7 +74,7 @@ vector<telegram_api::object_ptr<telegram_api::InputDialogPeer>> InputDialogId::g
const vector<InputDialogId> &input_dialog_ids) {
vector<telegram_api::object_ptr<telegram_api::InputDialogPeer>> result;
result.reserve(input_dialog_ids.size());
for (auto input_dialog_id : input_dialog_ids) {
for (const auto &input_dialog_id : input_dialog_ids) {
auto input_peer = input_dialog_id.get_input_peer();
if (input_peer != nullptr) {
result.push_back(telegram_api::make_object<telegram_api::inputDialogPeer>(std::move(input_peer)));
@ -87,7 +87,7 @@ vector<telegram_api::object_ptr<telegram_api::InputPeer>> InputDialogId::get_inp
const vector<InputDialogId> &input_dialog_ids) {
vector<telegram_api::object_ptr<telegram_api::InputPeer>> result;
result.reserve(input_dialog_ids.size());
for (auto input_dialog_id : input_dialog_ids) {
for (const auto &input_dialog_id : input_dialog_ids) {
auto input_peer = input_dialog_id.get_input_peer();
CHECK(input_peer != nullptr);
result.push_back(std::move(input_peer));

View File

@ -389,10 +389,10 @@ class GetDeepLinkInfoQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create_unauth(telegram_api::help_getDeepLinkInfo(link.str())));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::help_getDeepLinkInfo>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
@ -419,7 +419,7 @@ class GetDeepLinkInfoQuery final : public Td::ResultHandler {
}
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -440,7 +440,7 @@ class RequestUrlAuthQuery final : public Td::ResultHandler {
tl_object_ptr<telegram_api::InputPeer> input_peer;
if (full_message_id.get_dialog_id().is_valid()) {
dialog_id_ = full_message_id.get_dialog_id();
input_peer = td->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
CHECK(input_peer != nullptr);
flags |= telegram_api::messages_requestUrlAuth::PEER_MASK;
} else {
@ -451,24 +451,24 @@ class RequestUrlAuthQuery final : public Td::ResultHandler {
url_)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_requestUrlAuth>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
LOG(INFO) << "Receive " << to_string(result);
LOG(INFO) << "Receive result for RequestUrlAuthQuery: " << to_string(result);
switch (result->get_id()) {
case telegram_api::urlAuthResultRequest::ID: {
auto request = telegram_api::move_object_as<telegram_api::urlAuthResultRequest>(result);
UserId bot_user_id = ContactsManager::get_user_id(request->bot_);
if (!bot_user_id.is_valid()) {
return on_error(id, Status::Error(500, "Receive invalid bot_user_id"));
return on_error(Status::Error(500, "Receive invalid bot_user_id"));
}
td->contacts_manager_->on_get_user(std::move(request->bot_), "RequestUrlAuthQuery");
td_->contacts_manager_->on_get_user(std::move(request->bot_), "RequestUrlAuthQuery");
promise_.set_value(td_api::make_object<td_api::loginUrlInfoRequestConfirmation>(
url_, request->domain_, td->contacts_manager_->get_user_id_object(bot_user_id, "RequestUrlAuthQuery"),
url_, request->domain_, td_->contacts_manager_->get_user_id_object(bot_user_id, "RequestUrlAuthQuery"),
request->request_write_access_));
break;
}
@ -483,10 +483,10 @@ class RequestUrlAuthQuery final : public Td::ResultHandler {
}
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (!dialog_id_.is_valid() ||
!td->messages_manager_->on_get_dialog_error(dialog_id_, status, "RequestUrlAuthQuery")) {
LOG(INFO) << "RequestUrlAuthQuery returned " << status;
!td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "RequestUrlAuthQuery")) {
LOG(INFO) << "Receive error for RequestUrlAuthQuery: " << status;
}
promise_.set_value(td_api::make_object<td_api::loginUrlInfoOpen>(url_, false));
}
@ -507,7 +507,7 @@ class AcceptUrlAuthQuery final : public Td::ResultHandler {
tl_object_ptr<telegram_api::InputPeer> input_peer;
if (full_message_id.get_dialog_id().is_valid()) {
dialog_id_ = full_message_id.get_dialog_id();
input_peer = td->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
CHECK(input_peer != nullptr);
flags |= telegram_api::messages_acceptUrlAuth::PEER_MASK;
} else {
@ -521,10 +521,10 @@ class AcceptUrlAuthQuery final : public Td::ResultHandler {
button_id, url_)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_acceptUrlAuth>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
@ -532,7 +532,7 @@ class AcceptUrlAuthQuery final : public Td::ResultHandler {
switch (result->get_id()) {
case telegram_api::urlAuthResultRequest::ID:
LOG(ERROR) << "Receive unexpected " << to_string(result);
return on_error(id, Status::Error(500, "Receive unexpected urlAuthResultRequest"));
return on_error(Status::Error(500, "Receive unexpected urlAuthResultRequest"));
case telegram_api::urlAuthResultAccepted::ID: {
auto accepted = telegram_api::move_object_as<telegram_api::urlAuthResultAccepted>(result);
promise_.set_value(td_api::make_object<td_api::httpUrl>(accepted->url_));
@ -544,10 +544,10 @@ class AcceptUrlAuthQuery final : public Td::ResultHandler {
}
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (!dialog_id_.is_valid() ||
!td->messages_manager_->on_get_dialog_error(dialog_id_, status, "AcceptUrlAuthQuery")) {
LOG(INFO) << "AcceptUrlAuthQuery returned " << status;
!td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "AcceptUrlAuthQuery")) {
LOG(INFO) << "Receive error for AcceptUrlAuthQuery: " << status;
}
promise_.set_error(std::move(status));
}

View File

@ -157,12 +157,7 @@ Result<InputMessageLocation> process_input_message_location(
return Status::Error(400, "Wrong live location proximity alert radius specified");
}
InputMessageLocation result;
result.location = std::move(location);
result.live_period = period;
result.heading = heading;
result.proximity_alert_radius = proximity_alert_radius;
return std::move(result);
return InputMessageLocation(std::move(location), period, heading, proximity_alert_radius);
}
} // namespace td

View File

@ -126,6 +126,13 @@ struct InputMessageLocation {
int32 live_period;
int32 heading;
int32 proximity_alert_radius;
InputMessageLocation(Location &&location, int32 live_period, int32 heading, int32 proximity_alert_radius)
: location(std::move(location))
, live_period(live_period)
, heading(heading)
, proximity_alert_radius(proximity_alert_radius) {
}
};
Result<InputMessageLocation> process_input_message_location(
td_api::object_ptr<td_api::InputMessageContent> &&input_message_content) TD_WARN_UNUSED_RESULT;

View File

@ -1727,7 +1727,7 @@ static Result<InputMessageContent> create_input_message_content(
int32 type = 'i';
if (file_view.has_remote_location() && !file_view.remote_location().is_web()) {
auto photo_size_source = file_view.remote_location().get_source();
if (photo_size_source.get_type() == PhotoSizeSource::Type::Thumbnail) {
if (photo_size_source.get_type("create_input_message_content") == PhotoSizeSource::Type::Thumbnail) {
auto old_type = photo_size_source.thumbnail().thumbnail_type;
if (old_type != 't') {
type = old_type;
@ -5632,10 +5632,6 @@ void on_sent_message_content(Td *td, const MessageContent *content) {
}
}
StickerSetId add_sticker_set(Td *td, tl_object_ptr<telegram_api::InputStickerSet> &&input_sticker_set) {
return td->stickers_manager_->add_sticker_set(std::move(input_sticker_set));
}
bool is_unsent_animated_emoji_click(Td *td, DialogId dialog_id, const DialogAction &action) {
auto emoji = action.get_watching_animations_emoji();
if (emoji.empty()) {

View File

@ -20,7 +20,6 @@
#include "td/telegram/ReplyMarkup.h"
#include "td/telegram/secret_api.h"
#include "td/telegram/SecretInputMedia.h"
#include "td/telegram/StickerSetId.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/TopDialogCategory.h"
@ -245,8 +244,6 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
void on_sent_message_content(Td *td, const MessageContent *content);
StickerSetId add_sticker_set(Td *td, tl_object_ptr<telegram_api::InputStickerSet> &&input_sticker_set);
bool is_unsent_animated_emoji_click(Td *td, DialogId dialog_id, const DialogAction &action);
void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date);

View File

@ -20,7 +20,8 @@ MessageId::MessageId(ScheduledServerMessageId server_message_id, int32 send_date
LOG(ERROR) << "Scheduled message ID " << server_message_id.get() << " is invalid";
return;
}
id = (static_cast<int64>(send_date - (1 << 30)) << 21) | (server_message_id.get() << 3) | SCHEDULED_MASK;
id = (static_cast<int64>(send_date - (1 << 30)) << 21) | (static_cast<int64>(server_message_id.get()) << 3) |
SCHEDULED_MASK;
}
bool MessageId::is_valid() const {

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@
#pragma once
#include "td/telegram/AccessRights.h"
#include "td/telegram/AffectedHistory.h"
#include "td/telegram/ChannelId.h"
#include "td/telegram/DialogAction.h"
#include "td/telegram/DialogDate.h"
@ -512,15 +513,6 @@ class MessagesManager final : public Actor {
void get_dialog_info_full(DialogId dialog_id, Promise<Unit> &&promise, const char *source);
int64 get_dialog_event_log(DialogId dialog_id, const string &query, int64 from_event_id, int32 limit,
const tl_object_ptr<td_api::chatEventLogFilters> &filters, const vector<UserId> &user_ids,
Promise<Unit> &&promise);
void on_get_event_log(ChannelId channel_id, int64 random_id,
tl_object_ptr<telegram_api::channels_adminLogResults> &&events);
tl_object_ptr<td_api::chatEvents> get_chat_events_object(int64 random_id);
string get_dialog_title(DialogId dialog_id) const;
bool have_dialog(DialogId dialog_id) const;
@ -769,6 +761,9 @@ class MessagesManager final : public Actor {
tl_object_ptr<td_api::message> get_dialog_message_by_date_object(int64 random_id);
td_api::object_ptr<td_api::message> get_dialog_event_log_message_object(
DialogId dialog_id, tl_object_ptr<telegram_api::Message> &&message);
tl_object_ptr<td_api::message> get_message_object(FullMessageId full_message_id, const char *source);
tl_object_ptr<td_api::messages> get_messages_object(int32 total_count, DialogId dialog_id,
@ -1043,7 +1038,7 @@ class MessagesManager final : public Actor {
// Do not forget to update MessagesManager::update_message and all make_unique<Message> when this class is changed
struct Message {
int32 random_y;
int32 random_y = 0;
MessageId message_id;
UserId sender_user_id;
@ -2006,6 +2001,8 @@ class MessagesManager final : public Actor {
void do_delete_all_dialog_messages(Dialog *d, unique_ptr<Message> &message, bool is_permanently_deleted,
vector<int64> &deleted_message_ids);
void erase_delete_messages_log_event(uint64 log_event_id);
void delete_sent_message_on_server(DialogId dialog_id, MessageId message_id);
void delete_messages_on_server(DialogId dialog_id, vector<MessageId> message_ids, bool revoke, uint64 log_event_id,
@ -2033,6 +2030,14 @@ class MessagesManager final : public Actor {
void unpin_all_dialog_messages_on_server(DialogId dialog_id, uint64 log_event_id, Promise<Unit> &&promise);
using AffectedHistoryQuery = std::function<void(DialogId, Promise<AffectedHistory>)>;
void run_affected_history_query_until_complete(DialogId dialog_id, AffectedHistoryQuery query,
bool get_affected_messages, Promise<Unit> &&promise);
void on_get_affected_history(DialogId dialog_id, AffectedHistoryQuery query, bool get_affected_messages,
AffectedHistory affected_history, Promise<Unit> &&promise);
static MessageId find_message_by_date(const Message *m, int32 date);
static void find_messages_by_date(const Message *m, int32 min_date, int32 max_date, vector<MessageId> &message_ids);
@ -2999,12 +3004,6 @@ class MessagesManager final : public Actor {
void load_secret_thumbnail(FileId thumbnail_file_id);
static tl_object_ptr<telegram_api::channelAdminLogEventsFilter> get_channel_admin_log_events_filter(
const tl_object_ptr<td_api::chatEventLogFilters> &filters);
tl_object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
ChannelId channel_id, tl_object_ptr<telegram_api::ChannelAdminLogEventAction> &&action_ptr);
void on_upload_media(FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file,
tl_object_ptr<telegram_api::InputEncryptedFile> input_encrypted_file);
void on_upload_media_error(FileId file_id, Status status);
@ -3362,8 +3361,6 @@ class MessagesManager final : public Actor {
};
std::unordered_map<DialogId, MessageEmbeddingCodes, DialogIdHash> message_embedding_codes_[2];
std::unordered_map<int64, tl_object_ptr<td_api::chatEvents>> chat_events_; // random_id -> chat events
std::unordered_map<DialogId, vector<Promise<Unit>>, DialogIdHash> get_dialog_notification_settings_queries_;
std::unordered_map<DialogId, vector<Promise<Unit>>, DialogIdHash> get_dialog_queries_;

View File

@ -79,16 +79,16 @@ class SetContactSignUpNotificationQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::account_setContactSignUpNotification(is_disabled)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_setContactSignUpNotification>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (!G()->is_expected_error(status)) {
LOG(ERROR) << "Receive error for set contact sign up notification: " << status;
}
@ -107,17 +107,17 @@ class GetContactSignUpNotificationQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::account_getContactSignUpNotification()));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_getContactSignUpNotification>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
td->notification_manager_->on_get_disable_contact_registered_notifications(result_ptr.ok());
td_->notification_manager_->on_get_disable_contact_registered_notifications(result_ptr.ok());
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (!G()->is_expected_error(status)) {
LOG(ERROR) << "Receive error for get contact sign up notification: " << status;
}
@ -999,6 +999,7 @@ void NotificationManager::add_update_notification(NotificationGroupId notificati
}
void NotificationManager::flush_pending_updates(int32 group_id, const char *source) {
// no check for G()->close_flag() to flush pending notifications even while closing
auto it = pending_updates_.find(group_id);
if (it == pending_updates_.end()) {
return;
@ -1364,7 +1365,7 @@ void NotificationManager::flush_all_pending_updates(bool include_delayed_chats,
// flush groups in reverse order to not exceed max_notification_group_count_
VLOG(notifications) << "Flush pending updates in " << ready_group_keys.size() << " notification groups";
std::sort(ready_group_keys.begin(), ready_group_keys.end());
for (auto group_key : reversed(ready_group_keys)) {
for (const auto &group_key : reversed(ready_group_keys)) {
force_flush_pending_updates(group_key.group_id, "flush_all_pending_updates");
}
if (include_delayed_chats) {
@ -1374,6 +1375,7 @@ void NotificationManager::flush_all_pending_updates(bool include_delayed_chats,
bool NotificationManager::do_flush_pending_notifications(NotificationGroupKey &group_key, NotificationGroup &group,
vector<PendingNotification> &pending_notifications) {
// no check for G()->close_flag() to flush pending notifications even while closing
if (pending_notifications.empty()) {
return false;
}

View File

@ -677,7 +677,7 @@ Result<PasswordManager::PasswordInputSettings> PasswordManager::get_password_inp
tl_object_ptr<telegram_api::secureSecretSettings> new_secure_settings;
if (update_secure_secret) {
auto secret = have_secret ? std::move(private_state->secret.value()) : secure_storage::Secret::create_new();
auto secret = have_secret ? private_state->secret.value() : secure_storage::Secret::create_new();
auto algorithm =
make_tl_object<telegram_api::securePasswordKdfAlgoPBKDF2HMACSHA512iter100000>(create_salt(state.secure_salt));
auto encrypted_secret = secret.encrypt(

View File

@ -112,10 +112,10 @@ class PasswordManager final : public NetQueryCallback {
string current_client_salt;
string current_server_salt;
int32 current_srp_g;
int32 current_srp_g = 0;
string current_srp_p;
string current_srp_B;
int64 current_srp_id;
int64 current_srp_id = 0;
NewPasswordState new_state;

View File

@ -51,10 +51,10 @@ class SetBotShippingAnswerQuery final : public Td::ResultHandler {
flags, shipping_query_id, error_message, std::move(shipping_options))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_setBotShippingResults>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
bool result = result_ptr.ok();
@ -64,7 +64,7 @@ class SetBotShippingAnswerQuery final : public Td::ResultHandler {
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -88,10 +88,10 @@ class SetBotPreCheckoutAnswerQuery final : public Td::ResultHandler {
flags, false /*ignored*/, pre_checkout_query_id, error_message)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_setBotPrecheckoutResults>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
bool result = result_ptr.ok();
@ -101,7 +101,7 @@ class SetBotPreCheckoutAnswerQuery final : public Td::ResultHandler {
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -270,9 +270,9 @@ class GetPaymentFormQuery final : public Td::ResultHandler {
void send(DialogId dialog_id, ServerMessageId server_message_id,
tl_object_ptr<telegram_api::dataJSON> &&theme_parameters) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
return on_error(0, Status::Error(400, "Can't access the chat"));
return on_error(Status::Error(400, "Can't access the chat"));
}
int32 flags = 0;
@ -283,40 +283,40 @@ class GetPaymentFormQuery final : public Td::ResultHandler {
flags, std::move(input_peer), server_message_id.get(), std::move(theme_parameters))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_getPaymentForm>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto payment_form = result_ptr.move_as_ok();
LOG(INFO) << "Receive payment form: " << to_string(payment_form);
LOG(INFO) << "Receive result for GetPaymentFormQuery: " << to_string(payment_form);
td->contacts_manager_->on_get_users(std::move(payment_form->users_), "GetPaymentFormQuery");
td_->contacts_manager_->on_get_users(std::move(payment_form->users_), "GetPaymentFormQuery");
UserId payments_provider_user_id(payment_form->provider_id_);
if (!payments_provider_user_id.is_valid()) {
LOG(ERROR) << "Receive invalid payments provider " << payments_provider_user_id;
return on_error(id, Status::Error(500, "Receive invalid payments provider identifier"));
return on_error(Status::Error(500, "Receive invalid payments provider identifier"));
}
UserId seller_bot_user_id(payment_form->bot_id_);
if (!seller_bot_user_id.is_valid()) {
LOG(ERROR) << "Receive invalid seller " << seller_bot_user_id;
return on_error(id, Status::Error(500, "Receive invalid seller identifier"));
return on_error(Status::Error(500, "Receive invalid seller identifier"));
}
bool can_save_credentials = payment_form->can_save_credentials_;
bool need_password = payment_form->password_missing_;
promise_.set_value(make_tl_object<td_api::paymentForm>(
payment_form->form_id_, convert_invoice(std::move(payment_form->invoice_)), std::move(payment_form->url_),
td->contacts_manager_->get_user_id_object(seller_bot_user_id, "paymentForm seller"),
td->contacts_manager_->get_user_id_object(payments_provider_user_id, "paymentForm provider"),
td_->contacts_manager_->get_user_id_object(seller_bot_user_id, "paymentForm seller"),
td_->contacts_manager_->get_user_id_object(payments_provider_user_id, "paymentForm provider"),
convert_payment_provider(payment_form->native_provider_, std::move(payment_form->native_params_)),
convert_order_info(std::move(payment_form->saved_info_)),
convert_saved_credentials(std::move(payment_form->saved_credentials_)), can_save_credentials, need_password));
}
void on_error(uint64 id, Status status) final {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetPaymentFormQuery");
void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetPaymentFormQuery");
promise_.set_error(std::move(status));
}
};
@ -333,9 +333,9 @@ class ValidateRequestedInfoQuery final : public Td::ResultHandler {
void send(DialogId dialog_id, ServerMessageId server_message_id,
tl_object_ptr<telegram_api::paymentRequestedInfo> requested_info, bool allow_save) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
return on_error(0, Status::Error(400, "Can't access the chat"));
return on_error(Status::Error(400, "Can't access the chat"));
}
int32 flags = 0;
@ -350,22 +350,22 @@ class ValidateRequestedInfoQuery final : public Td::ResultHandler {
flags, false /*ignored*/, std::move(input_peer), server_message_id.get(), std::move(requested_info))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_validateRequestedInfo>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto validated_order_info = result_ptr.move_as_ok();
LOG(INFO) << "Receive validated order info: " << to_string(validated_order_info);
LOG(INFO) << "Receive result for ValidateRequestedInfoQuery: " << to_string(validated_order_info);
promise_.set_value(make_tl_object<td_api::validatedOrderInfo>(
std::move(validated_order_info->id_),
transform(std::move(validated_order_info->shipping_options_), convert_shipping_option)));
}
void on_error(uint64 id, Status status) final {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "ValidateRequestedInfoQuery");
void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "ValidateRequestedInfoQuery");
promise_.set_error(std::move(status));
}
};
@ -385,9 +385,9 @@ class SendPaymentFormQuery final : public Td::ResultHandler {
CHECK(input_credentials != nullptr);
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
return on_error(0, Status::Error(400, "Can't access the chat"));
return on_error(Status::Error(400, "Can't access the chat"));
}
int32 flags = 0;
@ -405,22 +405,22 @@ class SendPaymentFormQuery final : public Td::ResultHandler {
std::move(input_credentials), tip_amount)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_sendPaymentForm>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto payment_result = result_ptr.move_as_ok();
LOG(INFO) << "Receive payment result: " << to_string(payment_result);
LOG(INFO) << "Receive result for SendPaymentFormQuery: " << to_string(payment_result);
switch (payment_result->get_id()) {
case telegram_api::payments_paymentResult::ID: {
auto result = move_tl_object_as<telegram_api::payments_paymentResult>(payment_result);
td->updates_manager_->on_get_updates(std::move(result->updates_),
PromiseCreator::lambda([promise = std::move(promise_)](Unit) mutable {
promise.set_value(make_tl_object<td_api::paymentResult>(true, string()));
}));
td_->updates_manager_->on_get_updates(
std::move(result->updates_), PromiseCreator::lambda([promise = std::move(promise_)](Unit) mutable {
promise.set_value(make_tl_object<td_api::paymentResult>(true, string()));
}));
return;
}
case telegram_api::payments_paymentVerificationNeeded::ID: {
@ -433,8 +433,8 @@ class SendPaymentFormQuery final : public Td::ResultHandler {
}
}
void on_error(uint64 id, Status status) final {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "SendPaymentFormQuery");
void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "SendPaymentFormQuery");
promise_.set_error(std::move(status));
}
};
@ -450,49 +450,49 @@ class GetPaymentReceiptQuery final : public Td::ResultHandler {
void send(DialogId dialog_id, ServerMessageId server_message_id) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
return on_error(0, Status::Error(400, "Can't access the chat"));
return on_error(Status::Error(400, "Can't access the chat"));
}
send_query(G()->net_query_creator().create(
telegram_api::payments_getPaymentReceipt(std::move(input_peer), server_message_id.get())));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_getPaymentReceipt>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto payment_receipt = result_ptr.move_as_ok();
LOG(INFO) << "Receive payment receipt: " << to_string(payment_receipt);
LOG(INFO) << "Receive result for GetPaymentReceiptQuery: " << to_string(payment_receipt);
td->contacts_manager_->on_get_users(std::move(payment_receipt->users_), "GetPaymentReceiptQuery");
td_->contacts_manager_->on_get_users(std::move(payment_receipt->users_), "GetPaymentReceiptQuery");
UserId payments_provider_user_id(payment_receipt->provider_id_);
if (!payments_provider_user_id.is_valid()) {
LOG(ERROR) << "Receive invalid payments provider " << payments_provider_user_id;
return on_error(id, Status::Error(500, "Receive invalid payments provider identifier"));
return on_error(Status::Error(500, "Receive invalid payments provider identifier"));
}
UserId seller_bot_user_id(payment_receipt->bot_id_);
if (!seller_bot_user_id.is_valid()) {
LOG(ERROR) << "Receive invalid seller " << seller_bot_user_id;
return on_error(id, Status::Error(500, "Receive invalid seller identifier"));
return on_error(Status::Error(500, "Receive invalid seller identifier"));
}
auto photo = get_web_document_photo(td->file_manager_.get(), std::move(payment_receipt->photo_), dialog_id_);
auto photo = get_web_document_photo(td_->file_manager_.get(), std::move(payment_receipt->photo_), dialog_id_);
promise_.set_value(make_tl_object<td_api::paymentReceipt>(
payment_receipt->title_, payment_receipt->description_, get_photo_object(td->file_manager_.get(), photo),
payment_receipt->date_, td->contacts_manager_->get_user_id_object(seller_bot_user_id, "paymentReceipt seller"),
td->contacts_manager_->get_user_id_object(payments_provider_user_id, "paymentReceipt provider"),
payment_receipt->title_, payment_receipt->description_, get_photo_object(td_->file_manager_.get(), photo),
payment_receipt->date_, td_->contacts_manager_->get_user_id_object(seller_bot_user_id, "paymentReceipt seller"),
td_->contacts_manager_->get_user_id_object(payments_provider_user_id, "paymentReceipt provider"),
convert_invoice(std::move(payment_receipt->invoice_)), convert_order_info(std::move(payment_receipt->info_)),
convert_shipping_option(std::move(payment_receipt->shipping_)), std::move(payment_receipt->credentials_title_),
payment_receipt->tip_amount_));
}
void on_error(uint64 id, Status status) final {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetPaymentReceiptQuery");
void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetPaymentReceiptQuery");
promise_.set_error(std::move(status));
}
};
@ -508,18 +508,18 @@ class GetSavedInfoQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::payments_getSavedInfo()));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_getSavedInfo>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto saved_info = result_ptr.move_as_ok();
LOG(INFO) << "Receive saved info: " << to_string(saved_info);
LOG(INFO) << "Receive result for GetSavedInfoQuery: " << to_string(saved_info);
promise_.set_value(convert_order_info(std::move(saved_info->saved_info_)));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -544,16 +544,16 @@ class ClearSavedInfoQuery final : public Td::ResultHandler {
telegram_api::payments_clearSavedInfo(flags, false /*ignored*/, false /*ignored*/)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_clearSavedInfo>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -571,10 +571,10 @@ class GetBankCardInfoQuery final : public Td::ResultHandler {
G()->get_webfile_dc_id()));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_getBankCardData>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto response = result_ptr.move_as_ok();
@ -584,7 +584,7 @@ class GetBankCardInfoQuery final : public Td::ResultHandler {
promise_.set_value(td_api::make_object<td_api::bankCardInfo>(response->title_, std::move(actions)));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};

View File

@ -42,7 +42,7 @@ class PhoneNumberManager final : public NetActor {
ActorShared<> parent_;
uint64 query_id_ = 0;
uint64 net_query_id_ = 0;
NetQueryType net_query_type_;
NetQueryType net_query_type_ = NetQueryType::None;
SendCodeHelper send_code_helper_;

View File

@ -142,7 +142,8 @@ static StringBuilder &operator<<(StringBuilder &string_builder, PhotoFormat form
static FileId register_photo(FileManager *file_manager, const PhotoSizeSource &source, int64 id, int64 access_hash,
std::string file_reference, DialogId owner_dialog_id, int32 file_size, DcId dc_id,
PhotoFormat format) {
LOG(DEBUG) << "Receive " << format << " photo " << id << " of type " << source.get_file_type() << " from " << dc_id;
LOG(DEBUG) << "Receive " << format << " photo " << id << " of type " << source.get_file_type("register_photo")
<< " from " << dc_id;
auto suggested_name = PSTRING() << source.get_unique_name(id) << '.' << format;
auto file_location_source = owner_dialog_id.get_type() == DialogType::SecretChat ? FileLocationSource::FromUser
: FileLocationSource::FromServer;
@ -447,7 +448,7 @@ Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, PhotoSizeSo
res.type = 0;
}
}
if (source.get_type() == PhotoSizeSource::Type::Thumbnail) {
if (source.get_type("get_photo_size") == PhotoSizeSource::Type::Thumbnail) {
source.thumbnail().thumbnail_type = res.type;
}
@ -480,7 +481,7 @@ AnimationSize get_animation_size(FileManager *file_manager, PhotoSizeSource sour
res.main_frame_timestamp = size->video_start_ts_;
}
if (source.get_type() == PhotoSizeSource::Type::Thumbnail) {
if (source.get_type("get_animation_size") == PhotoSizeSource::Type::Thumbnail) {
source.thumbnail().thumbnail_type = res.type;
}

View File

@ -43,8 +43,8 @@ tl_object_ptr<telegram_api::InputPeer> PhotoSizeSource::DialogPhoto::get_input_p
}
}
FileType PhotoSizeSource::get_file_type() const {
switch (get_type()) {
FileType PhotoSizeSource::get_file_type(const char *source) const {
switch (get_type(source)) {
case Type::Thumbnail:
return thumbnail().file_type;
case Type::DialogPhotoSmall:
@ -68,7 +68,7 @@ string PhotoSizeSource::get_unique() const {
auto ptr = StackAllocator::alloc(16);
MutableSlice data = ptr.as_slice();
TlStorerUnsafe storer(data.ubegin());
switch (get_type()) {
switch (get_type("get_unique")) {
case Type::Legacy:
UNREACHABLE();
break;
@ -129,7 +129,7 @@ string PhotoSizeSource::get_unique() const {
}
string PhotoSizeSource::get_unique_name(int64 photo_id) const {
switch (get_type()) {
switch (get_type("get_unique_name")) {
case Type::Thumbnail:
CHECK(0 <= thumbnail().thumbnail_type && thumbnail().thumbnail_type <= 127);
return PSTRING() << photo_id << '_' << thumbnail().thumbnail_type;
@ -226,7 +226,7 @@ bool operator!=(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) {
}
StringBuilder &operator<<(StringBuilder &string_builder, const PhotoSizeSource &source) {
switch (source.get_type()) {
switch (source.get_type("operator<<")) {
case PhotoSizeSource::Type::Legacy:
return string_builder << "PhotoSizeSourceLegacy[]";
case PhotoSizeSource::Type::Thumbnail:

View File

@ -11,6 +11,7 @@
#include "td/telegram/telegram_api.h"
#include "td/utils/common.h"
#include "td/utils/logging.h"
#include "td/utils/StringBuilder.h"
#include "td/utils/Variant.h"
@ -45,7 +46,7 @@ struct PhotoSizeSource {
Thumbnail(FileType file_type, int32 thumbnail_type) : file_type(file_type), thumbnail_type(thumbnail_type) {
}
FileType file_type;
FileType file_type = FileType::None;
int32 thumbnail_type = 0;
};
@ -177,13 +178,13 @@ struct PhotoSizeSource {
return PhotoSizeSource(StickerSetThumbnailVersion(sticker_set_id, sticker_set_access_hash, version));
}
Type get_type() const {
Type get_type(const char *source) const {
auto offset = variant_.get_offset();
CHECK(offset >= 0);
LOG_CHECK(offset >= 0) << offset << ' ' << source;
return static_cast<Type>(offset);
}
FileType get_file_type() const;
FileType get_file_type(const char *source) const;
Thumbnail &thumbnail() {
return variant_.get<Thumbnail>();

View File

@ -62,7 +62,7 @@ class GetPollResultsQuery final : public Td::ResultHandler {
void send(PollId poll_id, FullMessageId full_message_id) {
poll_id_ = poll_id;
dialog_id_ = full_message_id.get_dialog_id();
auto input_peer = td->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
if (input_peer == nullptr) {
LOG(INFO) << "Can't reget poll, because have no read access to " << dialog_id_;
return promise_.set_value(nullptr);
@ -73,17 +73,17 @@ class GetPollResultsQuery final : public Td::ResultHandler {
G()->net_query_creator().create(telegram_api::messages_getPollResults(std::move(input_peer), message_id)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getPollResults>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) final {
if (!td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetPollResultsQuery") &&
void on_error(Status status) final {
if (!td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetPollResultsQuery") &&
status.message() != "MESSAGE_ID_INVALID") {
LOG(ERROR) << "Receive " << status << ", while trying to get results of " << poll_id_;
}
@ -104,7 +104,7 @@ class GetPollVotersQuery final : public Td::ResultHandler {
void send(PollId poll_id, FullMessageId full_message_id, BufferSlice &&option, const string &offset, int32 limit) {
poll_id_ = poll_id;
dialog_id_ = full_message_id.get_dialog_id();
auto input_peer = td->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
if (input_peer == nullptr) {
LOG(INFO) << "Can't get poll, because have no read access to " << dialog_id_;
return promise_.set_error(Status::Error(400, "Chat is not accessible"));
@ -121,17 +121,17 @@ class GetPollVotersQuery final : public Td::ResultHandler {
flags, std::move(input_peer), message_id, std::move(option), offset, limit)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getPollVotes>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) final {
if (!td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetPollVotersQuery") &&
void on_error(Status status) final {
if (!td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetPollVotersQuery") &&
status.message() != "MESSAGE_ID_INVALID") {
LOG(ERROR) << "Receive " << status << ", while trying to get voters of " << poll_id_;
}
@ -149,10 +149,10 @@ class SetPollAnswerActor final : public NetActorOnce {
void send(FullMessageId full_message_id, vector<BufferSlice> &&options, uint64 generation, NetQueryRef *query_ref) {
dialog_id_ = full_message_id.get_dialog_id();
auto input_peer = td->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
if (input_peer == nullptr) {
LOG(INFO) << "Can't set poll answer, because have no read access to " << dialog_id_;
return on_error(0, Status::Error(400, "Can't access the chat"));
return on_error(Status::Error(400, "Can't access the chat"));
}
auto message_id = full_message_id.get_message_id().get_server_message_id().get();
@ -160,14 +160,14 @@ class SetPollAnswerActor final : public NetActorOnce {
telegram_api::messages_sendVote(std::move(input_peer), message_id, std::move(options)));
*query_ref = query.get_weak();
auto sequence_id = -1;
send_closure(td->messages_manager_->sequence_dispatcher_, &MultiSequenceDispatcher::send_with_callback,
send_closure(td_->messages_manager_->sequence_dispatcher_, &MultiSequenceDispatcher::send_with_callback,
std::move(query), actor_shared(this), sequence_id);
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_sendVote>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
@ -175,8 +175,8 @@ class SetPollAnswerActor final : public NetActorOnce {
promise_.set_value(std::move(result));
}
void on_error(uint64 id, Status status) final {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "SetPollAnswerActor");
void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "SetPollAnswerActor");
promise_.set_error(std::move(status));
}
};
@ -191,10 +191,10 @@ class StopPollActor final : public NetActorOnce {
void send(FullMessageId full_message_id, unique_ptr<ReplyMarkup> &&reply_markup) {
dialog_id_ = full_message_id.get_dialog_id();
auto input_peer = td->messages_manager_->get_input_peer(dialog_id_, AccessRights::Edit);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Edit);
if (input_peer == nullptr) {
LOG(INFO) << "Can't close poll, because have no edit access to " << dialog_id_;
return on_error(0, Status::Error(400, "Can't access the chat"));
return on_error(Status::Error(400, "Can't access the chat"));
}
int32 flags = telegram_api::messages_editMessage::MEDIA_MASK;
@ -211,31 +211,31 @@ class StopPollActor final : public NetActorOnce {
auto query = G()->net_query_creator().create(telegram_api::messages_editMessage(
flags, false /*ignored*/, std::move(input_peer), message_id, string(), std::move(input_media),
std::move(input_reply_markup), vector<tl_object_ptr<telegram_api::MessageEntity>>(), 0));
if (td->auth_manager_->is_bot()) {
if (td_->auth_manager_->is_bot()) {
send_query(std::move(query));
} else {
auto sequence_id = -1;
send_closure(td->messages_manager_->sequence_dispatcher_, &MultiSequenceDispatcher::send_with_callback,
send_closure(td_->messages_manager_->sequence_dispatcher_, &MultiSequenceDispatcher::send_with_callback,
std::move(query), actor_shared(this), sequence_id);
}
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_editMessage>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for StopPoll: " << to_string(result);
td->updates_manager_->on_get_updates(std::move(result), std::move(promise_));
td_->updates_manager_->on_get_updates(std::move(result), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
if (!td->auth_manager_->is_bot() && status.message() == "MESSAGE_NOT_MODIFIED") {
void on_error(Status status) final {
if (!td_->auth_manager_->is_bot() && status.message() == "MESSAGE_NOT_MODIFIED") {
return promise_.set_value(Unit());
}
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "StopPollActor");
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "StopPollActor");
promise_.set_error(std::move(status));
}
};
@ -322,7 +322,7 @@ void PollManager::notify_on_poll_update(PollId poll_id) {
return;
}
for (auto full_message_id : it->second) {
for (const auto &full_message_id : it->second) {
td_->messages_manager_->on_external_update_message_content(full_message_id);
}
}
@ -456,8 +456,9 @@ vector<int32> PollManager::get_vote_percentage(const vector<int32> &voter_counts
option.count++;
}
vector<Option> sorted_options;
for (auto option : options) {
auto pos = option.second.pos;
for (const auto &it : options) {
const auto &option = it.second;
auto pos = option.pos;
if (gap[pos] > total_voter_count / 2) {
// do not round to wrong direction
continue;
@ -466,7 +467,7 @@ vector<int32> PollManager::get_vote_percentage(const vector<int32> &voter_counts
// round halves to the 50%
continue;
}
sorted_options.push_back(option.second);
sorted_options.push_back(option);
}
std::sort(sorted_options.begin(), sorted_options.end(), [&](const Option &lhs, const Option &rhs) {
if (gap[lhs.pos] != gap[rhs.pos]) {
@ -1151,12 +1152,12 @@ double PollManager::get_polling_timeout() const {
}
void PollManager::on_update_poll_timeout(PollId poll_id) {
CHECK(!td_->auth_manager_->is_bot());
CHECK(!is_local_poll_id(poll_id));
if (G()->close_flag()) {
return;
}
CHECK(!td_->auth_manager_->is_bot());
CHECK(!is_local_poll_id(poll_id));
auto poll = get_poll(poll_id);
CHECK(poll != nullptr);
if (poll->is_closed && poll->is_updated_after_close) {
@ -1182,11 +1183,10 @@ void PollManager::on_update_poll_timeout(PollId poll_id) {
}
void PollManager::on_close_poll_timeout(PollId poll_id) {
CHECK(!is_local_poll_id(poll_id));
if (G()->close_flag()) {
return;
}
CHECK(!is_local_poll_id(poll_id));
auto poll = get_poll_editable(poll_id);
CHECK(poll != nullptr);

View File

@ -26,10 +26,14 @@ template <class T = Unit>
class RequestActor : public Actor {
public:
RequestActor(ActorShared<Td> td_id, uint64 request_id)
: td_id_(std::move(td_id)), td(td_id_.get().get_actor_unsafe()), request_id_(request_id) {
: td_id_(std::move(td_id)), td_(td_id_.get().get_actor_unsafe()), request_id_(request_id) {
}
void loop() override {
if (G()->close_flag()) {
return do_send_error(Global::request_aborted_error());
}
PromiseActor<T> promise_actor;
FutureActor<T> future;
init_promise_future(&promise_actor, &future);
@ -65,9 +69,9 @@ class RequestActor : public Actor {
auto error = future_.move_as_error();
if (error == Status::Error<FutureActor<T>::HANGUP_ERROR_CODE>()) {
// dropping query due to lost authorization or lost promise
// td may be already closed, so we should check is auth_manager_ is empty
bool is_authorized = td->auth_manager_ && td->auth_manager_->is_authorized();
if (is_authorized) {
if (G()->close_flag()) {
do_send_error(Global::request_aborted_error());
} else if (!td_->auth_manager_->is_authorized()) {
LOG(ERROR) << "Promise was lost";
do_send_error(Status::Error(500, "Query can't be answered due to a bug in TDLib"));
} else {
@ -101,7 +105,7 @@ class RequestActor : public Actor {
protected:
ActorShared<Td> td_id_;
Td *td;
Td *td_;
void send_result(tl_object_ptr<td_api::Object> &&result) {
send_closure(td_id_, &Td::send_result, request_id_, std::move(result));

View File

@ -520,7 +520,7 @@ class SecretChatActor final : public NetQueryCallback {
return sb;
}
int32 message_id;
int32 message_id = 0;
private:
std::string data;
@ -537,7 +537,7 @@ class SecretChatActor final : public NetQueryCallback {
};
ChangesProcessor<StateChange> changes_processor_;
int32 saved_pfs_state_message_id_;
int32 saved_pfs_state_message_id_ = 0;
SeqNoState seq_no_state_;
bool seq_no_state_changed_ = false;
@ -559,7 +559,7 @@ class SecretChatActor final : public NetQueryCallback {
bool save_changes_finish = false;
bool save_message_finish = false;
LogEvent::Id log_event_id = 0;
int32 message_id;
int32 message_id = 0;
};
Container<InboundMessageState> inbound_message_states_;

View File

@ -141,10 +141,10 @@ class SetSecureValueErrorsQuery final : public Td::ResultHandler {
telegram_api::users_setSecureValueErrors(std::move(input_user), std::move(input_errors))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::users_setSecureValueErrors>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
bool ptr = result_ptr.move_as_ok();
@ -152,7 +152,7 @@ class SetSecureValueErrorsQuery final : public Td::ResultHandler {
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
if (status.code() != 0) {
promise_.set_error(std::move(status));
} else {
@ -1078,7 +1078,7 @@ void SecureManager::on_get_passport_authorization_form_secret(int32 authorizatio
auto *file_manager = G()->td().get_actor_unsafe()->file_manager_.get();
std::vector<TdApiSecureValue> values;
std::map<SecureValueType, SecureValueCredentials> all_credentials;
for (auto suitable_type : it->second.options) {
for (const auto &suitable_type : it->second.options) {
auto type = suitable_type.first;
for (auto &value : it->second.values) {
if (value == nullptr) {

View File

@ -183,7 +183,7 @@ struct SecureFileCredentials {
};
struct SecureValueCredentials {
SecureValueType type;
SecureValueType type = SecureValueType::None;
string hash;
optional<SecureDataCredentials> data;
std::vector<SecureFileCredentials> files;

View File

@ -40,24 +40,24 @@ class GetSponsoredMessagesQuery final : public Td::ResultHandler {
void send(ChannelId channel_id) {
channel_id_ = channel_id;
auto input_channel = td->contacts_manager_->get_input_channel(channel_id);
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
if (input_channel == nullptr) {
return promise_.set_error(Status::Error(400, "Chat info not found"));
}
send_query(G()->net_query_creator().create(telegram_api::channels_getSponsoredMessages(std::move(input_channel))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::channels_getSponsoredMessages>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) final {
td->contacts_manager_->on_get_channel_error(channel_id_, status, "GetSponsoredMessagesQuery");
void on_error(Status status) final {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "GetSponsoredMessagesQuery");
promise_.set_error(std::move(status));
}
};
@ -72,7 +72,7 @@ class ViewSponsoredMessageQuery final : public Td::ResultHandler {
void send(ChannelId channel_id, const string &message_id) {
channel_id_ = channel_id;
auto input_channel = td->contacts_manager_->get_input_channel(channel_id);
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
if (input_channel == nullptr) {
return promise_.set_error(Status::Error(400, "Chat info not found"));
}
@ -80,17 +80,17 @@ class ViewSponsoredMessageQuery final : public Td::ResultHandler {
telegram_api::channels_viewSponsoredMessage(std::move(input_channel), BufferSlice(message_id))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::channels_viewSponsoredMessage>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
td->contacts_manager_->on_get_channel_error(channel_id_, status, "ViewSponsoredMessageQuery");
void on_error(Status status) final {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ViewSponsoredMessageQuery");
promise_.set_error(std::move(status));
}
};

File diff suppressed because it is too large Load Diff

View File

@ -398,8 +398,8 @@ class StickersManager final : public Actor {
UserId user_id;
string title;
string short_name;
bool is_masks;
bool is_animated;
bool is_masks = false;
bool is_animated = false;
vector<FileId> file_ids;
vector<tl_object_ptr<td_api::InputSticker>> stickers;
string software;
@ -482,9 +482,9 @@ class StickersManager final : public Actor {
static string get_full_sticker_set_database_key(StickerSetId set_id);
string get_sticker_set_database_value(const StickerSet *s, bool with_stickers);
string get_sticker_set_database_value(const StickerSet *s, bool with_stickers, const char *source);
void update_sticker_set(StickerSet *sticker_set);
void update_sticker_set(StickerSet *sticker_set, const char *source);
void load_sticker_sets(vector<StickerSetId> &&sticker_set_ids, Promise<Unit> &&promise);
@ -580,7 +580,7 @@ class StickersManager final : public Actor {
void save_favorite_stickers_to_database();
template <class StorerT>
void store_sticker_set(const StickerSet *sticker_set, bool with_stickers, StorerT &storer) const;
void store_sticker_set(const StickerSet *sticker_set, bool with_stickers, StorerT &storer, const char *source) const;
template <class ParserT>
void parse_sticker_set(StickerSet *sticker_set, ParserT &parser);
@ -791,7 +791,7 @@ class StickersManager final : public Actor {
struct StickerSetLoadRequest {
Promise<Unit> promise;
Status error;
size_t left_queries;
size_t left_queries = 0;
};
std::unordered_map<uint32, StickerSetLoadRequest> sticker_set_load_requests_;

View File

@ -124,7 +124,8 @@ FileId StickersManager::parse_sticker(bool in_sticker_set, ParserT &parser) {
}
template <class StorerT>
void StickersManager::store_sticker_set(const StickerSet *sticker_set, bool with_stickers, StorerT &storer) const {
void StickersManager::store_sticker_set(const StickerSet *sticker_set, bool with_stickers, StorerT &storer,
const char *source) const {
size_t stickers_limit = with_stickers ? sticker_set->sticker_ids.size() : 5;
bool is_full = sticker_set->sticker_ids.size() <= stickers_limit;
bool was_loaded = sticker_set->was_loaded && is_full;
@ -169,7 +170,7 @@ void StickersManager::store_sticker_set(const StickerSet *sticker_set, bool with
store(stored_sticker_count, storer);
for (uint32 i = 0; i < stored_sticker_count; i++) {
auto sticker_id = sticker_set->sticker_ids[i];
store_sticker(sticker_id, true, storer, "store_sticker_set");
store_sticker(sticker_id, true, storer, source);
if (was_loaded) {
auto it = sticker_set->sticker_emojis_map_.find(sticker_id);

File diff suppressed because it is too large Load Diff

View File

@ -133,6 +133,11 @@ class Td final : public Actor {
template <class ActorT, class... ArgsT>
ActorId<ActorT> create_net_actor(ArgsT &&... args) {
LOG_CHECK(close_flag_ < 1) << close_flag_
#if TD_CLANG || TD_GCC
<< ' ' << __PRETTY_FUNCTION__
#endif
;
auto slot_id = request_actors_.create(ActorOwn<>(), RequestActorIdType);
inc_request_actor_refcnt();
auto actor = make_unique<ActorT>(std::forward<ArgsT>(args)...);
@ -217,11 +222,11 @@ class Td final : public Actor {
ResultHandler &operator=(const ResultHandler &) = delete;
virtual ~ResultHandler() = default;
virtual void on_result(NetQueryPtr query);
virtual void on_result(uint64 id, BufferSlice packet) {
virtual void on_result(BufferSlice packet) {
UNREACHABLE();
}
virtual void on_error(uint64 id, Status status) {
virtual void on_error(Status status) {
UNREACHABLE();
}
@ -230,10 +235,11 @@ class Td final : public Actor {
protected:
void send_query(NetQueryPtr query);
Td *td = nullptr;
Td *td_ = nullptr;
bool is_query_sent_ = false;
private:
void set_td(Td *new_td);
void set_td(Td *td);
};
template <class HandlerT, class... Args>
@ -355,8 +361,6 @@ class Td final : public Actor {
void on_config_option_updated(const string &name);
static void send(NetQueryPtr &&query);
class OnRequest;
class DownloadFileCallback;
@ -1316,7 +1320,7 @@ class Td final : public Actor {
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getFileExtension &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::cleanFileName &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getLanguagePackString &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getPhoneNumberInfoSync &request);
static td_api::object_ptr<td_api::Object> do_static_request(td_api::getPhoneNumberInfoSync &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getPushReceiverId &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getChatFilterDefaultIconName &request);
static td_api::object_ptr<td_api::Object> do_static_request(td_api::getJsonValue &request);

View File

@ -30,10 +30,10 @@ class GetTermsOfServiceUpdateQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::help_getTermsOfServiceUpdate()));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::help_getTermsOfServiceUpdate>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
@ -53,7 +53,7 @@ class GetTermsOfServiceUpdateQuery final : public Td::ResultHandler {
}
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -70,10 +70,10 @@ class AcceptTermsOfServiceQuery final : public Td::ResultHandler {
telegram_api::make_object<telegram_api::dataJSON>(terms_of_service_id))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::help_acceptTermsOfService>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto result = result_ptr.ok();
@ -83,7 +83,7 @@ class AcceptTermsOfServiceQuery final : public Td::ResultHandler {
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};

View File

@ -36,16 +36,16 @@ class GetChatThemesQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::account_getChatThemes(hash)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_getChatThemes>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};

View File

@ -42,7 +42,7 @@ class ThemeManager final : public Actor {
int32 message_accent_color = 0;
BackgroundId background_id;
BackgroundType background_type;
BaseTheme base_theme;
BaseTheme base_theme = BaseTheme::Classic;
vector<int32> message_colors;
bool animate_message_colors = false;

View File

@ -56,16 +56,16 @@ class GetTopPeersQuery final : public Td::ResultHandler {
false /*ignored*/, false /*ignored*/, false /*ignored*/, 0 /*offset*/, 100 /*limit*/, hash)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::contacts_getTopPeers>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -81,16 +81,16 @@ class ToggleTopPeersQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::contacts_toggleTopPeers(is_enabled)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::contacts_toggleTopPeers>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -100,7 +100,7 @@ class ResetTopPeerRatingQuery final : public Td::ResultHandler {
public:
void send(TopDialogCategory category, DialogId dialog_id) {
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
return;
}
@ -110,17 +110,17 @@ class ResetTopPeerRatingQuery final : public Td::ResultHandler {
telegram_api::contacts_resetTopPeerRating(get_input_top_peer_category(category), std::move(input_peer))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::contacts_resetTopPeerRating>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
// ignore the result
}
void on_error(uint64 id, Status status) final {
if (!td->messages_manager_->on_get_dialog_error(dialog_id_, status, "ResetTopPeerRatingQuery")) {
void on_error(Status status) final {
if (!td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "ResetTopPeerRatingQuery")) {
LOG(INFO) << "Receive error for ResetTopPeerRatingQuery: " << status;
}
}

View File

@ -98,16 +98,16 @@ class GetUpdatesStateQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::updates_getState()));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::updates_getState>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -124,16 +124,16 @@ class PingServerQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::updates_getState()));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::updates_getState>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -150,17 +150,17 @@ class GetDifferenceQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::updates_getDifference(0, pts, 0, date, qts)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
VLOG(get_difference) << "Receive getDifference result of size " << packet.size();
auto result_ptr = fetch_result<telegram_api::updates_getDifference>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};

View File

@ -174,7 +174,7 @@ class UpdatesManager final : public Actor {
class PendingQtsUpdate {
public:
double receive_time;
double receive_time = 0.0;
tl_object_ptr<telegram_api::Update> update;
vector<Promise<Unit>> promises;
};

View File

@ -76,19 +76,19 @@ class GetWebPagePreviewQuery final : public Td::ResultHandler {
G()->net_query_creator().create(telegram_api::messages_getWebPagePreview(flags, text, std::move(entities))));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getWebPagePreview>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetWebPagePreviewQuery: " << to_string(ptr);
td->web_pages_manager_->on_get_web_page_preview_success(request_id_, url_, std::move(ptr), std::move(promise_));
td_->web_pages_manager_->on_get_web_page_preview_success(request_id_, url_, std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
td->web_pages_manager_->on_get_web_page_preview_fail(request_id_, url_, std::move(status), std::move(promise_));
void on_error(Status status) final {
td_->web_pages_manager_->on_get_web_page_preview_fail(request_id_, url_, std::move(status), std::move(promise_));
}
};
@ -107,10 +107,10 @@ class GetWebPageQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::messages_getWebPage(url, hash)));
}
void on_result(uint64 id, BufferSlice packet) final {
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getWebPage>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
@ -121,19 +121,19 @@ class GetWebPageQuery final : public Td::ResultHandler {
int32 view_count = (web_page->flags_ & telegram_api::webPageNotModified::CACHED_PAGE_VIEWS_MASK) != 0
? web_page->cached_page_views_
: 0;
td->web_pages_manager_->on_get_web_page_instant_view_view_count(web_page_id_, view_count);
td_->web_pages_manager_->on_get_web_page_instant_view_view_count(web_page_id_, view_count);
return promise_.set_value(std::move(web_page_id_));
} else {
LOG(ERROR) << "Receive webPageNotModified for " << url_;
return on_error(id, Status::Error(500, "Receive webPageNotModified"));
return on_error(Status::Error(500, "Receive webPageNotModified"));
}
}
auto web_page_id = td->web_pages_manager_->on_get_web_page(std::move(ptr), DialogId());
td->web_pages_manager_->on_get_web_page_by_url(url_, web_page_id, false);
auto web_page_id = td_->web_pages_manager_->on_get_web_page(std::move(ptr), DialogId());
td_->web_pages_manager_->on_get_web_page_by_url(url_, web_page_id, false);
promise_.set_value(std::move(web_page_id));
}
void on_error(uint64 id, Status status) final {
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
@ -1295,11 +1295,11 @@ void WebPagesManager::on_web_page_changed(WebPageId web_page_id, bool have_web_p
auto it = web_page_messages_.find(web_page_id);
if (it != web_page_messages_.end()) {
vector<FullMessageId> full_message_ids;
for (auto full_message_id : it->second) {
for (const auto &full_message_id : it->second) {
full_message_ids.push_back(full_message_id);
}
CHECK(!full_message_ids.empty());
for (auto full_message_id : full_message_ids) {
for (const auto &full_message_id : full_message_ids) {
if (!have_web_page) {
td_->messages_manager_->delete_pending_message_web_page(full_message_id);
} else {
@ -1341,12 +1341,18 @@ const WebPagesManager::WebPageInstantView *WebPagesManager::get_web_page_instant
return &web_page->instant_view;
}
void WebPagesManager::on_pending_web_page_timeout_callback(void *web_pages_manager_ptr, int64 web_page_id) {
static_cast<WebPagesManager *>(web_pages_manager_ptr)->on_pending_web_page_timeout(WebPageId(web_page_id));
void WebPagesManager::on_pending_web_page_timeout_callback(void *web_pages_manager_ptr, int64 web_page_id_int) {
if (G()->close_flag()) {
return;
}
auto web_pages_manager = static_cast<WebPagesManager *>(web_pages_manager_ptr);
send_closure_later(web_pages_manager->actor_id(web_pages_manager), &WebPagesManager::on_pending_web_page_timeout,
WebPageId(web_page_id_int));
}
void WebPagesManager::on_pending_web_page_timeout(WebPageId web_page_id) {
if (have_web_page(web_page_id)) {
if (G()->close_flag() || have_web_page(web_page_id)) {
return;
}
@ -1354,7 +1360,7 @@ void WebPagesManager::on_pending_web_page_timeout(WebPageId web_page_id) {
auto it = web_page_messages_.find(web_page_id);
if (it != web_page_messages_.end()) {
vector<FullMessageId> full_message_ids;
for (auto full_message_id : it->second) {
for (const auto &full_message_id : it->second) {
if (full_message_id.get_dialog_id().get_type() != DialogType::SecretChat) {
full_message_ids.push_back(full_message_id);
}

View File

@ -129,7 +129,8 @@ class WebPagesManager final : public Actor {
tl_object_ptr<td_api::webPageInstantView> get_web_page_instant_view_object(
WebPageId web_page_id, const WebPageInstantView *web_page_instant_view) const;
static void on_pending_web_page_timeout_callback(void *web_pages_manager_ptr, int64 web_page_id);
static void on_pending_web_page_timeout_callback(void *web_pages_manager_ptr, int64 web_page_id_int);
void on_pending_web_page_timeout(WebPageId web_page_id);
void on_get_web_page_preview_success(int64 request_id, const string &url, WebPageId web_page_id,

View File

@ -676,7 +676,7 @@ class CliClient final : public Actor {
}
struct SearchQuery {
int32 limit;
int32 limit = 0;
string query;
};

View File

@ -49,14 +49,14 @@ class FileLoader : public FileLoaderActor {
bool is_ready = false;
};
struct FileInfo {
int64 size;
int64 size{0};
int64 expected_size{0};
bool is_size_final;
int32 part_size;
bool is_size_final{false};
int32 part_size{0};
std::vector<int> ready_parts;
bool use_part_count_limit = true;
bool only_check = false;
bool need_delay = false;
bool use_part_count_limit{true};
bool only_check{false};
bool need_delay{false};
int64 offset{0};
int64 limit{0};
bool is_upload{false};

View File

@ -334,7 +334,7 @@ class FullRemoteFileLocation {
void set_source(PhotoSizeSource source) {
CHECK(is_photo());
file_type_ = source.get_file_type();
file_type_ = source.get_file_type("set_source");
photo().source_ = std::move(source);
}
@ -399,7 +399,7 @@ class FullRemoteFileLocation {
const auto &id = photo().id_;
const auto &access_hash = photo().access_hash_;
const auto &source = photo().source_;
switch (source.get_type()) {
switch (source.get_type("as_input_file_location")) {
case PhotoSizeSource::Type::Legacy:
UNREACHABLE();
break;
@ -423,7 +423,7 @@ class FullRemoteFileLocation {
case PhotoSizeSource::Type::DialogPhotoSmall:
case PhotoSizeSource::Type::DialogPhotoBig: {
auto &dialog_photo = source.dialog_photo();
bool is_big = source.get_type() == PhotoSizeSource::Type::DialogPhotoBig;
bool is_big = source.get_type("as_input_file_location 2") == PhotoSizeSource::Type::DialogPhotoBig;
return make_tl_object<telegram_api::inputPeerPhotoFileLocation>(
is_big * telegram_api::inputPeerPhotoFileLocation::BIG_MASK, false /*ignored*/,
dialog_photo.get_input_peer(), id);
@ -440,7 +440,7 @@ class FullRemoteFileLocation {
case PhotoSizeSource::Type::DialogPhotoSmallLegacy:
case PhotoSizeSource::Type::DialogPhotoBigLegacy: {
auto &dialog_photo = source.dialog_photo_legacy();
bool is_big = source.get_type() == PhotoSizeSource::Type::DialogPhotoBigLegacy;
bool is_big = source.get_type("as_input_file_location 3") == PhotoSizeSource::Type::DialogPhotoBigLegacy;
return make_tl_object<telegram_api::inputPeerPhotoFileLocationLegacy>(
is_big * telegram_api::inputPeerPhotoFileLocationLegacy::BIG_MASK, false /*ignored*/,
dialog_photo.get_input_peer(), dialog_photo.volume_id, dialog_photo.local_id);
@ -510,7 +510,7 @@ class FullRemoteFileLocation {
// photo
FullRemoteFileLocation(const PhotoSizeSource &source, int64 id, int64 access_hash, DcId dc_id,
std::string file_reference)
: file_type_(source.get_file_type())
: file_type_(source.get_file_type("FullRemoteFileLocation"))
, dc_id_(dc_id)
, file_reference_(std::move(file_reference))
, variant_(PhotoRemoteFileLocation{id, access_hash, source}) {

View File

@ -73,7 +73,7 @@ void PhotoRemoteFileLocation::parse(ParserT &parser) {
return;
}
switch (source.get_type()) {
switch (source.get_type("PhotoRemoteFileLocation::parse")) {
case PhotoSizeSource::Type::Legacy:
source_ = PhotoSizeSource::full_legacy(volume_id, local_id, source.legacy().secret);
break;
@ -84,7 +84,7 @@ void PhotoRemoteFileLocation::parse(ParserT &parser) {
case PhotoSizeSource::Type::DialogPhotoSmall:
case PhotoSizeSource::Type::DialogPhotoBig: {
auto &dialog_photo = source.dialog_photo();
bool is_big = source.get_type() == PhotoSizeSource::Type::DialogPhotoBig;
bool is_big = source.get_type("PhotoRemoteFileLocation::parse") == PhotoSizeSource::Type::DialogPhotoBig;
source_ = PhotoSizeSource::dialog_photo_legacy(dialog_photo.dialog_id, dialog_photo.dialog_access_hash, is_big,
volume_id, local_id);
break;
@ -106,7 +106,7 @@ template <class StorerT>
void PhotoRemoteFileLocation::AsKey::store(StorerT &storer) const {
using td::store;
auto unique = key.source_.get_unique();
switch (key.source_.get_type()) {
switch (key.source_.get_type("PhotoRemoteFileLocation::AsKey::store")) {
case PhotoSizeSource::Type::Legacy:
case PhotoSizeSource::Type::StickerSetThumbnail:
UNREACHABLE();
@ -231,12 +231,12 @@ void FullRemoteFileLocation::parse(ParserT &parser) {
if (parser.get_error() != nullptr) {
return;
}
switch (photo().source_.get_type()) {
switch (photo().source_.get_type("FullRemoteFileLocation::parse")) {
case PhotoSizeSource::Type::Legacy:
case PhotoSizeSource::Type::FullLegacy:
break;
case PhotoSizeSource::Type::Thumbnail:
if (photo().source_.get_file_type() != file_type_ ||
if (photo().source_.get_file_type("FullRemoteFileLocation::parse") != file_type_ ||
(file_type_ != FileType::Photo && file_type_ != FileType::Thumbnail &&
file_type_ != FileType::EncryptedThumbnail)) {
parser.set_error("Invalid FileType in PhotoRemoteFileLocation Thumbnail");

View File

@ -321,7 +321,7 @@ class FileView {
if (!remote_location().is_photo()) {
return false;
}
auto type = remote_location().get_source().get_type();
auto type = remote_location().get_source().get_type("may_reload_photo");
return type != PhotoSizeSource::Type::Legacy && type != PhotoSizeSource::Type::FullLegacy &&
type != PhotoSizeSource::Type::Thumbnail;
}
@ -540,7 +540,7 @@ class FileManager final : public FileLoadManager::Callback {
int8 download_priority_{0};
int8 upload_priority_{0};
uint64 upload_order_;
uint64 upload_order_{0};
std::shared_ptr<DownloadCallback> download_callback_;
std::shared_ptr<UploadCallback> upload_callback_;

View File

@ -47,7 +47,7 @@ class FileUploader final : public FileLoader {
FileType file_type_ = FileType::Temp;
std::vector<UInt256> iv_map_;
UInt256 iv_;
UInt256 iv_{};
string generate_iv_;
int64 generate_offset_ = 0;
int64 next_offset_ = 0;
@ -55,8 +55,8 @@ class FileUploader final : public FileLoader {
FileFd fd_;
string fd_path_;
bool is_temp_ = false;
int64 file_id_;
bool big_flag_;
int64 file_id_ = 0;
bool big_flag_ = false;
Result<FileInfo> init() final TD_WARN_UNUSED_RESULT;
Status on_ok(int64 size) final TD_WARN_UNUSED_RESULT;

View File

@ -65,28 +65,28 @@ class PartsManager {
int64 checked_prefix_size_{0};
bool known_prefix_flag_{false};
int64 known_prefix_size_;
int64 known_prefix_size_{0};
int64 size_;
int64 expected_size_;
int64 min_size_;
int64 max_size_;
bool unknown_size_flag_;
int64 ready_size_;
int64 streaming_ready_size_;
int64 size_{0};
int64 expected_size_{0};
int64 min_size_{0};
int64 max_size_{0};
bool unknown_size_flag_{false};
int64 ready_size_{0};
int64 streaming_ready_size_{0};
size_t part_size_;
int part_count_;
int pending_count_;
int first_empty_part_;
int first_not_ready_part_;
size_t part_size_{0};
int part_count_{0};
int pending_count_{0};
int first_empty_part_{0};
int first_not_ready_part_{0};
int64 streaming_offset_{0};
int64 streaming_limit_{0};
int first_streaming_empty_part_;
int first_streaming_not_ready_part_;
int first_streaming_empty_part_{0};
int first_streaming_not_ready_part_{0};
vector<PartStatus> part_status_;
Bitmask bitmask_;
bool use_part_count_limit_;
bool use_part_count_limit_{false};
Status init_common(const vector<int> &ready_parts);
Status init_known_prefix(int64 known_prefix, size_t part_size,

View File

@ -35,7 +35,7 @@ class ResourceManager final : public Actor {
Mode mode_;
using NodeId = uint64;
struct Node final : public HeapNode {
NodeId node_id;
NodeId node_id = 0;
ResourceState resource_state_;
ActorShared<FileLoaderActor> callback_;

View File

@ -371,7 +371,7 @@ void ConnectionCreator::ping_proxy_resolved(int32 proxy_id, IPAddress ip_address
auto connection_promise = PromiseCreator::lambda(
[ip_address, promise = std::move(promise), actor_id = actor_id(this), transport_type = extra.transport_type,
debug_str = std::move(extra.debug_str)](Result<ConnectionData> r_connection_data) mutable {
debug_str = extra.debug_str](Result<ConnectionData> r_connection_data) mutable {
if (r_connection_data.is_error()) {
return promise.set_error(Status::Error(400, r_connection_data.error().public_message()));
}
@ -936,13 +936,13 @@ void ConnectionCreator::client_loop(ClientInfo &client) {
client.checking_connections++;
}
auto promise = PromiseCreator::lambda([actor_id = actor_id(this), check_mode, transport_type = extra.transport_type,
hash = client.hash, debug_str = extra.debug_str,
network_generation =
network_generation_](Result<ConnectionData> r_connection_data) mutable {
send_closure(std::move(actor_id), &ConnectionCreator::client_create_raw_connection, std::move(r_connection_data),
check_mode, std::move(transport_type), hash, std::move(debug_str), network_generation);
});
auto promise = PromiseCreator::lambda(
[actor_id = actor_id(this), check_mode, transport_type = extra.transport_type, hash = client.hash,
debug_str = extra.debug_str,
network_generation = network_generation_](Result<ConnectionData> r_connection_data) mutable {
send_closure(actor_id, &ConnectionCreator::client_create_raw_connection, std::move(r_connection_data),
check_mode, std::move(transport_type), hash, std::move(debug_str), network_generation);
});
auto stats_callback =
td::make_unique<detail::StatsCallback>(client.is_media ? media_net_stats_callback_ : common_net_stats_callback_,
@ -983,7 +983,7 @@ void ConnectionCreator::client_create_raw_connection(Result<ConnectionData> r_co
VLOG(connections) << "Failed connection (" << (check_mode ? "" : "un") << "checked) " << result.error() << ' '
<< debug_str;
}
send_closure(std::move(actor_id), &ConnectionCreator::client_add_connection, hash, std::move(result), check_mode,
send_closure(actor_id, &ConnectionCreator::client_add_connection, hash, std::move(result), check_mode,
auth_data_generation, session_id);
});
@ -1283,7 +1283,7 @@ void ConnectionCreator::loop() {
send_closure(
get_dns_resolver(), &GetHostByNameActor::run, proxy.server().str(), proxy.port(), prefer_ipv6,
PromiseCreator::lambda([actor_id = create_reference(resolve_proxy_query_token_)](Result<IPAddress> result) {
send_closure(std::move(actor_id), &ConnectionCreator::on_proxy_resolved, std::move(result), false);
send_closure(actor_id, &ConnectionCreator::on_proxy_resolved, std::move(result), false);
}));
}
} else {

View File

@ -161,8 +161,8 @@ class ConnectionCreator final : public NetQueryCallback {
bool inited{false};
size_t hash{0};
DcId dc_id;
bool allow_media_only;
bool is_media;
bool allow_media_only{false};
bool is_media{false};
std::set<int64> session_ids_;
unique_ptr<mtproto::AuthData> auth_data;
uint64 auth_data_generation{0};

View File

@ -39,8 +39,8 @@ class DcAuthManager final : public NetQueryCallback {
enum class State : int32 { Waiting, Export, Import, BeforeOk, Ok };
State state = State::Waiting;
uint64 wait_id;
int64 export_id;
uint64 wait_id = 0;
int64 export_id = 0;
BufferSlice export_bytes;
};

View File

@ -78,7 +78,7 @@ class DcOptionsSet {
struct DcOptionInfo {
DcOption option;
int64 stat_id;
int64 stat_id = -1;
size_t pos;
size_t order = 0;

View File

@ -16,7 +16,7 @@ namespace td {
class MtprotoHeader {
public:
struct Options {
int32 api_id;
int32 api_id = -1;
string system_language_code;
string device_model;
string system_version;

View File

@ -12,7 +12,7 @@
namespace td {
NetActor::NetActor() : td(static_cast<Td *>(G()->td().get_actor_unsafe())) {
NetActor::NetActor() : td_(static_cast<Td *>(G()->td().get_actor_unsafe())) {
}
void NetActor::set_parent(ActorShared<> parent) {
@ -22,9 +22,9 @@ void NetActor::set_parent(ActorShared<> parent) {
void NetActor::on_result(NetQueryPtr query) {
CHECK(query->is_ready());
if (query->is_ok()) {
on_result(query->id(), query->move_as_ok());
on_result(query->move_as_ok());
} else {
on_error(query->id(), query->move_as_error());
on_error(query->move_as_error());
}
on_result_finish();
}

View File

@ -22,26 +22,32 @@ class Td;
class NetActor : public NetQueryCallback {
public:
NetActor();
void set_parent(ActorShared<> parent);
void on_result(NetQueryPtr query) override;
virtual void on_result(uint64 id, BufferSlice packet) {
virtual void on_result(BufferSlice packet) {
UNREACHABLE();
}
virtual void on_error(uint64 id, Status status) {
virtual void on_error(Status status) {
UNREACHABLE();
}
virtual void on_result_finish() {
}
protected:
Td *td_;
ActorShared<> parent_;
void send_query(NetQueryPtr query);
Td *td;
};
class NetActorOnce : public NetActor {
void hangup() override {
on_error(0, Global::request_aborted_error());
on_error(Global::request_aborted_error());
stop();
}

View File

@ -80,7 +80,7 @@ void NetStatsManager::get_network_stats(bool current, Promise<NetworkStats> prom
NetStatsData total_files;
for_each_stat([&](NetStatsInfo &info, size_t id, CSlice name, FileType file_type) {
auto type_stats = info.stats_by_type[net_type_i];
const auto &type_stats = info.stats_by_type[net_type_i];
auto stats = current ? type_stats.mem_stats : type_stats.mem_stats + type_stats.db_stats;
if (id == 0) {
} else if (id == 1) {
@ -96,7 +96,7 @@ void NetStatsManager::get_network_stats(bool current, Promise<NetworkStats> prom
if (id == 1) {
return;
}
auto type_stats = info.stats_by_type[net_type_i];
const auto &type_stats = info.stats_by_type[net_type_i];
auto stats = current ? type_stats.mem_stats : type_stats.mem_stats + type_stats.db_stats;
NetworkStatsEntry entry;

View File

@ -140,8 +140,8 @@ class Session final
ListNode sent_queries_list_;
struct ConnectionInfo {
int8 connection_id;
Mode mode;
int8 connection_id = 0;
Mode mode = Mode::Tcp;
enum class State : int8 { Empty, Connecting, Ready } state = State::Empty;
CancellationTokenSource cancellation_token_source_;
unique_ptr<mtproto::SessionConnection> connection;

View File

@ -40,7 +40,7 @@ class SessionProxy final : public Actor {
private:
unique_ptr<Callback> callback_;
std::shared_ptr<AuthDataShared> auth_data_;
AuthKeyState auth_key_state_;
AuthKeyState auth_key_state_ = AuthKeyState::Empty;
bool is_main_;
bool allow_media_only_;
bool is_media_;

View File

@ -19,22 +19,22 @@ struct TdBytes TdCreateObjectBytes(unsigned char *data, int len);
struct TdRequest {
long long request_id;
TdFunction *function;
struct TdFunction *function;
};
struct TdResponse {
long long request_id;
int client_id;
TdObject *object;
struct TdObject *object;
};
int TdCClientCreateId();
void TdCClientSend(int client_id, struct TdRequest request);
TdResponse TdCClientReceive(double timeout);
struct TdResponse TdCClientReceive(double timeout);
TdObject *TdCClientExecute(TdFunction *function);
struct TdObject *TdCClientExecute(struct TdFunction *function);
#ifdef __cplusplus
}

View File

@ -95,7 +95,7 @@ class ConcurrentScheduler final : private Scheduler::Callback {
unique_ptr<detail::Iocp> iocp_;
td::thread iocp_thread_;
#endif
int32 extra_scheduler_;
int32 extra_scheduler_ = 0;
void on_finish() final;

View File

@ -597,7 +597,7 @@ class FutureActor final : public Actor {
private:
EventFull event_;
Result<T> result_ = Status::Error(500, "Empty FutureActor");
State state_;
State state_ = State::Waiting;
void set_value(T &&value) {
set_result(std::move(value));

View File

@ -18,6 +18,7 @@
#include "td/utils/List.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/MpscPollableQueue.h"
#include "td/utils/ObjectPool.h"
#include "td/utils/port/thread_local.h"
#include "td/utils/ScopeGuard.h"
@ -25,6 +26,7 @@
#include <functional>
#include <iterator>
#include <memory>
#include <utility>
namespace td {

View File

@ -73,10 +73,10 @@ SqliteDb::~SqliteDb() = default;
Status SqliteDb::init(CSlice path, bool allow_creation) {
// if database does not exist, delete all other files which could have been left from the old database
bool is_db_exists = stat(path).is_ok();
if (!is_db_exists) {
auto database_stat = stat(path);
if (database_stat.is_error()) {
if (!allow_creation) {
LOG(FATAL) << "Database was deleted during execution and can't be recreated";
LOG(FATAL) << "Database was deleted during execution and can't be recreated: " << database_stat.error();
}
TRY_STATUS(destroy(path));
}

View File

@ -134,7 +134,7 @@ class Binlog {
// AesCtrEncryption
BufferSlice aes_ctr_key_salt_;
UInt256 aes_ctr_key_;
UInt256 aes_ctr_key_{};
AesCtrState aes_ctr_state_;
bool byte_flow_flag_ = false;

View File

@ -62,7 +62,7 @@ class GetHostByNameActor final : public Actor {
ActorOwn<> query;
size_t pos = 0;
string real_host;
double begin_time;
double begin_time = 0.0;
std::vector<std::pair<int, Promise<IPAddress>>> promises;
};
std::unordered_map<string, Query> active_queries_[2];

View File

@ -183,9 +183,12 @@ void HttpConnectionBase::loop() {
state_ = State::Close;
}
if (state_ == State::Close) {
LOG_IF(INFO, fd_.need_flush_write()) << "Close nonempty connection";
LOG_IF(INFO, want_read && (!fd_.input_buffer().empty() || current_query_->type_ != HttpQuery::Type::Empty))
<< "Close connection while reading request/response";
if (fd_.need_flush_write()) {
LOG(INFO) << "Close nonempty connection";
}
if (want_read && (!fd_.input_buffer().empty() || current_query_->type_ != HttpQuery::Type::Empty)) {
LOG(INFO) << "Close connection while reading request/response";
}
return stop();
}
}

View File

@ -30,7 +30,7 @@ class HttpFile {
HttpFile(const HttpFile &) = delete;
HttpFile &operator=(const HttpFile &) = delete;
HttpFile(HttpFile &&other)
HttpFile(HttpFile &&other) noexcept
: field_name(std::move(other.field_name))
, name(std::move(other.name))
, content_type(std::move(other.content_type))

View File

@ -223,7 +223,7 @@ class JsonScope {
CHECK(is_active());
}
JsonScope(const JsonScope &other) = delete;
JsonScope(JsonScope &&other) : sb_(other.sb_), jb_(other.jb_), save_scope_(other.save_scope_) {
JsonScope(JsonScope &&other) noexcept : sb_(other.sb_), jb_(other.jb_), save_scope_(other.save_scope_) {
other.jb_ = nullptr;
}
JsonScope &operator=(const JsonScope &) = delete;

View File

@ -363,7 +363,7 @@ class Status {
}
Status clone_static() const TD_WARN_UNUSED_RESULT {
CHECK(is_ok() || get_info().static_flag);
CHECK(ptr_ != nullptr && get_info().static_flag);
Status result;
result.ptr_ = std::unique_ptr<char[], Deleter>(ptr_.get());
return result;

Some files were not shown because too many files have changed in this diff Show More