Replace getBlockedUsers with getBlockedChats.

GitOrigin-RevId: 431e0639095b9e01d1b897a52bca4430855560e4
This commit is contained in:
levlam 2020-09-20 03:29:00 +03:00
parent 54308a86fe
commit 446ba8d406
9 changed files with 151 additions and 146 deletions

View File

@ -4171,9 +4171,8 @@ sendCallRating call_id:int32 rating:int32 comment:string problems:vector<CallPro
sendCallDebugInformation call_id:int32 debug_information:string = Ok; sendCallDebugInformation call_id:int32 debug_information:string = Ok;
//@description Returns chats that were blocked by the current user @offset Number of chats to skip in the result; must be non-negative @limit The maximum number of chats to return; up to 100
//@description Returns users that were blocked by the current user @offset Number of users to skip in the result; must be non-negative @limit The maximum number of users to return; up to 100 getBlockedChats offset:int32 limit:int32 = Chats;
getBlockedUsers offset:int32 limit:int32 = Users;
//@description Adds a user to the contact list or edits an existing contact by their user identifier @contact The contact to add or edit; phone number can be empty and needs to be specified only if known, vCard is ignored //@description Adds a user to the contact list or edits an existing contact by their user identifier @contact The contact to add or edit; phone number can be empty and needs to be specified only if known, vCard is ignored

Binary file not shown.

View File

@ -349,65 +349,6 @@ class ResetWebAuthorizationsQuery : public Td::ResultHandler {
} }
}; };
class GetBlockedUsersQuery : public Td::ResultHandler {
Promise<Unit> promise_;
int32 offset_;
int32 limit_;
int64 random_id_;
public:
explicit GetBlockedUsersQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(int32 offset, int32 limit, int64 random_id) {
offset_ = offset;
limit_ = limit;
random_id_ = random_id;
send_query(G()->net_query_creator().create(telegram_api::contacts_getBlocked(offset, limit)));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::contacts_getBlocked>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetBlockedUsersQuery: " << to_string(ptr);
int32 constructor_id = ptr->get_id();
switch (constructor_id) {
case telegram_api::contacts_blocked::ID: {
auto blocked_users = move_tl_object_as<telegram_api::contacts_blocked>(ptr);
td->contacts_manager_->on_get_users(std::move(blocked_users->users_), "GetBlockedUsersQuery");
td->contacts_manager_->on_get_blocked_users_result(offset_, limit_, random_id_,
narrow_cast<int32>(blocked_users->blocked_.size()),
std::move(blocked_users->blocked_));
break;
}
case telegram_api::contacts_blockedSlice::ID: {
auto blocked_users = move_tl_object_as<telegram_api::contacts_blockedSlice>(ptr);
td->contacts_manager_->on_get_users(std::move(blocked_users->users_), "GetBlockedUsersQuery");
td->contacts_manager_->on_get_blocked_users_result(offset_, limit_, random_id_, blocked_users->count_,
std::move(blocked_users->blocked_));
break;
}
default:
UNREACHABLE();
}
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) override {
td->contacts_manager_->on_failed_get_blocked_users(random_id_);
promise_.set_error(std::move(status));
}
};
class GetContactsQuery : public Td::ResultHandler { class GetContactsQuery : public Td::ResultHandler {
public: public:
void send(int32 hash) { void send(int32 hash) {
@ -4634,67 +4575,6 @@ bool ContactsManager::is_valid_username(const string &username) {
return true; return true;
} }
int64 ContactsManager::get_blocked_users(int32 offset, int32 limit, Promise<Unit> &&promise) {
LOG(INFO) << "Get blocked users with offset = " << offset << " and limit = " << limit;
if (offset < 0) {
promise.set_error(Status::Error(3, "Parameter offset must be non-negative"));
return 0;
}
if (limit <= 0) {
promise.set_error(Status::Error(3, "Parameter limit must be positive"));
return 0;
}
int64 random_id;
do {
random_id = Random::secure_int64();
} while (random_id == 0 || found_blocked_users_.find(random_id) != found_blocked_users_.end());
found_blocked_users_[random_id]; // reserve place for result
td_->create_handler<GetBlockedUsersQuery>(std::move(promise))->send(offset, limit, random_id);
return random_id;
}
void ContactsManager::on_get_blocked_users_result(int32 offset, int32 limit, int64 random_id, int32 total_count,
vector<tl_object_ptr<telegram_api::peerBlocked>> &&blocked_peers) {
LOG(INFO) << "Receive " << blocked_peers.size() << " blocked users out of " << total_count;
auto it = found_blocked_users_.find(random_id);
CHECK(it != found_blocked_users_.end());
auto &result = it->second.second;
CHECK(result.empty());
for (auto &blocked_peer : blocked_peers) {
CHECK(blocked_peer != nullptr);
DialogId dialog_id(blocked_peer->peer_id_);
if (dialog_id.get_type() != DialogType::User) {
continue;
}
auto user_id = dialog_id.get_user_id();
if (have_user(user_id)) {
result.push_back(user_id);
} else {
LOG(ERROR) << "Have no info about " << user_id;
}
}
it->second.first = total_count;
}
void ContactsManager::on_failed_get_blocked_users(int64 random_id) {
auto it = found_blocked_users_.find(random_id);
CHECK(it != found_blocked_users_.end());
found_blocked_users_.erase(it);
}
tl_object_ptr<td_api::users> ContactsManager::get_blocked_users_object(int64 random_id) {
auto it = found_blocked_users_.find(random_id);
CHECK(it != found_blocked_users_.end());
auto result = get_users_object(it->second.first, it->second.second);
found_blocked_users_.erase(it);
return result;
}
int32 ContactsManager::get_user_was_online(const User *u, UserId user_id) const { int32 ContactsManager::get_user_was_online(const User *u, UserId user_id) const {
if (u == nullptr || u->is_deleted) { if (u == nullptr || u->is_deleted) {
return 0; return 0;

View File

@ -290,15 +290,6 @@ class ContactsManager : public Actor {
void disconnect_website(int64 authorizations_id, Promise<Unit> &&promise) const; void disconnect_website(int64 authorizations_id, Promise<Unit> &&promise) const;
void disconnect_all_websites(Promise<Unit> &&promise) const; void disconnect_all_websites(Promise<Unit> &&promise) const;
int64 get_blocked_users(int32 offset, int32 limit, Promise<Unit> &&promise);
void on_get_blocked_users_result(int32 offset, int32 limit, int64 random_id, int32 total_count,
vector<tl_object_ptr<telegram_api::peerBlocked>> &&blocked_peers);
void on_failed_get_blocked_users(int64 random_id);
tl_object_ptr<td_api::users> get_blocked_users_object(int64 random_id);
void add_contact(td_api::object_ptr<td_api::contact> &&contact, bool share_phone_number, Promise<Unit> &&promise); void add_contact(td_api::object_ptr<td_api::contact> &&contact, bool share_phone_number, Promise<Unit> &&promise);
std::pair<vector<UserId>, vector<int32>> import_contacts(const vector<tl_object_ptr<td_api::contact>> &contacts, std::pair<vector<UserId>, vector<int32>> import_contacts(const vector<tl_object_ptr<td_api::contact>> &contacts,
@ -1555,9 +1546,6 @@ class ContactsManager : public Actor {
std::unordered_map<ChannelId, vector<DialogParticipant>, ChannelIdHash> cached_channel_participants_; std::unordered_map<ChannelId, vector<DialogParticipant>, ChannelIdHash> cached_channel_participants_;
std::unordered_map<int64, std::pair<int32, vector<UserId>>>
found_blocked_users_; // random_id -> [total_count, [user_id]...]
bool are_contacts_loaded_ = false; bool are_contacts_loaded_ = false;
int32 next_contacts_sync_date_ = 0; int32 next_contacts_sync_date_ = 0;
Hints contacts_hints_; // search contacts by first name, last name and username Hints contacts_hints_; // search contacts by first name, last name and username

View File

@ -850,6 +850,66 @@ class GetCommonDialogsQuery : public Td::ResultHandler {
} }
}; };
class GetBlockedDialogsQuery : public Td::ResultHandler {
Promise<Unit> promise_;
int32 offset_;
int32 limit_;
int64 random_id_;
public:
explicit GetBlockedDialogsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(int32 offset, int32 limit, int64 random_id) {
offset_ = offset;
limit_ = limit;
random_id_ = random_id;
send_query(G()->net_query_creator().create(telegram_api::contacts_getBlocked(offset, limit)));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::contacts_getBlocked>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetBlockedDialogsQuery: " << to_string(ptr);
switch (ptr->get_id()) {
case telegram_api::contacts_blocked::ID: {
auto blocked_peers = move_tl_object_as<telegram_api::contacts_blocked>(ptr);
td->contacts_manager_->on_get_users(std::move(blocked_peers->users_), "GetBlockedDialogsQuery");
td->contacts_manager_->on_get_chats(std::move(blocked_peers->chats_), "GetBlockedDialogsQuery");
td->messages_manager_->on_get_blocked_dialogs(offset_, limit_, random_id_,
narrow_cast<int32>(blocked_peers->blocked_.size()),
std::move(blocked_peers->blocked_));
break;
}
case telegram_api::contacts_blockedSlice::ID: {
auto blocked_peers = move_tl_object_as<telegram_api::contacts_blockedSlice>(ptr);
td->contacts_manager_->on_get_users(std::move(blocked_peers->users_), "GetBlockedDialogsQuery");
td->contacts_manager_->on_get_chats(std::move(blocked_peers->chats_), "GetBlockedDialogsQuery");
td->messages_manager_->on_get_blocked_dialogs(offset_, limit_, random_id_, blocked_peers->count_,
std::move(blocked_peers->blocked_));
break;
}
default:
UNREACHABLE();
}
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) override {
td->messages_manager_->on_failed_get_blocked_dialogs(random_id_);
promise_.set_error(std::move(status));
}
};
class CreateChatQuery : public Td::ResultHandler { class CreateChatQuery : public Td::ResultHandler {
Promise<Unit> promise_; Promise<Unit> promise_;
int64 random_id_; int64 random_id_;
@ -15507,6 +15567,72 @@ void MessagesManager::on_get_common_dialogs(UserId user_id, int32 offset_chat_id
common_dialogs.total_count = total_count; common_dialogs.total_count = total_count;
} }
std::pair<int32, vector<DialogId>> MessagesManager::get_blocked_dialogs(int32 offset, int32 limit, int64 &random_id,
Promise<Unit> &&promise) {
LOG(INFO) << "Get blocked chats with offset = " << offset << " and limit = " << limit;
if (random_id != 0) {
// request has already been sent before
auto it = found_blocked_dialogs_.find(random_id);
CHECK(it != found_blocked_dialogs_.end());
auto result = std::move(it->second);
found_blocked_dialogs_.erase(it);
promise.set_value(Unit());
return result;
}
if (offset < 0) {
promise.set_error(Status::Error(3, "Parameter offset must be non-negative"));
return {};
}
if (limit <= 0) {
promise.set_error(Status::Error(3, "Parameter limit must be positive"));
return {};
}
do {
random_id = Random::secure_int64();
} while (random_id == 0 || found_blocked_dialogs_.find(random_id) != found_blocked_dialogs_.end());
found_blocked_dialogs_[random_id]; // reserve place for result
td_->create_handler<GetBlockedDialogsQuery>(std::move(promise))->send(offset, limit, random_id);
return {};
}
void MessagesManager::on_get_blocked_dialogs(int32 offset, int32 limit, int64 random_id, int32 total_count,
vector<tl_object_ptr<telegram_api::peerBlocked>> &&blocked_peers) {
LOG(INFO) << "Receive " << blocked_peers.size() << " blocked chats from offset " << offset << " out of "
<< total_count;
auto it = found_blocked_dialogs_.find(random_id);
CHECK(it != found_blocked_dialogs_.end());
auto &result = it->second.second;
CHECK(result.empty());
for (auto &blocked_peer : blocked_peers) {
CHECK(blocked_peer != nullptr);
DialogId dialog_id(blocked_peer->peer_id_);
force_create_dialog(dialog_id, "on_get_blocked_dialogs");
if (have_dialog(dialog_id)) {
result.push_back(dialog_id);
} else {
LOG(ERROR) << "Have no info about " << dialog_id;
}
}
if (!result.empty() && offset + result.size() > static_cast<size_t>(total_count)) {
LOG(ERROR) << "Fix total count of blocked chats from " << total_count << " to " << offset + result.size();
total_count = offset + narrow_cast<int32>(result.size());
}
it->second.first = total_count;
}
void MessagesManager::on_failed_get_blocked_dialogs(int64 random_id) {
auto it = found_blocked_dialogs_.find(random_id);
CHECK(it != found_blocked_dialogs_.end());
found_blocked_dialogs_.erase(it);
}
bool MessagesManager::have_message_force(FullMessageId full_message_id, const char *source) { bool MessagesManager::have_message_force(FullMessageId full_message_id, const char *source) {
return get_message_force(full_message_id, source) != nullptr; return get_message_force(full_message_id, source) != nullptr;
} }

View File

@ -553,6 +553,14 @@ class MessagesManager : public Actor {
std::pair<int32, vector<DialogId>> get_common_dialogs(UserId user_id, DialogId offset_dialog_id, int32 limit, std::pair<int32, vector<DialogId>> get_common_dialogs(UserId user_id, DialogId offset_dialog_id, int32 limit,
bool force, Promise<Unit> &&promise); bool force, Promise<Unit> &&promise);
std::pair<int32, vector<DialogId>> get_blocked_dialogs(int32 offset, int32 limit, int64 &random_id,
Promise<Unit> &&promise);
void on_get_blocked_dialogs(int32 offset, int32 limit, int64 random_id, int32 total_count,
vector<tl_object_ptr<telegram_api::peerBlocked>> &&blocked_peers);
void on_failed_get_blocked_dialogs(int64 random_id);
bool can_get_message_statistics(FullMessageId full_message_id); bool can_get_message_statistics(FullMessageId full_message_id);
bool have_message_force(FullMessageId full_message_id, const char *source); bool have_message_force(FullMessageId full_message_id, const char *source);
@ -3002,6 +3010,9 @@ class MessagesManager : public Actor {
}; };
std::unordered_map<UserId, CommonDialogs, UserIdHash> found_common_dialogs_; std::unordered_map<UserId, CommonDialogs, UserIdHash> found_common_dialogs_;
std::unordered_map<int64, std::pair<int32, vector<DialogId>>>
found_blocked_dialogs_; // random_id -> [total_count, [dialog_id]...]
std::unordered_map<int64, FullMessageId> get_dialog_message_by_date_results_; std::unordered_map<int64, FullMessageId> get_dialog_message_by_date_results_;
std::unordered_map<int64, std::pair<int32, vector<MessageId>>> std::unordered_map<int64, std::pair<int32, vector<MessageId>>>

View File

@ -2079,23 +2079,24 @@ class GetChatEventLogRequest : public RequestOnceActor {
} }
}; };
class GetBlockedUsersRequest : public RequestOnceActor { class GetBlockedChatsRequest : public RequestActor<> {
int32 offset_; int32 offset_;
int32 limit_; int32 limit_;
int64 random_id_; int64 random_id_;
std::pair<int32, vector<DialogId>> dialog_ids_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
random_id_ = td->contacts_manager_->get_blocked_users(offset_, limit_, std::move(promise)); dialog_ids_ = td->messages_manager_->get_blocked_dialogs(offset_, limit_, random_id_, std::move(promise));
} }
void do_send_result() override { void do_send_result() override {
send_result(td->contacts_manager_->get_blocked_users_object(random_id_)); send_result(MessagesManager::get_chats_object(dialog_ids_));
} }
public: public:
GetBlockedUsersRequest(ActorShared<Td> td, uint64 request_id, int32 offset, int32 limit) GetBlockedChatsRequest(ActorShared<Td> td, uint64 request_id, int32 offset, int32 limit)
: RequestOnceActor(std::move(td), request_id), offset_(offset), limit_(limit), random_id_(0) { : RequestActor(std::move(td), request_id), offset_(offset), limit_(limit), random_id_(0) {
} }
}; };
@ -6378,9 +6379,9 @@ void Td::on_request(uint64 id, const td_api::deleteFile &request) {
"td_api::deleteFile"); "td_api::deleteFile");
} }
void Td::on_request(uint64 id, const td_api::getBlockedUsers &request) { void Td::on_request(uint64 id, const td_api::getBlockedChats &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST(GetBlockedUsersRequest, request.offset_, request.limit_); CREATE_REQUEST(GetBlockedChatsRequest, request.offset_, request.limit_);
} }
void Td::on_request(uint64 id, td_api::addContact &request) { void Td::on_request(uint64 id, td_api::addContact &request) {

View File

@ -784,7 +784,7 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::deleteFile &request); void on_request(uint64 id, const td_api::deleteFile &request);
void on_request(uint64 id, const td_api::getBlockedUsers &request); void on_request(uint64 id, const td_api::getBlockedChats &request);
void on_request(uint64 id, td_api::addContact &request); void on_request(uint64 id, td_api::addContact &request);

View File

@ -2293,7 +2293,7 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getDeepLinkInfo>(args)); send_request(td_api::make_object<td_api::getDeepLinkInfo>(args));
} else if (op == "tme") { } else if (op == "tme") {
send_request(td_api::make_object<td_api::getRecentlyVisitedTMeUrls>(args)); send_request(td_api::make_object<td_api::getRecentlyVisitedTMeUrls>(args));
} else if (op == "gbu") { } else if (op == "gbc") {
string offset; string offset;
string limit; string limit;
@ -2304,7 +2304,7 @@ class CliClient final : public Actor {
if (limit.empty()) { if (limit.empty()) {
limit = "10"; limit = "10";
} }
send_request(td_api::make_object<td_api::getBlockedUsers>(to_integer<int32>(offset), to_integer<int32>(limit))); send_request(td_api::make_object<td_api::getBlockedChats>(to_integer<int32>(offset), to_integer<int32>(limit)));
} else if (op == "gu") { } else if (op == "gu") {
send_request(td_api::make_object<td_api::getUser>(as_user_id(args))); send_request(td_api::make_object<td_api::getUser>(as_user_id(args)));
} else if (op == "gsu") { } else if (op == "gsu") {