Add persisitent has_scheduled_database_messages. Now Message.has_scheduled_messages should be always correct.
GitOrigin-RevId: 8fd4e1feceeae1f96599250410745069ff42b3a1
This commit is contained in:
parent
6b6d9e509b
commit
f098a71926
@ -4307,6 +4307,7 @@ void MessagesManager::Dialog::store(StorerT &storer) const {
|
|||||||
STORE_FLAG(can_share_phone_number);
|
STORE_FLAG(can_share_phone_number);
|
||||||
STORE_FLAG(can_report_location);
|
STORE_FLAG(can_report_location);
|
||||||
STORE_FLAG(has_scheduled_server_messages);
|
STORE_FLAG(has_scheduled_server_messages);
|
||||||
|
STORE_FLAG(has_scheduled_database_messages);
|
||||||
END_STORE_FLAGS();
|
END_STORE_FLAGS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4466,6 +4467,7 @@ void MessagesManager::Dialog::parse(ParserT &parser) {
|
|||||||
PARSE_FLAG(can_share_phone_number);
|
PARSE_FLAG(can_share_phone_number);
|
||||||
PARSE_FLAG(can_report_location);
|
PARSE_FLAG(can_report_location);
|
||||||
PARSE_FLAG(has_scheduled_server_messages);
|
PARSE_FLAG(has_scheduled_server_messages);
|
||||||
|
PARSE_FLAG(has_scheduled_database_messages);
|
||||||
END_PARSE_FLAGS();
|
END_PARSE_FLAGS();
|
||||||
} else {
|
} else {
|
||||||
is_folder_id_inited = false;
|
is_folder_id_inited = false;
|
||||||
@ -14738,6 +14740,20 @@ void MessagesManager::open_dialog(Dialog *d) {
|
|||||||
send_update_chat_online_member_count(dialog_id, info.online_member_count);
|
send_update_chat_online_member_count(dialog_id, info.online_member_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (d->has_scheduled_database_messages && !d->is_has_scheduled_database_messages_checked) {
|
||||||
|
CHECK(G()->parameters().use_message_db);
|
||||||
|
|
||||||
|
LOG(INFO) << "Send check has_scheduled_database_messages request";
|
||||||
|
d->is_has_scheduled_database_messages_checked = true;
|
||||||
|
G()->td_db()->get_messages_db_async()->get_scheduled_messages(
|
||||||
|
dialog_id, 1,
|
||||||
|
PromiseCreator::lambda([dialog_id, actor_id = actor_id(this)](std::vector<BufferSlice> messages) {
|
||||||
|
if (messages.empty()) {
|
||||||
|
send_closure(actor_id, &MessagesManager::set_dialog_has_scheduled_database_messages, dialog_id, false);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14928,7 +14944,8 @@ td_api::object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_scheduled_messages = d->has_scheduled_server_messages || d->scheduled_messages != nullptr;
|
bool has_scheduled_messages =
|
||||||
|
d->has_scheduled_server_messages || d->has_scheduled_database_messages || d->scheduled_messages != nullptr;
|
||||||
return make_tl_object<td_api::chat>(
|
return make_tl_object<td_api::chat>(
|
||||||
d->dialog_id.get(), get_chat_type_object(d->dialog_id), get_chat_list_object(d), get_dialog_title(d->dialog_id),
|
d->dialog_id.get(), get_chat_type_object(d->dialog_id), get_chat_list_object(d), get_dialog_title(d->dialog_id),
|
||||||
get_chat_photo_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)),
|
get_chat_photo_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)),
|
||||||
@ -16864,6 +16881,17 @@ vector<MessageId> MessagesManager::get_dialog_scheduled_messages(DialogId dialog
|
|||||||
MessageId(ScheduledServerMessageId(), std::numeric_limits<int32>::max(), true), message_ids);
|
MessageId(ScheduledServerMessageId(), std::numeric_limits<int32>::max(), true), message_ids);
|
||||||
std::reverse(message_ids.begin(), message_ids.end());
|
std::reverse(message_ids.begin(), message_ids.end());
|
||||||
|
|
||||||
|
if (G()->parameters().use_message_db) {
|
||||||
|
bool has_scheduled_database_messages = false;
|
||||||
|
for (auto &message_id : message_ids) {
|
||||||
|
if (!message_id.is_yet_unsent()) {
|
||||||
|
has_scheduled_database_messages = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set_dialog_has_scheduled_database_messages(d->dialog_id, has_scheduled_database_messages);
|
||||||
|
}
|
||||||
|
|
||||||
if (d->scheduled_messages_sync_generation != scheduled_messages_sync_generation_) {
|
if (d->scheduled_messages_sync_generation != scheduled_messages_sync_generation_) {
|
||||||
vector<uint32> numbers;
|
vector<uint32> numbers;
|
||||||
for (auto &message_id : message_ids) {
|
for (auto &message_id : message_ids) {
|
||||||
@ -22093,7 +22121,12 @@ void MessagesManager::send_update_chat_action_bar(const Dialog *d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::send_update_chat_has_scheduled_messages(Dialog *d) {
|
void MessagesManager::send_update_chat_has_scheduled_messages(Dialog *d) {
|
||||||
bool has_scheduled_messages = d->has_scheduled_server_messages || d->scheduled_messages != nullptr;
|
if (d->scheduled_messages == nullptr && d->has_loaded_scheduled_messages_from_database) {
|
||||||
|
set_dialog_has_scheduled_database_messages_impl(d, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool has_scheduled_messages =
|
||||||
|
d->has_scheduled_server_messages || d->has_scheduled_database_messages || d->scheduled_messages != nullptr;
|
||||||
if (has_scheduled_messages == d->last_sent_has_scheduled_messages) {
|
if (has_scheduled_messages == d->last_sent_has_scheduled_messages) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -22953,6 +22986,29 @@ void MessagesManager::set_dialog_has_scheduled_server_messages(Dialog *d, bool h
|
|||||||
send_update_chat_has_scheduled_messages(d);
|
send_update_chat_has_scheduled_messages(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MessagesManager::set_dialog_has_scheduled_database_messages(DialogId dialog_id,
|
||||||
|
bool has_scheduled_database_messages) {
|
||||||
|
return set_dialog_has_scheduled_database_messages_impl(get_dialog(dialog_id), has_scheduled_database_messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessagesManager::set_dialog_has_scheduled_database_messages_impl(Dialog *d, bool has_scheduled_database_messages) {
|
||||||
|
CHECK(d != nullptr);
|
||||||
|
if (d->has_scheduled_database_messages == has_scheduled_database_messages) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d->has_scheduled_database_messages && d->scheduled_messages != nullptr &&
|
||||||
|
!d->scheduled_messages->message_id.is_yet_unsent()) {
|
||||||
|
// to prevent race between add_message_to_database and check of has_scheduled_database_messages
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(G()->parameters().use_message_db);
|
||||||
|
|
||||||
|
d->has_scheduled_database_messages = has_scheduled_database_messages;
|
||||||
|
on_dialog_updated(d->dialog_id, "set_dialog_has_scheduled_database_messages");
|
||||||
|
}
|
||||||
|
|
||||||
void MessagesManager::on_update_dialog_folder_id(DialogId dialog_id, FolderId folder_id) {
|
void MessagesManager::on_update_dialog_folder_id(DialogId dialog_id, FolderId folder_id) {
|
||||||
auto d = get_dialog_force(dialog_id);
|
auto d = get_dialog_force(dialog_id);
|
||||||
if (d == nullptr) {
|
if (d == nullptr) {
|
||||||
@ -25872,6 +25928,7 @@ void MessagesManager::add_message_to_database(const Dialog *d, const Message *m,
|
|||||||
CHECK(m != nullptr);
|
CHECK(m != nullptr);
|
||||||
MessageId message_id = m->message_id;
|
MessageId message_id = m->message_id;
|
||||||
if (message_id.is_scheduled()) {
|
if (message_id.is_scheduled()) {
|
||||||
|
set_dialog_has_scheduled_database_messages(d->dialog_id, true);
|
||||||
G()->td_db()->get_messages_db_async()->add_scheduled_message({d->dialog_id, message_id}, log_event_store(*m),
|
G()->td_db()->get_messages_db_async()->add_scheduled_message({d->dialog_id, message_id}, log_event_store(*m),
|
||||||
Auto()); // TODO Promise
|
Auto()); // TODO Promise
|
||||||
return;
|
return;
|
||||||
|
@ -1091,6 +1091,8 @@ class MessagesManager : public Actor {
|
|||||||
bool is_marked_as_unread = false;
|
bool is_marked_as_unread = false;
|
||||||
bool last_sent_has_scheduled_messages = false;
|
bool last_sent_has_scheduled_messages = false;
|
||||||
bool has_scheduled_server_messages = false;
|
bool has_scheduled_server_messages = false;
|
||||||
|
bool has_scheduled_database_messages = false;
|
||||||
|
bool is_has_scheduled_database_messages_checked = false;
|
||||||
bool has_loaded_scheduled_messages_from_database = false;
|
bool has_loaded_scheduled_messages_from_database = false;
|
||||||
|
|
||||||
bool increment_view_counter = false;
|
bool increment_view_counter = false;
|
||||||
@ -1931,6 +1933,10 @@ class MessagesManager : public Actor {
|
|||||||
|
|
||||||
void set_dialog_has_scheduled_server_messages(Dialog *d, bool has_scheduled_server_messages);
|
void set_dialog_has_scheduled_server_messages(Dialog *d, bool has_scheduled_server_messages);
|
||||||
|
|
||||||
|
void set_dialog_has_scheduled_database_messages(DialogId dialog_id, bool has_scheduled_database_messages);
|
||||||
|
|
||||||
|
void set_dialog_has_scheduled_database_messages_impl(Dialog *d, bool has_scheduled_database_messages);
|
||||||
|
|
||||||
void set_dialog_folder_id(Dialog *d, FolderId folder_id);
|
void set_dialog_folder_id(Dialog *d, FolderId folder_id);
|
||||||
|
|
||||||
void toggle_dialog_is_pinned_on_server(DialogId dialog_id, bool is_pinned, uint64 logevent_id);
|
void toggle_dialog_is_pinned_on_server(DialogId dialog_id, bool is_pinned, uint64 logevent_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user