From 348cf4829ce6cd53def1879c81bf1b656fa722b8 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 1 Jul 2021 03:00:00 +0300 Subject: [PATCH] Added ability to scroll media in section of scheduled messages. Fixed #8388. --- .../SourceFiles/data/data_shared_media.cpp | 52 ++++++++++++++----- Telegram/SourceFiles/data/data_shared_media.h | 7 ++- .../media/view/media_view_overlay_widget.cpp | 31 +++++++---- 3 files changed, 65 insertions(+), 25 deletions(-) diff --git a/Telegram/SourceFiles/data/data_shared_media.cpp b/Telegram/SourceFiles/data/data_shared_media.cpp index d27224a2a..75b6299c0 100644 --- a/Telegram/SourceFiles/data/data_shared_media.cpp +++ b/Telegram/SourceFiles/data/data_shared_media.cpp @@ -34,12 +34,13 @@ using Type = Storage::SharedMediaType; bool IsItemGoodForType(const not_null item, Type type) { const auto media = item->media(); - if (!media) { + if (!media || media->webpage()) { return false; } const auto photo = media->photo(); const auto photoType = (type == Type::Photo); - if (photoType && photo) { + const auto photoVideoType = (type == Type::PhotoVideo); + if ((photoType || photoVideoType) && photo) { return true; } @@ -47,10 +48,11 @@ bool IsItemGoodForType(const not_null item, Type type) { if (!document) { return false; } - const auto voiceType = (type == Type::VoiceFile) - || (type == Type::RoundVoiceFile); - const auto voiceDoc = (document->isVoiceMessage() - || document->isVideoMessage()); + const auto voiceType = (type == Type::VoiceFile); + const auto voiceDoc = document->isVoiceMessage(); + + const auto roundType = (type == Type::RoundFile); + const auto roundDoc = document->isVideoMessage(); const auto audioType = (type == Type::MusicFile); const auto audioDoc = document->isAudioFile(); @@ -61,11 +63,18 @@ bool IsItemGoodForType(const not_null item, Type type) { const auto videoType = (type == Type::Video); const auto videoDoc = document->isVideoFile(); + const auto voiceRoundType = (type == Type::RoundVoiceFile); + const auto fileType = (type == Type::File); + return (audioType && audioDoc) || (voiceType && voiceDoc) + || (roundType && roundDoc) + || (voiceRoundType && (roundDoc || voiceDoc)) || (gifType && gifDoc) - || (videoType && videoDoc) - || (photoType && document->isImage()); + || ((videoType || photoVideoType) && videoDoc) + || (fileType && (document->isTheme() + || document->isImage() + || !document->canBeStreamed())); } } // namespace @@ -461,12 +470,29 @@ rpl::producer SharedMediaWithLastViewer( int limitBefore, int limitAfter) { return [=](auto consumer) { + auto viewerKey = SharedMediaMergedKey( + SharedMediaWithLastSlice::ViewerKey(key), + key.type); + if (std::get_if>(&key.universalId)) { return SharedMediaMergedViewer( session, - SharedMediaMergedKey( - SharedMediaWithLastSlice::ViewerKey(key), - key.type), + std::move(viewerKey), + limitBefore, + limitAfter + ) | rpl::start_with_next([=](SparseIdsMergedSlice &&update) { + consumer.put_next(SharedMediaWithLastSlice( + session, + key, + std::move(update), + std::nullopt)); + }); + } + + if (key.scheduled) { + return SharedScheduledMediaViewer( + session, + std::move(viewerKey), limitBefore, limitAfter ) | rpl::start_with_next([=](SparseIdsMergedSlice &&update) { @@ -480,9 +506,7 @@ rpl::producer SharedMediaWithLastViewer( return rpl::combine( SharedMediaMergedViewer( session, - SharedMediaMergedKey( - SharedMediaWithLastSlice::ViewerKey(key), - key.type), + std::move(viewerKey), limitBefore, limitAfter), SharedMediaMergedViewer( diff --git a/Telegram/SourceFiles/data/data_shared_media.h b/Telegram/SourceFiles/data/data_shared_media.h index 673186152..393aab5ff 100644 --- a/Telegram/SourceFiles/data/data_shared_media.h +++ b/Telegram/SourceFiles/data/data_shared_media.h @@ -77,11 +77,13 @@ public: PeerId peerId, PeerId migratedPeerId, Type type, - UniversalMsgId universalId) + UniversalMsgId universalId, + bool scheduled = false) : peerId(peerId) , migratedPeerId(migratedPeerId) , type(type) - , universalId(universalId) { + , universalId(universalId) + , scheduled(scheduled) { Expects(v::is(universalId) || type == Type::ChatPhoto); } @@ -99,6 +101,7 @@ public: PeerId migratedPeerId = 0; Type type = Type::kCount; UniversalMsgId universalId; + bool scheduled = false; }; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index b4b92a4be..1bc6f4df4 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -1822,19 +1822,31 @@ auto OverlayWidget::sharedMediaKey() const -> std::optional { _photo }; } - if (!IsServerMsgId(_msgid.msg)) { - return std::nullopt; - } - auto keyForType = [this](SharedMediaType type) -> SharedMediaKey { + const auto isServerMsgId = IsServerMsgId(_msgid.msg); + const auto isScheduled = [&] { + if (isServerMsgId) { + return false; + } + if (const auto item = _session->data().message(_msgid)) { + return item->isScheduled(); + } + return false; + }(); + const auto keyForType = [&](SharedMediaType type) -> SharedMediaKey { return { _history->peer->id, _migrated ? _migrated->peer->id : 0, type, - (_msgid.channel == _history->channelId()) ? _msgid.msg : (_msgid.msg - ServerMaxMsgId) }; + (_msgid.channel == _history->channelId()) + ? _msgid.msg + : (_msgid.msg - ServerMaxMsgId), + isScheduled + }; }; - return - sharedMediaType() - | keyForType; + if (!isServerMsgId && !isScheduled) { + return std::nullopt; + } + return sharedMediaType() | keyForType; } Data::FileOrigin OverlayWidget::fileOrigin() const { @@ -1872,7 +1884,8 @@ bool OverlayWidget::validSharedMedia() const { auto inSameDomain = [](const Key &a, const Key &b) { return (a.type == b.type) && (a.peerId == b.peerId) - && (a.migratedPeerId == b.migratedPeerId); + && (a.migratedPeerId == b.migratedPeerId) + && (a.scheduled == b.scheduled); }; auto countDistanceInData = [&](const Key &a, const Key &b) { return [&](const SharedMediaWithLastSlice &data) {