diff options
| author | levlam <levlam@telegram.org> | 2025-02-18 15:35:03 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2025-02-18 15:35:03 +0300 |
| commit | aee91607e3e111611099325ced20b981228849e3 (patch) | |
| tree | 2bd8cad0e69a98efd85a50cc287fe82d03736d45 /td/telegram/DialogActionBar.cpp | |
| parent | 57aaa28e6aa7a0ba84ed099dde65840e2bb81aea (diff) | |
Add chatActionBarReportAddBlock.account_info.
Diffstat (limited to 'td/telegram/DialogActionBar.cpp')
| -rw-r--r-- | td/telegram/DialogActionBar.cpp | 104 |
1 files changed, 92 insertions, 12 deletions
diff --git a/td/telegram/DialogActionBar.cpp b/td/telegram/DialogActionBar.cpp index a4ef93152..d81df3646 100644 --- a/td/telegram/DialogActionBar.cpp +++ b/td/telegram/DialogActionBar.cpp @@ -54,6 +54,14 @@ unique_ptr<DialogActionBar> DialogActionBar::create( action_bar->join_request_dialog_title_ = std::move(peer_settings->request_chat_title_); action_bar->is_join_request_broadcast_ = peer_settings->request_chat_broadcast_; action_bar->join_request_date_ = peer_settings->request_chat_date_; + if (!parse_registration_month(action_bar->registration_month_, peer_settings->registration_month_)) { + LOG(ERROR) << "Receive invalid registration month " << peer_settings->registration_month_; + } + if (!parse_country_code(action_bar->phone_country_, peer_settings->phone_country_)) { + LOG(ERROR) << "Receive invalid phone number country code " << peer_settings->phone_country_; + } + action_bar->last_name_change_date_ = max(0, peer_settings->name_change_date_); + action_bar->last_photo_change_date_ = max(0, peer_settings->photo_change_date_); if (action_bar->is_empty()) { return nullptr; } @@ -65,6 +73,53 @@ bool DialogActionBar::is_empty() const { !can_report_location_ && !can_invite_members_ && join_request_dialog_title_.empty(); } +bool DialogActionBar::parse_registration_month(int32 ®istration_month, const string &str) { + if (str.empty()) { + return true; + } + if (str.size() != 7u || !is_digit(str[0]) || !is_digit(str[1]) || str[2] != '.' || !is_digit(str[3]) || + !is_digit(str[4]) || !is_digit(str[5]) || !is_digit(str[6])) { + return false; + } + auto month_int = (str[0] - '0') * 10 + (str[1] - '0'); + auto year_int = (str[3] - '0') * 1000 + (str[4] - '0') * 100 + (str[5] - '0') * 10 + (str[6] - '0'); + if (month_int < 1 || month_int > 12 || year_int < 2000) { + return false; + } + registration_month = month_int * 10000 + year_int; + return true; +} + +bool DialogActionBar::parse_country_code(int32 &country_code, const string &str) { + if (str.empty()) { + return true; + } + if (str.size() != 2u || str[0] < 'A' || str[0] > 'Z' || str[1] < 'A' || str[1] > 'Z') { + return false; + } + country_code = str[0] * 256 + str[1]; + return true; +} + +string DialogActionBar::get_country_code(int32 country) { + auto first_char = (country >> 8) & 255; + auto second_char = country & 255; + if (first_char < 'A' || first_char > 'Z' || second_char < 'A' || second_char > 'Z') { + return string(); + } + string result(2, static_cast<char>(first_char)); + result[1] = static_cast<char>(second_char); + return result; +} + +void DialogActionBar::clear_can_block_user() { + can_block_user_ = false; + registration_month_ = 0; + phone_country_ = 0; + last_name_change_date_ = 0; + last_photo_change_date_ = 0; +} + void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, bool has_outgoing_messages, FolderId folder_id) { auto dialog_type = dialog_id.get_type(); @@ -91,13 +146,30 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, bo can_report_location_ = false; can_report_spam_ = false; can_add_contact_ = false; - can_block_user_ = false; + clear_can_block_user(); can_share_phone_number_ = false; can_unarchive_ = false; can_invite_members_ = false; distance_ = -1; + } else { + // ignore + registration_month_ = 0; + phone_country_ = 0; + last_name_change_date_ = 0; + last_photo_change_date_ = 0; } } + if ((registration_month_ != 0 || phone_country_ != 0 || last_name_change_date_ != 0 || + last_photo_change_date_ != 0) && + !can_block_user_) { + LOG(ERROR) << "Receive account information in the action bar " << can_report_spam_ << '/' << can_add_contact_ << '/' + << can_block_user_ << '/' << can_share_phone_number_ << '/' << can_report_location_ << '/' + << can_unarchive_ << '/' << can_invite_members_; + registration_month_ = 0; + phone_country_ = 0; + last_name_change_date_ = 0; + last_photo_change_date_ = 0; + } if (join_request_dialog_title_.empty() && (is_join_request_broadcast_ || join_request_date_ != 0)) { LOG(ERROR) << "Receive join request date = " << join_request_date_ << " and " << is_join_request_broadcast_ << " in " << dialog_id; @@ -115,7 +187,7 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, bo << can_invite_members_; can_report_spam_ = false; can_add_contact_ = false; - can_block_user_ = false; + clear_can_block_user(); can_share_phone_number_ = false; can_unarchive_ = false; can_invite_members_ = false; @@ -132,7 +204,7 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, bo << '/' << can_share_phone_number_ << '/' << can_unarchive_ << '/' << can_invite_members_; can_report_spam_ = false; can_add_contact_ = false; - can_block_user_ = false; + clear_can_block_user(); can_share_phone_number_ = false; can_unarchive_ = false; CHECK(distance_ == -1); @@ -151,7 +223,7 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, bo can_share_phone_number_ = false; } if (is_me || is_dialog_blocked || is_deleted || is_contact) { - can_block_user_ = false; + clear_can_block_user(); can_add_contact_ = false; } } @@ -169,7 +241,7 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, bo << '/' << can_share_phone_number_ << '/' << can_unarchive_ << '/' << distance_; can_report_spam_ = false; can_add_contact_ = false; - can_block_user_ = false; + clear_can_block_user(); can_unarchive_ = false; } } @@ -179,7 +251,7 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, bo CHECK(!can_share_phone_number_); if (dialog_type != DialogType::User) { LOG(ERROR) << "Receive can_block_user in " << dialog_id; - can_block_user_ = false; + clear_can_block_user(); } else if (!can_report_spam_ || !can_add_contact_) { LOG(ERROR) << "Receive action bar " << can_report_spam_ << '/' << can_add_contact_ << '/' << can_block_user_; can_report_spam_ = true; @@ -196,7 +268,7 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, bo } else if (can_report_spam_ != can_block_user_) { LOG(ERROR) << "Receive action bar " << can_report_spam_ << '/' << can_add_contact_ << '/' << can_block_user_; can_report_spam_ = false; - can_block_user_ = false; + clear_can_block_user(); can_unarchive_ = false; } } @@ -242,7 +314,13 @@ td_api::object_ptr<td_api::ChatActionBar> DialogActionBar::get_chat_action_bar_o if (can_block_user_) { CHECK(dialog_type == DialogType::User); CHECK(can_report_spam_ && can_add_contact_); - return td_api::make_object<td_api::chatActionBarReportAddBlock>(can_unarchive_); + td_api::object_ptr<td_api::accountInfo> account_info; + if (registration_month_ > 0 || phone_country_ > 0 || last_name_change_date_ > 0 || last_photo_change_date_ > 0) { + account_info = td_api::make_object<td_api::accountInfo>(registration_month_ / 10000, registration_month_ % 10000, + get_country_code(phone_country_), last_name_change_date_, + last_photo_change_date_); + } + return td_api::make_object<td_api::chatActionBarReportAddBlock>(can_unarchive_, std::move(account_info)); } if (can_add_contact_) { CHECK(dialog_type == DialogType::User); @@ -262,7 +340,7 @@ bool DialogActionBar::on_dialog_unarchived() { can_unarchive_ = false; can_report_spam_ = false; - can_block_user_ = false; + clear_can_block_user(); // keep can_add_contact_ return true; } @@ -272,7 +350,7 @@ bool DialogActionBar::on_user_contact_added() { return false; } - can_block_user_ = false; + clear_can_block_user(); can_add_contact_ = false; // keep can_unarchive_ distance_ = -1; @@ -289,7 +367,7 @@ bool DialogActionBar::on_user_deleted() { is_join_request_broadcast_ = false; join_request_date_ = 0; can_share_phone_number_ = false; - can_block_user_ = false; + clear_can_block_user(); can_add_contact_ = false; distance_ = -1; return true; @@ -311,7 +389,9 @@ bool operator==(const DialogActionBar &lhs, const DialogActionBar &rhs) { lhs.distance_ == rhs.distance_ && lhs.can_invite_members_ == rhs.can_invite_members_ && lhs.join_request_dialog_title_ == rhs.join_request_dialog_title_ && lhs.is_join_request_broadcast_ == lhs.is_join_request_broadcast_ && - lhs.join_request_date_ == rhs.join_request_date_; + lhs.join_request_date_ == rhs.join_request_date_ && lhs.registration_month_ == rhs.registration_month_ && + lhs.phone_country_ == rhs.phone_country_ && lhs.last_name_change_date_ == rhs.last_name_change_date_ && + lhs.last_photo_change_date_ == rhs.last_photo_change_date_; } } // namespace td |
