From 6af09ec529538414a02c83252a080e1d591395e5 Mon Sep 17 00:00:00 2001 From: blank X Date: Sat, 29 Jan 2022 10:45:55 +0000 Subject: [PATCH] Show message when trying to unquoted forward a quiz (#303) Fixes #237 --- Telegram/Resources/langs/rewrites/en.json | 1 + Telegram/SourceFiles/data/data_media_types.cpp | 14 +++++++++----- Telegram/SourceFiles/data/data_media_types.h | 10 +++++----- Telegram/SourceFiles/history/history_message.cpp | 10 ++++++---- Telegram/SourceFiles/history/history_message.h | 6 ++++-- Telegram/SourceFiles/history/history_widget.cpp | 11 +++++++++++ Telegram/SourceFiles/mainwidget.cpp | 3 ++- Telegram/SourceFiles/window/window_peer_menu.cpp | 4 +++- 8 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index c1b89eb40..c22a1c1de 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -259,5 +259,6 @@ "ktg_settings_remember_compress_images": "Remember compress images", "ktg_settings_compress_images_default": "Compress images by default", "ktg_pip_not_supported": "Sorry, Picture-in-Picture mode is not supported here.", + "ktg_forward_quiz_unquoted": "Sorry, quizzes that are currently open and unvoted on cannot be forwarded unquoted.", "dummy_last_string": "" } diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index 7572b1db7..a2bf2f763 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "data/data_media_types.h" +#include "kotato/kotato_lang.h" #include "history/history.h" #include "history/history_item.h" #include "history/history_location_manager.h" @@ -411,7 +412,7 @@ bool Media::forceForwardedInfo() const { return false; } -QString Media::errorTextForForward(not_null peer) const { +QString Media::errorTextForForward(not_null peer, bool unquoted) const { return QString(); } @@ -603,7 +604,7 @@ bool MediaPhoto::allowsEditMedia() const { return true; } -QString MediaPhoto::errorTextForForward(not_null peer) const { +QString MediaPhoto::errorTextForForward(not_null peer, bool unquoted) const { return Data::RestrictionError( peer, ChatRestriction::SendMedia @@ -911,7 +912,7 @@ bool MediaFile::dropForwardedInfo() const { return _document->isSong(); } -QString MediaFile::errorTextForForward(not_null peer) const { +QString MediaFile::errorTextForForward(not_null peer, bool unquoted) const { if (const auto sticker = _document->sticker()) { if (const auto error = Data::RestrictionError( peer, @@ -1425,7 +1426,7 @@ TextForMimeData MediaGame::clipboardText() const { return TextForMimeData(); } -QString MediaGame::errorTextForForward(not_null peer) const { +QString MediaGame::errorTextForForward(not_null peer, bool unquoted) const { return Data::RestrictionError( peer, ChatRestriction::SendGames @@ -1573,10 +1574,13 @@ TextForMimeData MediaPoll::clipboardText() const { return TextForMimeData::Simple(text); } -QString MediaPoll::errorTextForForward(not_null peer) const { +QString MediaPoll::errorTextForForward(not_null peer, bool unquoted) const { if (_poll->publicVotes() && peer->isChannel() && !peer->isMegagroup()) { return tr::lng_restricted_send_public_polls(tr::now); } + if (unquoted && _poll->quiz() && !_poll->voted() && !_poll->closed()) { + return ktr("ktg_forward_quiz_unquoted"); + } return Data::RestrictionError( peer, ChatRestriction::SendPolls diff --git a/Telegram/SourceFiles/data/data_media_types.h b/Telegram/SourceFiles/data/data_media_types.h index 1b7890ff3..aeec47c43 100644 --- a/Telegram/SourceFiles/data/data_media_types.h +++ b/Telegram/SourceFiles/data/data_media_types.h @@ -112,7 +112,7 @@ public: virtual bool forwardedBecomesUnread() const; virtual bool dropForwardedInfo() const; virtual bool forceForwardedInfo() const; - virtual QString errorTextForForward(not_null peer) const; + virtual QString errorTextForForward(not_null peer, bool unquoted = false) const; [[nodiscard]] virtual bool consumeMessageText( const TextWithEntities &text); @@ -167,7 +167,7 @@ public: TextForMimeData clipboardText() const override; bool allowsEditCaption() const override; bool allowsEditMedia() const override; - QString errorTextForForward(not_null peer) const override; + QString errorTextForForward(not_null peer, bool unquoted = false) const override; bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override; @@ -207,7 +207,7 @@ public: bool allowsEditMedia() const override; bool forwardedBecomesUnread() const override; bool dropForwardedInfo() const override; - QString errorTextForForward(not_null peer) const override; + QString errorTextForForward(not_null peer, bool unquoted = false) const override; bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override; @@ -366,7 +366,7 @@ public: QString notificationText() const override; QString pinnedTextSubstring() const override; TextForMimeData clipboardText() const override; - QString errorTextForForward(not_null peer) const override; + QString errorTextForForward(not_null peer, bool unquoted = false) const override; bool dropForwardedInfo() const override; bool consumeMessageText(const TextWithEntities &text) override; @@ -428,7 +428,7 @@ public: QString notificationText() const override; QString pinnedTextSubstring() const override; TextForMimeData clipboardText() const override; - QString errorTextForForward(not_null peer) const override; + QString errorTextForForward(not_null peer, bool unquoted = false) const override; bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 6eb1ce720..e43e2668b 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -127,14 +127,15 @@ QString GetErrorTextForSending( not_null peer, const HistoryItemsList &items, const TextWithTags &comment, - bool ignoreSlowmodeCountdown) { + bool ignoreSlowmodeCountdown, + bool unquoted) { if (!peer->canWrite()) { return tr::lng_forward_cant(tr::now); } for (const auto &item : items) { if (const auto media = item->media()) { - const auto error = media->errorTextForForward(peer); + const auto error = media->errorTextForForward(peer, unquoted); if (!error.isEmpty() && error != qstr("skip")) { return error; } @@ -415,8 +416,9 @@ MTPMessageReplyHeader NewMessageReplyHeader(const Api::SendAction &action) { QString GetErrorTextForSending( not_null peer, const HistoryItemsList &items, - bool ignoreSlowmodeCountdown) { - return GetErrorTextForSending(peer, items, {}, ignoreSlowmodeCountdown); + bool ignoreSlowmodeCountdown, + bool unquoted) { + return GetErrorTextForSending(peer, items, {}, ignoreSlowmodeCountdown, unquoted); } struct HistoryMessage::CreateConfig { diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 37a79dddc..4194eb23b 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -43,12 +43,14 @@ void RequestDependentMessageData( [[nodiscard]] QString GetErrorTextForSending( not_null peer, const HistoryItemsList &items, - bool ignoreSlowmodeCountdown = false); + bool ignoreSlowmodeCountdown = false, + bool unquoted = false); [[nodiscard]] QString GetErrorTextForSending( not_null peer, const HistoryItemsList &items, const TextWithTags &comment, - bool ignoreSlowmodeCountdown = false); + bool ignoreSlowmodeCountdown = false, + bool unquoted = false); void FastShareMessage(not_null item); class HistoryMessage final : public HistoryItem { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 7d5543ac1..5548a780d 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -5915,6 +5915,17 @@ void HistoryWidget::contextMenuEvent(QContextMenuEvent *e) { int settingsKey) { if (_history && _toForward.options != newOptions) { _menu->addAction(ktr(langKey), [=] { + const auto error = GetErrorTextForSending( + _history->peer, + _toForward.items, + true, + newOptions != Options::PreserveInfo); + if (!error.isEmpty()) { + Ui::ShowMultilineToast({ + .text = error + }); + return; + } _toForward.options = newOptions; _history->setForwardDraft({ .ids = session().data().itemsToIds(_toForward.items), diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index b9a44ddce..e33a30ab9 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -489,7 +489,8 @@ bool MainWidget::setForwardDraft(PeerId peerId, Data::ForwardDraft &&draft) { const auto error = GetErrorTextForSending( peer, session().data().idsToItems(draft.ids), - true); + true, + draft.options != Data::ForwardOptions::PreserveInfo); if (!error.isEmpty()) { Ui::show(Box(error), Ui::LayerOption::KeepOther); return false; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 4072903e3..f03bbcca1 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -1249,7 +1249,9 @@ QPointer ShowForwardMessagesBox( const auto error = GetErrorTextForSending( peer, items, - comment); + comment, + false, /* ignoreSlowmodeCountdown */ + newDraft.options != Data::ForwardOptions::PreserveInfo); if (!error.isEmpty()) { return std::make_pair(error, peer); }