diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 1554dec22..a1c5da614 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -11625,21 +11625,6 @@ vector MessagesManager::find_dialog_messages(const Dialog *d, return message_ids; } -void MessagesManager::find_old_messages(const OrderedMessage *ordered_message, MessageId max_message_id, - vector &message_ids) { - if (ordered_message == nullptr) { - return; - } - - find_old_messages(ordered_message->left.get(), max_message_id, message_ids); - - if (ordered_message->message_id <= max_message_id) { - message_ids.push_back(ordered_message->message_id); - - find_old_messages(ordered_message->right.get(), max_message_id, message_ids); - } -} - void MessagesManager::find_newer_messages(const OrderedMessage *ordered_message, MessageId min_message_id, vector &message_ids) { if (ordered_message == nullptr) { @@ -13072,8 +13057,7 @@ void MessagesManager::set_dialog_max_unavailable_message_id(DialogId dialog_id, d->max_unavailable_message_id = max_unavailable_message_id; - vector message_ids; - find_old_messages(d->ordered_messages.messages_.get(), max_unavailable_message_id, message_ids); + auto message_ids = d->ordered_messages.find_older_messages(max_unavailable_message_id); vector deleted_message_ids; bool need_update_dialog_pos = false; diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index d9c53712f..8603e212d 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2185,9 +2185,6 @@ class MessagesManager final : public Actor { static void find_messages_by_date(const Dialog *d, const OrderedMessage *ordered_message, int32 min_date, int32 max_date, vector &message_ids); - static void find_old_messages(const OrderedMessage *ordered_message, MessageId max_message_id, - vector &message_ids); - static void find_newer_messages(const OrderedMessage *ordered_message, MessageId min_message_id, vector &message_ids); diff --git a/td/telegram/OrderedMessage.cpp b/td/telegram/OrderedMessage.cpp index 038b264e9..55989087f 100644 --- a/td/telegram/OrderedMessage.cpp +++ b/td/telegram/OrderedMessage.cpp @@ -77,4 +77,25 @@ void OrderedMessages::erase(MessageId message_id) { CHECK(*v == nullptr); } +static void do_find_older_messages(const OrderedMessage *ordered_message, MessageId max_message_id, + vector &message_ids) { + if (ordered_message == nullptr) { + return; + } + + do_find_older_messages(ordered_message->left.get(), max_message_id, message_ids); + + if (ordered_message->message_id <= max_message_id) { + message_ids.push_back(ordered_message->message_id); + + do_find_older_messages(ordered_message->right.get(), max_message_id, message_ids); + } +} + +vector OrderedMessages::find_older_messages(MessageId max_message_id) const { + vector message_ids; + do_find_older_messages(messages_.get(), max_message_id, message_ids); + return message_ids; +} + } // namespace td diff --git a/td/telegram/OrderedMessage.h b/td/telegram/OrderedMessage.h index 35596b937..2af59cff5 100644 --- a/td/telegram/OrderedMessage.h +++ b/td/telegram/OrderedMessage.h @@ -30,6 +30,8 @@ struct OrderedMessages { OrderedMessage *insert(MessageId message_id); void erase(MessageId message_id); + + vector find_older_messages(MessageId max_message_id) const; }; } // namespace td