diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 2d3ab41f4..19381287d 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -3658,7 +3658,7 @@ class SendMultiMediaQuery final : public Td::ResultHandler { is_result_wrong = true; } for (auto &sent_message : sent_messages) { - if (MessagesManager::get_message_dialog_id(*sent_message) != dialog_id_) { + if (MessagesManager::get_message_dialog_id(sent_message.first) != dialog_id_) { is_result_wrong = true; } } @@ -4155,7 +4155,7 @@ class ForwardMessagesQuery final : public Td::ResultHandler { is_result_wrong = true; } for (auto &sent_message : sent_messages) { - if (MessagesManager::get_message_dialog_id(*sent_message) != to_dialog_id_) { + if (MessagesManager::get_message_dialog_id(sent_message.first) != to_dialog_id_) { is_result_wrong = true; } } @@ -13254,19 +13254,19 @@ MessageId MessagesManager::get_message_id(const tl_object_ptr &message_ptr) { +DialogId MessagesManager::get_message_dialog_id(const telegram_api::Message *message_ptr) { CHECK(message_ptr != nullptr); switch (message_ptr->get_id()) { case telegram_api::messageEmpty::ID: { - auto message = static_cast(message_ptr.get()); + auto message = static_cast(message_ptr); return message->peer_id_ == nullptr ? DialogId() : DialogId(message->peer_id_); } case telegram_api::message::ID: { - auto message = static_cast(message_ptr.get()); + auto message = static_cast(message_ptr); return DialogId(message->peer_id_); } case telegram_api::messageService::ID: { - auto message = static_cast(message_ptr.get()); + auto message = static_cast(message_ptr); return DialogId(message->peer_id_); } default: @@ -13275,6 +13275,10 @@ DialogId MessagesManager::get_message_dialog_id(const tl_object_ptr &message_ptr) { + return get_message_dialog_id(message_ptr.get()); +} + FullMessageId MessagesManager::get_full_message_id(const tl_object_ptr &message_ptr, bool is_scheduled) { return {get_message_dialog_id(message_ptr), get_message_id(message_ptr, is_scheduled)}; @@ -31970,8 +31974,8 @@ void MessagesManager::check_send_message_result(int64 random_id, DialogId dialog }; if (sent_messages.size() != 1u || sent_messages_random_ids.size() != 1u || - *sent_messages_random_ids.begin() != random_id || get_message_dialog_id(*sent_messages[0]) != dialog_id || - is_invalid_poll_message(sent_messages[0]->get())) { + *sent_messages_random_ids.begin() != random_id || get_message_dialog_id(sent_messages[0].first) != dialog_id || + is_invalid_poll_message(sent_messages[0].first)) { LOG(ERROR) << "Receive wrong result for sending message with random_id " << random_id << " from " << source << " to " << dialog_id << ": " << oneline(to_string(*updates_ptr)); Dialog *d = get_dialog(dialog_id); @@ -33398,19 +33402,23 @@ void MessagesManager::on_create_new_dialog_success(int64 random_id, tl_object_pt return on_create_new_dialog_fail(random_id, Status::Error(500, "Unsupported server response"), std::move(promise)); } - auto message = *sent_messages.begin(); + auto *message = sent_messages.begin()->first; // int64 message_random_id = *sent_messages_random_ids.begin(); // TODO check that message_random_id equals random_id after messages_createChat will be updated - auto dialog_id = get_message_dialog_id(*message); + if (sent_messages.begin()->second) { + return on_create_new_dialog_fail(random_id, Status::Error(500, "Scheduled message received"), std::move(promise)); + } + + auto dialog_id = get_message_dialog_id(message); if (dialog_id.get_type() != expected_type) { return on_create_new_dialog_fail(random_id, Status::Error(500, "Chat of wrong type has been created"), std::move(promise)); } - if ((*message)->get_id() != telegram_api::messageService::ID) { + if (message->get_id() != telegram_api::messageService::ID) { return on_create_new_dialog_fail(random_id, Status::Error(500, "Invalid message received"), std::move(promise)); } - auto action_id = static_cast((*message).get())->action_->get_id(); + auto action_id = static_cast(message)->action_->get_id(); if (action_id != telegram_api::messageActionChatCreate::ID && action_id != telegram_api::messageActionChannelCreate::ID) { return on_create_new_dialog_fail(random_id, Status::Error(500, "Invalid service message received"), diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 56baa6370..bea734ba0 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -167,6 +167,8 @@ class MessagesManager final : public Actor { static MessageId get_message_id(const tl_object_ptr &message_ptr, bool is_scheduled); + static DialogId get_message_dialog_id(const telegram_api::Message *message_ptr); + static DialogId get_message_dialog_id(const tl_object_ptr &message_ptr); static FullMessageId get_full_message_id(const tl_object_ptr &message_ptr, bool is_scheduled); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 60fc8bef1..39745d32a 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1151,10 +1151,10 @@ FlatHashSet UpdatesManager::get_sent_messages_random_ids(const telegram_a if (update->get_id() == telegram_api::updateMessageID::ID) { int64 random_id = static_cast(update.get())->random_id_; if (random_id != 0) { - bool found_message = false; - for (auto *message : new_messages) { - // TODO - } + bool found_message = true; + // for (auto *message : new_messages) { + // TODO + // } if (found_message && !random_ids.insert(random_id).second) { LOG(ERROR) << "Receive twice updateMessageID for " << random_id; } @@ -1216,24 +1216,26 @@ bool UpdatesManager::is_additional_service_message(const telegram_api::Message * return action_id == telegram_api::messageActionSetMessagesTTL::ID; } -vector *> UpdatesManager::get_new_messages( +vector> UpdatesManager::get_new_messages( const telegram_api::Updates *updates_ptr) { - vector *> messages; + vector> messages; auto updates = get_updates(updates_ptr); if (updates != nullptr) { for (auto &update : *updates) { - const tl_object_ptr *message = nullptr; + const telegram_api::Message *message = nullptr; + bool is_scheduled = false; auto constructor_id = update->get_id(); if (constructor_id == telegram_api::updateNewMessage::ID) { - message = &static_cast(update.get())->message_; + message = static_cast(update.get())->message_.get(); } else if (constructor_id == telegram_api::updateNewChannelMessage::ID) { - message = &static_cast(update.get())->message_; + message = static_cast(update.get())->message_.get(); } else if (constructor_id == telegram_api::updateNewScheduledMessage::ID) { - message = &static_cast(update.get())->message_; + message = static_cast(update.get())->message_.get(); + is_scheduled = true; } - if (is_additional_service_message((*message).get())) { - messages.push_back(message); + if (is_additional_service_message(message)) { + messages.emplace_back(message, is_scheduled); } } } diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index b0a442aa3..8a580886a 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -31,6 +31,7 @@ #include #include +#include namespace td { @@ -107,7 +108,8 @@ class UpdatesManager final : public Actor { static const telegram_api::Message *get_message_by_random_id(const telegram_api::Updates *updates_ptr, DialogId dialog_id, int64 random_id); - static vector *> get_new_messages( + // [Message, is_scheduled] + static vector> get_new_messages( const telegram_api::Updates *updates_ptr); static vector get_update_new_group_call_ids(const telegram_api::Updates *updates_ptr);