Skip to content

Commit ef28251

Browse files
committed
Various improvements.
1 parent 04adfc8 commit ef28251

23 files changed

+84
-78
lines changed

‎td/telegram/LanguagePackManager.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1199,9 +1199,9 @@ static td_api::object_ptr<td_api::LanguagePackStringValue> copy_language_pack_st
11991199
}
12001200
case td_api::languagePackStringValuePluralized::ID: {
12011201
auto old_value = static_cast<const td_api::languagePackStringValuePluralized *>(value);
1202-
return make_tl_object<td_api::languagePackStringValuePluralized>(
1203-
std::move(old_value->zero_value_), std::move(old_value->one_value_), std::move(old_value->two_value_),
1204-
std::move(old_value->few_value_), std::move(old_value->many_value_), std::move(old_value->other_value_));
1202+
return make_tl_object<td_api::languagePackStringValuePluralized>(old_value->zero_value_, old_value->one_value_,
1203+
old_value->two_value_, old_value->few_value_,
1204+
old_value->many_value_, old_value->other_value_);
12051205
}
12061206
case td_api::languagePackStringValueDeleted::ID:
12071207
return make_tl_object<td_api::languagePackStringValueDeleted>();

‎td/telegram/LinkManager.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
14591459
}
14601460
if (arg.first == "ref" && is_valid_start_parameter(arg.second) && !arg.second.empty()) {
14611461
// resolve?domain=<bot_username>&ref=<referrer>
1462-
return td::make_unique<InternalLinkDialogReferralProgram>(std::move(username), std::move(arg.second));
1462+
return td::make_unique<InternalLinkDialogReferralProgram>(std::move(username), arg.second);
14631463
}
14641464
if (arg.first == "start" && is_valid_start_parameter(arg.second)) {
14651465
auto prefixes = get_referral_program_start_parameter_prefixes();
@@ -1964,7 +1964,7 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
19641964
}
19651965
if (arg.first == "ref" && is_valid_start_parameter(arg.second) && !arg.second.empty()) {
19661966
// /<bot_username>?ref=<referrer>
1967-
return td::make_unique<InternalLinkDialogReferralProgram>(std::move(username), std::move(arg.second));
1967+
return td::make_unique<InternalLinkDialogReferralProgram>(std::move(username), arg.second);
19681968
}
19691969
if (arg.first == "start" && is_valid_start_parameter(arg.second)) {
19701970
auto prefixes = get_referral_program_start_parameter_prefixes();
@@ -2486,10 +2486,10 @@ Result<string> LinkManager::get_internal_link_impl(const td_api::InternalLinkTyp
24862486
return std::move(static_cast<td_api::internalLinkTypeMessage &>(*parsed_object).url_);
24872487
}
24882488
case td_api::internalLinkTypeMessageDraft::ID: {
2489-
auto link = static_cast<const td_api::internalLinkTypeMessageDraft *>(type_ptr);
2489+
auto *link = static_cast<const td_api::internalLinkTypeMessageDraft *>(type_ptr);
24902490
string text;
24912491
if (link->text_ != nullptr) {
2492-
text = std::move(link->text_->text_);
2492+
text = link->text_->text_;
24932493
}
24942494
string url;
24952495
if (link->contains_link_) {

‎td/telegram/MessageContent.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -3183,9 +3183,7 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
31833183
file_id.is_valid());
31843184

31853185
InlineMessageContent result;
3186-
tl_object_ptr<telegram_api::ReplyMarkup> reply_markup;
3187-
result.disable_web_page_preview = false;
3188-
result.invert_media = false;
3186+
telegram_api::object_ptr<telegram_api::ReplyMarkup> reply_markup;
31893187
switch (bot_inline_message->get_id()) {
31903188
case telegram_api::botInlineMessageText::ID: {
31913189
auto inline_message = telegram_api::move_object_as<telegram_api::botInlineMessageText>(bot_inline_message);
@@ -7343,6 +7341,7 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
73437341
auto m = make_unique<MessageGame>(
73447342
Game(td, via_bot_user_id, std::move(media->game_), std::move(message), owner_dialog_id));
73457343
if (m->game.is_empty()) {
7344+
message = m->game.get_text();
73467345
break;
73477346
}
73487347
return std::move(m);

‎td/telegram/MessageContent.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ struct InputMessageContent {
8787
struct InlineMessageContent {
8888
unique_ptr<MessageContent> message_content;
8989
unique_ptr<ReplyMarkup> message_reply_markup;
90-
bool disable_web_page_preview;
91-
bool invert_media;
90+
bool disable_web_page_preview = false;
91+
bool invert_media = false;
9292
};
9393

9494
void store_message_content(const MessageContent *content, LogEventStorerCalcLength &storer);

‎td/telegram/MessageImportManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ void MessageImportManager::start_import_messages(DialogId dialog_id, int64 impor
441441
}));
442442
auto lock_promise = multipromise.get_promise();
443443

444-
for (auto attached_file_upload_id : attached_file_upload_ids) {
444+
for (const auto &attached_file_upload_id : attached_file_upload_ids) {
445445
upload_imported_message_attachment(dialog_id, import_id, attached_file_upload_id, false,
446446
multipromise.get_promise());
447447
}

‎td/telegram/MessagesManager.cpp

+22-20
Original file line numberDiff line numberDiff line change
@@ -3825,7 +3825,7 @@ void MessagesManager::on_live_location_expire_timeout() {
38253825
LOG(INFO) << "Have no messages to delete";
38263826
schedule_active_live_location_expiration();
38273827
} else {
3828-
for (auto message_full_id : to_delete_message_full_ids) {
3828+
for (const auto &message_full_id : to_delete_message_full_ids) {
38293829
bool is_deleted = delete_active_live_location(message_full_id);
38303830
CHECK(is_deleted);
38313831
}
@@ -6685,7 +6685,7 @@ void MessagesManager::restore_missing_messages_after_get_difference() {
66856685
}
66866686
}
66876687
}
6688-
for (auto message_full_id : restored_message_full_ids) {
6688+
for (const auto &message_full_id : restored_message_full_ids) {
66896689
messages_to_restore_.erase(message_full_id);
66906690
}
66916691
if (missing_messages.empty()) {
@@ -13541,7 +13541,6 @@ void MessagesManager::get_dialogs_from_list(DialogListId dialog_list_id, int32 l
1354113541
auto &task = get_dialogs_tasks_[task_id];
1354213542
task.dialog_list_id = dialog_list_id;
1354313543
task.dialog_list_unique_id = list->unique_id_;
13544-
task.retry_count = 5;
1354513544
task.limit = limit;
1354613545
task.promise = std::move(promise);
1354713546
get_dialogs_from_list_impl(task_id);
@@ -14410,13 +14409,13 @@ void MessagesManager::get_messages(DialogId dialog_id, const vector<MessageId> &
1441014409

1441114410
void MessagesManager::get_message_from_server(MessageFullId message_full_id, Promise<Unit> &&promise,
1441214411
const char *source,
14413-
tl_object_ptr<telegram_api::InputMessage> input_message) {
14412+
telegram_api::object_ptr<telegram_api::InputMessage> input_message) {
1441414413
get_messages_from_server({message_full_id}, std::move(promise), source, std::move(input_message));
1441514414
}
1441614415

1441714416
void MessagesManager::get_messages_from_server(vector<MessageFullId> &&message_ids, Promise<Unit> &&promise,
1441814417
const char *source,
14419-
tl_object_ptr<telegram_api::InputMessage> input_message) {
14418+
telegram_api::object_ptr<telegram_api::InputMessage> input_message) {
1442014419
TRY_STATUS_PROMISE(promise, G()->close_status());
1442114420

1442214421
if (message_ids.empty()) {
@@ -14428,8 +14427,9 @@ void MessagesManager::get_messages_from_server(vector<MessageFullId> &&message_i
1442814427
CHECK(message_ids.size() == 1);
1442914428
}
1443014429

14431-
vector<tl_object_ptr<telegram_api::InputMessage>> ordinary_message_ids;
14432-
FlatHashMap<ChannelId, vector<tl_object_ptr<telegram_api::InputMessage>>, ChannelIdHash> channel_message_ids;
14430+
vector<telegram_api::object_ptr<telegram_api::InputMessage>> ordinary_message_ids;
14431+
FlatHashMap<ChannelId, vector<telegram_api::object_ptr<telegram_api::InputMessage>>, ChannelIdHash>
14432+
channel_message_ids;
1443314433
FlatHashMap<DialogId, vector<int32>, DialogIdHash> scheduled_message_ids;
1443414434
for (auto &message_full_id : message_ids) {
1443514435
auto dialog_id = message_full_id.get_dialog_id();
@@ -14442,7 +14442,7 @@ void MessagesManager::get_messages_from_server(vector<MessageFullId> &&message_i
1444214442
}
1444314443

1444414444
if (input_message == nullptr) {
14445-
input_message = make_tl_object<telegram_api::inputMessageID>(message_id.get_server_message_id().get());
14445+
input_message = telegram_api::make_object<telegram_api::inputMessageID>(message_id.get_server_message_id().get());
1444614446
}
1444714447

1444814448
switch (dialog_id.get_type()) {
@@ -14951,7 +14951,8 @@ void MessagesManager::on_get_message_link_dialog(MessageLinkInfo &&info, DialogI
1495114951

1495214952
Dialog *d = get_dialog_force(dialog_id, "on_get_message_link_dialog");
1495314953
CHECK(d != nullptr);
14954-
get_message_force_from_server(d, info.message_id,
14954+
auto message_id = info.message_id;
14955+
get_message_force_from_server(d, message_id,
1495514956
PromiseCreator::lambda([actor_id = actor_id(this), info = std::move(info), dialog_id,
1495614957
promise = std::move(promise)](Result<Unit> &&result) mutable {
1495714958
if (result.is_error()) {
@@ -17637,7 +17638,7 @@ void MessagesManager::schedule_active_live_location_expiration() {
1763717638
live_location_expire_timeout_.cancel_timeout();
1763817639
} else {
1763917640
double expires_in = std::numeric_limits<int32>::max();
17640-
for (auto message_full_id : active_live_location_message_full_ids_) {
17641+
for (const auto &message_full_id : active_live_location_message_full_ids_) {
1764117642
const auto *m = get_message(message_full_id);
1764217643
CHECK(m != nullptr);
1764317644
double live_period = get_message_content_live_location_period(m->content.get());
@@ -18588,6 +18589,7 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId
1858818589
auto debug_last_new_message_id = d->last_new_message_id;
1858918590

1859018591
bool have_error = false;
18592+
auto message_count = messages.size();
1859118593
auto message_ids = on_get_messages_from_database(
1859218594
d, std::move(messages), d->have_full_history ? MessageId::min() : d->first_database_message_id, have_error,
1859318595
"on_get_history_from_database");
@@ -18650,7 +18652,7 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId
1865018652
}
1865118653
}
1865218654

18653-
if (from_the_end && messages.empty() && d->ordered_messages.empty()) {
18655+
if (from_the_end && message_count == 0 && d->ordered_messages.empty()) {
1865418656
if (d->have_full_history) {
1865518657
set_dialog_is_empty(d, "on_get_history_from_database empty");
1865618658
} else if (d->last_database_message_id.is_valid()) {
@@ -18691,10 +18693,10 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId
1869118693
<< " from database from the end, but expected messages from " << d->first_database_message_id
1869218694
<< " up to " << d->last_database_message_id
1869318695
<< ". Have old last_database_message_id = " << old_last_database_message_id << " and "
18694-
<< messages.size() << " received messages";
18696+
<< message_count << " received messages";
1869518697
} else {
18696-
LOG(ERROR) << "Receive " << messages.size() << " unusable messages [" << first_received_message_id
18697-
<< " ... " << last_received_message_id << "] in " << dialog_id
18698+
LOG(ERROR) << "Receive " << message_count << " unusable messages [" << first_received_message_id << " ... "
18699+
<< last_received_message_id << "] in " << dialog_id
1869818700
<< " from database from the end, but expected messages from " << d->first_database_message_id
1869918701
<< " up to " << d->last_database_message_id;
1870018702
}
@@ -20178,12 +20180,12 @@ vector<FileId> MessagesManager::get_message_file_ids(const Message *m) const {
2017820180
void MessagesManager::cancel_upload_message_content_files(const vector<FileUploadId> &file_upload_ids,
2017920181
const vector<FileUploadId> &thumbnail_file_upload_ids) {
2018020182
// always cancel file upload, it should be a no-op in the worst case
20181-
for (auto file_upload_id : file_upload_ids) {
20183+
for (const auto &file_upload_id : file_upload_ids) {
2018220184
if (being_uploaded_files_.erase(file_upload_id) || file_upload_id.is_valid()) {
2018320185
cancel_upload_file(file_upload_id, "cancel_upload_message_content_files");
2018420186
}
2018520187
}
20186-
for (auto file_upload_id : thumbnail_file_upload_ids) {
20188+
for (const auto &file_upload_id : thumbnail_file_upload_ids) {
2018720189
if (being_uploaded_thumbnails_.erase(file_upload_id) || being_loaded_secret_thumbnails_.erase(file_upload_id) ||
2018820190
file_upload_id.is_valid()) {
2018920191
cancel_upload_file(file_upload_id, "cancel_upload_message_content_files");
@@ -20225,7 +20227,7 @@ void MessagesManager::cancel_send_message_query(DialogId dialog_id, Message *m)
2022520227
{
2022620228
auto it = replied_yet_unsent_messages_.find({dialog_id, m->message_id});
2022720229
if (it != replied_yet_unsent_messages_.end()) {
20228-
for (auto message_full_id : it->second) {
20230+
for (const auto &message_full_id : it->second) {
2022920231
auto reply_d = get_dialog(message_full_id.get_dialog_id());
2023020232
CHECK(reply_d != nullptr);
2023120233
auto replied_m = get_message(reply_d, message_full_id.get_message_id());
@@ -22914,7 +22916,7 @@ void MessagesManager::update_message_max_reply_media_timestamp_in_replied_messag
2291422916

2291522917
LOG(INFO) << "Update max_reply_media_timestamp for replies of " << message_full_id;
2291622918

22917-
for (auto replied_message_full_id : it->second) {
22919+
for (const auto &replied_message_full_id : it->second) {
2291822920
auto replied_dialog_id = replied_message_full_id.get_dialog_id();
2291922921
Dialog *d = get_dialog(replied_dialog_id);
2292022922
auto m = get_message(d, replied_message_full_id.get_message_id());
@@ -22932,7 +22934,7 @@ void MessagesManager::update_story_max_reply_media_timestamp_in_replied_messages
2293222934

2293322935
LOG(INFO) << "Update max_reply_media_timestamp for replies of " << story_full_id;
2293422936

22935-
for (auto replied_message_full_id : it->second) {
22937+
for (const auto &replied_message_full_id : it->second) {
2293622938
auto replied_dialog_id = replied_message_full_id.get_dialog_id();
2293722939
Dialog *d = get_dialog(replied_dialog_id);
2293822940
auto m = get_message(d, replied_message_full_id.get_message_id());
@@ -26410,7 +26412,7 @@ void MessagesManager::update_reply_to_message_id(DialogId dialog_id, MessageId o
2641026412
CHECK(old_message_id.is_yet_unsent());
2641126413
CHECK(new_message_id == MessageId() || new_message_id.is_valid() || new_message_id.is_valid_scheduled());
2641226414

26413-
for (auto message_full_id : it->second) {
26415+
for (const auto &message_full_id : it->second) {
2641426416
auto reply_d = get_dialog(message_full_id.get_dialog_id());
2641526417
CHECK(reply_d != nullptr);
2641626418
auto replied_m = get_message(reply_d, message_full_id.get_message_id());

‎td/telegram/MessagesManager.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,10 @@ class MessagesManager final : public Actor {
564564
void get_messages(DialogId dialog_id, const vector<MessageId> &message_ids, Promise<Unit> &&promise);
565565

566566
void get_message_from_server(MessageFullId message_full_id, Promise<Unit> &&promise, const char *source,
567-
tl_object_ptr<telegram_api::InputMessage> input_message = nullptr);
567+
telegram_api::object_ptr<telegram_api::InputMessage> input_message = nullptr);
568568

569569
void get_messages_from_server(vector<MessageFullId> &&message_ids, Promise<Unit> &&promise, const char *source,
570-
tl_object_ptr<telegram_api::InputMessage> input_message = nullptr);
570+
telegram_api::object_ptr<telegram_api::InputMessage> input_message = nullptr);
571571

572572
void get_message_properties(DialogId dialog_id, MessageId message_id,
573573
Promise<td_api::object_ptr<td_api::messageProperties>> &&promise);
@@ -1818,9 +1818,9 @@ class MessagesManager final : public Actor {
18181818
bool drop_author = false;
18191819
bool drop_media_captions = false;
18201820

1821-
Dialog *from_dialog;
1821+
Dialog *from_dialog = nullptr;
18221822
MessageId top_thread_message_id;
1823-
Dialog *to_dialog;
1823+
Dialog *to_dialog = nullptr;
18241824
MessageSendOptions message_send_options;
18251825
};
18261826

@@ -3255,9 +3255,9 @@ class MessagesManager final : public Actor {
32553255

32563256
struct GetDialogsTask {
32573257
DialogListId dialog_list_id;
3258-
int64 dialog_list_unique_id;
3259-
int32 limit;
3260-
int32 retry_count;
3258+
int64 dialog_list_unique_id = 0;
3259+
int32 limit = 0;
3260+
int32 retry_count = 5;
32613261
DialogDate last_dialog_date = MIN_DIALOG_DATE;
32623262
Promise<td_api::object_ptr<td_api::chats>> promise;
32633263
};

‎td/telegram/NotificationManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ void NotificationManager::flush_pending_updates(int32 group_id, const char *sour
11141114
// all other additions and edits can be merged to the first addition/edit
11151115
// i.e. in edit+delete+add chain we want to remove deletion and merge addition to the edit
11161116

1117-
auto group_key = group_keys_[NotificationGroupId(group_id)];
1117+
const auto &group_key = group_keys_[NotificationGroupId(group_id)];
11181118
bool is_hidden = group_key.last_notification_date == 0 || get_last_updated_group_key() < group_key;
11191119
bool is_changed = true;
11201120
while (is_changed) {

‎td/telegram/NotificationSound.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class NotificationSoundLocal final : public NotificationSound {
3636

3737
class NotificationSoundRingtone final : public NotificationSound {
3838
public:
39-
int64 ringtone_id_;
39+
int64 ringtone_id_ = 0;
4040

4141
NotificationSoundRingtone() = default;
4242
explicit NotificationSoundRingtone(int64 ringtone_id) : ringtone_id_(ringtone_id) {
@@ -234,7 +234,7 @@ unique_ptr<NotificationSound> get_notification_sound(telegram_api::NotificationS
234234
case telegram_api::notificationSoundNone::ID:
235235
return make_unique<NotificationSoundNone>();
236236
case telegram_api::notificationSoundLocal::ID: {
237-
const auto *sound = static_cast<telegram_api::notificationSoundLocal *>(notification_sound);
237+
auto *sound = static_cast<telegram_api::notificationSoundLocal *>(notification_sound);
238238
return td::make_unique<NotificationSoundLocal>(std::move(sound->title_), std::move(sound->data_));
239239
}
240240
case telegram_api::notificationSoundRingtone::ID: {

‎td/telegram/PhoneNumberManager.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class PhoneNumberManager final : public Actor {
3838
void check_code(string code, Promise<Unit> &&promise);
3939

4040
private:
41-
enum class Type : int32 { ChangePhone, VerifyPhone, ConfirmPhone };
41+
enum class Type : int32 { None, ChangePhone, VerifyPhone, ConfirmPhone };
4242
enum class State : int32 { Ok, WaitCode } state_ = State::Ok;
4343

4444
void tear_down() final;
@@ -56,7 +56,7 @@ class PhoneNumberManager final : public Actor {
5656
Td *td_;
5757
ActorShared<> parent_;
5858

59-
Type type_;
59+
Type type_ = Type::None;
6060
SendCodeHelper send_code_helper_;
6161
int64 generation_ = 0;
6262
};

‎td/telegram/ReactionManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ void ReactionManager::on_get_message_effects(
13441344
for (const auto &available_effect : effects->effects_) {
13451345
Effect effect;
13461346
effect.id_ = MessageEffectId(available_effect->id_);
1347-
effect.emoji_ = std::move(available_effect->emoticon_);
1347+
effect.emoji_ = available_effect->emoticon_;
13481348
effect.is_premium_ = available_effect->premium_required_;
13491349
if (available_effect->static_icon_id_ != 0) {
13501350
auto it = stickers.find(available_effect->static_icon_id_);

‎td/telegram/UserManager.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,14 @@ class UserManager final : public Actor {
239239

240240
struct BotData {
241241
string username;
242-
bool can_be_edited;
243-
bool can_join_groups;
244-
bool can_read_all_group_messages;
245-
bool has_main_app;
246-
bool is_inline;
247-
bool is_business;
248-
bool need_location;
249-
bool can_be_added_to_attach_menu;
242+
bool can_be_edited = false;
243+
bool can_join_groups = false;
244+
bool can_read_all_group_messages = false;
245+
bool has_main_app = false;
246+
bool is_inline = false;
247+
bool is_business = false;
248+
bool need_location = false;
249+
bool can_be_added_to_attach_menu = false;
250250
};
251251
Result<BotData> get_bot_data(UserId user_id) const TD_WARN_UNUSED_RESULT;
252252

‎td/telegram/WebPageBlock.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1211,8 +1211,8 @@ class WebPageBlockEmbedded final : public WebPageBlock {
12111211
Photo poster_photo;
12121212
Dimensions dimensions;
12131213
WebPageBlockCaption caption;
1214-
bool is_full_width;
1215-
bool allow_scrolling;
1214+
bool is_full_width = false;
1215+
bool allow_scrolling = false;
12161216

12171217
public:
12181218
WebPageBlockEmbedded() = default;
@@ -1277,7 +1277,7 @@ class WebPageBlockEmbeddedPost final : public WebPageBlock {
12771277
string url;
12781278
string author;
12791279
Photo author_photo;
1280-
int32 date;
1280+
int32 date = 0;
12811281
vector<unique_ptr<WebPageBlock>> page_blocks;
12821282
WebPageBlockCaption caption;
12831283

@@ -1651,7 +1651,7 @@ class WebPageBlockTable final : public WebPageBlock {
16511651
class WebPageBlockDetails final : public WebPageBlock {
16521652
RichText header;
16531653
vector<unique_ptr<WebPageBlock>> page_blocks;
1654-
bool is_open;
1654+
bool is_open = false;
16551655

16561656
public:
16571657
WebPageBlockDetails() = default;

0 commit comments

Comments
 (0)