Remove null messages from search-like request responses.
This commit is contained in:
parent
fdf5b73db3
commit
f11877f6ed
@ -19911,7 +19911,7 @@ tl_object_ptr<td_api::messages> MessagesManager::get_dialog_history(DialogId dia
|
||||
|
||||
LOG(INFO) << "Return " << messages.size() << " messages in result to getChatHistory";
|
||||
promise.set_value(Unit()); // can return some messages
|
||||
return get_messages_object(-1, std::move(messages)); // TODO return real total_count of messages in the dialog
|
||||
return get_messages_object(-1, std::move(messages), false); // TODO return real total_count of messages in the dialog
|
||||
}
|
||||
|
||||
class MessagesManager::ReadHistoryOnServerLogEvent {
|
||||
@ -22268,26 +22268,36 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::messages> MessagesManager::get_messages_object(int32 total_count, DialogId dialog_id,
|
||||
const vector<MessageId> &message_ids) {
|
||||
const vector<MessageId> &message_ids,
|
||||
bool skip_not_found) {
|
||||
Dialog *d = get_dialog(dialog_id);
|
||||
CHECK(d != nullptr);
|
||||
return get_messages_object(total_count, transform(message_ids, [this, dialog_id, d](MessageId message_id) {
|
||||
return get_message_object(dialog_id,
|
||||
get_message_force(d, message_id, "get_messages_object"));
|
||||
}));
|
||||
auto message_objects = transform(message_ids, [this, dialog_id, d](MessageId message_id) {
|
||||
return get_message_object(dialog_id, get_message_force(d, message_id, "get_messages_object"));
|
||||
});
|
||||
return get_messages_object(total_count, std::move(message_objects), skip_not_found);
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::messages> MessagesManager::get_messages_object(int32 total_count,
|
||||
const vector<FullMessageId> &full_message_ids) {
|
||||
return get_messages_object(total_count, transform(full_message_ids, [this](FullMessageId full_message_id) {
|
||||
return get_message_object(full_message_id);
|
||||
}));
|
||||
const vector<FullMessageId> &full_message_ids,
|
||||
bool skip_not_found) {
|
||||
auto message_objects = transform(
|
||||
full_message_ids, [this](FullMessageId full_message_id) { return get_message_object(full_message_id); });
|
||||
return get_messages_object(total_count, std::move(message_objects), skip_not_found);
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::messages> MessagesManager::get_messages_object(
|
||||
int32 total_count, vector<tl_object_ptr<td_api::message>> &&messages) {
|
||||
if (total_count == -1) {
|
||||
total_count = narrow_cast<int32>(messages.size());
|
||||
tl_object_ptr<td_api::messages> MessagesManager::get_messages_object(int32 total_count,
|
||||
vector<tl_object_ptr<td_api::message>> &&messages,
|
||||
bool skip_not_found) {
|
||||
auto message_count = narrow_cast<int32>(messages.size());
|
||||
if (total_count < message_count) {
|
||||
if (total_count != -1) {
|
||||
LOG(ERROR) << "Have wrong total_count = " << total_count << ", while having " << message_count << " messages";
|
||||
}
|
||||
total_count = message_count;
|
||||
}
|
||||
if (skip_not_found && td::remove(messages, nullptr)) {
|
||||
total_count -= message_count - static_cast<int32>(messages.size());
|
||||
}
|
||||
return td_api::make_object<td_api::messages>(total_count, std::move(messages));
|
||||
}
|
||||
|
@ -787,9 +787,10 @@ class MessagesManager : public Actor {
|
||||
tl_object_ptr<td_api::message> get_message_object(FullMessageId full_message_id);
|
||||
|
||||
tl_object_ptr<td_api::messages> get_messages_object(int32 total_count, DialogId dialog_id,
|
||||
const vector<MessageId> &message_ids);
|
||||
const vector<MessageId> &message_ids, bool skip_not_found);
|
||||
|
||||
tl_object_ptr<td_api::messages> get_messages_object(int32 total_count, const vector<FullMessageId> &full_message_ids);
|
||||
tl_object_ptr<td_api::messages> get_messages_object(int32 total_count, const vector<FullMessageId> &full_message_ids,
|
||||
bool skip_not_found);
|
||||
|
||||
void add_pending_update(tl_object_ptr<telegram_api::Update> &&update, int32 new_pts, int32 pts_count,
|
||||
bool force_apply, const char *source);
|
||||
@ -2282,7 +2283,8 @@ class MessagesManager : public Actor {
|
||||
bool for_event_log = false) const;
|
||||
|
||||
static tl_object_ptr<td_api::messages> get_messages_object(int32 total_count,
|
||||
vector<tl_object_ptr<td_api::message>> &&messages);
|
||||
vector<tl_object_ptr<td_api::message>> &&messages,
|
||||
bool skip_not_found);
|
||||
|
||||
vector<DialogId> sort_dialogs_by_order(const vector<DialogId> &dialog_ids, int32 limit) const;
|
||||
|
||||
|
@ -1135,7 +1135,7 @@ class GetMessagesRequest : public RequestOnceActor {
|
||||
}
|
||||
|
||||
void do_send_result() override {
|
||||
send_result(td->messages_manager_->get_messages_object(-1, dialog_id_, message_ids_));
|
||||
send_result(td->messages_manager_->get_messages_object(-1, dialog_id_, message_ids_, false));
|
||||
}
|
||||
|
||||
public:
|
||||
@ -1446,7 +1446,7 @@ class GetMessageThreadHistoryRequest : public RequestActor<> {
|
||||
}
|
||||
|
||||
void do_send_result() override {
|
||||
send_result(td->messages_manager_->get_messages_object(-1, messages_.first, messages_.second));
|
||||
send_result(td->messages_manager_->get_messages_object(-1, messages_.first, messages_.second, true));
|
||||
}
|
||||
|
||||
public:
|
||||
@ -1483,7 +1483,7 @@ class SearchChatMessagesRequest : public RequestActor<> {
|
||||
}
|
||||
|
||||
void do_send_result() override {
|
||||
send_result(td->messages_manager_->get_messages_object(messages_.first, dialog_id_, messages_.second));
|
||||
send_result(td->messages_manager_->get_messages_object(messages_.first, dialog_id_, messages_.second, true));
|
||||
}
|
||||
|
||||
void do_send_error(Status &&status) override {
|
||||
@ -1567,7 +1567,7 @@ class SearchMessagesRequest : public RequestActor<> {
|
||||
}
|
||||
|
||||
void do_send_result() override {
|
||||
send_result(td->messages_manager_->get_messages_object(messages_.first, messages_.second));
|
||||
send_result(td->messages_manager_->get_messages_object(messages_.first, messages_.second, true));
|
||||
}
|
||||
|
||||
void do_send_error(Status &&status) override {
|
||||
@ -1612,7 +1612,7 @@ class SearchCallMessagesRequest : public RequestActor<> {
|
||||
}
|
||||
|
||||
void do_send_result() override {
|
||||
send_result(td->messages_manager_->get_messages_object(messages_.first, messages_.second));
|
||||
send_result(td->messages_manager_->get_messages_object(messages_.first, messages_.second, true));
|
||||
}
|
||||
|
||||
public:
|
||||
@ -1639,7 +1639,7 @@ class SearchChatRecentLocationMessagesRequest : public RequestActor<> {
|
||||
}
|
||||
|
||||
void do_send_result() override {
|
||||
send_result(td->messages_manager_->get_messages_object(messages_.first, dialog_id_, messages_.second));
|
||||
send_result(td->messages_manager_->get_messages_object(messages_.first, dialog_id_, messages_.second, true));
|
||||
}
|
||||
|
||||
public:
|
||||
@ -1656,7 +1656,7 @@ class GetActiveLiveLocationMessagesRequest : public RequestActor<> {
|
||||
}
|
||||
|
||||
void do_send_result() override {
|
||||
send_result(td->messages_manager_->get_messages_object(-1, full_message_ids_));
|
||||
send_result(td->messages_manager_->get_messages_object(-1, full_message_ids_, true));
|
||||
}
|
||||
|
||||
public:
|
||||
@ -1724,7 +1724,7 @@ class GetChatScheduledMessagesRequest : public RequestActor<> {
|
||||
}
|
||||
|
||||
void do_send_result() override {
|
||||
send_result(td->messages_manager_->get_messages_object(-1, dialog_id_, message_ids_));
|
||||
send_result(td->messages_manager_->get_messages_object(-1, dialog_id_, message_ids_, true));
|
||||
}
|
||||
|
||||
public:
|
||||
@ -5690,7 +5690,7 @@ void Td::on_request(uint64 id, td_api::sendMessageAlbum &request) {
|
||||
}
|
||||
|
||||
send_closure(actor_id(this), &Td::send_result, id,
|
||||
messages_manager_->get_messages_object(-1, dialog_id, r_message_ids.ok()));
|
||||
messages_manager_->get_messages_object(-1, dialog_id, r_message_ids.ok(), false));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::sendBotStartMessage &request) {
|
||||
@ -5887,7 +5887,7 @@ void Td::on_request(uint64 id, td_api::forwardMessages &request) {
|
||||
}
|
||||
|
||||
send_closure(actor_id(this), &Td::send_result, id,
|
||||
messages_manager_->get_messages_object(-1, dialog_id, r_message_ids.ok()));
|
||||
messages_manager_->get_messages_object(-1, dialog_id, r_message_ids.ok(), false));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::resendMessages &request) {
|
||||
@ -5899,7 +5899,7 @@ void Td::on_request(uint64 id, const td_api::resendMessages &request) {
|
||||
}
|
||||
|
||||
send_closure(actor_id(this), &Td::send_result, id,
|
||||
messages_manager_->get_messages_object(-1, dialog_id, r_message_ids.ok()));
|
||||
messages_manager_->get_messages_object(-1, dialog_id, r_message_ids.ok(), false));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getWebPagePreview &request) {
|
||||
|
Loading…
Reference in New Issue
Block a user