/* 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 "history/history_item.h" #include "base/timer.h" class History; namespace Main { class Session; } // namespace Main namespace Data { class Session; struct SponsoredMessage final { QByteArray randomId; PeerId fromId; TextWithEntities textWithEntities; History *history = nullptr; MsgId msgId; }; class SponsoredMessages final { public: using RandomId = QByteArray; explicit SponsoredMessages(not_null owner); SponsoredMessages(const SponsoredMessages &other) = delete; SponsoredMessages &operator=(const SponsoredMessages &other) = delete; ~SponsoredMessages(); [[nodiscard]] bool canHaveFor(not_null history) const; void request(not_null history); [[nodiscard]] bool append(not_null history); void clearItems(not_null history); [[nodiscard]] MsgId channelPost(const FullMsgId &fullId) const; void view(const FullMsgId &fullId); private: using OwnedItem = std::unique_ptr; struct Entry { OwnedItem item; SponsoredMessage sponsored; }; struct List { std::vector entries; bool showedAll = false; }; struct Request { mtpRequestId requestId = 0; crl::time lastReceived = 0; }; void parse( not_null history, const MTPmessages_sponsoredMessages &list); void append( not_null history, List &list, const MTPSponsoredMessage &message); void clearOldRequests(); const Entry *find(const FullMsgId &fullId) const; const not_null _session; base::Timer _clearTimer; base::flat_map, List> _data; base::flat_map, Request> _requests; base::flat_map _viewRequests; rpl::lifetime _lifetime; }; } // namespace Data