Move limit increase to OrderedMessages::get_history.

This commit is contained in:
levlam 2023-05-05 16:31:33 +03:00
parent aef0cfe4bc
commit 47b225c11f
2 changed files with 10 additions and 12 deletions

View File

@ -21003,12 +21003,6 @@ tl_object_ptr<td_api::messages> MessagesManager::get_dialog_history(DialogId dia
<< " tries left, have_full_history = " << d->have_full_history
<< ", have_full_history_source = " << d->have_full_history_source;
bool is_limit_increased = false;
if (limit == -offset) {
limit++;
is_limit_increased = true;
}
auto message_ids =
d->ordered_messages.get_history(d->last_message_id, from_message_id, offset, limit, left_tries == 0);
if (!message_ids.empty()) {
@ -21024,12 +21018,6 @@ tl_object_ptr<td_api::messages> MessagesManager::get_dialog_history(DialogId dia
return nullptr;
}
LOG(INFO) << "Have " << message_ids.size() << " messages out of requested "
<< (is_limit_increased ? "increased " : "exact ") << limit;
if (is_limit_increased && static_cast<size_t>(limit) == message_ids.size()) {
message_ids.pop_back();
}
LOG(INFO) << "Return " << message_ids << " in result to getChatHistory";
promise.set_value(Unit()); // can return some messages
return get_messages_object(-1, dialog_id, message_ids, true,

View File

@ -336,6 +336,12 @@ void OrderedMessages::traverse_messages(const std::function<bool(MessageId)> &ne
vector<MessageId> OrderedMessages::get_history(MessageId last_message_id, MessageId &from_message_id, int32 &offset,
int32 &limit, bool force) const {
CHECK(limit > 0);
bool is_limit_increased = false;
if (limit == -offset) {
limit++;
is_limit_increased = true;
}
CHECK(-limit < offset && offset <= 0);
auto it = get_const_iterator(from_message_id);
@ -422,6 +428,10 @@ vector<MessageId> OrderedMessages::get_history(MessageId last_message_id, Messag
if (from_the_end) {
from_message_id = MessageId();
}
if (is_limit_increased && static_cast<size_t>(limit) == message_ids.size()) {
message_ids.pop_back();
}
return message_ids;
}