From fd9bcb2489863615d600f8d81bac49d59609c8df Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 9 Jul 2026 18:46:27 +0400 Subject: [PATCH] Fix location sends replying to ephemeral messages --- Telegram/SourceFiles/api/api_sending.cpp | 22 ++++++++++++++++ .../data/components/ephemeral_messages.cpp | 25 +++++++++++++++++++ .../data/components/ephemeral_messages.h | 4 +++ .../inline_bots/bot_attach_web_view.cpp | 6 ++++- 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/api/api_sending.cpp b/Telegram/SourceFiles/api/api_sending.cpp index 14f4fccc1e..b052758950 100644 --- a/Telegram/SourceFiles/api/api_sending.cpp +++ b/Telegram/SourceFiles/api/api_sending.cpp @@ -76,6 +76,28 @@ void SendSimpleMedia(SendAction action, MTPInputMedia inputMedia) { action.generateLocal = false; api->sendAction(action); + if (!action.options.scheduled + && !action.options.shortcutId + && session->ephemeralMessages().sendSimpleMedia( + history, + action.replyTo, + inputMedia)) { + api->finishForwarding(action); + return; + } + + if (action.replyTo.messageId + && !IsServerMsgId(action.replyTo.messageId.msg) + && !session->data().message(action.replyTo.messageId)) { + action.replyTo = { + .messageId = (action.replyTo.topicRootId + ? FullMsgId(peer->id, action.replyTo.topicRootId) + : FullMsgId()), + .topicRootId = action.replyTo.topicRootId, + .monoforumPeerId = action.replyTo.monoforumPeerId, + }; + } + const auto randomId = base::RandomValue(); auto flags = NewMessageFlags(peer); diff --git a/Telegram/SourceFiles/data/components/ephemeral_messages.cpp b/Telegram/SourceFiles/data/components/ephemeral_messages.cpp index ca25935b4d..284d954009 100644 --- a/Telegram/SourceFiles/data/components/ephemeral_messages.cpp +++ b/Telegram/SourceFiles/data/components/ephemeral_messages.cpp @@ -472,6 +472,31 @@ bool EphemeralMessages::sendMedia( return true; } +bool EphemeralMessages::sendSimpleMedia( + not_null history, + FullReplyTo replyTo, + const MTPInputMedia &media) { + const auto target = _session->data().message(replyTo.messageId); + if (!target || !target->isEphemeral()) { + return false; + } + if (!target->out()) { + const auto entry = findByItem(target); + const auto bot = entry ? botForSending(*entry) : nullptr; + if (bot) { + request( + history, + bot, + TextWithEntities(), + media, + true, + entry->ephemeralId, + MsgId(0)); + } + } + return true; +} + void EphemeralMessages::request( not_null history, not_null bot, diff --git a/Telegram/SourceFiles/data/components/ephemeral_messages.h b/Telegram/SourceFiles/data/components/ephemeral_messages.h index 5a03e7fe62..5bd2dc70f5 100644 --- a/Telegram/SourceFiles/data/components/ephemeral_messages.h +++ b/Telegram/SourceFiles/data/components/ephemeral_messages.h @@ -54,6 +54,10 @@ public: [[nodiscard]] bool sendMedia( not_null item, const MTPInputMedia &media); + [[nodiscard]] bool sendSimpleMedia( + not_null history, + FullReplyTo replyTo, + const MTPInputMedia &media); void noteCallbackTopic( not_null history, PeerId botId, diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index 9303b3445f..110bc2e045 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/local_url_handlers.h" #include "core/shortcuts.h" #include "core/ui_integration.h" // TextContext +#include "data/components/ephemeral_messages.h" #include "data/components/location_pickers.h" #include "data/data_bot_app.h" #include "data/data_changes.h" @@ -2870,7 +2871,10 @@ void ChooseAndSendLocation( }; const auto state = std::make_shared(); state->send = [=](Data::InputVenue venue, Api::SendAction action) { - if (const auto strong = weak.get()) { + const auto strong = weak.get(); + const auto ephemeralReply = session->ephemeralMessages() + .isEphemeralBotReply(action.replyTo.messageId); + if (strong && !ephemeralReply) { const auto withPaymentApproved = [=](int stars) { if (const auto onstack = state->send) { auto copy = action;