/* 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 Folder; class Histories final { public: enum class RequestType : uchar { None, History, ReadInbox, Delete, Send, }; 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); void requestDialogEntry(not_null folder); void requestDialogEntry( not_null history, Fn callback = nullptr); void dialogEntryApplied(not_null history); void changeDialogUnreadMark(not_null history, bool unread); //void changeDialogUnreadMark(not_null feed, bool unread); // #feed void deleteMessages( not_null history, const QVector &ids, bool revoke); void deleteAllMessages( not_null history, MsgId deleteTillId, bool justClear, bool revoke); int sendRequest( not_null history, RequestType type, Fn finish)> generator); void cancelRequest(not_null history, int id); private: struct PostponedHistoryRequest { Fn finish)> generator; }; struct SentRequest { Fn finish)> generator; 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 postponedRequestEntry = 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); void checkPostponed(not_null history, int id); void finishSentRequest( not_null history, not_null state, int id); [[nodiscard]] bool postponeHistoryRequest(const State &state) const; [[nodiscard]] bool postponeEntryRequest(const State &state) const; void sendDialogRequests(); void applyPeerDialogs(const MTPmessages_PeerDialogs &dialogs); const not_null _owner; std::unordered_map> _map; base::flat_map, State> _states; base::Timer _readRequestsTimer; base::flat_set> _dialogFolderRequests; base::flat_map< not_null, std::vector>> _dialogRequests; base::flat_map< not_null, std::vector>> _dialogRequestsPending; }; } // namespace Data