From 9a44005187bf18f5eca8da6536e21401b3c81a78 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 25 Sep 2023 21:56:36 +0300 Subject: [PATCH] Add UpdatesManager::fix_short_message_flags. --- td/telegram/UpdatesManager.cpp | 47 ++++++++++++++-------------------- td/telegram/UpdatesManager.h | 2 ++ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 963bac01c..bdc2f4d3a 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1081,6 +1081,16 @@ bool UpdatesManager::is_acceptable_update(const telegram_api::Update *update) co return true; } +int32 UpdatesManager::fix_short_message_flags(int32 flags) { + auto disallowed_flags = MessagesManager::MESSAGE_FLAG_HAS_REPLY_MARKUP | MessagesManager::MESSAGE_FLAG_HAS_MEDIA | + MessagesManager::MESSAGE_FLAG_HAS_REACTIONS | MessagesManager::MESSAGE_FLAG_HAS_REPLY_INFO; + if ((flags & disallowed_flags) != 0) { + LOG(ERROR) << "Receive short message with flags " << flags; + flags = flags & ~disallowed_flags; + } + return flags | MessagesManager::MESSAGE_FLAG_HAS_FROM_ID; +} + void UpdatesManager::on_get_updates(tl_object_ptr &&updates_ptr, Promise &&promise) { send_closure_later(actor_id(this), &UpdatesManager::on_get_updates_impl, std::move(updates_ptr), std::move(promise)); } @@ -1132,24 +1142,14 @@ void UpdatesManager::on_get_updates_impl(tl_object_ptr up break; case telegram_api::updateShortMessage::ID: { auto update = move_tl_object_as(updates_ptr); - if (update->flags_ & MessagesManager::MESSAGE_FLAG_HAS_REPLY_MARKUP) { - LOG(ERROR) << "Receive updateShortMessage with reply_markup"; - update->flags_ ^= MessagesManager::MESSAGE_FLAG_HAS_REPLY_MARKUP; - } - if (update->flags_ & MessagesManager::MESSAGE_FLAG_HAS_MEDIA) { - LOG(ERROR) << "Receive updateShortMessage with media"; - update->flags_ ^= MessagesManager::MESSAGE_FLAG_HAS_MEDIA; - } - auto from_id = update->out_ ? td_->contacts_manager_->get_my_id().get() : update->user_id_; - update->flags_ |= MessagesManager::MESSAGE_FLAG_HAS_FROM_ID; - auto message = make_tl_object( - update->flags_, update->out_, update->mentioned_, update->media_unread_, update->silent_, false, false, false, - false, false, false, update->id_, make_tl_object(from_id), - make_tl_object(update->user_id_), std::move(update->fwd_from_), update->via_bot_id_, - std::move(update->reply_to_), update->date_, update->message_, nullptr, nullptr, std::move(update->entities_), - 0, 0, nullptr, 0, string(), 0, nullptr, Auto(), update->ttl_period_); + fix_short_message_flags(update->flags_), update->out_, update->mentioned_, update->media_unread_, + update->silent_, false, false, false, false, false, false, update->id_, + make_tl_object(from_id), make_tl_object(update->user_id_), + std::move(update->fwd_from_), update->via_bot_id_, std::move(update->reply_to_), update->date_, + update->message_, nullptr, nullptr, std::move(update->entities_), 0, 0, nullptr, 0, string(), 0, nullptr, + Auto(), update->ttl_period_); on_pending_update( make_tl_object(std::move(message), update->pts_, update->pts_count_), 0, std::move(promise), "telegram_api::updateShortMessage"); @@ -1157,19 +1157,10 @@ void UpdatesManager::on_get_updates_impl(tl_object_ptr up } case telegram_api::updateShortChatMessage::ID: { auto update = move_tl_object_as(updates_ptr); - if (update->flags_ & MessagesManager::MESSAGE_FLAG_HAS_REPLY_MARKUP) { - LOG(ERROR) << "Receive updateShortChatMessage with reply_markup"; - update->flags_ ^= MessagesManager::MESSAGE_FLAG_HAS_REPLY_MARKUP; - } - if (update->flags_ & MessagesManager::MESSAGE_FLAG_HAS_MEDIA) { - LOG(ERROR) << "Receive updateShortChatMessage with media"; - update->flags_ ^= MessagesManager::MESSAGE_FLAG_HAS_MEDIA; - } - - update->flags_ |= MessagesManager::MESSAGE_FLAG_HAS_FROM_ID; auto message = make_tl_object( - update->flags_, update->out_, update->mentioned_, update->media_unread_, update->silent_, false, false, false, - false, false, false, update->id_, make_tl_object(update->from_id_), + fix_short_message_flags(update->flags_), update->out_, update->mentioned_, update->media_unread_, + update->silent_, false, false, false, false, false, false, update->id_, + make_tl_object(update->from_id_), make_tl_object(update->chat_id_), std::move(update->fwd_from_), update->via_bot_id_, std::move(update->reply_to_), update->date_, update->message_, nullptr, nullptr, std::move(update->entities_), 0, 0, nullptr, 0, string(), 0, nullptr, Auto(), update->ttl_period_); diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index 1e04723f9..64380681f 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -461,6 +461,8 @@ class UpdatesManager final : public Actor { bool is_acceptable_update(const telegram_api::Update *update) const; + static int32 fix_short_message_flags(int32 flags); + void on_update(tl_object_ptr update, Promise &&promise); void on_update(tl_object_ptr update, Promise &&promise); void on_update(tl_object_ptr update, Promise &&promise);