Add only_valid parameter to UserId::get_user_ids.

This commit is contained in:
levlam 2024-06-27 12:53:33 +03:00
parent 8a53dff652
commit 83204d4b2d
3 changed files with 9 additions and 11 deletions

View File

@ -17,25 +17,22 @@
namespace td {
BusinessRecipients::BusinessRecipients(telegram_api::object_ptr<telegram_api::businessRecipients> recipients)
: user_ids_(UserId::get_user_ids(recipients->users_))
: user_ids_(UserId::get_user_ids(recipients->users_, true))
, existing_chats_(recipients->existing_chats_)
, new_chats_(recipients->new_chats_)
, contacts_(recipients->contacts_)
, non_contacts_(recipients->non_contacts_)
, exclude_selected_(recipients->exclude_selected_) {
td::remove_if(user_ids_, [](UserId user_id) { return !user_id.is_valid(); });
}
BusinessRecipients::BusinessRecipients(telegram_api::object_ptr<telegram_api::businessBotRecipients> recipients)
: user_ids_(UserId::get_user_ids(recipients->users_))
, excluded_user_ids_(UserId::get_user_ids(recipients->exclude_users_))
: user_ids_(UserId::get_user_ids(recipients->users_, true))
, excluded_user_ids_(UserId::get_user_ids(recipients->exclude_users_, true))
, existing_chats_(recipients->existing_chats_)
, new_chats_(recipients->new_chats_)
, contacts_(recipients->contacts_)
, non_contacts_(recipients->non_contacts_)
, exclude_selected_(recipients->exclude_selected_) {
td::remove_if(user_ids_, [](UserId user_id) { return !user_id.is_valid(); });
td::remove_if(excluded_user_ids_, [](UserId user_id) { return !user_id.is_valid(); });
}
BusinessRecipients::BusinessRecipients(td_api::object_ptr<td_api::businessRecipients> recipients, bool allow_excluded) {

View File

@ -30264,13 +30264,11 @@ void MessagesManager::on_update_dialog_pending_join_requests(DialogId dialog_id,
return;
}
set_dialog_pending_join_requests(d, pending_join_request_count, UserId::get_user_ids(pending_requesters));
set_dialog_pending_join_requests(d, pending_join_request_count, UserId::get_user_ids(pending_requesters, true));
}
void MessagesManager::fix_pending_join_requests(DialogId dialog_id, int32 &pending_join_request_count,
vector<UserId> &pending_join_request_user_ids) const {
td::remove_if(pending_join_request_user_ids, [](UserId user_id) { return !user_id.is_valid(); });
bool need_drop_pending_join_requests = [&] {
if (pending_join_request_count < 0) {
return true;

View File

@ -29,11 +29,14 @@ class UserId {
template <class T, typename = std::enable_if_t<std::is_convertible<T, int64>::value>>
UserId(T user_id) = delete;
static vector<UserId> get_user_ids(const vector<int64> &input_user_ids) {
static vector<UserId> get_user_ids(const vector<int64> &input_user_ids, bool only_valid = false) {
vector<UserId> user_ids;
user_ids.reserve(input_user_ids.size());
for (auto &input_user_id : input_user_ids) {
user_ids.emplace_back(input_user_id);
UserId user_id(input_user_id);
if (!only_valid || user_id.is_valid()) {
user_ids.emplace_back(user_id);
}
}
return user_ids;
}