diff --git a/Telegram/SourceFiles/calls/group/calls_group_viewport.cpp b/Telegram/SourceFiles/calls/group/calls_group_viewport.cpp index 0cff14bf9..c2df3f711 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_viewport.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_viewport.cpp @@ -525,16 +525,30 @@ Viewport::Layout Viewport::countWide(int outerWidth, int outerHeight) const { } void Viewport::showLarge(const VideoEndpoint &endpoint) { - const auto i = ranges::find(_tiles, endpoint, &VideoTile::endpoint); - const auto large = (i != end(_tiles)) ? i->get() : nullptr; - if (_large != large) { - prepareLargeChangeAnimation(); - _large = large; - updateTopControlsVisibility(); - startLargeChangeAnimation(); - } + // If a video get's switched off, GroupCall first unpins it, + // then removes it from Large endpoint, then removes from active tracks. + // + // If we want to animate large video removal properly, we need to + // delay this update and start animation directly from removing of the + // track from the active list. Otherwise final state won't be correct. + _updateLargeScheduled = [=] { + const auto i = ranges::find(_tiles, endpoint, &VideoTile::endpoint); + const auto large = (i != end(_tiles)) ? i->get() : nullptr; + if (_large != large) { + prepareLargeChangeAnimation(); + _large = large; + updateTopControlsVisibility(); + startLargeChangeAnimation(); + } - Ensures(!_large || !_large->trackOrUserpicSize().isEmpty()); + Ensures(!_large || !_large->trackOrUserpicSize().isEmpty()); + }; + crl::on_main(widget(), [=] { + if (!_updateLargeScheduled) { + return; + } + base::take(_updateLargeScheduled)(); + }); } void Viewport::updateTilesGeometry() { diff --git a/Telegram/SourceFiles/calls/group/calls_group_viewport.h b/Telegram/SourceFiles/calls/group/calls_group_viewport.h index d0c1f9048..3d15bf1be 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_viewport.h +++ b/Telegram/SourceFiles/calls/group/calls_group_viewport.h @@ -176,6 +176,7 @@ private: rpl::event_stream _qualityRequests; float64 _controlsShownRatio = 1.; VideoTile *_large = nullptr; + Fn _updateLargeScheduled; Ui::Animations::Simple _largeChangeAnimation; Layout _startTilesLayout; Layout _finishTilesLayout;