mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-08-14 07:23:46 +00:00
Added ephemeral send of media with command captions.
This commit is contained in:
@@ -4189,6 +4189,17 @@ void ApiWrap::sendFiles(
|
||||
SendMediaType type,
|
||||
std::shared_ptr<SendingAlbum> 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;
|
||||
|
||||
@@ -333,6 +333,15 @@ bool EphemeralMessages::wouldSend(const Api::MessageToSend &message) const {
|
||||
!= nullptr;
|
||||
}
|
||||
|
||||
bool EphemeralMessages::hasEphemeralCommand(
|
||||
not_null<PeerData*> 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<HistoryItem*> 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()) {
|
||||
|
||||
@@ -43,6 +43,9 @@ public:
|
||||
not_null<const HistoryItem*> item) const;
|
||||
|
||||
[[nodiscard]] bool wouldSend(const Api::MessageToSend &message) const;
|
||||
[[nodiscard]] bool hasEphemeralCommand(
|
||||
not_null<PeerData*> peer,
|
||||
const QString &text) const;
|
||||
[[nodiscard]] bool isEphemeralBotReply(FullMsgId replyToId) const;
|
||||
[[nodiscard]] bool trySend(const Api::MessageToSend &message);
|
||||
void send(
|
||||
|
||||
Reference in New Issue
Block a user