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);
});
}
_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()) {

View file

@ -188,7 +188,11 @@ void ShowInFolder(not_null<DocumentData*> document) {
void AddSaveDocumentAction(
not_null<Ui::PopupMenu*> menu,
Data::FileOrigin origin,
not_null<DocumentData*> document) {
not_null<DocumentData*> document,
not_null<ListWidget*> 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(

View file

@ -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));
}
}
}
}

View file

@ -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