Restrict saving files as if noforwards.

This commit is contained in:
John Preston 2021-11-05 21:49:23 +04:00
parent fd6751233e
commit 96c910190b
4 changed files with 33 additions and 19 deletions

View file

@ -1776,9 +1776,11 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
showContextInFolder(document); showContextInFolder(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, [=] { _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); saveDocumentToFile(itemId, document);
})); }));
}
if (document->hasAttachedStickers()) { if (document->hasAttachedStickers()) {
_menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] { _menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] {
session->api().attachedStickers().requestAttachedStickerSets( session->api().attachedStickers().requestAttachedStickerSets(
@ -1932,11 +1934,13 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
Api::ToggleFavedSticker(document, itemId); Api::ToggleFavedSticker(document, itemId);
}); });
} }
if (_peer->allowsForwarding()) {
_menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { _menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] {
saveDocumentToFile(itemId, document); saveDocumentToFile(itemId, document);
})); }));
} }
} }
}
if (const auto media = item->media()) { if (const auto media = item->media()) {
if (const auto poll = media->poll()) { if (const auto poll = media->poll()) {
HistoryView::AddPollActions( HistoryView::AddPollActions(

View file

@ -188,7 +188,11 @@ void ShowInFolder(not_null<DocumentData*> document) {
void AddSaveDocumentAction( void AddSaveDocumentAction(
not_null<Ui::PopupMenu*> menu, not_null<Ui::PopupMenu*> menu,
Data::FileOrigin origin, Data::FileOrigin origin,
not_null<DocumentData*> document) { not_null<DocumentData*> document,
not_null<ListWidget*> list) {
if (list->hasCopyRestriction()) {
return;
}
const auto save = [=] { const auto save = [=] {
DocumentSaveClickHandler::Save( DocumentSaveClickHandler::Save(
origin, origin,
@ -272,7 +276,7 @@ void AddDocumentActions(
tr::lng_context_attached_stickers(tr::now), tr::lng_context_attached_stickers(tr::now),
std::move(callback)); std::move(callback));
} }
AddSaveDocumentAction(menu, contextId, document); AddSaveDocumentAction(menu, contextId, document, list);
} }
void AddPostLinkAction( void AddPostLinkAction(

View file

@ -1595,6 +1595,7 @@ void ListWidget::showContextMenu(
document, document,
DocumentSaveClickHandler::Mode::ToNewFile); DocumentSaveClickHandler::Mode::ToNewFile);
}); });
if (_peer->allowsForwarding()) {
_contextMenu->addAction( _contextMenu->addAction(
(isVideo (isVideo
? tr::lng_context_save_video(tr::now) ? tr::lng_context_save_video(tr::now)
@ -1607,6 +1608,7 @@ void ListWidget::showContextMenu(
} }
} }
} }
}
} else if (link) { } else if (link) {
const auto actionText = link->copyToClipboardContextItemText(); const auto actionText = link->copyToClipboardContextItemText();
if (!actionText.isEmpty()) { if (!actionText.isEmpty()) {

View file

@ -727,7 +727,9 @@ void OverlayWidget::refreshNavVisibility() {
} }
bool OverlayWidget::contentCanBeSaved() const { bool OverlayWidget::contentCanBeSaved() const {
if (_photo) { if (hasCopyRestriction()) {
return false;
} else if (_photo) {
return _photo->hasVideo() || _photoMedia->loaded(); return _photo->hasVideo() || _photoMedia->loaded();
} else if (_document) { } else if (_document) {
return _document->filepath(true).isEmpty() && !_document->loading(); return _document->filepath(true).isEmpty() && !_document->loading();
@ -943,7 +945,9 @@ void OverlayWidget::fillContextMenuActions(const MenuCallback &addAction) {
if (canDelete) { if (canDelete) {
addAction(tr::lng_mediaview_delete(tr::now), [=] { deleteMedia(); }); addAction(tr::lng_mediaview_delete(tr::now), [=] { deleteMedia(); });
} }
if (!hasCopyRestriction()) {
addAction(tr::lng_mediaview_save_as(tr::now), [=] { saveAs(); }); addAction(tr::lng_mediaview_save_as(tr::now), [=] { saveAs(); });
}
if (const auto overviewType = computeOverviewType()) { if (const auto overviewType = computeOverviewType()) {
const auto text = _document const auto text = _document