/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "base/timer.h" #include "base/weak_ptr.h" #include "data/components/sponsored_messages.h" namespace ChatHelpers { class Show; } // namespace ChatHelpers namespace Main { class Session; } // namespace Main namespace Ui { class RpWidget; } // namespace Ui namespace Media::View { class PlaybackSponsored final : public base::has_weak_ptr { public: PlaybackSponsored( not_null controls, std::shared_ptr show, not_null item); ~PlaybackSponsored(); void start(); void setPaused(bool paused); [[nodiscard]] rpl::lifetime &lifetime(); [[nodiscard]] static bool Has(HistoryItem *item); private: class Message; struct State { crl::time now = 0; Data::SponsoredForVideoState data; }; void update(); void finish(); void updatePaused(); void showPremiumPromo(); void setPausedInside(bool paused); void setPausedOutside(bool paused); void show(const Data::SponsoredMessage &data); void hide(crl::time now); [[nodiscard]] State computeState() const; void saveState(); const not_null _parent; const not_null _session; const std::shared_ptr _show; const FullMsgId _itemId; rpl::variable _controlsGeometry; std::unique_ptr _widget; rpl::variable _allowCloseAt; crl::time _start = 0; bool _started = false; bool _paused = false; bool _pausedInside = false; bool _pausedOutside = false; base::Timer _timer; std::optional _data; rpl::lifetime _lifetime; }; } // namespace Media::View