diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 25d2edeb..a8267ca8 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -12398,6 +12398,11 @@ unique_ptr MessagesManager::do_delete_scheduled_messag auto result = treap_delete_message(v); + if (message_id.is_scheduled_server()) { + size_t erased = d->scheduled_message_date.erase(message_id.get_scheduled_server_message_id()); + CHECK(erased != 0); + } + cancel_send_deleted_message(d->dialog_id, result.get()); return nullptr; @@ -25426,6 +25431,12 @@ MessagesManager::Message *MessagesManager::add_scheduled_message_to_dialog(Dialo update_used_hashtags(dialog_id, m); } + if (message_id.is_scheduled_server()) { + int32 &date = d->scheduled_message_date[message_id.get_scheduled_server_message_id()]; + CHECK(date == 0); + date = m->date; + } + Message *result_message = treap_insert_message(&d->scheduled_messages, std::move(message)); CHECK(result_message != nullptr); CHECK(d->scheduled_messages != nullptr); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 4a2b44c9..e7e916e0 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1103,6 +1103,8 @@ class MessagesManager : public Actor { // application start, used to guarantee that all assigned message identifiers // are different + std::unordered_map scheduled_message_date; + std::unordered_map yet_unsent_message_id_to_persistent_message_id; std::unordered_set deleted_message_ids; diff --git a/td/telegram/ScheduledServerMessageId.h b/td/telegram/ScheduledServerMessageId.h index c9364ed4..16aa4c58 100644 --- a/td/telegram/ScheduledServerMessageId.h +++ b/td/telegram/ScheduledServerMessageId.h @@ -8,6 +8,7 @@ #include "td/utils/common.h" +#include #include namespace td { @@ -50,4 +51,10 @@ class ScheduledServerMessageId { } }; +struct ScheduledServerMessageIdHash { + std::size_t operator()(ScheduledServerMessageId message_id) const { + return std::hash()(message_id.get()); + } +}; + } // namespace td