diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 89ca9eed8f..80441d8d05 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -4189,6 +4189,17 @@ void ApiWrap::sendFiles( SendMediaType type, std::shared_ptr album, SendAction action) { + auto &ephemeral = _session->ephemeralMessages(); + if (album && !ephemeral.isEphemeralBotReply(action.replyTo.messageId)) { + const auto peer = action.history->peer; + for (const auto &file : list.files) { + if (ephemeral.hasEphemeralCommand(peer, file.caption.text)) { + LOG(("API Error: " + "Dropped album send with ephemeral command caption.")); + return; + } + } + } const auto to = FileLoadTaskOptions(action); if (album) { album->options = to.options; diff --git a/Telegram/SourceFiles/data/components/ephemeral_messages.cpp b/Telegram/SourceFiles/data/components/ephemeral_messages.cpp index 284d954009..f13c11b26a 100644 --- a/Telegram/SourceFiles/data/components/ephemeral_messages.cpp +++ b/Telegram/SourceFiles/data/components/ephemeral_messages.cpp @@ -333,6 +333,15 @@ bool EphemeralMessages::wouldSend(const Api::MessageToSend &message) const { != nullptr; } +bool EphemeralMessages::hasEphemeralCommand( + not_null peer, + const QString &text) const { + if (!peer->isChat() && !peer->isMegagroup()) { + return false; + } + return findCommandBot(peer, text.trimmed()) != nullptr; +} + bool EphemeralMessages::isEphemeralBotReply(FullMsgId replyToId) const { const auto target = _session->data().message(replyToId); return target && target->isEphemeral() && !target->out(); @@ -448,8 +457,30 @@ void EphemeralMessages::send( bool EphemeralMessages::sendMedia( not_null item, const MTPInputMedia &media) { - const auto target = _session->data().message(item->replyTo().messageId); + const auto history = item->history(); + const auto replyTo = item->replyTo(); + const auto target = _session->data().message(replyTo.messageId); if (!target || !target->isEphemeral()) { + const auto topicRoot = replyTo.topicRootId; + const auto realReply = replyTo.messageId + && !(topicRoot && replyTo.messageId.msg == topicRoot); + if (!realReply) { + const auto bot = findCommandBot( + history->peer, + item->originalText().text.trimmed()); + if (bot) { + request( + history, + bot, + item->originalText(), + media, + true, + 0, + item->topicRootId(), + item->fullId()); + return true; + } + } return false; } if (!target->out()) { diff --git a/Telegram/SourceFiles/data/components/ephemeral_messages.h b/Telegram/SourceFiles/data/components/ephemeral_messages.h index 5bd2dc70f5..b52e06da41 100644 --- a/Telegram/SourceFiles/data/components/ephemeral_messages.h +++ b/Telegram/SourceFiles/data/components/ephemeral_messages.h @@ -43,6 +43,9 @@ public: not_null item) const; [[nodiscard]] bool wouldSend(const Api::MessageToSend &message) const; + [[nodiscard]] bool hasEphemeralCommand( + not_null peer, + const QString &text) const; [[nodiscard]] bool isEphemeralBotReply(FullMsgId replyToId) const; [[nodiscard]] bool trySend(const Api::MessageToSend &message); void send(