Add OrderedMessages::find_messages_by_date.
This commit is contained in:
parent
961c9802af
commit
f92d108319
@ -11823,8 +11823,7 @@ void MessagesManager::delete_dialog_messages_by_date(DialogId dialog_id, int32 m
|
||||
|
||||
// TODO delete in database by dates
|
||||
|
||||
vector<MessageId> message_ids;
|
||||
find_messages_by_date(d, d->ordered_messages.messages_.get(), min_date, max_date, message_ids);
|
||||
auto message_ids = d->ordered_messages.find_messages_by_date(min_date, max_date, get_get_message_date(d));
|
||||
|
||||
delete_dialog_messages(d, message_ids, false, DELETE_MESSAGE_USER_REQUEST_SOURCE);
|
||||
|
||||
@ -22867,6 +22866,14 @@ void MessagesManager::on_get_affected_history(DialogId dialog_id, AffectedHistor
|
||||
}
|
||||
}
|
||||
|
||||
std::function<int32(MessageId)> MessagesManager::get_get_message_date(const Dialog *d) const {
|
||||
return [this, d](MessageId message_id) {
|
||||
auto *m = get_message(d, message_id);
|
||||
CHECK(m != nullptr);
|
||||
return m->date;
|
||||
};
|
||||
}
|
||||
|
||||
MessageId MessagesManager::find_message_by_date(const Dialog *d, const OrderedMessage *ordered_message, int32 date) {
|
||||
if (ordered_message == nullptr) {
|
||||
return MessageId();
|
||||
@ -22886,25 +22893,6 @@ MessageId MessagesManager::find_message_by_date(const Dialog *d, const OrderedMe
|
||||
return ordered_message->message_id;
|
||||
}
|
||||
|
||||
void MessagesManager::find_messages_by_date(const Dialog *d, const OrderedMessage *ordered_message, int32 min_date,
|
||||
int32 max_date, vector<MessageId> &message_ids) {
|
||||
if (ordered_message == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Message *m = get_message(d, ordered_message->message_id);
|
||||
CHECK(m != nullptr);
|
||||
if (m->date >= min_date) {
|
||||
find_messages_by_date(d, ordered_message->left.get(), min_date, max_date, message_ids);
|
||||
if (m->date <= max_date) {
|
||||
message_ids.push_back(m->message_id);
|
||||
}
|
||||
}
|
||||
if (m->date <= max_date) {
|
||||
find_messages_by_date(d, ordered_message->right.get(), min_date, max_date, message_ids);
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesManager::on_get_dialog_message_by_date_from_database(DialogId dialog_id, int32 date, int64 random_id,
|
||||
Result<MessageDbDialogMessage> result,
|
||||
Promise<Unit> promise) {
|
||||
|
@ -2180,10 +2180,9 @@ class MessagesManager final : public Actor {
|
||||
|
||||
static vector<MessageId> find_dialog_messages(const Dialog *d, const std::function<bool(const Message *)> &condition);
|
||||
|
||||
static MessageId find_message_by_date(const Dialog *d, const OrderedMessage *ordered_message, int32 date);
|
||||
std::function<int32(MessageId)> get_get_message_date(const Dialog *d) const;
|
||||
|
||||
static void find_messages_by_date(const Dialog *d, const OrderedMessage *ordered_message, int32 min_date,
|
||||
int32 max_date, vector<MessageId> &message_ids);
|
||||
static MessageId find_message_by_date(const Dialog *d, const OrderedMessage *ordered_message, int32 date);
|
||||
|
||||
void find_unloadable_messages(const Dialog *d, int32 unload_before_date, const OrderedMessage *ordered_message,
|
||||
vector<MessageId> &message_ids, bool &has_left_to_unload_messages) const;
|
||||
|
@ -119,4 +119,28 @@ vector<MessageId> OrderedMessages::find_newer_messages(MessageId min_message_id)
|
||||
return message_ids;
|
||||
}
|
||||
|
||||
void do_find_messages_by_date(const OrderedMessage *ordered_message, int32 min_date, int32 max_date,
|
||||
const std::function<int32(MessageId)> &get_date, vector<MessageId> &message_ids) {
|
||||
if (ordered_message == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto date = get_date(ordered_message->message_id);
|
||||
if (date >= min_date) {
|
||||
do_find_messages_by_date(ordered_message->left.get(), min_date, max_date, get_date, message_ids);
|
||||
if (date <= max_date) {
|
||||
message_ids.push_back(ordered_message->message_id);
|
||||
}
|
||||
}
|
||||
if (date <= max_date) {
|
||||
do_find_messages_by_date(ordered_message->right.get(), min_date, max_date, get_date, message_ids);
|
||||
}
|
||||
}
|
||||
|
||||
vector<MessageId> OrderedMessages::find_messages_by_date(int32 min_date, int32 max_date,
|
||||
const std::function<int32(MessageId)> &get_date) const {
|
||||
vector<MessageId> message_ids;
|
||||
do_find_messages_by_date(messages_.get(), min_date, max_date, get_date, message_ids);
|
||||
return message_ids;
|
||||
}
|
||||
} // namespace td
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include "td/utils/common.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace td {
|
||||
|
||||
struct OrderedMessage {
|
||||
@ -34,6 +36,9 @@ struct OrderedMessages {
|
||||
vector<MessageId> find_older_messages(MessageId max_message_id) const;
|
||||
|
||||
vector<MessageId> find_newer_messages(MessageId min_message_id) const;
|
||||
|
||||
vector<MessageId> find_messages_by_date(int32 min_date, int32 max_date,
|
||||
const std::function<int32(MessageId)> &get_date) const;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
Loading…
Reference in New Issue
Block a user