Fix MessagesManager::get_next_yet_unsent_scheduled_message_id.

GitOrigin-RevId: 2a3a76652e809d46b5395f8cfd505ae625e30459
This commit is contained in:
levlam 2020-02-29 20:36:49 +03:00
parent e0f27dd9c0
commit 0a5d563a2f
2 changed files with 19 additions and 11 deletions

View File

@ -17823,7 +17823,7 @@ MessagesManager::Message *MessagesManager::get_message_to_send(
bool need_update = false; bool need_update = false;
CHECK(have_input_peer(dialog_id, AccessRights::Read)); CHECK(have_input_peer(dialog_id, AccessRights::Read));
auto result = add_message_to_dialog(d, std::move(m), true, &need_update, need_update_dialog_pos, "send message"); auto result = add_message_to_dialog(d, std::move(m), true, &need_update, need_update_dialog_pos, "send message");
CHECK(result != nullptr); LOG_CHECK(result != nullptr) << message_id << " " << debug_add_message_to_dialog_fail_reason_;
send_update_chat_has_scheduled_messages(d, false); send_update_chat_has_scheduled_messages(d, false);
return result; return result;
} }
@ -23391,18 +23391,23 @@ MessageId MessagesManager::get_next_local_message_id(Dialog *d) {
return get_next_message_id(d, MessageType::Local); return get_next_message_id(d, MessageType::Local);
} }
MessageId MessagesManager::get_next_yet_unsent_scheduled_message_id(const Dialog *d, int32 date) { MessageId MessagesManager::get_next_yet_unsent_scheduled_message_id(Dialog *d, int32 date) {
CHECK(date > 0); CHECK(date > 0);
MessageId message_id(ScheduledServerMessageId(1), date);
auto it = MessagesConstIterator(d, MessageId(ScheduledServerMessageId(), date + 1, true)); auto it = MessagesConstIterator(d, MessageId(ScheduledServerMessageId(), date + 1, true));
int32 prev_date = 0; if (*it != nullptr && (*it)->message_id > message_id) {
if (*it != nullptr) { message_id = (*it)->message_id;
prev_date = (*it)->message_id.get_scheduled_message_date();
} }
if (prev_date < date) {
return MessageId(ScheduledServerMessageId(1), date).get_next_message_id(MessageType::YetUnsent); auto &last_assigned_message_id = d->last_assigned_scheduled_message_id[date];
if (last_assigned_message_id != MessageId() && last_assigned_message_id > message_id) {
message_id = last_assigned_message_id;
} }
CHECK(*it != nullptr);
return (*it)->message_id.get_next_message_id(MessageType::YetUnsent); last_assigned_message_id = message_id.get_next_message_id(MessageType::YetUnsent);
return last_assigned_message_id;
} }
void MessagesManager::fail_send_message(FullMessageId full_message_id, int error_code, const string &error_message) { void MessagesManager::fail_send_message(FullMessageId full_message_id, int error_code, const string &error_message) {
@ -23703,7 +23708,8 @@ void MessagesManager::repair_dialog_scheduled_messages(Dialog *d) {
// TODO create logevent // TODO create logevent
auto dialog_id = d->dialog_id; auto dialog_id = d->dialog_id;
LOG(INFO) << "Repair scheduled messages in " << dialog_id; LOG(INFO) << "Repair scheduled messages in " << dialog_id << " with generation "
<< d->last_repair_scheduled_messages_generation;
get_dialog_scheduled_messages(dialog_id, false, true, get_dialog_scheduled_messages(dialog_id, false, true,
PromiseCreator::lambda([actor_id = actor_id(this), dialog_id](Unit) { PromiseCreator::lambda([actor_id = actor_id(this), dialog_id](Unit) {
send_closure(G()->messages_manager(), &MessagesManager::get_dialog_scheduled_messages, send_closure(G()->messages_manager(), &MessagesManager::get_dialog_scheduled_messages,

View File

@ -1135,6 +1135,8 @@ class MessagesManager : public Actor {
std::unordered_map<MessageId, MessageId, MessageIdHash> yet_unsent_message_id_to_persistent_message_id; std::unordered_map<MessageId, MessageId, MessageIdHash> yet_unsent_message_id_to_persistent_message_id;
std::unordered_map<int32, MessageId> last_assigned_scheduled_message_id; // date -> message_id
std::unordered_set<MessageId, MessageIdHash> deleted_message_ids; std::unordered_set<MessageId, MessageIdHash> deleted_message_ids;
std::unordered_set<ScheduledServerMessageId, ScheduledServerMessageIdHash> deleted_scheduled_server_message_ids; std::unordered_set<ScheduledServerMessageId, ScheduledServerMessageIdHash> deleted_scheduled_server_message_ids;
@ -2389,7 +2391,7 @@ class MessagesManager : public Actor {
static MessageId get_next_yet_unsent_message_id(Dialog *d); static MessageId get_next_yet_unsent_message_id(Dialog *d);
static MessageId get_next_yet_unsent_scheduled_message_id(const Dialog *d, int32 date); static MessageId get_next_yet_unsent_scheduled_message_id(Dialog *d, int32 date);
bool add_recently_found_dialog_internal(DialogId dialog_id); bool add_recently_found_dialog_internal(DialogId dialog_id);