From 96c910190b5a737678f2f1610f877b82389860ab Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 5 Nov 2021 21:49:23 +0400 Subject: [PATCH] Restrict saving files as if noforwards. --- .../history/history_inner_widget.cpp | 16 +++++++++------ .../view/history_view_context_menu.cpp | 8 ++++++-- .../info/media/info_media_list_widget.cpp | 20 ++++++++++--------- .../media/view/media_view_overlay_widget.cpp | 8 ++++++-- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 447c41429..ed3725bc0 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1776,9 +1776,11 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { showContextInFolder(document); }); } - _menu->addAction(lnkIsVideo ? tr::lng_context_save_video(tr::now) : (lnkIsVoice ? tr::lng_context_save_audio(tr::now) : (lnkIsAudio ? tr::lng_context_save_audio_file(tr::now) : tr::lng_context_save_file(tr::now))), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { - saveDocumentToFile(itemId, document); - })); + if (_peer->allowsForwarding()) { + _menu->addAction(lnkIsVideo ? tr::lng_context_save_video(tr::now) : (lnkIsVoice ? tr::lng_context_save_audio(tr::now) : (lnkIsAudio ? tr::lng_context_save_audio_file(tr::now) : tr::lng_context_save_file(tr::now))), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { + saveDocumentToFile(itemId, document); + })); + } if (document->hasAttachedStickers()) { _menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] { session->api().attachedStickers().requestAttachedStickerSets( @@ -1932,9 +1934,11 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { Api::ToggleFavedSticker(document, itemId); }); } - _menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { - saveDocumentToFile(itemId, document); - })); + if (_peer->allowsForwarding()) { + _menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { + saveDocumentToFile(itemId, document); + })); + } } } if (const auto media = item->media()) { diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index ce8b19d4c..9bc30dd53 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -188,7 +188,11 @@ void ShowInFolder(not_null document) { void AddSaveDocumentAction( not_null menu, Data::FileOrigin origin, - not_null document) { + not_null document, + not_null list) { + if (list->hasCopyRestriction()) { + return; + } const auto save = [=] { DocumentSaveClickHandler::Save( origin, @@ -272,7 +276,7 @@ void AddDocumentActions( tr::lng_context_attached_stickers(tr::now), std::move(callback)); } - AddSaveDocumentAction(menu, contextId, document); + AddSaveDocumentAction(menu, contextId, document, list); } void AddPostLinkAction( diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 0a72d810d..5584b182f 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -1595,15 +1595,17 @@ void ListWidget::showContextMenu( document, DocumentSaveClickHandler::Mode::ToNewFile); }); - _contextMenu->addAction( - (isVideo - ? tr::lng_context_save_video(tr::now) - : isVoice - ? tr::lng_context_save_audio(tr::now) - : isAudio - ? tr::lng_context_save_audio_file(tr::now) - : tr::lng_context_save_file(tr::now)), - std::move(handler)); + if (_peer->allowsForwarding()) { + _contextMenu->addAction( + (isVideo + ? tr::lng_context_save_video(tr::now) + : isVoice + ? tr::lng_context_save_audio(tr::now) + : isAudio + ? tr::lng_context_save_audio_file(tr::now) + : tr::lng_context_save_file(tr::now)), + std::move(handler)); + } } } } diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 8b1763fc8..6d4e8df8f 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -727,7 +727,9 @@ void OverlayWidget::refreshNavVisibility() { } bool OverlayWidget::contentCanBeSaved() const { - if (_photo) { + if (hasCopyRestriction()) { + return false; + } else if (_photo) { return _photo->hasVideo() || _photoMedia->loaded(); } else if (_document) { return _document->filepath(true).isEmpty() && !_document->loading(); @@ -943,7 +945,9 @@ void OverlayWidget::fillContextMenuActions(const MenuCallback &addAction) { if (canDelete) { addAction(tr::lng_mediaview_delete(tr::now), [=] { deleteMedia(); }); } - addAction(tr::lng_mediaview_save_as(tr::now), [=] { saveAs(); }); + if (!hasCopyRestriction()) { + addAction(tr::lng_mediaview_save_as(tr::now), [=] { saveAs(); }); + } if (const auto overviewType = computeOverviewType()) { const auto text = _document