/* 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 History; class HistoryItem; namespace Main { class Session; } // namespace Main namespace Data { class Session; class Histories final { public: explicit Histories(not_null owner); [[nodiscard]] Session &owner() const; [[nodiscard]] Main::Session &session() const; [[nodiscard]] History *find(PeerId peerId); [[nodiscard]] not_null findOrCreate(PeerId peerId); void unloadAll(); void clearAll(); void readInbox(not_null history); void readInboxTill(not_null item); void readInboxTill(not_null history, MsgId tillId); void readInboxOnNewMessage(not_null item); void readClientSideMessage(not_null item); void sendPendingReadInbox(not_null history); private: enum class RequestType : uchar { None, DialogsEntry, History, ReadInbox, Delete, }; enum class Action : uchar { Send, Postpone, Skip, }; struct PostponedRequest { Fn done)> generator; RequestType type = RequestType::None; }; struct SentRequest { mtpRequestId id = 0; RequestType type = RequestType::None; }; struct State { base::flat_map postponed; base::flat_map sent; crl::time readWhen = 0; MsgId readTill = 0; int autoincrement = 0; bool thenRequestEntry = false; }; void readInboxTill(not_null history, MsgId tillId, bool force); void sendReadRequests(); void sendReadRequest(not_null history, State &state); [[nodiscard]] State *lookup(not_null history); void checkEmptyState(not_null history); int sendRequest( not_null history, RequestType type, Fn done)> generator); void checkPostponed(not_null history, int requestId); [[nodiscard]] Action chooseAction( State &state, RequestType type, bool fromPostponed = false) const; const not_null _owner; std::unordered_map> _map; base::flat_map, State> _states; base::Timer _readRequestsTimer; }; } // namespace Data