Simplify on_get_message_from_database usage.
This commit is contained in:
parent
314035a129
commit
813e32a265
@ -12656,9 +12656,7 @@ void MessagesManager::ttl_db_on_result(Result<std::pair<std::vector<MessagesDbMe
|
|||||||
LOG(INFO) << "Receive ttl_db query result " << tag("new expires_till", ttl_db_expires_till_)
|
LOG(INFO) << "Receive ttl_db query result " << tag("new expires_till", ttl_db_expires_till_)
|
||||||
<< tag("got messages", result.first.size());
|
<< tag("got messages", result.first.size());
|
||||||
for (auto &dialog_message : result.first) {
|
for (auto &dialog_message : result.first) {
|
||||||
on_get_message_from_database(dialog_message.dialog_id,
|
on_get_message_from_database(dialog_message, false, "ttl_db_on_result");
|
||||||
get_dialog_force(dialog_message.dialog_id, "ttl_db_on_result"), dialog_message.data,
|
|
||||||
false, "ttl_db_on_result");
|
|
||||||
}
|
}
|
||||||
ttl_db_loop(G()->server_time());
|
ttl_db_loop(G()->server_time());
|
||||||
}
|
}
|
||||||
@ -21761,7 +21759,7 @@ void MessagesManager::on_search_dialog_messages_db_result(int64 random_id, Dialo
|
|||||||
|
|
||||||
res.reserve(messages.size());
|
res.reserve(messages.size());
|
||||||
for (auto &message : messages) {
|
for (auto &message : messages) {
|
||||||
auto m = on_get_message_from_database(dialog_id, d, message, false, "on_search_dialog_messages_db_result");
|
auto m = on_get_message_from_database(d, dialog_id, message, false, "on_search_dialog_messages_db_result");
|
||||||
if (m != nullptr && first_db_message_id <= m->message_id) {
|
if (m != nullptr && first_db_message_id <= m->message_id) {
|
||||||
if (filter == MessageSearchFilter::UnreadMention && !m->contains_unread_mention) {
|
if (filter == MessageSearchFilter::UnreadMention && !m->contains_unread_mention) {
|
||||||
// skip already read by d->last_read_all_mentions_message_id mentions
|
// skip already read by d->last_read_all_mentions_message_id mentions
|
||||||
@ -21897,9 +21895,7 @@ void MessagesManager::on_messages_db_fts_result(Result<MessagesDbFtsResult> resu
|
|||||||
|
|
||||||
res.reserve(fts_result.messages.size());
|
res.reserve(fts_result.messages.size());
|
||||||
for (auto &message : fts_result.messages) {
|
for (auto &message : fts_result.messages) {
|
||||||
auto m = on_get_message_from_database(message.dialog_id,
|
auto m = on_get_message_from_database(message, false, "on_messages_db_fts_result");
|
||||||
get_dialog_force(message.dialog_id, "on_messages_db_fts_result"),
|
|
||||||
message.data, false, "on_messages_db_fts_result");
|
|
||||||
if (m != nullptr) {
|
if (m != nullptr) {
|
||||||
res.push_back(FullMessageId(message.dialog_id, m->message_id));
|
res.push_back(FullMessageId(message.dialog_id, m->message_id));
|
||||||
}
|
}
|
||||||
@ -21932,9 +21928,7 @@ void MessagesManager::on_messages_db_calls_result(Result<MessagesDbCallsResult>
|
|||||||
|
|
||||||
res.reserve(calls_result.messages.size());
|
res.reserve(calls_result.messages.size());
|
||||||
for (auto &message : calls_result.messages) {
|
for (auto &message : calls_result.messages) {
|
||||||
auto m = on_get_message_from_database(message.dialog_id,
|
auto m = on_get_message_from_database(message, false, "on_messages_db_calls_result");
|
||||||
get_dialog_force(message.dialog_id, "on_messages_db_calls_result"),
|
|
||||||
message.data, false, "on_messages_db_calls_result");
|
|
||||||
|
|
||||||
if (m != nullptr && first_db_message_id <= m->message_id) {
|
if (m != nullptr && first_db_message_id <= m->message_id) {
|
||||||
res.push_back(FullMessageId(message.dialog_id, m->message_id));
|
res.push_back(FullMessageId(message.dialog_id, m->message_id));
|
||||||
@ -22085,7 +22079,7 @@ void MessagesManager::on_get_dialog_message_by_date_from_database(DialogId dialo
|
|||||||
CHECK(d != nullptr);
|
CHECK(d != nullptr);
|
||||||
if (result.is_ok()) {
|
if (result.is_ok()) {
|
||||||
Message *m =
|
Message *m =
|
||||||
on_get_message_from_database(dialog_id, d, result.ok(), false, "on_get_dialog_message_by_date_from_database");
|
on_get_message_from_database(d, dialog_id, result.ok(), false, "on_get_dialog_message_by_date_from_database");
|
||||||
if (m != nullptr) {
|
if (m != nullptr) {
|
||||||
auto message_id = find_message_by_date(d->messages.get(), date);
|
auto message_id = find_message_by_date(d->messages.get(), date);
|
||||||
if (!message_id.is_valid()) {
|
if (!message_id.is_valid()) {
|
||||||
@ -27511,7 +27505,7 @@ vector<Notification> MessagesManager::get_message_notifications_from_database_fo
|
|||||||
<< " messages with notifications from database in " << group_info.group_id << '/'
|
<< " messages with notifications from database in " << group_info.group_id << '/'
|
||||||
<< d->dialog_id;
|
<< d->dialog_id;
|
||||||
for (auto &message : messages) {
|
for (auto &message : messages) {
|
||||||
auto m = on_get_message_from_database(d->dialog_id, d, std::move(message), false,
|
auto m = on_get_message_from_database(d, d->dialog_id, message, false,
|
||||||
"get_message_notifications_from_database_force");
|
"get_message_notifications_from_database_force");
|
||||||
if (m == nullptr) {
|
if (m == nullptr) {
|
||||||
VLOG(notifications) << "Receive from database a broken message";
|
VLOG(notifications) << "Receive from database a broken message";
|
||||||
@ -27767,8 +27761,7 @@ void MessagesManager::on_get_message_notifications_from_database(DialogId dialog
|
|||||||
VLOG(notifications) << "Loaded " << messages.size() << " messages with notifications in " << group_info.group_id
|
VLOG(notifications) << "Loaded " << messages.size() << " messages with notifications in " << group_info.group_id
|
||||||
<< '/' << dialog_id << " from database";
|
<< '/' << dialog_id << " from database";
|
||||||
for (auto &message : messages) {
|
for (auto &message : messages) {
|
||||||
auto m = on_get_message_from_database(dialog_id, d, std::move(message), false,
|
auto m = on_get_message_from_database(d, dialog_id, message, false, "on_get_message_notifications_from_database");
|
||||||
"on_get_message_notifications_from_database");
|
|
||||||
if (m == nullptr) {
|
if (m == nullptr) {
|
||||||
VLOG(notifications) << "Receive from database a broken message";
|
VLOG(notifications) << "Receive from database a broken message";
|
||||||
continue;
|
continue;
|
||||||
@ -27942,7 +27935,7 @@ void MessagesManager::do_remove_message_notification(DialogId dialog_id, bool fr
|
|||||||
Dialog *d = get_dialog(dialog_id);
|
Dialog *d = get_dialog(dialog_id);
|
||||||
CHECK(d != nullptr);
|
CHECK(d != nullptr);
|
||||||
|
|
||||||
auto m = on_get_message_from_database(dialog_id, d, std::move(result[0]), false, "do_remove_message_notification");
|
auto m = on_get_message_from_database(d, dialog_id, result[0], false, "do_remove_message_notification");
|
||||||
if (m != nullptr && m->notification_id == notification_id &&
|
if (m != nullptr && m->notification_id == notification_id &&
|
||||||
is_from_mention_notification_group(d, m) == from_mentions && is_message_notification_active(d, m)) {
|
is_from_mention_notification_group(d, m) == from_mentions && is_message_notification_active(d, m)) {
|
||||||
remove_message_notification_id(d, m, false, false);
|
remove_message_notification_id(d, m, false, false);
|
||||||
@ -32127,10 +32120,16 @@ MessagesManager::Message *MessagesManager::get_message_force(Dialog *d, MessageI
|
|||||||
if (r_value.is_error()) {
|
if (r_value.is_error()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return on_get_message_from_database(d->dialog_id, d, r_value.ok(), message_id.is_scheduled(), source);
|
return on_get_message_from_database(d, d->dialog_id, r_value.ok(), message_id.is_scheduled(), source);
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagesManager::Message *MessagesManager::on_get_message_from_database(DialogId dialog_id, Dialog *d,
|
MessagesManager::Message *MessagesManager::on_get_message_from_database(const MessagesDbMessage &message,
|
||||||
|
bool is_scheduled, const char *source) {
|
||||||
|
return on_get_message_from_database(get_dialog_force(message.dialog_id, source), message.dialog_id, message.data,
|
||||||
|
is_scheduled, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagesManager::Message *MessagesManager::on_get_message_from_database(Dialog *d, DialogId dialog_id,
|
||||||
const BufferSlice &value, bool is_scheduled,
|
const BufferSlice &value, bool is_scheduled,
|
||||||
const char *source) {
|
const char *source) {
|
||||||
if (value.empty()) {
|
if (value.empty()) {
|
||||||
@ -34063,10 +34062,9 @@ MessagesManager::Dialog *MessagesManager::get_dialog_by_message_id(MessageId mes
|
|||||||
auto r_value =
|
auto r_value =
|
||||||
G()->td_db()->get_messages_db_sync()->get_message_by_unique_message_id(message_id.get_server_message_id());
|
G()->td_db()->get_messages_db_sync()->get_message_by_unique_message_id(message_id.get_server_message_id());
|
||||||
if (r_value.is_ok()) {
|
if (r_value.is_ok()) {
|
||||||
auto dialog_id = r_value.ok().dialog_id;
|
Message *m = on_get_message_from_database(r_value.ok(), false, "get_dialog_by_message_id");
|
||||||
Message *m = on_get_message_from_database(dialog_id, get_dialog_force(dialog_id, "get_dialog_by_message_id"),
|
|
||||||
r_value.ok().data, false, "get_dialog_by_message_id");
|
|
||||||
if (m != nullptr) {
|
if (m != nullptr) {
|
||||||
|
auto dialog_id = r_value.ok().dialog_id;
|
||||||
CHECK(m->message_id == message_id);
|
CHECK(m->message_id == message_id);
|
||||||
LOG_CHECK(message_id_to_dialog_id_[message_id] == dialog_id)
|
LOG_CHECK(message_id_to_dialog_id_[message_id] == dialog_id)
|
||||||
<< message_id << ' ' << dialog_id << ' ' << message_id_to_dialog_id_[message_id] << ' '
|
<< message_id << ' ' << dialog_id << ' ' << message_id_to_dialog_id_[message_id] << ' '
|
||||||
@ -34097,7 +34095,7 @@ MessageId MessagesManager::get_message_id_by_random_id(Dialog *d, int64 random_i
|
|||||||
auto r_value = G()->td_db()->get_messages_db_sync()->get_message_by_random_id(d->dialog_id, random_id);
|
auto r_value = G()->td_db()->get_messages_db_sync()->get_message_by_random_id(d->dialog_id, random_id);
|
||||||
if (r_value.is_ok()) {
|
if (r_value.is_ok()) {
|
||||||
debug_add_message_to_dialog_fail_reason_ = "not called";
|
debug_add_message_to_dialog_fail_reason_ = "not called";
|
||||||
Message *m = on_get_message_from_database(d->dialog_id, d, r_value.ok(), false, "get_message_id_by_random_id");
|
Message *m = on_get_message_from_database(d, d->dialog_id, r_value.ok(), false, "get_message_id_by_random_id");
|
||||||
if (m != nullptr) {
|
if (m != nullptr) {
|
||||||
LOG_CHECK(m->random_id == random_id)
|
LOG_CHECK(m->random_id == random_id)
|
||||||
<< random_id << " " << m->random_id << " " << d->random_id_to_message_id[random_id] << " "
|
<< random_id << " " << m->random_id << " " << d->random_id_to_message_id[random_id] << " "
|
||||||
|
@ -2659,7 +2659,9 @@ class MessagesManager final : public Actor {
|
|||||||
void get_message_force_from_server(Dialog *d, MessageId message_id, Promise<Unit> &&promise,
|
void get_message_force_from_server(Dialog *d, MessageId message_id, Promise<Unit> &&promise,
|
||||||
tl_object_ptr<telegram_api::InputMessage> input_message = nullptr);
|
tl_object_ptr<telegram_api::InputMessage> input_message = nullptr);
|
||||||
|
|
||||||
Message *on_get_message_from_database(DialogId dialog_id, Dialog *d, const BufferSlice &value, bool is_scheduled,
|
Message *on_get_message_from_database(const MessagesDbMessage &message, bool is_scheduled, const char *source);
|
||||||
|
|
||||||
|
Message *on_get_message_from_database(Dialog *d, DialogId dialog_id, const BufferSlice &value, bool is_scheduled,
|
||||||
const char *source);
|
const char *source);
|
||||||
|
|
||||||
void get_dialog_message_by_date_from_server(const Dialog *d, int32 date, int64 random_id, bool after_database_search,
|
void get_dialog_message_by_date_from_server(const Dialog *d, int32 date, int64 random_id, bool after_database_search,
|
||||||
|
Loading…
Reference in New Issue
Block a user