Reduce "this" usages.

This commit is contained in:
levlam 2021-10-23 21:17:00 +03:00
parent 0c1469f7c6
commit c24501f2d9
10 changed files with 71 additions and 64 deletions

View File

@ -112,8 +112,7 @@ class QueryImpl {
void do_store(StorerT &storer) const {
storer.store_binary(query_.message_id);
storer.store_binary(query_.seq_no);
Slice header = this->header_;
Slice invoke_header = Slice();
Slice invoke_header;
// TODO(refactor):
// invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@ -138,7 +137,7 @@ class QueryImpl {
const Storer &data_storer =
query_.gzip_flag ? static_cast<const Storer &>(gzip_storer) : static_cast<const Storer &>(plain_storer);
auto invoke_header_storer = create_storer(invoke_header);
auto header_storer = create_storer(header);
auto header_storer = create_storer(header_);
auto suff_storer = create_storer(invoke_header_storer, data_storer);
auto all_storer = create_storer(header_storer, suff_storer);

View File

@ -3128,19 +3128,22 @@ tl_object_ptr<td_api::chatStatisticsSupergroup> ContactsManager::convert_megagro
td::remove_if(obj->top_inviters_,
[](auto &obj) { return !UserId(obj->user_id_).is_valid() || obj->invitations_ < 0; });
auto top_senders = transform(std::move(obj->top_posters_), [this](auto &&top_poster) {
auto top_senders =
transform(std::move(obj->top_posters_), [this](tl_object_ptr<telegram_api::statsGroupTopPoster> &&top_poster) {
return td_api::make_object<td_api::chatStatisticsMessageSenderInfo>(
this->get_user_id_object(UserId(top_poster->user_id_), "get_top_senders"), top_poster->messages_,
get_user_id_object(UserId(top_poster->user_id_), "get_top_senders"), top_poster->messages_,
top_poster->avg_chars_);
});
auto top_administrators = transform(std::move(obj->top_admins_), [this](auto &&top_admin) {
auto top_administrators =
transform(std::move(obj->top_admins_), [this](tl_object_ptr<telegram_api::statsGroupTopAdmin> &&top_admin) {
return td_api::make_object<td_api::chatStatisticsAdministratorActionsInfo>(
this->get_user_id_object(UserId(top_admin->user_id_), "get_top_administrators"), top_admin->deleted_,
get_user_id_object(UserId(top_admin->user_id_), "get_top_administrators"), top_admin->deleted_,
top_admin->kicked_, top_admin->banned_);
});
auto top_inviters = transform(std::move(obj->top_inviters_), [this](auto &&top_inviter) {
auto top_inviters =
transform(std::move(obj->top_inviters_), [this](tl_object_ptr<telegram_api::statsGroupTopInviter> &&top_inviter) {
return td_api::make_object<td_api::chatStatisticsInviterInfo>(
this->get_user_id_object(UserId(top_inviter->user_id_), "get_top_inviters"), top_inviter->invitations_);
get_user_id_object(UserId(top_inviter->user_id_), "get_top_inviters"), top_inviter->invitations_);
});
return make_tl_object<td_api::chatStatisticsSupergroup>(

View File

@ -2739,12 +2739,12 @@ class BlockFromRepliesQuery final : public Td::ResultHandler {
explicit BlockFromRepliesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(MessageId message_id, bool delete_message, bool delete_all_messages, bool report_spam) {
void send(MessageId message_id, bool need_delete_message, bool need_delete_all_messages, bool report_spam) {
int32 flags = 0;
if (delete_message) {
if (need_delete_message) {
flags |= telegram_api::contacts_blockFromReplies::DELETE_MESSAGE_MASK;
}
if (delete_all_messages) {
if (need_delete_all_messages) {
flags |= telegram_api::contacts_blockFromReplies::DELETE_HISTORY_MASK;
}
if (report_spam) {
@ -16623,8 +16623,8 @@ void MessagesManager::on_get_common_dialogs(UserId user_id, int64 offset_chat_id
common_dialogs.total_count = total_count;
}
void MessagesManager::block_message_sender_from_replies(MessageId message_id, bool delete_message,
bool delete_all_messages, bool report_spam,
void MessagesManager::block_message_sender_from_replies(MessageId message_id, bool need_delete_message,
bool need_delete_all_messages, bool report_spam,
Promise<Unit> &&promise) {
auto dialog_id = DialogId(ContactsManager::get_replies_bot_user_id());
Dialog *d = get_dialog_force(dialog_id, "block_message_sender_from_replies");
@ -16649,20 +16649,19 @@ void MessagesManager::block_message_sender_from_replies(MessageId message_id, bo
}
bool need_update_dialog_pos = false;
vector<int64> deleted_message_ids;
if (delete_message) {
auto p = this->delete_message(d, message_id, true, &need_update_dialog_pos, "block_message_sender_from_replies");
if (need_delete_message) {
auto p = delete_message(d, message_id, true, &need_update_dialog_pos, "block_message_sender_from_replies");
CHECK(p.get() == m);
deleted_message_ids.push_back(p->message_id.get());
}
if (delete_all_messages && sender_user_id.is_valid()) {
if (need_delete_all_messages && sender_user_id.is_valid()) {
vector<MessageId> message_ids;
find_messages(d->messages.get(), message_ids, [sender_user_id](const Message *m) {
return !m->is_outgoing && m->forward_info != nullptr && m->forward_info->sender_user_id == sender_user_id;
});
for (auto user_message_id : message_ids) {
auto p = this->delete_message(d, user_message_id, true, &need_update_dialog_pos,
"block_message_sender_from_replies 2");
auto p = delete_message(d, user_message_id, true, &need_update_dialog_pos, "block_message_sender_from_replies 2");
deleted_message_ids.push_back(p->message_id.get());
}
}
@ -16673,7 +16672,7 @@ void MessagesManager::block_message_sender_from_replies(MessageId message_id, bo
send_update_delete_messages(dialog_id, std::move(deleted_message_ids), true, false);
block_message_sender_from_replies_on_server(message_id, delete_message, delete_all_messages, report_spam, 0,
block_message_sender_from_replies_on_server(message_id, need_delete_message, need_delete_all_messages, report_spam, 0,
std::move(promise));
}
@ -16708,24 +16707,25 @@ class MessagesManager::BlockMessageSenderFromRepliesOnServerLogEvent {
};
uint64 MessagesManager::save_block_message_sender_from_replies_on_server_log_event(MessageId message_id,
bool delete_message,
bool delete_all_messages,
bool need_delete_message,
bool need_delete_all_messages,
bool report_spam) {
BlockMessageSenderFromRepliesOnServerLogEvent log_event{message_id, delete_message, delete_all_messages, report_spam};
BlockMessageSenderFromRepliesOnServerLogEvent log_event{message_id, need_delete_message, need_delete_all_messages,
report_spam};
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::BlockMessageSenderFromRepliesOnServer,
get_log_event_storer(log_event));
}
void MessagesManager::block_message_sender_from_replies_on_server(MessageId message_id, bool delete_message,
bool delete_all_messages, bool report_spam,
void MessagesManager::block_message_sender_from_replies_on_server(MessageId message_id, bool need_delete_message,
bool need_delete_all_messages, bool report_spam,
uint64 log_event_id, Promise<Unit> &&promise) {
if (log_event_id == 0) {
log_event_id = save_block_message_sender_from_replies_on_server_log_event(message_id, delete_message,
delete_all_messages, report_spam);
log_event_id = save_block_message_sender_from_replies_on_server_log_event(message_id, need_delete_message,
need_delete_all_messages, report_spam);
}
td_->create_handler<BlockFromRepliesQuery>(get_erase_log_event_promise(log_event_id, std::move(promise)))
->send(message_id, delete_message, delete_all_messages, report_spam);
->send(message_id, need_delete_message, need_delete_all_messages, report_spam);
}
void MessagesManager::get_blocked_dialogs(int32 offset, int32 limit,

View File

@ -544,7 +544,7 @@ class MessagesManager final : public Actor {
std::pair<int32, vector<DialogId>> get_common_dialogs(UserId user_id, DialogId offset_dialog_id, int32 limit,
bool force, Promise<Unit> &&promise);
void block_message_sender_from_replies(MessageId message_id, bool delete_message, bool delete_all_messages,
void block_message_sender_from_replies(MessageId message_id, bool need_delete_message, bool need_delete_all_messages,
bool report_spam, Promise<Unit> &&promise);
void get_blocked_dialogs(int32 offset, int32 limit, Promise<td_api::object_ptr<td_api::messageSenders>> &&promise);
@ -1986,8 +1986,9 @@ class MessagesManager final : public Actor {
void delete_all_call_messages_from_server(bool revoke, uint64 log_event_id, Promise<Unit> &&promise);
void block_message_sender_from_replies_on_server(MessageId message_id, bool delete_message, bool delete_all_messages,
bool report_spam, uint64 log_event_id, Promise<Unit> &&promise);
void block_message_sender_from_replies_on_server(MessageId message_id, bool need_delete_message,
bool need_delete_all_messages, bool report_spam, uint64 log_event_id,
Promise<Unit> &&promise);
void delete_all_channel_messages_from_user_on_server(ChannelId channel_id, UserId user_id, uint64 log_event_id,
Promise<Unit> &&promise);
@ -3052,8 +3053,10 @@ class MessagesManager final : public Actor {
static uint64 save_delete_all_call_messages_from_server_log_event(bool revoke);
static uint64 save_block_message_sender_from_replies_on_server_log_event(MessageId message_id, bool delete_message,
bool delete_all_messages, bool report_spam);
static uint64 save_block_message_sender_from_replies_on_server_log_event(MessageId message_id,
bool need_delete_message,
bool need_delete_all_messages,
bool report_spam);
static uint64 save_delete_all_channel_messages_from_user_on_server_log_event(ChannelId channel_id, UserId user_id);

View File

@ -1565,8 +1565,8 @@ void SecretChatActor::on_outbound_send_message_result(NetQueryPtr query, Promise
LOG(INFO) << "Outbound secret message [send_message] failed, rewrite it with dummy "
<< tag("log_event_id", state->message->log_event_id()) << tag("error", error);
state->send_result_ = [this, random_id = state->message->random_id, error_code = error.code(),
error_message = error.message()](Promise<> promise) {
this->context_->on_send_message_error(random_id, Status::Error(error_code, error_message), std::move(promise));
error_message = error.message().str()](Promise<> promise) {
context_->on_send_message_error(random_id, Status::Error(error_code, error_message), std::move(promise));
};
state->send_result_(std::move(send_message_error_promise));
} else {
@ -1598,7 +1598,7 @@ void SecretChatActor::on_outbound_send_message_result(NetQueryPtr query, Promise
state->send_result_ = [this, random_id = state->message->random_id,
message_id = MessageId(ServerMessageId(state->message->message_id)),
date = sent->date_](Promise<> promise) {
this->context_->on_send_message_ok(random_id, message_id, date, nullptr, std::move(promise));
context_->on_send_message_ok(random_id, message_id, date, nullptr, std::move(promise));
};
state->send_result_(std::move(send_message_finish_promise));
return;
@ -1611,7 +1611,7 @@ void SecretChatActor::on_outbound_send_message_result(NetQueryPtr query, Promise
state->send_result_ = [this, random_id = state->message->random_id,
message_id = MessageId(ServerMessageId(state->message->message_id)),
date = sent->date_](Promise<> promise) {
this->context_->on_send_message_ok(random_id, message_id, date, nullptr, std::move(promise));
context_->on_send_message_ok(random_id, message_id, date, nullptr, std::move(promise));
};
} else {
state->message->file = log_event::EncryptedInputFile::from_input_encrypted_file(
@ -1619,7 +1619,7 @@ void SecretChatActor::on_outbound_send_message_result(NetQueryPtr query, Promise
state->send_result_ = [this, random_id = state->message->random_id,
message_id = MessageId(ServerMessageId(state->message->message_id)),
date = sent->date_, file = *file](Promise<> promise) {
this->context_->on_send_message_ok(random_id, message_id, date, make_unique<EncryptedFile>(file),
context_->on_send_message_ok(random_id, message_id, date, make_unique<EncryptedFile>(file),
std::move(promise));
};
}

View File

@ -302,8 +302,9 @@ void FileLoader::on_result(NetQueryPtr query) {
if (next) {
if (ordered_flag_) {
auto seq_no = part.id;
ordered_parts_.add(seq_no, std::make_pair(part, std::move(query)),
[this](auto seq_no, auto &&p) { this->on_part_query(p.first, std::move(p.second)); });
ordered_parts_.add(
seq_no, std::make_pair(part, std::move(query)),
[this](uint64 seq_no, std::pair<Part, NetQueryPtr> &&p) { on_part_query(p.first, std::move(p.second)); });
} else {
on_part_query(part, std::move(query));
}

View File

@ -826,7 +826,7 @@ FileManager::FileManager(unique_ptr<Context> context) : context_(std::move(conte
#endif
};
G()->td_db()->with_db_path([this](CSlice path) { this->bad_paths_.insert(path.str()); });
G()->td_db()->with_db_path([bad_paths = &bad_paths_](CSlice path) { bad_paths->insert(path.str()); });
}
void FileManager::init_actor() {
@ -3738,9 +3738,10 @@ void FileManager::on_error_impl(FileNodePtr node, Query::Type type, bool was_act
if (FileReferenceManager::is_file_reference_error(status)) {
string file_reference;
Slice prefix = "#BASE64";
auto pos = status.message().rfind('#');
if (pos < status.message().size() && begins_with(status.message().substr(pos), prefix)) {
auto r_file_reference = base64_decode(status.message().substr(pos + prefix.size()));
Slice error_message = status.message();
auto pos = error_message.rfind('#');
if (pos < error_message.size() && begins_with(error_message.substr(pos), prefix)) {
auto r_file_reference = base64_decode(error_message.substr(pos + prefix.size()));
if (r_file_reference.is_ok()) {
file_reference = r_file_reference.move_as_ok();
} else {

View File

@ -558,10 +558,10 @@ class FileManager final : public FileLoadManager::Callback {
mutable FileLocationSource file_location_source_;
FileId file_id_;
bool operator==(const RemoteInfo &other) const {
return this->remote_ == other.remote_;
return remote_ == other.remote_;
}
bool operator<(const RemoteInfo &other) const {
return this->remote_ < other.remote_;
return remote_ < other.remote_;
}
};
Enumerator<RemoteInfo> remote_location_info_;

View File

@ -28,16 +28,16 @@ void NetQueryDelayer::delay(NetQueryPtr query) {
if (code < 0) {
// skip
} else if (code == 500) {
auto msg = query->error().message();
if (msg == "WORKER_BUSY_TOO_LONG_RETRY") {
auto error_message = query->error().message();
if (error_message == "WORKER_BUSY_TOO_LONG_RETRY") {
timeout = 1; // it is dangerous to resend query without timeout, so use 1
}
} else if (code == 420) {
auto msg = query->error().message();
auto error_message = query->error().message();
for (auto prefix :
{Slice("FLOOD_WAIT_"), Slice("SLOWMODE_WAIT_"), Slice("2FA_CONFIRM_WAIT_"), Slice("TAKEOUT_INIT_DELAY_")}) {
if (begins_with(msg, prefix)) {
timeout = clamp(to_integer<int>(msg.substr(prefix.size())), 1, 14 * 24 * 60 * 60);
if (begins_with(error_message, prefix)) {
timeout = clamp(to_integer<int>(error_message.substr(prefix.size())), 1, 14 * 24 * 60 * 60);
break;
}
}

View File

@ -294,15 +294,15 @@ NetQueryDispatcher::NetQueryDispatcher() = default;
NetQueryDispatcher::~NetQueryDispatcher() = default;
void NetQueryDispatcher::try_fix_migrate(NetQueryPtr &net_query) {
auto msg = net_query->error().message();
auto error_message = net_query->error().message();
static constexpr CSlice prefixes[] = {"PHONE_MIGRATE_", "NETWORK_MIGRATE_", "USER_MIGRATE_"};
for (auto &prefix : prefixes) {
if (msg.substr(0, prefix.size()) == prefix) {
auto new_main_dc_id = to_integer<int32>(msg.substr(prefix.size()));
if (error_message.substr(0, prefix.size()) == prefix) {
auto new_main_dc_id = to_integer<int32>(error_message.substr(prefix.size()));
set_main_dc_id(new_main_dc_id);
if (!net_query->dc_id().is_main()) {
LOG(ERROR) << msg << " from query to non-main dc " << net_query->dc_id();
LOG(ERROR) << "Receive " << error_message << " for query to non-main DC" << net_query->dc_id();
net_query->resend(DcId::internal(new_main_dc_id));
} else {
net_query->resend();