Add get_message_sender_dialog_ids.

This commit is contained in:
levlam 2021-11-15 12:52:40 +03:00
parent 5987ca69ff
commit 21c8c752be
4 changed files with 52 additions and 37 deletions

View File

@ -103,22 +103,7 @@ class GetGroupCallJoinAsQuery final : public Td::ResultHandler {
td_->contacts_manager_->on_get_users(std::move(ptr->users_), "GetGroupCallJoinAsQuery");
td_->contacts_manager_->on_get_chats(std::move(ptr->chats_), "GetGroupCallJoinAsQuery");
vector<td_api::object_ptr<td_api::MessageSender>> participant_aliaces;
for (auto &peer : ptr->peers_) {
DialogId dialog_id(peer);
if (!dialog_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << dialog_id << " as join as peer for " << dialog_id_;
continue;
}
if (dialog_id.get_type() != DialogType::User) {
td_->messages_manager_->force_create_dialog(dialog_id, "GetGroupCallJoinAsQuery");
}
participant_aliaces.push_back(get_message_sender_object(td_, dialog_id, "GetGroupCallJoinAsQuery"));
}
promise_.set_value(td_api::make_object<td_api::messageSenders>(static_cast<int32>(participant_aliaces.size()),
std::move(participant_aliaces)));
promise_.set_value(convert_message_senders_object(td_, ptr->peers_));
}
void on_error(Status status) final {

View File

@ -11,6 +11,9 @@
#include "td/telegram/MessagesManager.h"
#include "td/telegram/Td.h"
#include "td/utils/algorithm.h"
#include "td/utils/misc.h"
namespace td {
td_api::object_ptr<td_api::MessageSender> get_message_sender_object_const(Td *td, UserId user_id, DialogId dialog_id,
@ -54,6 +57,44 @@ td_api::object_ptr<td_api::MessageSender> get_message_sender_object(Td *td, Dial
return get_message_sender_object(td, UserId(), dialog_id, source);
}
vector<DialogId> get_message_sender_dialog_ids(Td *td,
const vector<telegram_api::object_ptr<telegram_api::Peer>> &peers) {
vector<DialogId> message_sender_dialog_ids;
message_sender_dialog_ids.reserve(peers.size());
for (auto &peer : peers) {
DialogId dialog_id(peer);
if (!dialog_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << dialog_id << " as message sender";
continue;
}
if (dialog_id.get_type() == DialogType::User) {
if (!td->contacts_manager_->have_user(dialog_id.get_user_id())) {
LOG(ERROR) << "Have no info about " << dialog_id.get_user_id();
continue;
}
} else {
if (!td->messages_manager_->have_dialog_info(dialog_id)) {
continue;
}
td->messages_manager_->force_create_dialog(dialog_id, "get_message_sender_dialog_ids");
if (!td->messages_manager_->have_dialog(dialog_id)) {
continue;
}
}
message_sender_dialog_ids.push_back(dialog_id);
}
return message_sender_dialog_ids;
}
td_api::object_ptr<td_api::messageSenders> convert_message_senders_object(
Td *td, const vector<telegram_api::object_ptr<telegram_api::Peer>> &peers) {
auto dialog_ids = get_message_sender_dialog_ids(td, peers);
auto message_senders = transform(dialog_ids, [td](DialogId dialog_id) {
return get_message_sender_object(td, dialog_id, "convert_message_senders_object");
});
return td_api::make_object<td_api::messageSenders>(narrow_cast<int32>(dialog_ids.size()), std::move(message_senders));
}
Result<DialogId> get_message_sender_dialog_id(const td_api::object_ptr<td_api::MessageSender> &message_sender_id) {
if (message_sender_id == nullptr) {
return Status::Error(400, "Member identifier is not specified");

View File

@ -28,6 +28,12 @@ td_api::object_ptr<td_api::MessageSender> get_message_sender_object(Td *td, User
td_api::object_ptr<td_api::MessageSender> get_message_sender_object(Td *td, DialogId dialog_id, const char *source);
vector<DialogId> get_message_sender_dialog_ids(Td *td,
const vector<telegram_api::object_ptr<telegram_api::Peer>> &peers);
td_api::object_ptr<td_api::messageSenders> convert_message_senders_object(
Td *td, const vector<telegram_api::object_ptr<telegram_api::Peer>> &peers);
Result<DialogId> get_message_sender_dialog_id(const td_api::object_ptr<td_api::MessageSender> &message_sender_id);
} // namespace td

View File

@ -16872,27 +16872,10 @@ void MessagesManager::on_get_blocked_dialogs(int32 offset, int32 limit, int32 to
Promise<td_api::object_ptr<td_api::messageSenders>> &&promise) {
LOG(INFO) << "Receive " << blocked_peers.size() << " blocked chats from offset " << offset << " out of "
<< total_count;
vector<DialogId> dialog_ids;
for (auto &blocked_peer : blocked_peers) {
CHECK(blocked_peer != nullptr);
DialogId dialog_id(blocked_peer->peer_id_);
if (dialog_id.get_type() == DialogType::User) {
if (td_->contacts_manager_->have_user(dialog_id.get_user_id())) {
dialog_ids.push_back(dialog_id);
} else {
LOG(ERROR) << "Have no info about " << dialog_id.get_user_id();
}
} else {
if (have_dialog_info(dialog_id)) {
force_create_dialog(dialog_id, "on_get_blocked_dialogs");
if (have_dialog(dialog_id)) {
dialog_ids.push_back(dialog_id);
}
} else {
LOG(ERROR) << "Have no info about " << dialog_id;
}
}
}
auto peers = transform(std::move(blocked_peers), [](tl_object_ptr<telegram_api::peerBlocked> &&blocked_peer) {
return std::move(blocked_peer->peer_id_);
});
auto dialog_ids = get_message_sender_dialog_ids(td_, std::move(peers));
if (!dialog_ids.empty() && offset + dialog_ids.size() > static_cast<size_t>(total_count)) {
LOG(ERROR) << "Fix total count of blocked chats from " << total_count << " to " << offset + dialog_ids.size();
total_count = offset + narrow_cast<int32>(dialog_ids.size());