Fix inline GIFs play start in separate windows.

Fixes #25694.
This commit is contained in:
John Preston 2023-01-18 14:57:07 +04:00
parent b3667d69a1
commit 2c75fe033c
9 changed files with 16 additions and 53 deletions

View File

@ -286,10 +286,6 @@ void ResolveDocument(
|| document->isVoiceMessage()
|| document->isVideoMessage()) {
::Media::Player::instance()->playPause({ document, msgId });
} else if (item
&& document->isAnimation()
&& HistoryView::Gif::CanPlayInline(document)) {
document->owner().requestAnimationPlayInline(item);
} else {
showDocument();
}

View File

@ -1695,29 +1695,12 @@ void Session::requestItemTextRefresh(not_null<HistoryItem*> item) {
}
}
void Session::requestAnimationPlayInline(not_null<HistoryItem*> item) {
_animationPlayInlineRequest.fire_copy(item);
if (const auto media = item->media()) {
if (const auto data = media->document()) {
if (data && data->isVideoMessage()) {
const auto msgId = item->fullId();
::Media::Player::instance()->playPause({ data, msgId });
}
}
}
}
void Session::requestUnreadReactionsAnimation(not_null<HistoryItem*> item) {
enumerateItemViews(item, [&](not_null<ViewElement*> view) {
view->animateUnreadReactions();
});
}
rpl::producer<not_null<HistoryItem*>> Session::animationPlayInlineRequest() const {
return _animationPlayInlineRequest.events();
}
rpl::producer<not_null<const HistoryItem*>> Session::itemRemoved() const {
return _itemRemoved.events();
}

View File

@ -275,9 +275,7 @@ public:
void requestItemViewRefresh(not_null<HistoryItem*> item);
[[nodiscard]] rpl::producer<not_null<HistoryItem*>> itemViewRefreshRequest() const;
void requestItemTextRefresh(not_null<HistoryItem*> item);
void requestAnimationPlayInline(not_null<HistoryItem*> item);
void requestUnreadReactionsAnimation(not_null<HistoryItem*> item);
[[nodiscard]] rpl::producer<not_null<HistoryItem*>> animationPlayInlineRequest() const;
void notifyHistoryUnloaded(not_null<const History*> history);
[[nodiscard]] rpl::producer<not_null<const History*>> historyUnloaded() const;
void notifyItemDataChange(not_null<HistoryItem*> item);
@ -861,7 +859,6 @@ private:
rpl::event_stream<not_null<HistoryItem*>> _itemViewRefreshRequest;
rpl::event_stream<not_null<HistoryItem*>> _itemTextRefreshRequest;
rpl::event_stream<not_null<HistoryItem*>> _itemDataChanges;
rpl::event_stream<not_null<HistoryItem*>> _animationPlayInlineRequest;
rpl::event_stream<not_null<const HistoryItem*>> _itemRemoved;
rpl::event_stream<not_null<const ViewElement*>> _viewRemoved;
rpl::event_stream<not_null<const History*>> _historyUnloaded;

View File

@ -294,14 +294,6 @@ InnerWidget::InnerWidget(
view->itemDataChanged();
}
}, lifetime());
session().data().animationPlayInlineRequest(
) | rpl::start_with_next([=](auto item) {
if (const auto view = viewForItem(item)) {
if (const auto media = view->media()) {
media->playAnimation();
}
}
}, lifetime());
session().data().itemVisibilityQueries(
) | rpl::filter([=](
const Data::Session::ItemVisibilityQuery &query) {

View File

@ -553,15 +553,6 @@ HistoryWidget::HistoryWidget(
});
}, lifetime());
session().data().animationPlayInlineRequest(
) | rpl::start_with_next([=](not_null<HistoryItem*> item) {
if (const auto view = item->mainView()) {
if (const auto media = view->media()) {
media->playAnimation();
}
}
}, lifetime());
session().data().webPageUpdates(
) | rpl::filter([=](not_null<WebPageData*> page) {
return (_previewData == page.get());

View File

@ -341,14 +341,6 @@ ListWidget::ListWidget(
view->itemDataChanged();
}
}, lifetime());
session().data().animationPlayInlineRequest(
) | rpl::start_with_next([this](auto item) {
if (const auto view = viewForItem(item)) {
if (const auto media = view->media()) {
media->playAnimation();
}
}
}, lifetime());
session().downloaderTaskFinished(
) | rpl::start_with_next([=] {

View File

@ -117,13 +117,16 @@ void File::checkAnimationFinished() const {
}
void File::setDocumentLinks(
not_null<DocumentData*> document,
not_null<HistoryItem*> realParent) {
not_null<HistoryItem*> realParent,
Fn<bool()> openHook) {
const auto context = realParent->fullId();
setLinks(
std::make_shared<DocumentOpenClickHandler>(
document,
crl::guard(this, [=](FullMsgId id) {
_parent->delegate()->elementOpenDocument(document, id);
if (!openHook || !openHook()) {
_parent->delegate()->elementOpenDocument(document, id);
}
}),
context),
std::make_shared<DocumentSaveClickHandler>(document, context),

View File

@ -52,7 +52,8 @@ protected:
FileClickHandlerPtr &&cancell);
void setDocumentLinks(
not_null<DocumentData*> document,
not_null<HistoryItem*> realParent);
not_null<HistoryItem*> realParent,
Fn<bool()> openHook = nullptr);
// >= 0 will contain download / upload string, _statusSize = loaded bytes
// < 0 will contain played string, _statusSize = -(seconds + 1) played

View File

@ -89,7 +89,15 @@ Gif::Gif(
, _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right())
, _spoiler(spoiler ? std::make_unique<MediaSpoiler>() : nullptr)
, _downloadSize(Ui::FormatSizeText(_data->size)) {
setDocumentLinks(_data, realParent);
setDocumentLinks(_data, realParent, [=] {
if (!_data->createMediaView()->canBePlayed(realParent)
|| !_data->isAnimation()
|| !CanPlayInline(_data)) {
return false;
}
playAnimation(false);
return true;
});
setStatusSize(Ui::FileStatusSizeReady);
if (_spoiler) {