From c849d17667dd18d858d183d4fbbb25cc6c8f8301 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 5 Nov 2021 22:32:26 +0400 Subject: [PATCH] Remove corner download if noforwards. --- Telegram/SourceFiles/data/data_document.cpp | 6 ++-- Telegram/SourceFiles/data/data_document.h | 2 +- .../SourceFiles/data/data_document_media.cpp | 4 +-- .../SourceFiles/data/data_document_media.h | 2 +- .../data/data_document_resolver.cpp | 2 +- .../SourceFiles/data/data_shared_media.cpp | 2 +- .../history/history_inner_widget.cpp | 28 +++++++++++-------- .../view/history_view_context_menu.cpp | 2 +- .../view/media/history_view_document.cpp | 11 ++++---- .../history/view/media/history_view_gif.cpp | 15 +++++----- .../inline_bots/inline_bot_layout_item.cpp | 2 +- .../media/view/media_view_overlay_widget.cpp | 10 +++---- .../SourceFiles/overview/overview_layout.cpp | 23 +++++++-------- 13 files changed, 59 insertions(+), 50 deletions(-) diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index e3983403d4..c7849e800c 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -1158,12 +1158,14 @@ bool DocumentData::useStreamingLoader() const { || isVoiceMessage(); } -bool DocumentData::canBeStreamed() const { +bool DocumentData::canBeStreamed(HistoryItem *item) const { // Streaming couldn't be used with external player // Maybe someone brave will implement this once upon a time... return hasRemoteLocation() && supportsStreaming() - && (!cUseExternalVideoPlayer() || !isVideoFile()); + && (!isVideoFile() + || !cUseExternalVideoPlayer() + || (item && !item->history()->peer->allowsForwarding())); } void DocumentData::setInappPlaybackFailed() { diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index f2eeb688fa..1b8c3da61e 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -233,7 +233,7 @@ public: [[nodiscard]] Storage::Cache::Key cacheKey() const; [[nodiscard]] uint8 cacheTag() const; - [[nodiscard]] bool canBeStreamed() const; + [[nodiscard]] bool canBeStreamed(HistoryItem *item) const; [[nodiscard]] auto createStreamingLoader( Data::FileOrigin origin, bool forceRemoteLoader) const diff --git a/Telegram/SourceFiles/data/data_document_media.cpp b/Telegram/SourceFiles/data/data_document_media.cpp index 8e5c63fec2..47481cdbb1 100644 --- a/Telegram/SourceFiles/data/data_document_media.cpp +++ b/Telegram/SourceFiles/data/data_document_media.cpp @@ -348,10 +348,10 @@ float64 DocumentMedia::progress() const { : (loaded() ? 1. : 0.); } -bool DocumentMedia::canBePlayed() const { +bool DocumentMedia::canBePlayed(HistoryItem *item) const { return !_owner->inappPlaybackFailed() && _owner->useStreamingLoader() - && (loaded() || _owner->canBeStreamed()); + && (loaded() || _owner->canBeStreamed(item)); } bool DocumentMedia::thumbnailEnoughForSticker() const { diff --git a/Telegram/SourceFiles/data/data_document_media.h b/Telegram/SourceFiles/data/data_document_media.h index 9329023c98..5a2fea7c71 100644 --- a/Telegram/SourceFiles/data/data_document_media.h +++ b/Telegram/SourceFiles/data/data_document_media.h @@ -74,7 +74,7 @@ public: [[nodiscard]] QByteArray bytes() const; [[nodiscard]] bool loaded(bool check = false) const; [[nodiscard]] float64 progress() const; - [[nodiscard]] bool canBePlayed() const; + [[nodiscard]] bool canBePlayed(HistoryItem *item) const; void automaticLoad(Data::FileOrigin origin, const HistoryItem *item); diff --git a/Telegram/SourceFiles/data/data_document_resolver.cpp b/Telegram/SourceFiles/data/data_document_resolver.cpp index 7c23357347..8a8e9cab17 100644 --- a/Telegram/SourceFiles/data/data_document_resolver.cpp +++ b/Telegram/SourceFiles/data/data_document_resolver.cpp @@ -252,7 +252,7 @@ void ResolveDocument( if (document->isTheme() && media->loaded(true)) { showDocument(); location.accessDisable(); - } else if (media->canBePlayed()) { + } else if (media->canBePlayed(item)) { if (document->isAudioFile() || document->isVoiceMessage() || document->isVideoMessage()) { diff --git a/Telegram/SourceFiles/data/data_shared_media.cpp b/Telegram/SourceFiles/data/data_shared_media.cpp index e6afc073ff..6f584ecbbe 100644 --- a/Telegram/SourceFiles/data/data_shared_media.cpp +++ b/Telegram/SourceFiles/data/data_shared_media.cpp @@ -74,7 +74,7 @@ bool IsItemGoodForType(const not_null item, Type type) { || ((videoType || photoVideoType) && videoDoc) || (fileType && (document->isTheme() || document->isImage() - || !document->canBeStreamed())); + || !document->canBeStreamed(item))); } } // namespace diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index ed3725bc00..f61bd23743 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1302,7 +1302,7 @@ std::unique_ptr HistoryInner::prepareDrag() { const auto pressedHandler = ClickHandler::getPressed(); if (dynamic_cast(pressedHandler.get()) - || !_peer->allowsForwarding()) { + || hasCopyRestriction()) { return nullptr; } @@ -1546,7 +1546,7 @@ void HistoryInner::mouseActionFinish( if (QGuiApplication::clipboard()->supportsSelection() && !_selected.empty() && _selected.cbegin()->second != FullSelection - && _peer->allowsForwarding()) { + && !hasCopyRestriction()) { const auto [item, selection] = *_selected.cbegin(); if (const auto view = item->mainView()) { TextUtilities::SetClipboardText( @@ -1725,7 +1725,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { }; const auto addPhotoActions = [&](not_null photo) { const auto media = photo->activeMediaView(); - if (!photo->isNull() && media && media->loaded() && _peer->allowsForwarding()) { + if (!photo->isNull() && media && media->loaded() && !hasCopyRestriction()) { _menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { savePhotoToFile(photo); })); @@ -1767,16 +1767,18 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { openContextGif(itemId); }); } - _menu->addAction(tr::lng_context_save_gif(tr::now), [=] { - saveContextGif(itemId); - }); + if (!hasCopyRestriction()) { + _menu->addAction(tr::lng_context_save_gif(tr::now), [=] { + saveContextGif(itemId); + }); + } } if (!document->filepath(true).isEmpty()) { _menu->addAction(Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), [=] { showContextInFolder(document); }); } - if (_peer->allowsForwarding()) { + if (!hasCopyRestriction()) { _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); })); @@ -1830,7 +1832,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { if (lnkPhoto || lnkDocument) { const auto item = _dragStateItem; const auto itemId = item ? item->fullId() : FullMsgId(); - if (isUponSelected > 0 && _peer->allowsForwarding()) { + if (isUponSelected > 0 && !hasCopyRestriction()) { _menu->addAction( (isUponSelected > 1 ? tr::lng_context_copy_selected_items(tr::now) @@ -1911,7 +1913,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { const auto view = item ? item->mainView() : nullptr; if (isUponSelected > 0) { - if (_peer->allowsForwarding()) { + if (!hasCopyRestriction()) { _menu->addAction( ((isUponSelected > 1) ? tr::lng_context_copy_selected_items(tr::now) @@ -1934,7 +1936,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { Api::ToggleFavedSticker(document, itemId); }); } - if (_peer->allowsForwarding()) { + if (!hasCopyRestriction()) { _menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { saveDocumentToFile(itemId, document); })); @@ -1963,7 +1965,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { if (!item->isService() && view && !link - && _peer->allowsForwarding() + && !hasCopyRestriction() && (view->hasVisibleText() || mediaHasTextForCopy)) { _menu->addAction(tr::lng_context_copy_text(tr::now), [=] { copyContextText(itemId); @@ -2135,7 +2137,9 @@ void HistoryInner::openContextGif(FullMsgId itemId) { } void HistoryInner::saveContextGif(FullMsgId itemId) { - if (const auto item = session().data().message(itemId)) { + if (hasCopyRestriction()) { + return; + } else if (const auto item = session().data().message(itemId)) { if (const auto media = item->media()) { if (const auto document = media->document()) { Api::ToggleSavedGif(document, item->fullId(), true); diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 9bc30dd531..e39bfa6d3b 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -241,7 +241,7 @@ void AddDocumentActions( OpenGif(list->controller(), contextId); }); } - if (document->isGifv()) { + if (document->isGifv() && !list->hasCopyRestriction()) { menu->addAction(tr::lng_context_save_gif(tr::now), [=] { SaveGif(list->controller(), contextId); }); diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index 502e7b4872..5ef488dbba 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -329,7 +329,7 @@ void Document::draw( const auto cornerDownload = downloadInCorner(); - if (!_dataMedia->canBePlayed()) { + if (!_dataMedia->canBePlayed(_realParent)) { _dataMedia->automaticLoad(_realParent->fullId(), _realParent); } bool loaded = dataLoaded(), displayLoading = _data->displayLoading(); @@ -452,8 +452,8 @@ void Document::draw( return _data->isSongWithCover() ? sti->historyFileThumbPause : stm->historyFilePause; - } else if (loaded || _dataMedia->canBePlayed()) { - return _dataMedia->canBePlayed() + } else if (loaded || _dataMedia->canBePlayed(_realParent)) { + return _dataMedia->canBePlayed(_realParent) ? (_data->isSongWithCover() ? sti->historyFileThumbPlay : stm->historyFilePlay) @@ -593,7 +593,8 @@ void Document::ensureDataMediaCreated() const { bool Document::downloadInCorner() const { return _data->isAudioFile() - && _data->canBeStreamed() + && _realParent->history()->peer->allowsForwarding() + && _data->canBeStreamed(_realParent) && !_data->inappPlaybackFailed() && _realParent->isRegular(); } @@ -782,7 +783,7 @@ TextState Document::textState( && (!_data->loading() || downloadInCorner()) && !_data->uploading() && !_data->isNull()) { - if (loaded || _dataMedia->canBePlayed()) { + if (loaded || _dataMedia->canBePlayed(_realParent)) { result.link = _openl; } else { result.link = _savel; diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 75772a124e..6b5d07b9a5 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -264,7 +264,8 @@ QSize Gif::videoSize() const { bool Gif::downloadInCorner() const { return _data->isVideoFile() && (_data->loading() || !autoplayEnabled()) - && _data->canBeStreamed() + && _realParent->history()->peer->allowsForwarding() + && _data->canBeStreamed(_realParent) && !_data->inappPlaybackFailed() && !_parent->data()->isSending(); } @@ -288,7 +289,7 @@ void Gif::draw(Painter &p, const PaintContext &context) const { const auto stm = context.messageStyle(); const auto autoPaused = _parent->delegate()->elementIsGifPaused(); const auto cornerDownload = downloadInCorner(); - const auto canBePlayed = _dataMedia->canBePlayed(); + const auto canBePlayed = _dataMedia->canBePlayed(_realParent); const auto autoplay = autoplayEnabled() && canBePlayed && CanPlayInline(_data); @@ -836,7 +837,7 @@ TextState Gif::textState(QPoint point, StateRequest request) const { ? _cancell : _realParent->isSending() ? nullptr - : (dataLoaded() || _dataMedia->canBePlayed()) + : (dataLoaded() || _dataMedia->canBePlayed(_realParent)) ? _openl : _data->loading() ? _cancell @@ -917,7 +918,7 @@ void Gif::drawGrouped( const auto autoPaused = _parent->delegate()->elementIsGifPaused(); const auto fullFeatured = fullFeaturedGrouped(sides); const auto cornerDownload = fullFeatured && downloadInCorner(); - const auto canBePlayed = _dataMedia->canBePlayed(); + const auto canBePlayed = _dataMedia->canBePlayed(_realParent); const auto autoplay = fullFeatured && autoplayEnabled() && canBePlayed @@ -1109,7 +1110,7 @@ TextState Gif::getStateGrouped( ? _cancell : _realParent->isSending() ? nullptr - : (dataLoaded() || _dataMedia->canBePlayed()) + : (dataLoaded() || _dataMedia->canBePlayed(_realParent)) ? _openl : _data->loading() ? _cancell @@ -1258,7 +1259,7 @@ void Gif::updateStatusText() const { statusSize = _data->uploadingData->offset; } else if (!downloadInCorner() && _data->loading()) { statusSize = _data->loadOffset(); - } else if (dataLoaded() || _dataMedia->canBePlayed()) { + } else if (dataLoaded() || _dataMedia->canBePlayed(_realParent)) { statusSize = Ui::FileStatusSizeLoaded; } else { statusSize = Ui::FileStatusSizeReady; @@ -1386,7 +1387,7 @@ void Gif::playAnimation(bool autoplay) { } if (_streamed) { stopAnimation(); - } else if (_dataMedia->canBePlayed()) { + } else if (_dataMedia->canBePlayed(_realParent)) { if (!autoplayEnabled()) { history()->owner().checkPlayingAnimations(); } diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp index 811d93d392..4b764bc257 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp @@ -190,7 +190,7 @@ ClickHandlerPtr ItemBase::getResultPreviewHandler() const { _result->_content_url, false); } else if (const auto document = _result->_document - ; document && document->createMediaView()->canBePlayed()) { + ; document && document->createMediaView()->canBePlayed(nullptr)) { return std::make_shared(); } else if (_result->_photo) { return std::make_shared(); diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 6d4e8df8f7..b6e36b2688 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -1212,7 +1212,7 @@ bool OverlayWidget::radialAnimationCallback(crl::time now) { update(radialRect()); } const auto ready = _document && _documentMedia->loaded(); - const auto streamVideo = ready && _documentMedia->canBePlayed(); + const auto streamVideo = ready && _documentMedia->canBePlayed(_message); const auto tryOpenImage = ready && (_document->size < Images::kReadBytesLimit); if (ready && ((tryOpenImage && !_radial.animating()) || streamVideo)) { @@ -1693,7 +1693,7 @@ void OverlayWidget::downloadMedia() { void OverlayWidget::saveCancel() { if (_document && _document->loading()) { _document->cancel(); - if (_documentMedia->canBePlayed()) { + if (_documentMedia->canBePlayed(_message)) { redisplayContent(); } } @@ -2429,7 +2429,7 @@ void OverlayWidget::displayDocument( ).toImage()); } } else { - if (_documentMedia->canBePlayed() + if (_documentMedia->canBePlayed(_message) && initStreaming(continueStreaming)) { } else if (_document->isVideoFile()) { _documentMedia->automaticLoad(fileOrigin(), _message); @@ -2577,7 +2577,7 @@ void OverlayWidget::displayFinished() { } bool OverlayWidget::canInitStreaming() const { - return (_document && _documentMedia->canBePlayed()) + return (_document && _documentMedia->canBePlayed(_message)) || (_photo && _photo->videoCanBePlayed()); } @@ -4106,7 +4106,7 @@ void OverlayWidget::preloadData(int delta) { const auto [i, ok] = documents.emplace( (*document)->createMediaView()); (*i)->thumbnailWanted(fileOrigin(entity)); - if (!(*i)->canBePlayed()) { + if (!(*i)->canBePlayed(entity.item)) { (*i)->automaticLoad(fileOrigin(entity), entity.item); } } diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 06e1ac4995..e20eff9369 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -484,7 +484,7 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const if (!selected && !context->selecting && radialOpacity < 1.) { if (clip.intersects(QRect(0, _height - st::normalFont->height, _width, st::normalFont->height))) { - const auto download = !loaded && !_dataMedia->canBePlayed(); + const auto download = !loaded && !_dataMedia->canBePlayed(parent()); const auto &icon = download ? (selected ? st::overviewVideoDownloadSelected : st::overviewVideoDownload) : (selected ? st::overviewVideoPlaySelected : st::overviewVideoPlay); @@ -510,7 +510,7 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const if (selected) { p.setBrush(st::msgDateImgBgSelected); } else { - auto over = ClickHandler::showAsActive((_data->loading() || _data->uploading()) ? _cancell : (loaded || _dataMedia->canBePlayed()) ? _openl : _savel); + auto over = ClickHandler::showAsActive((_data->loading() || _data->uploading()) ? _cancell : (loaded || _dataMedia->canBePlayed(parent())) ? _openl : _savel); p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, _a_iconOver.value(over ? 1. : 0.))); } @@ -576,7 +576,7 @@ TextState Video::getState( ensureDataMediaCreated(); const auto link = (_data->loading() || _data->uploading()) ? _cancell - : (dataLoaded() || _dataMedia->canBePlayed()) + : (dataLoaded() || _dataMedia->canBePlayed(parent())) ? _openl : _savel; return { parent(), link }; @@ -704,7 +704,7 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const } const auto &checkLink = (_data->loading() || _data->uploading()) ? _cancell - : (_dataMedia->canBePlayed() || loaded) + : (_dataMedia->canBePlayed(parent()) || loaded) ? _openl : _savel; if (selected) { @@ -732,7 +732,7 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const return &(selected ? _st.voiceCancelSelected : _st.voiceCancel); } else if (showPause) { return &(selected ? _st.voicePauseSelected : _st.voicePause); - } else if (_dataMedia->canBePlayed()) { + } else if (_dataMedia->canBePlayed(parent())) { return &(selected ? _st.voicePlaySelected : _st.voicePlay); } return &(selected @@ -802,7 +802,7 @@ TextState Voice::getState( if (inner.contains(point)) { const auto link = (_data->loading() || _data->uploading()) ? _cancell - : (_dataMedia->canBePlayed() || loaded) + : (_dataMedia->canBePlayed(parent()) || loaded) ? _openl : _savel; return { parent(), link }; @@ -969,7 +969,8 @@ Document::Document( bool Document::downloadInCorner() const { return _data->isAudioFile() - && _data->canBeStreamed() + && parent()->history()->peer->allowsForwarding() + && _data->canBeStreamed(parent()) && !_data->inappPlaybackFailed() && parent()->isRegular(); } @@ -1033,7 +1034,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con } else { const auto over = ClickHandler::showAsActive(isLoading ? _cancell - : (loaded || _dataMedia->canBePlayed()) + : (loaded || _dataMedia->canBePlayed(parent())) ? _openl : _savel); p.setBrush(anim::brush( @@ -1055,7 +1056,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con return &(selected ? _st.voicePauseSelected : _st.voicePause); - } else if (loaded || _dataMedia->canBePlayed()) { + } else if (loaded || _dataMedia->canBePlayed(parent())) { return &(selected ? _st.voicePlaySelected : _st.voicePlay); @@ -1068,7 +1069,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con return &(selected ? _st.songCancelSelected : _st.songCancel); } else if (showPause) { return &(selected ? _st.songPauseSelected : _st.songPause); - } else if (loaded || _dataMedia->canBePlayed()) { + } else if (loaded || _dataMedia->canBePlayed(parent())) { return &(selected ? _st.songPlaySelected : _st.songPlay); } return &(selected ? _st.songDownloadSelected : _st.songDownload); @@ -1280,7 +1281,7 @@ TextState Document::getState( const auto link = (!downloadInCorner() && (_data->loading() || _data->uploading())) ? _cancell - : (loaded || _dataMedia->canBePlayed()) + : (loaded || _dataMedia->canBePlayed(parent())) ? _openl : _savel; return { parent(), link };