/* 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" class HistoryItem; class DocumentData; namespace Data { class DocumentMedia; } // namespace Data namespace Main { class Session; } // namespace Main namespace HistoryView { class Element; } // namespace HistoryView namespace ChatHelpers { struct EmojiInteractionPlayRequest { not_null item; std::shared_ptr media; crl::time shouldHaveStartedAt = 0; }; class EmojiInteractions final { public: explicit EmojiInteractions(not_null session); ~EmojiInteractions(); using PlayRequest = EmojiInteractionPlayRequest; void start(not_null view); [[nodiscard]] rpl::producer playRequests() const { return _playRequests.events(); } private: struct Animation { EmojiPtr emoji; not_null document; std::shared_ptr media; crl::time scheduledAt = 0; crl::time startedAt = 0; int index = 0; }; struct CheckResult { crl::time nextCheckAt = 0; bool waitingForDownload = false; }; [[nodiscard]] static CheckResult Combine(CheckResult a, CheckResult b); void check(crl::time now = 0); [[nodiscard]] CheckResult checkAnimations(crl::time now); [[nodiscard]] CheckResult checkAccumulated(crl::time now); void sendAccumulated( crl::time now, not_null item, std::vector &animations); void setWaitingForDownload(bool waiting); const not_null _session; base::flat_map< not_null, std::vector> _animations; base::Timer _checkTimer; rpl::event_stream _playRequests; bool _waitingForDownload = false; rpl::lifetime _downloadCheckLifetime; rpl::lifetime _lifetime; }; } // namespace ChatHelpers